Class: Ack

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/ack.rb

Constant Summary collapse

@@cur =

Current object of class

nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAck

Returns a new instance of Ack.



135
136
137
138
# File 'lib/vimamsa/ack.rb', line 135

def initialize()
  @buf = nil
  @line_to_id = {}
end

Instance Attribute Details

#bufObject (readonly)

Returns the value of attribute buf.



125
126
127
# File 'lib/vimamsa/ack.rb', line 125

def buf
  @buf
end

Class Method Details

.curObject



128
129
130
# File 'lib/vimamsa/ack.rb', line 128

def self.cur()
  return @@cur
end

.initObject



132
133
# File 'lib/vimamsa/ack.rb', line 132

def self.init()
end

Instance Method Details

#ack_buffer(_instr, b = nil) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/vimamsa/ack.rb', line 140

def ack_buffer(_instr, b = nil)
  if _instr.nil? or _instr.strip.size <= 1
    message("No input for ack")
    return
  end
  instr = Shellwords.escape(_instr)
  bufstr = ""
  for path in vma.get_content_search_paths
    bufstr += run_cmd("ack -Q --type-add=gd=.gd -ki --nohtml --nojs --nojson #{instr} #{path}")
  end

  b = ""
  list = []
  for x in bufstr.lines
    if x.match(/(.*?):(\d+):(.+)/) # non greedy: *?
      fn = $1
      lineno = $2
      matchpart = $3
      pp [fn, lineno, matchpart]
      b << "[#{fn},#{lineno},#{matchpart}]\n"
      list << { fpath: fn, lineno: lineno, matchpart: matchpart }
    end
  end

  gb = group_by_folder(list)
  s = ""
  @line_to_nfo = {}
  i = 0
  for x in gb
    if x[:type] == :file
      s << "╰─#{x[:bname]}:#{x[:nfo][:lineno]}:#{x[:nfo][:matchpart]}\n"
      @line_to_nfo[i] = x
    end
    if x[:type] == :dir
      s << "📂#{x[:path]}:\n"
    end
    i += 1
  end

  if s.size > 5
    @buf = create_new_buffer(s, "ack")
    @buf.module = self
    @buf.line_action_handler = self.method("select_line")
    Gui.highlight_match(@buf, _instr, color: cnf.match.highlight.color!)
  else
    message("No results for input:#{instr}")
  end
end

#select_line(lineno) ⇒ Object



189
190
191
192
193
# File 'lib/vimamsa/ack.rb', line 189

def select_line(lineno)
  debug "def select_line #{lineno}", 2
  nfo = @line_to_nfo[lineno][:nfo]
  jump_to_file(nfo[:fpath], nfo[:lineno].to_i)
end