vimamsa 0.1.6 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82ad35212b7d75bfd5b702943ff3ed3180f7f1bd0b3912840e9ecfdf6126e467
4
- data.tar.gz: 8eff2ee35e1ecc2d791ff1fbf4a881e6aada9b38d35ce11e356b316b536bc642
3
+ metadata.gz: ca98d0950bc33d6c918e17c2092489ac69d5e5b722d781fe0f83736ccdfabb82
4
+ data.tar.gz: f4347a60b616dc3ea2575e3fe53c59397bf90d84f44fed7c28f0d792e5fc900d
5
5
  SHA512:
6
- metadata.gz: 440d5d3b5b537fc9d3848d0f187df77dd045cde34643db356cd88ae5591e4e8c1c8596aac50f170ef7124dbd8784deddaff2d436f46dac0a8a180ccfeae4a9aa
7
- data.tar.gz: c058e9db468553e29f617186ea0d65d04014307b7797c5dad013b5b3738fab57c0f7a44e7401ae9606e88581ac4f557fad3665c6dc8f784781619a310c114b95
6
+ metadata.gz: f3254d05d66c7dd92f79d9393986da65f9401e3b48627c620c7c9bf0cfec20c039b640a72cd70100f01757637a8af17a645228e3f0f789a0f09c6fc6ecf710ea
7
+ data.tar.gz: 2391bb4e5a93ae86f180a7138799323dbe01bf8ac94385d8f523f109025a13511ea3ba10a31b9b9cedd02ee495822d2b162dda6bab2b8f8b0a2c61f068f6b42c
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/main.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
+
@@ -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="heading1" map-to="def:heading2"/>
36
- <style id="heading3" name="heading1" map-to="def:heading3"/>
37
- <style id="heading4" name="heading1" map-to="def:heading4"/>
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,25 +1,77 @@
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 = "<html><h2>Search contents of text files</h2>
8
+ <div style='width:300px'>
9
+ <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>"
10
+
11
+ nfo = "<span size='x-large'>Search contents of all files using ack</span>
12
+ Will search the following directories:
13
+ #{search_paths}
14
+
15
+ <span>Hint: add empty file named .vma_project to directories you want to search in.
16
+ If .vma_project exists in parent directory of current file, searches within that directory.
17
+ </span>"
18
+
19
+ callback = proc { |x| FileContentSearch.search_buffer(x) }
20
+ gui_one_input_action(nfo, "Search:", "search", callback)
21
+ end
22
+
23
+ def self.search_buffer(instr, b = nil)
24
+ # instr = Shellwords.escape(instr)
25
+ fext = Set[".txt"]
26
+ dlist = []
27
+ for d in vma.get_content_search_paths
28
+ dlist = dlist + Dir.glob("#{d}/**/*").select { |e| File.file?(e) and fext.include?(File.extname(e)) and File.size(e) < 200e3 }
29
+ end
30
+ bufstr = "Results:\n\n"
31
+ for fp in dlist
32
+ txt = read_file("",fp)
33
+ ind = scan_indexes(txt, /#{instr}/i)
34
+ if !ind.empty?
35
+ for x in ind
36
+ # Ripl.start :binding => binding
37
+
38
+ starti = x - 30
39
+ endi = x + 30
40
+ starti = 0 if starti < 0
41
+ endi = txt.size - 1 if endi >= txt.size
42
+ bufstr << "#{fp}:c#{x} "
43
+ bufstr << txt[starti..endi].gsub("\n"," ")
44
+ bufstr << "\n"
45
+ end
46
+ end
47
+ end
48
+ create_new_file(nil, bufstr)
49
+ end
50
+ end
51
+
3
52
  def gui_ack()
53
+ search_paths = vma.get_content_search_paths.join("<br/>")
54
+
4
55
  nfo = "<html><h2>Search contents of all files using ack</h2>
5
56
  <div style='width:300px'>
6
57
  <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
-
58
+
8
59
  nfo = "<span size='x-large'>Search contents of all files using ack</span>
60
+ Will search the following directories:
61
+ #{search_paths}
9
62
 
10
- <span>Hint: add empty file named .vma_project to directories you want to search in.
63
+ <span>Hint: add empty file named .vma_project to directories you want to search in.
11
64
  If .vma_project exists in parent directory of current file, searches within that directory.
12
65
  </span>"
13
-
14
-
15
- callback = proc{|x| ack_buffer(x)}
66
+
67
+ callback = proc { |x| ack_buffer(x) }
16
68
  gui_one_input_action(nfo, "Search:", "search", callback)
17
69
  end
18
70
 
19
71
  def ack_buffer(instr, b = nil)
20
- instr = instr.gsub("'", ".") # TODO
72
+ instr = Shellwords.escape(instr)
21
73
  bufstr = ""
22
- for path in $vma.get_content_search_paths
74
+ for path in vma.get_content_search_paths
23
75
  bufstr += run_cmd("ack -Q --type-add=gd=.gd -k --nohtml --nojs --nojson '#{instr}' #{path}")
24
76
  end
25
77
  if bufstr.size > 5
@@ -29,3 +81,34 @@ def ack_buffer(instr, b = nil)
29
81
  end
30
82
  end
31
83
 
84
+ def gui_ack()
85
+ search_paths = vma.get_content_search_paths.join("<br/>")
86
+
87
+ nfo = "<html><h2>Search contents of all files using ack</h2>
88
+ <div style='width:300px'>
89
+ <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>"
90
+
91
+ nfo = "<span size='x-large'>Search contents of all files using ack</span>
92
+ Will search the following directories:
93
+ #{search_paths}
94
+
95
+ <span>Hint: add empty file named .vma_project to directories you want to search in.
96
+ If .vma_project exists in parent directory of current file, searches within that directory.
97
+ </span>"
98
+
99
+ callback = proc { |x| ack_buffer(x) }
100
+ gui_one_input_action(nfo, "Search:", "search", callback)
101
+ end
102
+
103
+ def ack_buffer(instr, b = nil)
104
+ instr = Shellwords.escape(instr)
105
+ bufstr = ""
106
+ for path in vma.get_content_search_paths
107
+ bufstr += run_cmd("ack -Q --type-add=gd=.gd -ki --nohtml --nojs --nojson #{instr} #{path}")
108
+ end
109
+ if bufstr.size > 5
110
+ create_new_file(nil, bufstr)
111
+ else
112
+ message("No results for input:#{instr}")
113
+ end
114
+ end
@@ -28,7 +28,7 @@ def reg_act(id, callfunc, name = "", opt = {})
28
28
  end
29
29
 
30
30
  def missing_callfunc
31
- puts "missing_callfunc"
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
- puts a.inspect
89
+ debug a.inspect
78
90
 
79
91
  r = a.collect { |x| [x[0][0], 0, x] }
80
- puts r.inspect
92
+ debug r.inspect
81
93
  $item_list = r
82
94
 
83
- r = a.collect { |x| ["[#{x[0][:key]}] #{x[0][:str]}", 0, x] }
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
- puts "Selected:" + acc.to_s
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
- puts "Symbol"
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
- puts scores.inspect
128
+ debug scores.inspect
110
129
  scores = scores[0..30]
111
130
 
112
131
  return scores