Class: VER::Executor::ExGrep
Overview
Constant Summary
Constants inherited
from VER::Entry
VER::Entry::BACKWARD_WORD, VER::Entry::FORWARD_WORD
Instance Method Summary
collapse
Methods inherited from VER::Entry
#accept_line, #beginning_of_history, #cursor=, #delete, #delete_next_char, #delete_next_word, #delete_prev_char, #delete_prev_word, #deleting, #end_of_history, #end_of_line, #error, #event, #events, #insert, #insert_selection, #insert_string, #insert_tab, #kill, #kill_end_of_line, #killing, #message, #next_char, #next_history, #next_word, #paste, #prev_char, #prev_word, #previous_history, #sel_end_of_line, #sel_next_char, #sel_next_word, #sel_prev_char, #sel_prev_word, #sel_start_of_line, #start_of_line, #style, #transpose_chars, #value=, #virtual_movement
Instance Method Details
#action(selected) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/ver/executor/grep.rb', line 69
def action(selected)
item = tree.focus_item
file, line, _ = item.options(:values)
return unless file && line
VER.find_or_create_buffer(file.to_s, line.to_i)
callback.destroy(false)
end
|
#after_update ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/ver/executor/grep.rb', line 18
def after_update
total = tree.winfo_width - 50
tree.column('file', width: (total * 0.3).to_i, stretch: false, anchor: :w)
tree.column('line', width: 50, stretch: false, anchor: :e)
tree.column('source', width: (total * 0.7).to_i, stretch: false, anchor: :w)
end
|
#choices(glob_needle) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/ver/executor/grep.rb', line 26
def choices(glob_needle)
choices = []
return [] if glob_needle =~ /^\s*$/
glob, needle = glob_needle.split(/\s+/, 2)
unless needle
glob, needle = '*', glob
self.value = "#{glob} #{needle}"
end
return [] if needle =~ /^\s*$/
begin
regexp = Regexp.new(needle)
rescue RegexpError, SyntaxError
regexp = Regexp.new(Regexp.escape(needle))
end
grep_with(glob, regexp)
end
|
#grep_with(glob, regexp, with_root = true) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/ver/executor/grep.rb', line 48
def grep_with(glob, regexp, with_root = true)
results = []
root = with_root ? @root/glob : glob
root.glob do |path|
next unless path.file?
path.open do |io|
begin
io.each_line.with_index do |line, index|
next unless line =~ regexp
results << [path.to_s, index + 1, line]
end
rescue ArgumentError end
end
end
results
end
|
#setup ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/ver/executor/grep.rb', line 5
def setup
@root = caller.project_root || Pathname(Dir.pwd)
tree.configure(
show: [:headings],
columns: %w[file line source],
displaycolumns: %w[file line source],
)
tree.heading('file', text: 'File')
tree.heading('line', text: 'Line')
tree.heading('source', text: 'Source')
end
|
#sync_value_with_tree_selection ⇒ Object
78
79
|
# File 'lib/ver/executor/grep.rb', line 78
def sync_value_with_tree_selection
end
|