Class: FileContentSearch

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

Overview

Interface for ack! beyondgrep.com/

Class Method Summary collapse

Class Method Details

.search_buffer(instr, b = nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vimamsa/ack.rb', line 19

def self.search_buffer(instr, b = nil)
  # instr = Shellwords.escape(instr)
  fext = Set[".txt"]
  dlist = []
  for d in vma.get_content_search_paths
    # Search for files with extension .txt and size < 200k
    dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and fext.include?(File.extname(e)) and File.size(e) < 200e3 }
  end
  bufstr = "Results:\n\n"
  for fp in dlist
    txt = read_file("",fp)
    ind = scan_indexes(txt, /#{instr}/i)
    if !ind.empty?
      for x in ind
        starti = x - 30
        endi = x + 30
        starti = 0 if starti < 0
        endi = txt.size - 1 if endi >= txt.size
        bufstr << "#{fp}:c#{x} "
        bufstr << txt[starti..endi].gsub("\n"," ")
        bufstr << "\n"
      end
    end
  end
  create_new_file(nil, bufstr)
end

.start_guiObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/vimamsa/ack.rb', line 4

def self.start_gui()
  search_paths = vma.get_content_search_paths.join("<br/>")

nfo = "<span size='x-large'>Search contents of text files</span>
Will search all .txt files in the following directories:
#{search_paths}

<span>Hint: add empty file named .vma_project to directories you want to search in. 
 If .vma_project exists in parent directory of current file, searches within that directory.
</span>"

  callback = proc { |x| FileContentSearch.search_buffer(x) }
  gui_one_input_action(nfo, "Search:", "search", callback)
end