vimamsa 0.1.18 → 0.1.20
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/custom_example.rb +1 -1
- data/demo.txt +1 -1
- data/exe/vimamsa +1 -1
- data/ext/vmaext/extconf.rb +5 -0
- data/lib/vimamsa/ack.rb +7 -16
- data/lib/vimamsa/buffer.rb +10 -5
- data/lib/vimamsa/buffer_changetext.rb +1 -1
- data/lib/vimamsa/buffer_list.rb +44 -10
- data/lib/vimamsa/conf.rb +28 -60
- data/lib/vimamsa/debug.rb +1 -1
- data/lib/vimamsa/editor.rb +22 -27
- data/lib/vimamsa/file_finder.rb +78 -10
- data/lib/vimamsa/gui.rb +119 -153
- data/lib/vimamsa/gui_dialog.rb +11 -8
- data/lib/vimamsa/gui_form_generator.rb +6 -8
- data/lib/vimamsa/gui_menu.rb +12 -10
- data/lib/vimamsa/gui_select_window.rb +3 -1
- data/lib/vimamsa/gui_sourceview.rb +41 -23
- data/lib/vimamsa/key_actions.rb +16 -13
- data/lib/vimamsa/key_binding_tree.rb +0 -2
- data/lib/vimamsa/key_bindings_vimlike.rb +1 -2
- data/lib/vimamsa/langservp.rb +1 -2
- data/lib/vimamsa/macro.rb +1 -1
- data/lib/vimamsa/text_transforms.rb +4 -1
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +3 -0
- data/vimamsa.gemspec +3 -2
- metadata +16 -3
- data/.vma_project +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b635655f9d50eb870f5593b8d2e63cfacff5ed0aece9b197ca8805622799ab0
|
4
|
+
data.tar.gz: 8c579b33d9d5e5d48c25fef3da47ca77eb9ba9bf713cf7c2895c1af5e2cf2d30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1027546a7e21d7832e546f4ccd7eb9064aece5b7c13bef4d83477082351b2cc74e136c952999c69de70581aa651af2a5e8fd14960a1b52c91a0d0a7d08bd530c
|
7
|
+
data.tar.gz: 3784552302bd4f7541320785f250fe9c4aa36e6bcd7d1317f9f85b776900211a1f7d5644891de6ae224703dca6ce9c0eda12fc894d1d4f73523e6bd149b6aebf
|
data/custom_example.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# c = Converter.new(lambda { |x| h = {}; x.split(/\s+/).each { |y| h[y] = 1 }; h.keys.join(" ") }, :lambda, :uniqwords)
|
5
5
|
|
6
6
|
# Eval selected text as ruby code (e.g. use as calculator)
|
7
|
+
|
7
8
|
# bindkey "V , e", "vma.buf.convert_selected_text(:eval)"
|
8
9
|
# syntax: bindkey "mode key1 key2 ..."
|
9
10
|
|
@@ -26,7 +27,6 @@
|
|
26
27
|
|
27
28
|
|
28
29
|
|
29
|
-
|
30
30
|
def insert_date()
|
31
31
|
# $buffer.insert_txt("#{DateTime.now().strftime("==========\n%Y-%m-%d")}\n")
|
32
32
|
vma.buf.insert_txt("#{DateTime.now().strftime("%Y-%m-%d")}\n")
|
data/demo.txt
CHANGED
data/exe/vimamsa
CHANGED
@@ -9,7 +9,7 @@ selfpath = File.readlink(selfpath) if File.lstat(selfpath).symlink?
|
|
9
9
|
scriptdir = File.expand_path(File.dirname(selfpath) + "/..")
|
10
10
|
|
11
11
|
# If process is already running, open the parameter file in the running process and exit.
|
12
|
-
listen_dir = File.expand_path("~/.vimamsa/listen")
|
12
|
+
listen_dir = File.expand_path("~/.config/vimamsa/listen")
|
13
13
|
if File.exist?(listen_dir) and !ARGV[0].nil?
|
14
14
|
tmpf = Tempfile.new("vmarun", listen_dir)
|
15
15
|
fp = tmpf.path
|
data/ext/vmaext/extconf.rb
CHANGED
@@ -6,6 +6,11 @@ require 'mkmf'
|
|
6
6
|
module_name = "vimamsa"
|
7
7
|
extension_name = 'vmaext'
|
8
8
|
|
9
|
+
# $CFLAGS << " -Wall -fpermissive "
|
10
|
+
# $CXXFLAGS << " -Wall -fpermissive "
|
11
|
+
|
12
|
+
# have_library( 'stdc++' );
|
13
|
+
|
9
14
|
dir_config(extension_name) # The destination
|
10
15
|
create_makefile(extension_name) # Create Makefile
|
11
16
|
|
data/lib/vimamsa/ack.rb
CHANGED
@@ -4,21 +4,13 @@ class FileContentSearch
|
|
4
4
|
def self.start_gui()
|
5
5
|
search_paths = vma.get_content_search_paths.join("<br/>")
|
6
6
|
|
7
|
-
nfo = "<span size='x-large'>Search contents of text files</span>
|
8
|
-
Will search all .txt files in the following directories:
|
9
|
-
#{search_paths}
|
10
|
-
|
11
|
-
<span>Hint: add empty file named .vma_project to directories you want to search in.
|
12
|
-
If .vma_project exists in parent directory of current file, searches within that directory.
|
13
|
-
</span>"
|
14
|
-
|
15
7
|
callback = proc { |x| FileContentSearch.search_buffer(x) }
|
16
8
|
|
17
9
|
params = {}
|
18
10
|
params["inputs"] = {}
|
19
11
|
params["inputs"]["search"] = { :label => "Search:", :type => :entry }
|
20
12
|
params["inputs"]["extensions"] = { :label => "Limit to file extensions:", :type => :entry }
|
21
|
-
params["inputs"]["extensions"][:initial_text] =
|
13
|
+
params["inputs"]["extensions"][:initial_text] = cnf.default_search_extensions!.join(",")
|
22
14
|
params["inputs"]["btn1"] = { :label => "Search", :type => :button }
|
23
15
|
|
24
16
|
params[:callback] = callback
|
@@ -92,17 +84,12 @@ end
|
|
92
84
|
def gui_ack()
|
93
85
|
search_paths = vma.get_content_search_paths.join("<br/>")
|
94
86
|
|
95
|
-
nfo = "<html><h2>Search contents of all files using ack</h2>
|
96
|
-
<div style='width:300px'>
|
97
|
-
<p>Hint: add empty file named .vma_project to dirs you want to search.</p>\n<p>If .vma_project exists in parent dir of current file, searches within that dir</p></div></html>"
|
98
|
-
|
99
87
|
nfo = "<span size='x-large'>Search contents of all files using ack</span>
|
100
88
|
Will search the following directories:
|
101
89
|
#{search_paths}
|
102
90
|
|
103
|
-
<span>
|
104
|
-
|
105
|
-
</span>"
|
91
|
+
<span>Note: Directory determined automatically as the first parent directory of a last accessed file which includes file/dir named .git or .vma_project. Or, if not found, the last accessed directory.
|
92
|
+
</span>"
|
106
93
|
|
107
94
|
callback = proc { |x| Ack.new.ack_buffer(x) }
|
108
95
|
gui_one_input_action(nfo, "Search:", "search", callback)
|
@@ -151,6 +138,10 @@ class Ack
|
|
151
138
|
end
|
152
139
|
|
153
140
|
def ack_buffer(_instr, b = nil)
|
141
|
+
if _instr.nil? or _instr.strip.size <= 1
|
142
|
+
message("No input for ack")
|
143
|
+
return
|
144
|
+
end
|
154
145
|
instr = Shellwords.escape(_instr)
|
155
146
|
bufstr = ""
|
156
147
|
for path in vma.get_content_search_paths
|
data/lib/vimamsa/buffer.rb
CHANGED
@@ -271,7 +271,7 @@ class Buffer < String
|
|
271
271
|
|
272
272
|
def unindent
|
273
273
|
debug("unindent", 2)
|
274
|
-
|
274
|
+
cnf.tab.width!.times {
|
275
275
|
p = @pos - 1
|
276
276
|
if p >= 0
|
277
277
|
if self[p] == " "
|
@@ -754,7 +754,7 @@ class Buffer < String
|
|
754
754
|
end
|
755
755
|
|
756
756
|
def update_highlights(pos, changeamount, changestr)
|
757
|
-
return if !self.is_highlighted
|
757
|
+
return if !self.is_highlighted
|
758
758
|
lpos, cpos = get_line_and_col_pos(pos)
|
759
759
|
if @highlights and @highlights[lpos]
|
760
760
|
hl = @highlights[lpos]
|
@@ -1063,7 +1063,11 @@ class Buffer < String
|
|
1063
1063
|
# message("Open link #{word}")
|
1064
1064
|
linep = get_file_line_pointer(word)
|
1065
1065
|
debug "linep'#{linep}'"
|
1066
|
-
|
1066
|
+
if word[0] != "/" and word[0] != "~"
|
1067
|
+
path = File.expand_path("#{bufs.last_dir}/#{word}")
|
1068
|
+
else
|
1069
|
+
path = File.expand_path(word)
|
1070
|
+
end
|
1067
1071
|
wtype = nil
|
1068
1072
|
if is_url(word)
|
1069
1073
|
wtype = :url
|
@@ -1089,7 +1093,7 @@ class Buffer < String
|
|
1089
1093
|
return [fn, :hpt_link]
|
1090
1094
|
end
|
1091
1095
|
end
|
1092
|
-
|
1096
|
+
|
1093
1097
|
return [word, wtype]
|
1094
1098
|
end
|
1095
1099
|
|
@@ -1158,7 +1162,7 @@ class Buffer < String
|
|
1158
1162
|
c = c.force_encoding("UTF-8"); #TODO:correct?
|
1159
1163
|
|
1160
1164
|
c = "\n" if c == "\r"
|
1161
|
-
if
|
1165
|
+
if cnf.indent_based_on_last_line? and c == "\n" and @lpos > 0
|
1162
1166
|
# Indent start of new line based on last line
|
1163
1167
|
last_line = line(@lpos)
|
1164
1168
|
m = /^( +)([^ ]+|$)/.match(last_line)
|
@@ -1593,3 +1597,4 @@ def backup_all_buffers()
|
|
1593
1597
|
end
|
1594
1598
|
message("Backup all buffers")
|
1595
1599
|
end
|
1600
|
+
|
@@ -264,7 +264,7 @@ class Buffer < String
|
|
264
264
|
convert = cnf.tab.to_spaces_default?
|
265
265
|
convert = true if cnf.tab.to_spaces_languages?.include?(@lang)
|
266
266
|
convert = false if cnf.tab.to_spaces_not_languages?.include?(@lang)
|
267
|
-
tw =
|
267
|
+
tw = cnf.tab.width!
|
268
268
|
if convert
|
269
269
|
indent_to = (@cpos / tw) * tw + tw
|
270
270
|
indentdiff = indent_to - @cpos
|
data/lib/vimamsa/buffer_list.rb
CHANGED
@@ -65,7 +65,7 @@ class BufferList
|
|
65
65
|
# TODO: implement using heap/priorityque
|
66
66
|
@list.sort_by! { |x| x.access_time }
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
def each(&block)
|
70
70
|
for x in slist
|
71
71
|
block.call(x)
|
@@ -187,21 +187,55 @@ class BufferList
|
|
187
187
|
@navigation_idx = 0
|
188
188
|
end
|
189
189
|
|
190
|
-
def
|
191
|
-
|
190
|
+
def history_switch(dir = -1)
|
191
|
+
# -1: from newest towards oldest
|
192
|
+
# +1: from oldest towards newest
|
193
|
+
|
194
|
+
@navigation_idx += dir * -1
|
192
195
|
@navigation_idx = 0 if @navigation_idx >= list.size
|
196
|
+
@navigation_idx = list.size - 1 if @navigation_idx < 0
|
197
|
+
|
198
|
+
# most recent is at end of slist
|
193
199
|
b = slist[-1 - @navigation_idx]
|
194
|
-
|
200
|
+
puts "@navigation_idx=#{@navigation_idx}"
|
201
|
+
non_active = slist.select{|x|!x.is_active?}
|
202
|
+
return if non_active.size == 0
|
203
|
+
|
204
|
+
# Take another one from the history if buffer is already open in a window (active)
|
205
|
+
navtmp = @navigation_idx
|
206
|
+
i = 1
|
207
|
+
while b.is_active?
|
208
|
+
pp "b.is_active b=#{b.id}"
|
209
|
+
navtmp += dir * -1
|
210
|
+
b = slist[-1 - navtmp]
|
211
|
+
if b.nil? # went past the beginning or end of array slist
|
212
|
+
# Start from the end
|
213
|
+
if navtmp != 0 and dir == -1 # did not already start from the end
|
214
|
+
navtmp = 0
|
215
|
+
i = 0
|
216
|
+
b = slist[-1 - navtmp]
|
217
|
+
elsif navtmp == list.size and dir == 1
|
218
|
+
navtmp = list.size
|
219
|
+
i = 0
|
220
|
+
b = slist[-1 - navtmp]
|
221
|
+
else
|
222
|
+
return # No buffer exists which is not active already
|
223
|
+
end
|
224
|
+
end
|
225
|
+
i += 1
|
226
|
+
end
|
227
|
+
@navigation_idx = navtmp
|
228
|
+
|
229
|
+
pp "IND:#{@navigation_idx} RECENT:#{slist.collect { |x| x.fname }.join("\n")}"
|
195
230
|
set_current_buffer(b.id, false)
|
196
231
|
end
|
197
232
|
|
198
|
-
def
|
199
|
-
|
200
|
-
|
233
|
+
def history_switch_backwards()
|
234
|
+
history_switch(-1)
|
235
|
+
end
|
201
236
|
|
202
|
-
|
203
|
-
|
204
|
-
set_current_buffer(b.id, false)
|
237
|
+
def history_switch_forwards()
|
238
|
+
history_switch(+1)
|
205
239
|
end
|
206
240
|
|
207
241
|
def get_last_non_active_buffer
|
data/lib/vimamsa/conf.rb
CHANGED
@@ -1,43 +1,36 @@
|
|
1
|
-
$cnf = {} # TODO
|
2
1
|
|
3
|
-
|
4
|
-
return $cnf[id]
|
5
|
-
end
|
6
|
-
|
7
|
-
def set_conf(id, val)
|
8
|
-
$cnf[id] = val
|
9
|
-
end
|
10
|
-
|
11
|
-
def setcnf(id, val)
|
12
|
-
set_conf(id, val)
|
13
|
-
end
|
14
|
-
|
15
|
-
setcnf :custom_lsp, {}
|
16
|
-
|
17
|
-
setcnf :indent_based_on_last_line, true
|
18
|
-
setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc", ".php", ".sh", ".m", ".gd", ".js", ".py"]
|
19
|
-
setcnf :default_search_extensions, ["txt", "rb"]
|
20
|
-
|
21
|
-
setcnf "log.verbose", 1
|
22
|
-
setcnf :enable_lsp, false
|
23
|
-
|
24
|
-
setcnf :tab_width, 2
|
25
|
-
setcnf :tab_to_spaces_default, false
|
26
|
-
setcnf :tab_to_spaces_languages, ["c", "java", "ruby", "hyperplaintext", "php"]
|
27
|
-
setcnf :tab_to_spaces_not_languages, ["makefile"]
|
28
|
-
|
29
|
-
setcnf :workspace_folders, []
|
30
|
-
|
31
|
-
|
32
|
-
# New way to configure:
|
33
|
-
# To set conf value:
|
2
|
+
# Set conf value by:
|
34
3
|
# cnf.foo.bar.baz = 3
|
35
4
|
|
36
|
-
#
|
5
|
+
# Get conf value by:
|
37
6
|
# cnf.foo.bar.baz?
|
38
7
|
# cnf.foo.bar.baz!
|
39
8
|
# get(cnf.foo.bar.baz)
|
40
|
-
# (All get the same result)
|
9
|
+
# (All ways get the same result)
|
10
|
+
|
11
|
+
$confh = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
12
|
+
# set cnf.foo.bar.baz, 3
|
13
|
+
# => $confh = {:foo=>{:bar=>{:baz=>3}}}
|
14
|
+
def set(_id, val)
|
15
|
+
a = $confh
|
16
|
+
id = _id.to_a
|
17
|
+
last = id.pop
|
18
|
+
for x in id
|
19
|
+
a = a[x]
|
20
|
+
end
|
21
|
+
a[last] = val
|
22
|
+
end
|
23
|
+
|
24
|
+
def get(id)
|
25
|
+
id = id.to_a
|
26
|
+
a = $confh
|
27
|
+
for x in id
|
28
|
+
return nil if a[x].nil?
|
29
|
+
return nil if a.empty?
|
30
|
+
a = a[x]
|
31
|
+
end
|
32
|
+
return a
|
33
|
+
end
|
41
34
|
|
42
35
|
class ConfId
|
43
36
|
def initialize(first)
|
@@ -104,32 +97,6 @@ class Conf
|
|
104
97
|
end
|
105
98
|
end
|
106
99
|
|
107
|
-
|
108
|
-
|
109
|
-
$confh = Hash.new { |h, k| h[k] = Hash.new(&h.default_proc) }
|
110
|
-
# set cnf.foo.bar.baz, 3
|
111
|
-
# => $confh = {:foo=>{:bar=>{:baz=>3}}}
|
112
|
-
def set(_id, val)
|
113
|
-
a = $confh
|
114
|
-
id = _id.to_a
|
115
|
-
last = id.pop
|
116
|
-
for x in id
|
117
|
-
a = a[x]
|
118
|
-
end
|
119
|
-
a[last] = val
|
120
|
-
end
|
121
|
-
|
122
|
-
def get(id)
|
123
|
-
id = id.to_a
|
124
|
-
a = $confh
|
125
|
-
for x in id
|
126
|
-
return nil if a[x].nil?
|
127
|
-
return nil if a.empty?
|
128
|
-
a = a[x]
|
129
|
-
end
|
130
|
-
return a
|
131
|
-
end
|
132
|
-
|
133
100
|
$vimamsa_conf = Conf.new
|
134
101
|
|
135
102
|
def cnf()
|
@@ -158,6 +125,7 @@ cnf.lsp.enabled = false
|
|
158
125
|
cnf.font.size = 11
|
159
126
|
cnf.font.family = "Monospace"
|
160
127
|
|
128
|
+
cnf.startup_file=false
|
161
129
|
|
162
130
|
cnf.macro.animation_delay = 0.02
|
163
131
|
|
data/lib/vimamsa/debug.rb
CHANGED
@@ -63,7 +63,7 @@ def savedebug(message, e)
|
|
63
63
|
dbginfo["trace"] = e.backtrace() if e
|
64
64
|
dbginfo["trace_str"] = dbginfo["trace"].join("\n")
|
65
65
|
dbginfo["edit_history"] = buf.edit_history
|
66
|
-
dbginfo["cnf"] = $
|
66
|
+
dbginfo["cnf"] = $vimamsa_conf
|
67
67
|
dbginfo["register"] = vma.register
|
68
68
|
dbginfo["clipboard"] = vma.clipboard
|
69
69
|
# dbginfo["last_event"] = $last_event
|
data/lib/vimamsa/editor.rb
CHANGED
@@ -91,37 +91,29 @@ class Editor
|
|
91
91
|
|
92
92
|
@gui.init_menu
|
93
93
|
|
94
|
-
mkdir_if_not_exists("
|
95
|
-
mkdir_if_not_exists("
|
96
|
-
mkdir_if_not_exists("
|
97
|
-
listen_dir =
|
94
|
+
mkdir_if_not_exists(get_dot_path(""))
|
95
|
+
mkdir_if_not_exists(get_dot_path("backup"))
|
96
|
+
mkdir_if_not_exists(get_dot_path("testfoobar")) #TODO
|
97
|
+
listen_dir = get_dot_path("listen")
|
98
|
+
mkdir_if_not_exists(listen_dir)
|
98
99
|
listener = Listen.to(listen_dir) do |modified, added, removed|
|
99
100
|
debug([modified: modified, added: added, removed: removed])
|
100
101
|
open_file_listener(added)
|
101
102
|
end
|
102
103
|
listener.start
|
103
104
|
|
104
|
-
custom_fn =
|
105
|
+
custom_fn = get_dot_path("custom.rb")
|
105
106
|
if !File.exist?(custom_fn)
|
106
107
|
example_custom = IO.read(ppath("custom_example.rb"))
|
107
108
|
IO.write(custom_fn, example_custom)
|
108
109
|
end
|
109
110
|
|
110
|
-
mkdir_if_not_exists("~/.vimamsa/custom.rb")
|
111
|
-
|
112
|
-
$cnf[:theme] = "Twilight_edit"
|
113
|
-
$cnf[:syntax_highlight] = true
|
114
111
|
settings_path = get_dot_path("settings.rb")
|
115
112
|
if File.exist?(settings_path)
|
116
|
-
|
113
|
+
# = eval(IO.read(settings_path))
|
114
|
+
#TODO
|
117
115
|
end
|
118
116
|
|
119
|
-
# set_gui_style(1)
|
120
|
-
|
121
|
-
#TODO: remove
|
122
|
-
dotfile = read_file("", "~/.vimamsarc")
|
123
|
-
eval(dotfile) if dotfile
|
124
|
-
|
125
117
|
custom_script = read_file("", custom_fn)
|
126
118
|
eval(custom_script) if custom_script
|
127
119
|
|
@@ -137,13 +129,12 @@ class Editor
|
|
137
129
|
require "vimamsa/langservp"
|
138
130
|
@langsrv["ruby"] = LangSrv.new("ruby")
|
139
131
|
@langsrv["cpp"] = LangSrv.new("cpp")
|
132
|
+
#TODO: if language enabled in config?
|
140
133
|
end
|
141
134
|
|
142
|
-
# build_options
|
143
|
-
|
144
135
|
fname = nil
|
145
|
-
if
|
146
|
-
fname_ = File.expand_path(
|
136
|
+
if cnf.startup_file?
|
137
|
+
fname_ = File.expand_path(cnf.startup_file!)
|
147
138
|
if File.exist?(fname_)
|
148
139
|
fname = fname_
|
149
140
|
end
|
@@ -275,7 +266,7 @@ class Editor
|
|
275
266
|
end
|
276
267
|
|
277
268
|
def can_open_extension?(filepath)
|
278
|
-
exts =
|
269
|
+
exts = cnf.extensions_to_open!
|
279
270
|
extname = Pathname.new(filepath).extname.downcase
|
280
271
|
can_open = exts.include?(extname)
|
281
272
|
debug "CAN OPEN?: #{can_open}"
|
@@ -290,7 +281,6 @@ end
|
|
290
281
|
|
291
282
|
def _quit()
|
292
283
|
vma.shutdown
|
293
|
-
# Gtk.main_quit
|
294
284
|
end
|
295
285
|
|
296
286
|
def fatal_error(msg)
|
@@ -623,7 +613,7 @@ def hook_draw()
|
|
623
613
|
end
|
624
614
|
|
625
615
|
def get_dot_path(sfx)
|
626
|
-
dot_dir = File.expand_path("~/.vimamsa")
|
616
|
+
dot_dir = File.expand_path("~/.config/vimamsa")
|
627
617
|
Dir.mkdir(dot_dir) unless File.exist?(dot_dir)
|
628
618
|
dpath = "#{dot_dir}/#{sfx}"
|
629
619
|
return dpath
|
@@ -646,11 +636,16 @@ def find_project_dir_of_fn(fn)
|
|
646
636
|
parent_dirs = (0..(pcomp.size - 2)).collect { |x| "/" + pcomp[0..x].join("/") }.reverse
|
647
637
|
projdir = nil
|
648
638
|
for pdir in parent_dirs
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
639
|
+
candfns = []
|
640
|
+
candfns << "#{pdir}/.vma_project"
|
641
|
+
candfns << "#{pdir}/.git"
|
642
|
+
for candfn in candfns
|
643
|
+
if File.exist?(candfn)
|
644
|
+
projdir = pdir
|
645
|
+
break
|
646
|
+
end
|
653
647
|
end
|
648
|
+
return if !projdir.nil?
|
654
649
|
end
|
655
650
|
return projdir
|
656
651
|
end
|
data/lib/vimamsa/file_finder.rb
CHANGED
@@ -1,31 +1,87 @@
|
|
1
1
|
require "parallel"
|
2
|
+
require "stridx"
|
2
3
|
|
3
4
|
# Limit file search to these extensions:
|
4
|
-
|
5
|
-
|
5
|
+
cnf.find_extensions = [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".java", ".js", ".py"]
|
6
|
+
cnf.search_dirs = []
|
7
|
+
|
8
|
+
class StringIndex
|
9
|
+
def initialize()
|
10
|
+
@idx = StrIdx::StringIndex.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def find(str, minChars: 2)
|
14
|
+
minChars = 3 if minChars.class != Integer
|
15
|
+
minChars = 2 if minChars < 2
|
16
|
+
minChars = 6 if minChars > 6 #TODO: implement option in C++
|
17
|
+
|
18
|
+
@idx.find(str)
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(str, id)
|
22
|
+
@idx.add(str, id)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# ruby -e "$:.unshift File.dirname(__FILE__); require 'stridx'; idx = CppStringIndex.new(2); idx.add('foobar00',3); idx.add('fo0br',5); pp idx.find('foo');"
|
6
27
|
|
7
28
|
class FileFinder
|
29
|
+
@@idx_updating = true
|
30
|
+
@@dir_list = []
|
31
|
+
|
8
32
|
def self.update_index()
|
9
33
|
message("Start updating file index")
|
10
34
|
Thread.new {
|
11
35
|
recursively_find_files()
|
12
|
-
message("Finnish updating file index")
|
13
36
|
}
|
14
37
|
end
|
15
38
|
|
16
39
|
def initialize()
|
17
40
|
vma.hook.register(:shutdown, self.method("save"))
|
18
41
|
@@dir_list = vma.marshal_load("file_index")
|
42
|
+
@@dir_list ||= []
|
43
|
+
update_search_idx
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.update_search_idx
|
47
|
+
Thread.new {
|
48
|
+
sleep 0.1
|
49
|
+
@@idx = StringIndex.new
|
50
|
+
@@idx_updating = true
|
51
|
+
|
52
|
+
aa = []; @@dir_list.each_with_index { |x, i| aa << [x, i] }
|
53
|
+
|
54
|
+
# Parallel.map(aa, in_threads: 8) do |(x, i)|
|
55
|
+
# @@idx.add(x, i)
|
56
|
+
# end
|
57
|
+
|
58
|
+
i = 0
|
59
|
+
for x in @@dir_list
|
60
|
+
i += 1
|
61
|
+
# str_idx_addToIndex(x, i)
|
62
|
+
@@idx.add(x, i)
|
63
|
+
end
|
64
|
+
@@idx_updating = false
|
65
|
+
message("Finish updating file index")
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def updating?
|
70
|
+
@@idx_updating
|
71
|
+
end
|
72
|
+
|
73
|
+
def update_search_idx
|
74
|
+
FileFinder.update_search_idx
|
19
75
|
end
|
20
76
|
|
21
77
|
def save()
|
22
|
-
|
78
|
+
debug "SAVE FILE INDEX", 2
|
23
79
|
vma.marshal_save("file_index", @@dir_list)
|
24
80
|
end
|
25
81
|
|
26
82
|
def start_gui()
|
27
|
-
if
|
28
|
-
message("FileFinder: No
|
83
|
+
if cnf.search_dirs!.empty?
|
84
|
+
message("FileFinder: No cnf.search_dirs defined")
|
29
85
|
return
|
30
86
|
end
|
31
87
|
l = []
|
@@ -46,7 +102,7 @@ class FileFinder
|
|
46
102
|
|
47
103
|
def gui_file_finder_update_callback(search_str = "")
|
48
104
|
debug "FILE FINDER UPDATE CALLBACK: #{search_str}"
|
49
|
-
if (search_str.size
|
105
|
+
if (search_str.size >= 3)
|
50
106
|
files = filter_files(search_str)
|
51
107
|
@file_search_list = files
|
52
108
|
return files
|
@@ -67,19 +123,32 @@ class FileFinder
|
|
67
123
|
debug("START find files")
|
68
124
|
dlist = []
|
69
125
|
|
70
|
-
for d in
|
126
|
+
for d in cnf.search_dirs!
|
71
127
|
debug("FIND FILEs IN #{d}")
|
72
|
-
dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and
|
128
|
+
dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and cnf.find_extensions!.include?(File.extname(e)) }
|
73
129
|
debug("FIND FILEs IN #{d} END")
|
74
130
|
end
|
75
131
|
@@dir_list = dlist
|
132
|
+
update_search_idx
|
76
133
|
debug("END find files")
|
77
134
|
return @@dir_list
|
78
135
|
end
|
79
136
|
|
80
137
|
def filter_files(search_str)
|
138
|
+
puts "search list: #{@@dir_list.size}"
|
81
139
|
dir_hash = {}
|
82
140
|
|
141
|
+
res = @@idx.find(search_str)
|
142
|
+
resultarr = []
|
143
|
+
for (idx, score) in res
|
144
|
+
fn = @@dir_list[idx - 1]
|
145
|
+
puts "#{idx} #{score} #{fn}"
|
146
|
+
resultarr << [fn, score]
|
147
|
+
end
|
148
|
+
return resultarr
|
149
|
+
|
150
|
+
# Ripl.start :binding => binding
|
151
|
+
|
83
152
|
scores = Parallel.map(@@dir_list, in_threads: 8) do |file|
|
84
153
|
[file, srn_dst(search_str, file)]
|
85
154
|
end
|
@@ -95,4 +164,3 @@ class FileFinder
|
|
95
164
|
return dir_hash
|
96
165
|
end
|
97
166
|
end
|
98
|
-
|