vimamsa 0.1.7 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/custom_example.rb +47 -0
- data/demo.txt +25 -0
- data/lang/hyperplaintext.lang +9 -25
- data/lib/vimamsa/ack.rb +55 -9
- data/lib/vimamsa/actions.rb +27 -8
- data/lib/vimamsa/buffer.rb +120 -82
- data/lib/vimamsa/buffer_list.rb +48 -30
- data/lib/vimamsa/buffer_manager.rb +83 -0
- data/lib/vimamsa/conf.rb +21 -0
- data/lib/vimamsa/debug.rb +11 -10
- data/lib/vimamsa/easy_jump.rb +15 -20
- data/lib/vimamsa/editor.rb +100 -85
- data/lib/vimamsa/encrypt.rb +3 -3
- data/lib/vimamsa/file_finder.rb +6 -9
- data/lib/vimamsa/file_history.rb +3 -3
- data/lib/vimamsa/file_manager.rb +16 -13
- data/lib/vimamsa/gui.rb +95 -90
- data/lib/vimamsa/gui_image.rb +43 -0
- data/lib/vimamsa/gui_menu.rb +11 -2
- data/lib/vimamsa/gui_select_window.rb +16 -13
- data/lib/vimamsa/gui_sourceview.rb +66 -38
- data/lib/vimamsa/hyper_plain_text.rb +40 -21
- data/lib/vimamsa/key_actions.rb +38 -13
- data/lib/vimamsa/key_binding_tree.rb +50 -126
- data/lib/vimamsa/key_bindings_vimlike.rb +26 -24
- data/lib/vimamsa/macro.rb +5 -5
- data/lib/vimamsa/main.rb +3 -3
- data/lib/vimamsa/rbvma.rb +22 -18
- data/lib/vimamsa/search.rb +2 -2
- data/lib/vimamsa/search_replace.rb +25 -22
- data/lib/vimamsa/text_transforms.rb +3 -1
- data/lib/vimamsa/util.rb +34 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +5 -0
- data/sheep.jpg +0 -0
- data/styles/dark.xml +1 -0
- data/styles/molokai_edit.xml +1 -1
- data/vimamsa.gemspec +2 -2
- metadata +16 -11
- data/lib/vimamsa/gui_gtk_sourceview.rb +0 -294
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bfc14cb231bc93909b4866e08cbd4503b4f4444527c0b65b4a9edb11d863faa0
|
4
|
+
data.tar.gz: 7b63cdbff33cdcdbf7d6f5d025d8ec13a6f39a3ee937f716ec990bba743f3239
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2176d7aaa01be873deb8687cf2b8d75044edba4ccfc3685cf334cae973c93e15ba6dc47d9667a9848209329b043f2ba8daf049f4340ddb130538584e17b5a5de
|
7
|
+
data.tar.gz: afcdd6c30018dc971fc165d8ed6f63f5b2ccf109a167d0ec39cf03c150ac03d7765c4c0d83e3a6ceabaae74cf44f759144dbe5e2d9aee1b191182ca7fb622035
|
data/README.md
CHANGED
@@ -26,11 +26,16 @@ Packages for optional features:
|
|
26
26
|
sudo apt install ack-grep clang-format
|
27
27
|
```
|
28
28
|
|
29
|
-
For customization, edit
|
29
|
+
For customization, edit ~/.vimamsa/custom.rb
|
30
|
+
|
31
|
+
## Screenshots
|
32
|
+
|
33
|
+
<a href="https://samiddhi.net/vimamsa/screenshot1.png" target="_blank"><img src="https://samiddhi.net/vimamsa/screenshot1.png" width="400"/></a>
|
34
|
+
<a href="https://samiddhi.net/vimamsa/screenshot2.png" target="_blank"><img src="https://samiddhi.net/vimamsa/screenshot2.png" width="400"/></a>
|
30
35
|
|
31
36
|
## Key bindings
|
32
37
|
|
33
|
-
Key bindings are very much like in VIm. For details, see file lib/vimamsa/key_bindings.rb and lib/vimamsa/
|
38
|
+
Key bindings are very much like in VIm. For details, see file lib/vimamsa/key_bindings.rb and lib/vimamsa/key_bindings_vimlike.rb
|
34
39
|
|
35
40
|
Keys that work somewhat similarly as in Vim:
|
36
41
|
|
@@ -72,7 +77,7 @@ ctrl-x means press and hold ctrl key, press x
|
|
72
77
|
</td></tr>
|
73
78
|
<tr> <td style="text-align:center;">,b</td> <td style="text-align:left;"> Switch buffer (jump to other open file)</td></tr>
|
74
79
|
<tr> <td style="text-align:center;">,g</td> <td style="text-align:left;">search for input string inside current buffer</td></tr>
|
75
|
-
<tr> <td style="text-align:center;">,f</td> <td style="text-align:left;">
|
80
|
+
<tr> <td style="text-align:center;">,f</td> <td style="text-align:left;">File finder</td></tr>
|
76
81
|
<tr> <td style="text-align:center;">space c</td> <td style="text-align:left;">insert character "c"</td></tr>
|
77
82
|
</tbody>
|
78
83
|
</table>
|
@@ -116,7 +121,7 @@ ctrl-x means press and hold ctrl key, press x
|
|
116
121
|
</tbody>
|
117
122
|
</table>
|
118
123
|
|
119
|
-
Bindings can be customized in ~/.
|
124
|
+
Bindings can be customized in ~/.vimamsa/custom.rb
|
120
125
|
For example, to bind ctrl-n to action "create new file":
|
121
126
|
```
|
122
127
|
bindkey 'C ctrl-n', 'create_new_file()'
|
data/custom_example.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Examples for customization
|
2
|
+
|
3
|
+
# Extract unique words
|
4
|
+
# c = Converter.new(lambda { |x| h = {}; x.split(/\s+/).each { |y| h[y] = 1 }; h.keys.join(" ") }, :lambda, :uniqwords)
|
5
|
+
|
6
|
+
# Eval selected text as ruby code (e.g. use as calculator)
|
7
|
+
# bindkey "V , e", "vma.buf.convert_selected_text(:eval)"
|
8
|
+
# syntax: bindkey "mode key1 key2 ..."
|
9
|
+
|
10
|
+
# Execute in new gnome-terminal tab
|
11
|
+
# bindkey "C , , t", :execute_current_line_in_terminal
|
12
|
+
|
13
|
+
# setcnf :tab_width, 4
|
14
|
+
|
15
|
+
# Open this file every time the program starts
|
16
|
+
# setcnf :startup_file, "~/Documents/startup.txt"
|
17
|
+
|
18
|
+
def insert_date()
|
19
|
+
# $buffer.insert_txt("#{DateTime.now().strftime("==========\n%Y-%m-%d")}\n")
|
20
|
+
vma.buf.insert_txt("#{DateTime.now().strftime("%Y-%m-%d")}\n")
|
21
|
+
end
|
22
|
+
|
23
|
+
def collect_c_header()
|
24
|
+
# Matches e.g.:
|
25
|
+
# static void funcname(parameters)
|
26
|
+
s = buf.scan(/^(([\w]+\s*){1,3} \w+\((.|\n)+?\))/).collect { |x| x[0] + ";" }.join("\n")
|
27
|
+
buf.insert_txt(s)
|
28
|
+
end
|
29
|
+
reg_act(:collect_c_header, proc { collect_c_header }, "Collect function definitions for c header file")
|
30
|
+
|
31
|
+
# Extract all numbers from txt selection
|
32
|
+
c = Converter.new(lambda { |x| x.scan(/([\+\-]?\d+(\.\d+)?)/).collect { |x| x[0] }.join(" ") }, :lambda, :getnums)
|
33
|
+
# (find converter using action search input:"conv getnum")
|
34
|
+
|
35
|
+
|
36
|
+
def insert_lorem_ipsum()
|
37
|
+
lorem_ipsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
|
38
|
+
|
39
|
+
Curabitur pretium tincidunt lacus. Nulla gravida orci a odio. Nullam varius, turpis et commodo pharetra, est eros bibendum elit, nec luctus magna felis sollicitudin mauris. Integer in mauris eu nibh euismod gravida. Duis ac tellus et risus vulputate vehicula. Donec lobortis risus a elit. Etiam tempor. Ut ullamcorper, ligula eu tempor congue, eros est euismod turpis, id tincidunt sapien risus a quam. Maecenas fermentum consequat mi. Donec fermentum. Pellentesque malesuada nulla a mi. Duis sapien sem, aliquet nec, commodo eget, consequat quis, neque. Aliquam faucibus, elit ut dictum aliquet, felis nisl adipiscing sapien, sed malesuada diam lacus eget erat. Cras mollis scelerisque nunc. Nullam arcu. Aliquam consequat. Curabitur augue lorem, dapibus quis, laoreet et, pretium ac, nisi. Aenean magna nisl, mollis quis, molestie eu, feugiat in, orci. In hac habitasse platea dictumst."
|
40
|
+
|
41
|
+
vma.buf.insert_txt(lorem_ipsum)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Find with action search ([C] , , s)
|
45
|
+
reg_act(:insert_lorem_ipsum, proc { insert_lorem_ipsum }, "Insert lorem ipsum")
|
46
|
+
|
47
|
+
|
data/demo.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
❙Demo❙
|
2
|
+
|
3
|
+
◼ General
|
4
|
+
Links: press ⦁enter⦁ while cursor on
|
5
|
+
⟦README.md⟧
|
6
|
+
|
7
|
+
Extension .txt can be omitted:
|
8
|
+
⟦demo⟧
|
9
|
+
|
10
|
+
◼◼ Level 2
|
11
|
+
◼◼◼ Level 3
|
12
|
+
◼◼◼◼ Level 4
|
13
|
+
◼ Help
|
14
|
+
⟦help:keybindings⟧
|
15
|
+
|
16
|
+
Customizations:
|
17
|
+
⟦~/.vimamsa/custom.rb⟧
|
18
|
+
|
19
|
+
◼ Images
|
20
|
+
Images work in .txt-files by drag&drop. (experimental)
|
21
|
+
⟦img:sheep.jpg⟧
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
data/lang/hyperplaintext.lang
CHANGED
@@ -1,26 +1,4 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<!--
|
3
|
-
|
4
|
-
This file is part of GtkSourceView
|
5
|
-
|
6
|
-
Authors: Marco Barisione, Emanuele Aina
|
7
|
-
Copyright (C) 2005-2007 Marco Barisione <barisione@gmail.com>
|
8
|
-
Copyright (C) 2005-2007 Emanuele Aina
|
9
|
-
|
10
|
-
GtkSourceView is free software; you can redistribute it and/or
|
11
|
-
modify it under the terms of the GNU Lesser General Public
|
12
|
-
License as published by the Free Software Foundation; either
|
13
|
-
version 2.1 of the License, or (at your option) any later version.
|
14
|
-
|
15
|
-
GtkSourceView is distributed in the hope that it will be useful,
|
16
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
18
|
-
Lesser General Public License for more details.
|
19
|
-
|
20
|
-
You should have received a copy of the GNU Lesser General Public License
|
21
|
-
along with this library; if not, see <http://www.gnu.org/licenses/>.
|
22
|
-
|
23
|
-
-->
|
24
2
|
<language id="hyperplaintext" name="HyperPlainText" version="2.0" _section="Source">
|
25
3
|
<metadata>
|
26
4
|
<property name="mimetypes">text/x-c;text/x-csrc;image/x-xpixmap</property>
|
@@ -32,9 +10,10 @@
|
|
32
10
|
<style id="title" name="title" map-to="def:title"/>
|
33
11
|
<style id="hyperlink" name="hyperlink" map-to="def:hyperlink"/>
|
34
12
|
<style id="heading1" name="heading1" map-to="def:heading1"/>
|
35
|
-
<style id="heading2" name="
|
36
|
-
<style id="heading3" name="
|
37
|
-
<style id="heading4" name="
|
13
|
+
<style id="heading2" name="heading2" map-to="def:heading2"/>
|
14
|
+
<style id="heading3" name="heading4" map-to="def:heading3"/>
|
15
|
+
<style id="heading4" name="heading4" map-to="def:heading4"/>
|
16
|
+
<style id="bold" name="bold" map-to="def:bold"/>
|
38
17
|
<style id="string" name="String" map-to="def:string"/>
|
39
18
|
<style id="floating-point" name="Floating point number" map-to="def:floating-point"/>
|
40
19
|
</styles>
|
@@ -86,6 +65,10 @@
|
|
86
65
|
<context id="title" style-ref="title">
|
87
66
|
<match>(^❙.*❙)</match>
|
88
67
|
</context>
|
68
|
+
|
69
|
+
<context id="bold" style-ref="bold">
|
70
|
+
<match>(⦁.*⦁)</match>
|
71
|
+
</context>
|
89
72
|
|
90
73
|
<context id="hyperlink" style-ref="hyperlink">
|
91
74
|
<match>(⟦.*⟧)</match>
|
@@ -121,6 +104,7 @@
|
|
121
104
|
<context ref="heading2"/>
|
122
105
|
<context ref="heading3"/>
|
123
106
|
<context ref="heading4"/>
|
107
|
+
<context ref="bold"/>
|
124
108
|
<context ref="float"/>
|
125
109
|
</include>
|
126
110
|
</context>
|
data/lib/vimamsa/ack.rb
CHANGED
@@ -1,26 +1,73 @@
|
|
1
1
|
# Interface for ack! https://beyondgrep.com/
|
2
2
|
|
3
|
+
class FileContentSearch
|
4
|
+
def self.start_gui()
|
5
|
+
search_paths = vma.get_content_search_paths.join("<br/>")
|
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
|
+
callback = proc { |x| FileContentSearch.search_buffer(x) }
|
16
|
+
gui_one_input_action(nfo, "Search:", "search", callback)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.search_buffer(instr, b = nil)
|
20
|
+
# instr = Shellwords.escape(instr)
|
21
|
+
fext = Set[".txt"]
|
22
|
+
dlist = []
|
23
|
+
for d in vma.get_content_search_paths
|
24
|
+
# Search for files with extension .txt and size < 200k
|
25
|
+
dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and fext.include?(File.extname(e)) and File.size(e) < 200e3 }
|
26
|
+
end
|
27
|
+
bufstr = "Results:\n\n"
|
28
|
+
for fp in dlist
|
29
|
+
txt = read_file("",fp)
|
30
|
+
ind = scan_indexes(txt, /#{instr}/i)
|
31
|
+
if !ind.empty?
|
32
|
+
for x in ind
|
33
|
+
starti = x - 30
|
34
|
+
endi = x + 30
|
35
|
+
starti = 0 if starti < 0
|
36
|
+
endi = txt.size - 1 if endi >= txt.size
|
37
|
+
bufstr << "#{fp}:c#{x} "
|
38
|
+
bufstr << txt[starti..endi].gsub("\n"," ")
|
39
|
+
bufstr << "\n"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
create_new_file(nil, bufstr)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
3
47
|
def gui_ack()
|
48
|
+
search_paths = vma.get_content_search_paths.join("<br/>")
|
49
|
+
|
4
50
|
nfo = "<html><h2>Search contents of all files using ack</h2>
|
5
51
|
<div style='width:300px'>
|
6
52
|
<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>"
|
7
|
-
|
53
|
+
|
8
54
|
nfo = "<span size='x-large'>Search contents of all files using ack</span>
|
55
|
+
Will search the following directories:
|
56
|
+
#{search_paths}
|
9
57
|
|
10
|
-
|
58
|
+
<span>Hint: add empty file named .vma_project to directories you want to search in.
|
11
59
|
If .vma_project exists in parent directory of current file, searches within that directory.
|
12
60
|
</span>"
|
13
|
-
|
14
|
-
|
15
|
-
callback = proc{|x| ack_buffer(x)}
|
61
|
+
|
62
|
+
callback = proc { |x| ack_buffer(x) }
|
16
63
|
gui_one_input_action(nfo, "Search:", "search", callback)
|
17
64
|
end
|
18
65
|
|
19
66
|
def ack_buffer(instr, b = nil)
|
20
|
-
instr =
|
67
|
+
instr = Shellwords.escape(instr)
|
21
68
|
bufstr = ""
|
22
|
-
for path in
|
23
|
-
bufstr += run_cmd("ack -Q --type-add=gd=.gd -
|
69
|
+
for path in vma.get_content_search_paths
|
70
|
+
bufstr += run_cmd("ack -Q --type-add=gd=.gd -ki --nohtml --nojs --nojson #{instr} #{path}")
|
24
71
|
end
|
25
72
|
if bufstr.size > 5
|
26
73
|
create_new_file(nil, bufstr)
|
@@ -28,4 +75,3 @@ def ack_buffer(instr, b = nil)
|
|
28
75
|
message("No results for input:#{instr}")
|
29
76
|
end
|
30
77
|
end
|
31
|
-
|
data/lib/vimamsa/actions.rb
CHANGED
@@ -28,7 +28,7 @@ def reg_act(id, callfunc, name = "", opt = {})
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def missing_callfunc
|
31
|
-
|
31
|
+
debug "missing_callfunc"
|
32
32
|
end
|
33
33
|
|
34
34
|
#TODO: remove
|
@@ -47,10 +47,12 @@ end
|
|
47
47
|
|
48
48
|
def search_actions()
|
49
49
|
l = []
|
50
|
+
opt = { :title => "Search actions.", :desc => "Fuzzy search for actions. <up> or <down> to change selcted. <enter> to select current." }
|
50
51
|
$select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
|
51
52
|
gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
|
52
53
|
"search_actions_select_callback",
|
53
|
-
"search_actions_update_callback"
|
54
|
+
"search_actions_update_callback",
|
55
|
+
opt)
|
54
56
|
end
|
55
57
|
|
56
58
|
$item_list = []
|
@@ -63,6 +65,16 @@ def search_actions_update_callback(search_str = "")
|
|
63
65
|
act = $actions[act_id]
|
64
66
|
item = {}
|
65
67
|
item[:key] = ""
|
68
|
+
|
69
|
+
for mode_str in ["C", "V"]
|
70
|
+
c_kbd = vma.kbd.act_bindings[mode_str][act_id]
|
71
|
+
if c_kbd.class == String
|
72
|
+
item[:key] = "[#{mode_str} #{c_kbd}] "
|
73
|
+
break
|
74
|
+
end
|
75
|
+
end
|
76
|
+
# c_kbd = vma.kbd.act_bindings[mode_str][nfo[:action]]
|
77
|
+
# Ripl.start :binding => binding
|
66
78
|
item[:action] = act_id
|
67
79
|
item[:str] = act_id.to_s
|
68
80
|
if $actions[act_id].method_name != ""
|
@@ -74,13 +86,15 @@ def search_actions_update_callback(search_str = "")
|
|
74
86
|
item_list = item_list2
|
75
87
|
|
76
88
|
a = filter_items(item_list, 0, search_str)
|
77
|
-
|
89
|
+
debug a.inspect
|
78
90
|
|
79
91
|
r = a.collect { |x| [x[0][0], 0, x] }
|
80
|
-
|
92
|
+
debug r.inspect
|
81
93
|
$item_list = r
|
82
94
|
|
83
|
-
|
95
|
+
# Ripl.start :binding => binding
|
96
|
+
|
97
|
+
r = a.collect { |x| ["#{x[0][:key]}#{x[0][:str]}", 0, x] }
|
84
98
|
return r
|
85
99
|
end
|
86
100
|
|
@@ -88,13 +102,13 @@ def search_actions_select_callback(search_str, idx)
|
|
88
102
|
item = $item_list[idx][2]
|
89
103
|
acc = item[0][:action]
|
90
104
|
|
91
|
-
|
105
|
+
debug "Selected:" + acc.to_s
|
92
106
|
gui_select_window_close(0)
|
93
107
|
|
94
108
|
if acc.class == String
|
95
109
|
eval(acc)
|
96
110
|
elsif acc.class == Symbol
|
97
|
-
|
111
|
+
debug "Symbol"
|
98
112
|
call(acc)
|
99
113
|
end
|
100
114
|
end
|
@@ -102,11 +116,16 @@ end
|
|
102
116
|
def filter_items(item_list, item_key, search_str)
|
103
117
|
# Ripl.start :binding => binding
|
104
118
|
item_hash = {}
|
119
|
+
puts item_list.inspect
|
105
120
|
scores = Parallel.map(item_list, in_threads: 8) do |item|
|
121
|
+
if item[:str].class != String
|
122
|
+
puts item.inspect
|
123
|
+
exit!
|
124
|
+
end
|
106
125
|
[item, srn_dst(search_str, item[:str])]
|
107
126
|
end
|
108
127
|
scores.sort_by! { |x| -x[1] }
|
109
|
-
|
128
|
+
debug scores.inspect
|
110
129
|
scores = scores[0..30]
|
111
130
|
|
112
131
|
return scores
|