Class: VimMate::VimWidget
- Includes:
- Vim::Integration
- Defined in:
- lib/vim_mate/vim_widget.rb
Overview
A window that can display and send information to the GTK GUI of Vim (gVim)
Constant Summary
Constants included from Vim::Integration
Constants included from Vim::Netbeans
Instance Attribute Summary
Attributes included from Vim::Netbeans
Instance Method Summary collapse
-
#focus! ⇒ Object
Set the focus to Vim.
- #get_all_buffer_paths ⇒ Object
- #get_current_buffer_number ⇒ Object
- #get_current_buffer_path ⇒ Object
-
#initialize ⇒ VimWidget
constructor
Create the VimWindow.
- #jump_to_line(line) ⇒ Object
-
#open(path, kind = :open) ⇒ Object
Open the specified file in Vim.
- #open_and_jump_to_line(path, lnum) ⇒ Object
-
#source_vimmate_extras ⇒ Object
generate multiline functions that will be sourced on startup.
-
#start ⇒ Object
Start Vim’s window.
-
#window ⇒ Object
The “window” for this object.
Methods included from Vim::Netbeans
#interpret_message, #new_seqno, #remember_reply, #replies, #send_command, #send_function, #send_message, #server, #vim
Methods included from Vim::Buffers
#buffers, #last_buffer, #new_buffer
Constructor Details
#initialize ⇒ VimWidget
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 49 |
# File 'lib/vim_mate/vim_widget.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 @extras_sourced = false end |
Instance Method Details
#focus! ⇒ Object
Set the focus to Vim
119 120 121 122 |
# File 'lib/vim_mate/vim_widget.rb', line 119 def focus! @gtk_socket.can_focus = true @gtk_socket.has_focus = true end |
#get_all_buffer_paths ⇒ Object
144 145 146 |
# File 'lib/vim_mate/vim_widget.rb', line 144 def get_all_buffer_paths buffers[1..-1] end |
#get_current_buffer_number ⇒ Object
140 141 142 |
# File 'lib/vim_mate/vim_widget.rb', line 140 def get_current_buffer_number send_function('getCursor') end |
#get_current_buffer_path ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/vim_mate/vim_widget.rb', line 124 def get_current_buffer_path if @vim_started #`gvim --servername #{@vim_server_name} --remote-send ':redir! > outputfile<cr>'` #`gvim --servername #{@vim_server_name} --remote-send ':echo getcwd()<cr>'` #`gvim --servername #{@vim_server_name} --remote-send ':echo bufname(bufnr(""))<cr>'` #`gvim --servername #{@vim_server_name} --remote-send ':redir END<cr>'` get_current_buffer_number cwd = exec_gvim "--remote-expr 'getcwd()'".chomp+'/' if cwd return cwd + exec_gvim(%Q~--remote-expr 'bufname(bufnr(""))'~) end end end |
#jump_to_line(line) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/vim_mate/vim_widget.rb', line 96 def jump_to_line(line) start if line >= 0 # TODO use neatbeans remote_send "<ESC><ESC><ESC>:#{line}<CR>" end end |
#open(path, kind = :open) ⇒ Object
Open the specified file in Vim
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/vim_mate/vim_widget.rb', line 67 def open(path, kind = :open) start path = path.gsub "'", "\\'" case kind when :split remote_send '<ESC><ESC><ESC>:split<CR>' when :open, :split exec_gvim "--remote '#{path}'" when :tab exec_gvim "--remote-tab '#{path}'" else raise "Unknow open kind: #{kind}" end remote_send "<ESC><ESC><ESC>:buffer #{path}<CR>" focus! #Signal.emit_file_opened(path) self end |
#open_and_jump_to_line(path, lnum) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/vim_mate/vim_widget.rb', line 86 def open_and_jump_to_line(path,lnum) unless buffer = buffers.index(path) open path, Config[:files_default_open_in_tabs] ? :tab_open : :open sleep 0.5 end send_command buffer, 'setDot', [lnum,0] focus! self end |
#source_vimmate_extras ⇒ Object
generate multiline functions that will be sourced on startup
57 58 59 60 61 62 63 64 |
# File 'lib/vim_mate/vim_widget.rb', line 57 def source_vimmate_extras return if @extras_sourced if @vim_started source_path = File.join( File.dirname(__FILE__), '..', 'vim', 'source.vim') remote_send "<ESC><ESC><ESC>:source #{source_path}<CR>" @extras_sourced = true end end |
#start ⇒ Object
Start Vim’s window. This must be called after the window which will contain Vim is visible.
106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/vim_mate/vim_widget.rb', line 106 def start return if @vim_started @vim_started = true listen fork do exec_gvim "--socketid #{@gtk_socket.id} -nb:localhost:#{port}:#{Password}" end sleep 0.5 source_vimmate_extras self end |
#window ⇒ Object
The “window” for this object
52 53 54 |
# File 'lib/vim_mate/vim_widget.rb', line 52 def window @gtk_socket end |