Class: VimMate::VimWindow
- Inherits:
-
Object
- Object
- VimMate::VimWindow
- Defined in:
- lib/vimmatelib/vim_window.rb
Overview
A window that can display and send information to the GTK GUI of Vim (gVim)
Instance Method Summary collapse
-
#focus_vim ⇒ Object
Set the focus to Vim.
-
#gtk_window ⇒ Object
The “window” for this object.
-
#initialize ⇒ VimWindow
constructor
Create the VimWindow.
-
#open(path, kind = :open) ⇒ Object
Open the specified file in Vim.
-
#start ⇒ Object
Start Vim’s window.
Constructor Details
#initialize ⇒ VimWindow
Create the VimWindow. You must call start after this window is visible
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vimmatelib/vim_window.rb', line 34 def initialize # A unique Vim server name @vim_server_name = "VimMate_#{Process.pid}" @gtk_socket = Gtk::Socket.new @gtk_socket.show_all @gtk_socket.signal_connect("delete_event") do false end @gtk_socket.signal_connect("destroy") do Gtk.main_quit end @gtk_socket.can_focus = true @gtk_socket.has_focus = true @vim_started = false end |
Instance Method Details
#focus_vim ⇒ Object
Set the focus to Vim
87 88 89 90 |
# File 'lib/vimmatelib/vim_window.rb', line 87 def focus_vim @gtk_socket.can_focus = true @gtk_socket.has_focus = true end |
#gtk_window ⇒ Object
The “window” for this object
51 52 53 |
# File 'lib/vimmatelib/vim_window.rb', line 51 def gtk_window @gtk_socket end |
#open(path, kind = :open) ⇒ Object
Open the specified file in Vim
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/vimmatelib/vim_window.rb', line 56 def open(path, kind = :open) start path = path.gsub "'", "\\'" case kind when :open, :split_open if kind == :split_open `gvim --servername #{@vim_server_name} --remote-send '<ESC><ESC><ESC>:split<CR>'` end `gvim --servername #{@vim_server_name} --remote '#{path}'` when :tab_open `gvim --servername #{@vim_server_name} --remote-tab '#{path}'` else raise "Unknow open kind: #{kind}" end `gvim --servername #{@vim_server_name} --remote-send '<ESC><ESC><ESC>:buffer #{path}<CR>'` focus_vim self end |
#start ⇒ Object
Start Vim’s window. This must be called after the window which will contain Vim is visible.
77 78 79 80 81 82 83 84 |
# File 'lib/vimmatelib/vim_window.rb', line 77 def start return if @vim_started @vim_started = true fork do `gvim --socketid #{@gtk_socket.id} --servername #{@vim_server_name}` end self end |