Class: VimMate::VimWindow

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

Constructor Details

#initializeVimWindow

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_vimObject

Set the focus to Vim



86
87
88
89
# File 'lib/vimmatelib/vim_window.rb', line 86

def focus_vim
  @gtk_socket.can_focus = true
  @gtk_socket.has_focus = true
end

#gtk_windowObject

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
# 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>'`
  self
end

#startObject

Start Vim’s window. This must be called after the window which will contain Vim is visible.



76
77
78
79
80
81
82
83
# File 'lib/vimmatelib/vim_window.rb', line 76

def start
  return if @vim_started
  @vim_started = true
  fork do
    `gvim --socketid #{@gtk_socket.id} --servername #{@vim_server_name}`
  end
  self
end