Class: VimMate::VimWidget

Inherits:
Object
  • Object
show all
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

Vim::Integration::Executable, Vim::Integration::Password

Constants included from Vim::Netbeans

Vim::Netbeans::SERVER_MUTEX

Instance Attribute Summary

Attributes included from Vim::Netbeans

#port, #seqno

Instance Method Summary collapse

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

#initializeVimWidget

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/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
end

Instance Method Details

#extras_source_pathObject



55
56
57
# File 'lib/vim_mate/vim_widget.rb', line 55

def extras_source_path
  File.join( File.dirname(__FILE__), '..', 'vim', 'source.vim')
end

#focus!Object

Set the focus to Vim



114
115
116
117
# File 'lib/vim_mate/vim_widget.rb', line 114

def focus!
  @gtk_socket.can_focus = true
  @gtk_socket.has_focus = true
end

#get_all_buffer_pathsObject



139
140
141
# File 'lib/vim_mate/vim_widget.rb', line 139

def get_all_buffer_paths
  buffers[1..-1]
end

#get_current_buffer_numberObject



135
136
137
# File 'lib/vim_mate/vim_widget.rb', line 135

def get_current_buffer_number
  send_function('getCursor')
end

#get_current_buffer_pathObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/vim_mate/vim_widget.rb', line 119

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



90
91
92
93
94
95
96
# File 'lib/vim_mate/vim_widget.rb', line 90

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/vim_mate/vim_widget.rb', line 60

def open(path, kind = :open)
  start
  path = path.gsub "'", "\\'"
  case kind
  when :split
    remote_send '<ESC><ESC><ESC>:split<CR>'
    exec_gvim "--remote '#{path}'"
  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



80
81
82
83
84
85
86
87
88
# File 'lib/vim_mate/vim_widget.rb', line 80

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

#startObject

Start Vim’s window. This must be called after the window which will contain Vim is visible. FIXME disabled netbeans, crashes to often



101
102
103
104
105
106
107
108
109
110
111
# File 'lib/vim_mate/vim_widget.rb', line 101

def start
  return if @vim_started
  return unless @gtk_socket
  @vim_started = true
  listen
  fork do
    #exec %Q[#{Executable} --servername #{@vim_server_name} --socketid #{@gtk_socket.id} -nb:localhost:#{port}:#{Password} -S #{extras_source_path}]
    exec %Q[#{Executable} --servername #{@vim_server_name} --socketid #{@gtk_socket.id} -S #{extras_source_path}]
  end
  self
end

#windowObject

The “window” for this object



51
52
53
# File 'lib/vim_mate/vim_widget.rb', line 51

def window
  @gtk_socket
end