Module: VER::Methods::CTags

Defined in:
lib/ver/methods/ctags.rb

Overview

TODO: add project directory and Dir.pwd to lookup path, maybe share code

with the project directory lookup

Class Method Summary collapse

Class Method Details

.content(text) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/ver/methods/ctags.rb', line 67

def content(text)
  dir = text.filename.dirname
  file = nil

  loop do
    file = dir/'tags'
    break if file.file? || dir.root?
    dir = dir.parent
  end

  return unless file.file?

  file.open 'rb' do |io|
    io.each_line do |line|
      head, tail = line.split(/;"\t/, 2)
      yield(*head.split("\t"))
    end
  end
end

.execute(text, file_name, ex_cmd) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ver/methods/ctags.rb', line 47

def execute(text, file_name, ex_cmd)
  case ex_cmd
  when /^\d+$/
    VER.ctag_stack << Bookmarks::Bookmark.new(nil, *Bookmark.value(text))

    VER.find_or_create_buffer(file_name, ex_cmd.to_i)
  when /^\/(.*)\/$/
    VER.ctag_stack << Bookmarks::Bookmark.new(nil, *Bookmark.value(text))

    source = $1.gsub(/(?!\\)([()])/, '\\\\\\1')
    regexp = Regexp.new(source)

    VER.find_or_create_buffer(file_name) do |buffer|
      Search.jump(buffer.text, regexp)
    end
  else
    raise ArgumentError, "Unknown Ex command: %p" % [ex_cmd]
  end
end

.find(text, needle) ⇒ Object



40
41
42
43
44
45
# File 'lib/ver/methods/ctags.rb', line 40

def find(text, needle)
  content text do |tag_name, file_name, ex_cmd|
    next unless tag_name == needle
    return execute(text, file_name, ex_cmd)
  end
end

.find_current(text) ⇒ Object



8
9
10
11
# File 'lib/ver/methods/ctags.rb', line 8

def find_current(text)
  word = text.get('insert wordstart', 'insert wordend')
  find(text, word)
end

.go(text, name = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ver/methods/ctags.rb', line 23

def go(text, name = nil)
  if name
    content text do |tag_name, file_name, ex_cmd|
      next unless tag_name == name
      return execute(text, file_name, ex_cmd)
    end
  else
    text.ask 'Tag name: ' do |answer, action|
      case action
      when :attempt
        go(text, answer)
        :abort
      end
    end
  end
end

.prev(text, count = text.prefix_count) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ver/methods/ctags.rb', line 13

def prev(text, count = text.prefix_count)
  bm = VER.ctag_stack.pop(count).first

  if bm
    Bookmark.open(text, bm)
  else
    message("Tag stack empty.")
  end
end