Class: WatchTower::Editor::Vim

Inherits:
Object
  • Object
show all
Includes:
BasePs
Defined in:
lib/watch_tower/editor/vim.rb

Constant Summary collapse

VIM_EXTENSION_PATH =
File.join(EDITOR_EXTENSIONS_PATH, 'watchtower.vim')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BasePs

included

Constructor Details

#initializeVim

Returns a new instance of Vim.



15
16
17
18
19
20
# File 'lib/watch_tower/editor/vim.rb', line 15

def initialize
  # Get the list of supported vims
  supported_vims
  # Fetch the version
  @version ||= fetch_version
end

Instance Attribute Details

#versionObject (readonly)

Set the attributes read/write of this class.



13
14
15
# File 'lib/watch_tower/editor/vim.rb', line 13

def version
  @version
end

Instance Method Details

#current_pathsArray

Return the open documents of all vim servers

Returns:

  • (Array)

    Absolute paths to all open documents



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/watch_tower/editor/vim.rb', line 39

def current_paths
  if is_running?
    # Init documents
    documents = []
    servers.each do |server|
      stdin, stdout, stderr, wait_thr = Open3.popen3 "#{editor} --servername #{server} --remote-expr 'watchtower#ls()'"

      if stderr.read =~ /Invalid expression received: Send expression failed/i
        # Close the pipes
        [stdin, stdout, stderr].each { |p| p.try(:close) }
        # Send the extenstion to the ViM server
        send_extensions_to_editor
        # Ask ViM for the documents again
        stdin, stdout, stderr, wait_thr = Open3.popen3 "#{editor} --servername #{server} --remote-expr 'watchtower#ls()'"
      end

      documents += stdout.read.split("\n")

      # Close the pipes
      [stdin, stdout, stderr].each { |p| p.try(:close) }
    end

    documents.uniq
  end
end

#is_running?Boolean

Is it running ?

Returns:

  • (Boolean)

    Is ViM running ?



32
33
34
# File 'lib/watch_tower/editor/vim.rb', line 32

def is_running?
  servers && servers.any?
end

#nameString

Return the name of the Editor

Returns:

  • (String)

    The editor’s name



25
26
27
# File 'lib/watch_tower/editor/vim.rb', line 25

def name
  "ViM"
end