Module: Rvim::Tags
- Defined in:
- lib/rvim/tags.rb
Defined Under Namespace
Classes: Entry
Class Method Summary collapse
- .all ⇒ Object
- .find(name) ⇒ Object
- .load(paths) ⇒ Object
- .loaded_paths ⇒ Object
-
.locate(excmd, lines) ⇒ Object
Given an excmd string and a buffer, return [line_index, byte_pointer] or nil if the command can’t be resolved.
- .reset! ⇒ Object
Class Method Details
.all ⇒ Object
40 41 42 |
# File 'lib/rvim/tags.rb', line 40 def all @tags ||= [] end |
.find(name) ⇒ Object
36 37 38 |
# File 'lib/rvim/tags.rb', line 36 def find(name) all.select { |t| t.name == name } end |
.load(paths) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rvim/tags.rb', line 8 def load(paths) @tags = [] @loaded_paths = [] Array(paths).each do |path| next unless File.exist?(path) @loaded_paths << path base_dir = File.dirname(File.(path)) File.foreach(path) do |raw| next if raw.start_with?('!') line = raw.chomp parts = line.split("\t", 3) next if parts.size < 3 name, file, rest = parts excmd = if (idx = rest.index(%(;"))) rest[0...idx] else rest end full_file = File.(file, base_dir) @tags << Entry.new(name: name, file: full_file, excmd: excmd) end end @tags end |
.loaded_paths ⇒ Object
44 45 46 |
# File 'lib/rvim/tags.rb', line 44 def loaded_paths @loaded_paths ||= [] end |
.locate(excmd, lines) ⇒ Object
Given an excmd string and a buffer, return [line_index, byte_pointer] or nil if the command can’t be resolved.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rvim/tags.rb', line 55 def locate(excmd, lines) return nil if excmd.nil? || lines.nil? s = excmd.to_s.strip if s.match?(/\A\d+\z/) return [s.to_i - 1, 0] end m = /\A\/(.*)\/\z/.match(s) || /\A\?(.*)\?\z/.match(s) return nil unless m pattern = m[1] pattern = pattern.sub(/\A\^/, '').sub(/\$\z/, '') pattern = pattern.gsub(/\\([\/^$])/) { Regexp.last_match(1) } lines.each_with_index do |line, i| return [i, 0] if line.to_s.include?(pattern) end nil end |
.reset! ⇒ Object
48 49 50 51 |
# File 'lib/rvim/tags.rb', line 48 def reset! @tags = [] @loaded_paths = [] end |