vimamsa 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -3
- data/custom_example.rb +11 -1
- data/demo.txt +2 -2
- data/exe/vimamsa +1 -1
- data/lib/vimamsa/ack.rb +57 -9
- data/lib/vimamsa/actions.rb +1 -1
- data/lib/vimamsa/buffer.rb +272 -44
- data/lib/vimamsa/buffer_list.rb +57 -16
- data/lib/vimamsa/buffer_manager.rb +19 -3
- data/lib/vimamsa/conf.rb +10 -1
- data/lib/vimamsa/debug.rb +7 -3
- data/lib/vimamsa/easy_jump.rb +9 -5
- data/lib/vimamsa/editor.rb +55 -41
- data/lib/vimamsa/file_finder.rb +70 -72
- data/lib/vimamsa/file_history.rb +2 -3
- data/lib/vimamsa/file_manager.rb +1 -1
- data/lib/vimamsa/form_generator.rb +122 -0
- data/lib/vimamsa/gui.rb +467 -120
- data/lib/vimamsa/gui_image.rb +12 -6
- data/lib/vimamsa/gui_menu.rb +26 -21
- data/lib/vimamsa/gui_select_window.rb +40 -21
- data/lib/vimamsa/gui_sourceview.rb +171 -78
- data/lib/vimamsa/hyper_plain_text.rb +34 -1
- data/lib/vimamsa/key_actions.rb +13 -1
- data/lib/vimamsa/key_binding_tree.rb +26 -14
- data/lib/vimamsa/key_bindings_vimlike.rb +54 -25
- data/lib/vimamsa/langservp.rb +172 -0
- data/lib/vimamsa/macro.rb +9 -8
- data/lib/vimamsa/main.rb +0 -1
- data/lib/vimamsa/rbvma.rb +7 -4
- data/lib/vimamsa/search.rb +2 -1
- data/lib/vimamsa/search_replace.rb +36 -106
- data/lib/vimamsa/util.rb +47 -1
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +1 -6
- data/styles/molokai_edit.xml +3 -0
- data/vimamsa.gemspec +10 -10
- metadata +24 -22
data/lib/vimamsa/file_finder.rb
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
require "parallel"
|
2
|
+
|
3
|
+
# Limit file search to these extensions:
|
4
|
+
$find_extensions = [".txt", ".h", ".c", ".cpp", ".hpp", ".rb"]
|
5
|
+
$search_dirs = []
|
6
|
+
|
2
7
|
class FileFinder
|
8
|
+
def self.update_index()
|
9
|
+
message("Start updating file index")
|
10
|
+
Thread.new {
|
11
|
+
recursively_find_files()
|
12
|
+
message("Finnish updating file index")
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
3
16
|
def initialize()
|
4
|
-
|
5
|
-
|
17
|
+
vma.hook.register(:shutdown, self.method("save"))
|
18
|
+
@dir_list = vma.marshal_load("file_index")
|
6
19
|
end
|
7
20
|
|
8
21
|
def save()
|
9
|
-
|
22
|
+
debug "SAVE FILE INDEX", 2
|
23
|
+
vma.marshal_save("file_index", @dir_list)
|
10
24
|
end
|
11
25
|
|
12
26
|
def start_gui()
|
@@ -16,85 +30,69 @@ class FileFinder
|
|
16
30
|
end
|
17
31
|
l = []
|
18
32
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
19
|
-
if
|
20
|
-
Thread.new { recursively_find_files() }
|
33
|
+
if @dir_list == nil
|
34
|
+
Thread.new { FileFinder.recursively_find_files() }
|
21
35
|
end
|
22
36
|
|
37
|
+
# select_callback = proc { |search_str, idx| gui_file_finder_select_callback(search_str, idx) }
|
38
|
+
select_callback = self.method("gui_file_finder_select_callback")
|
39
|
+
update_callback = self.method("gui_file_finder_update_callback")
|
40
|
+
|
23
41
|
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
24
|
-
|
25
|
-
|
42
|
+
# "gui_file_finder_select_callback",
|
43
|
+
select_callback,
|
44
|
+
update_callback)
|
26
45
|
end
|
27
|
-
end
|
28
46
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
dlist = []
|
40
|
-
|
41
|
-
for d in $search_dirs
|
42
|
-
debug("FIND FILEs IN #{d}")
|
43
|
-
dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and $find_extensions.include?(File.extname(e)) }
|
44
|
-
debug("FIND FILEs IN #{d} END") end #$dir_list = Dir.glob('./**/*').select { |e| File.file? e }
|
45
|
-
debug("END find files2")
|
46
|
-
$dir_list = dlist
|
47
|
-
debug("END find files")
|
48
|
-
return $dir_list
|
49
|
-
end
|
50
|
-
|
51
|
-
def filter_files(search_str)
|
52
|
-
dir_hash = {}
|
53
|
-
scores = Parallel.map($dir_list, in_threads: 8) do |file|
|
54
|
-
[file, srn_dst(search_str, file)]
|
55
|
-
end
|
56
|
-
for s in scores
|
57
|
-
dir_hash[s[0]] = s[1] if s[1] > 0
|
58
|
-
end
|
59
|
-
# debug scores
|
60
|
-
dir_hash = dir_hash.sort_by { |k, v| -v }
|
61
|
-
dir_hash = dir_hash[0..20]
|
62
|
-
dir_hash.map do |file, d|
|
63
|
-
debug "D:#{d} #{file}"
|
47
|
+
def gui_file_finder_update_callback(search_str = "")
|
48
|
+
debug "FILE FINDER UPDATE CALLBACK: #{search_str}"
|
49
|
+
if (search_str.size > 1)
|
50
|
+
files = filter_files(search_str)
|
51
|
+
@file_search_list = files
|
52
|
+
return files
|
53
|
+
#debug files.inspect
|
54
|
+
#return files.values
|
55
|
+
end
|
56
|
+
return []
|
64
57
|
end
|
65
|
-
return dir_hash
|
66
|
-
end
|
67
58
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
return files
|
74
|
-
#debug files.inspect
|
75
|
-
#return files.values
|
59
|
+
def gui_file_finder_select_callback(search_str, idx)
|
60
|
+
selected_file = @file_search_list[idx][0]
|
61
|
+
debug "FILE FINDER SELECT CALLBACK: s=#{search_str},i=#{idx}: #{selected_file}"
|
62
|
+
gui_select_window_close(0)
|
63
|
+
open_new_file(selected_file)
|
76
64
|
end
|
77
|
-
return []
|
78
|
-
end
|
79
65
|
|
80
|
-
def
|
81
|
-
|
82
|
-
|
83
|
-
gui_select_window_close(0)
|
84
|
-
open_new_file(selected_file)
|
85
|
-
end
|
66
|
+
def self.recursively_find_files()
|
67
|
+
debug("START find files")
|
68
|
+
dlist = []
|
86
69
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
70
|
+
for d in $search_dirs
|
71
|
+
debug("FIND FILEs IN #{d}")
|
72
|
+
dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and $find_extensions.include?(File.extname(e)) }
|
73
|
+
debug("FIND FILEs IN #{d} END")
|
74
|
+
end #@dir_list = Dir.glob('./**/*').select { |e| File.file? e }
|
75
|
+
debug("END find files2")
|
76
|
+
@dir_list = dlist
|
77
|
+
debug("END find files")
|
78
|
+
return @dir_list
|
92
79
|
end
|
93
|
-
end
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
81
|
+
def filter_files(search_str)
|
82
|
+
dir_hash = {}
|
83
|
+
scores = Parallel.map(@dir_list, in_threads: 8) do |file|
|
84
|
+
[file, srn_dst(search_str, file)]
|
85
|
+
end
|
86
|
+
for s in scores
|
87
|
+
dir_hash[s[0]] = s[1] if s[1] > 0
|
88
|
+
end
|
89
|
+
# debug scores
|
90
|
+
dir_hash = dir_hash.sort_by { |k, v| -v }
|
91
|
+
dir_hash = dir_hash[0..20]
|
92
|
+
dir_hash.map do |file, d|
|
93
|
+
debug "D:#{d} #{file}"
|
94
|
+
end
|
95
|
+
return dir_hash
|
96
|
+
end
|
100
97
|
end
|
98
|
+
|
data/lib/vimamsa/file_history.rb
CHANGED
@@ -8,8 +8,8 @@ class FileHistory
|
|
8
8
|
# x = self.method("update")
|
9
9
|
# x.call("ASFASF")
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
vma.hook.register(:change_buffer, self.method("update"))
|
12
|
+
vma.hook.register(:shutdown, self.method("save"))
|
13
13
|
|
14
14
|
reg_act(:fhist_remove_nonexisting, proc { remove_nonexisting }, "Cleanup history, remove non-existing files")
|
15
15
|
|
@@ -98,7 +98,6 @@ def gui_file_history_update_callback(search_str = "")
|
|
98
98
|
end
|
99
99
|
|
100
100
|
def gui_file_history_select_callback(search_str, idx)
|
101
|
-
# selected_file = $file_search_list[idx][0]
|
102
101
|
selected_file = $search_list[idx][0]
|
103
102
|
|
104
103
|
debug "FILE HISTORY SELECT CALLBACK: s=#{search_str},i=#{idx}: #{selected_file}"
|
data/lib/vimamsa/file_manager.rb
CHANGED
@@ -0,0 +1,122 @@
|
|
1
|
+
# PopupFormGenerator.new().run
|
2
|
+
class PopupFormGenerator
|
3
|
+
def submit()
|
4
|
+
for id, entry in @vals
|
5
|
+
@ret[id] = entry.text
|
6
|
+
end
|
7
|
+
if !@callback.nil?
|
8
|
+
@callback.call(@ret)
|
9
|
+
end
|
10
|
+
@window.destroy
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(params = nil)
|
14
|
+
@ret = {}
|
15
|
+
@window = Gtk::Window.new()
|
16
|
+
# @window.screen = main_window.screen
|
17
|
+
# @window.title = title
|
18
|
+
# params = {}
|
19
|
+
# params["inputs"] = {}
|
20
|
+
# params["inputs"]["search"] = { :label => "Search", :type => :entry }
|
21
|
+
# params["inputs"]["replace"] = { :label => "Replace", :type => :entry }
|
22
|
+
# params["inputs"]["btn1"] = { :label => "Replace all", :type => :button }
|
23
|
+
# params[:callback] = proc { |x| puts "====="; puts x.inspect; puts "=====" }
|
24
|
+
|
25
|
+
|
26
|
+
@callback = params[:callback]
|
27
|
+
@window.title = ""
|
28
|
+
|
29
|
+
frame = Gtk::Frame.new()
|
30
|
+
frame.margin_bottom = 8
|
31
|
+
frame.margin_top = 8
|
32
|
+
frame.margin_end = 8
|
33
|
+
frame.margin_start = 8
|
34
|
+
|
35
|
+
@window.set_child(frame)
|
36
|
+
|
37
|
+
# @window.title = params["title"]
|
38
|
+
|
39
|
+
# @callback = params["callback"]
|
40
|
+
|
41
|
+
vbox = Gtk::Box.new(:vertical, 8)
|
42
|
+
vbox.margin_bottom = 8
|
43
|
+
vbox.margin_top = 8
|
44
|
+
vbox.margin_end = 8
|
45
|
+
vbox.margin_start = 8
|
46
|
+
|
47
|
+
frame.set_child(vbox)
|
48
|
+
|
49
|
+
if params.has_key?("title")
|
50
|
+
infolabel = Gtk::Label.new
|
51
|
+
infolabel.markup = params["title"]
|
52
|
+
#TODO:gtk4
|
53
|
+
# vbox.pack_start(infolabel, :expand => false, :fill => false, :padding => 0)
|
54
|
+
vbox.pack_end(infolabel, :expand => false, :fill => false, :padding => 0)
|
55
|
+
end
|
56
|
+
|
57
|
+
hbox = Gtk::Box.new(:horizontal, 8)
|
58
|
+
@vals = {}
|
59
|
+
@default_button = nil
|
60
|
+
|
61
|
+
for id, elem in params["inputs"]
|
62
|
+
if elem[:type] == :button
|
63
|
+
button = Gtk::Button.new(:label => elem[:label])
|
64
|
+
hbox.pack_end(button, :expand => false, :fill => false, :padding => 0)
|
65
|
+
if elem[:default_focus] == true
|
66
|
+
@default_button = button
|
67
|
+
end
|
68
|
+
button.signal_connect "clicked" do
|
69
|
+
@ret[id] = "submit"
|
70
|
+
submit
|
71
|
+
end
|
72
|
+
elsif elem[:type] == :entry
|
73
|
+
label = Gtk::Label.new(elem[:label])
|
74
|
+
entry = Gtk::Entry.new
|
75
|
+
if elem.has_key?(:initial_text)
|
76
|
+
entry.text = elem[:initial_text]
|
77
|
+
end
|
78
|
+
hbox.pack_end(label, :expand => false, :fill => false, :padding => 0)
|
79
|
+
hbox.pack_end(entry, :expand => false, :fill => false, :padding => 0)
|
80
|
+
@vals[id] = entry
|
81
|
+
|
82
|
+
press = Gtk::EventControllerKey.new
|
83
|
+
press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE)
|
84
|
+
entry.add_controller(press)
|
85
|
+
press.signal_connect "key-pressed" do |gesture, keyval, keycode, y|
|
86
|
+
if keyval == Gdk::Keyval::KEY_Return
|
87
|
+
submit
|
88
|
+
true
|
89
|
+
elsif keyval == Gdk::Keyval::KEY_Escape
|
90
|
+
@window.destroy
|
91
|
+
true
|
92
|
+
else
|
93
|
+
false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
vbox.pack_end(hbox, :expand => false, :fill => false, :padding => 0)
|
100
|
+
|
101
|
+
cancel_button = Gtk::Button.new(:label => "Cancel")
|
102
|
+
cancel_button.signal_connect "clicked" do
|
103
|
+
@window.destroy
|
104
|
+
end
|
105
|
+
hbox.pack_end(cancel_button, :expand => false, :fill => false, :padding => 0)
|
106
|
+
@cancel_button = cancel_button
|
107
|
+
return
|
108
|
+
end
|
109
|
+
|
110
|
+
def run
|
111
|
+
if !@window.visible?
|
112
|
+
@window.show
|
113
|
+
else
|
114
|
+
@window.destroy
|
115
|
+
end
|
116
|
+
if !@default_button.nil?
|
117
|
+
@default_button.grab_focus
|
118
|
+
end
|
119
|
+
@window.set_focus_visible(true)
|
120
|
+
@window
|
121
|
+
end
|
122
|
+
end
|