vimamsa 0.1.8 → 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: 6000318b31060bff83029148c2cf47cc6ff8c5939d2fc1d54951a54e8b49a538
4
- data.tar.gz: 500cd81fe9bd605276a0802f182980c5a93d77ab5d2221548586673e85a85832
3
+ metadata.gz: ca98d0950bc33d6c918e17c2092489ac69d5e5b722d781fe0f83736ccdfabb82
4
+ data.tar.gz: f4347a60b616dc3ea2575e3fe53c59397bf90d84f44fed7c28f0d792e5fc900d
5
5
  SHA512:
6
- metadata.gz: 8b687b1b72df46bd9bc35622b239e9525e2dc15884f1066557e82c474e99c280577a32a3a7f60a776f5b6be0866dc86c79e2b364780413821a491160ad73875f
7
- data.tar.gz: d5e8da0e6263f74f27ee84781efdea5126411a68ace27d244da6c5b9203924196d10bbe91541319af91539089c6391dfadfde3f76cbac6f475b2002c1fbaa16c
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
@@ -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 != ""
@@ -80,7 +92,9 @@ def search_actions_update_callback(search_str = "")
80
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
 
@@ -102,7 +116,12 @@ 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] }
@@ -10,11 +10,13 @@ $buffer_history = [0]
10
10
 
11
11
  $update_highlight = false
12
12
 
13
+ $ifuncon = false
14
+
13
15
  class Buffer < String
14
16
 
15
17
  #attr_reader (:pos, :cpos, :lpos)
16
18
 
17
- attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang
19
+ attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :dirname, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang, :images
18
20
  attr_writer :call_func, :update_highlight
19
21
  attr_accessor :gui_update_highlight, :update_hl_startpos, :update_hl_endpos, :hl_queue, :syntax_parser, :highlights, :gui_reset_highlight, :is_parsing_syntax, :line_ends, :bt, :line_action_handler, :module, :active_kbd_mode, :title, :subtitle
20
22
 
@@ -24,10 +26,11 @@ class Buffer < String
24
26
  debug "Buffer.rb: def initialize"
25
27
  super(str)
26
28
 
29
+ @images = []
27
30
  @lang = nil
28
31
  @id = @@num_buffers
29
32
  @@num_buffers += 1
30
- gui_create_buffer(@id)
33
+ gui_create_buffer(@id, self)
31
34
  debug "NEW BUFFER fn=#{fname} ID:#{@id}"
32
35
 
33
36
  @module = nil
@@ -123,31 +126,31 @@ class Buffer < String
123
126
  end
124
127
 
125
128
  def view()
126
- # Get the VSourceView < GtkSource::View object corresponding to this buffer
129
+ # Get the VSourceView < GtkSource::View object corresponding to this buffer
127
130
  return vma.gui.buffers[@id]
128
131
  end
129
132
 
130
133
  def add_image(imgpath, pos)
131
134
  return if !is_legal_pos(pos)
132
135
 
133
- pixbuf = GdkPixbuf::Pixbuf.new(:file => imgpath)
134
-
135
- # puts GdkPixbuf::InterpType.constants
136
- # GdkPixbuf::InterpType::HYPER
137
- # https://docs.gtk.org/gdk-pixbuf/enum.InterpType.html#bilinear
138
- # https://docs.gtk.org/gdk-pixbuf/method.Pixbuf.scale_simple.html
139
- imglimit = view.visible_rect.width - 5
140
- if pixbuf.width > imglimit
141
- nwidth = imglimit
142
- nheight = (pixbuf.height * (imglimit.to_f / pixbuf.width)).to_i
143
- pixbuf = pixbuf.scale_simple(nwidth, nheight, GdkPixbuf::InterpType::HYPER)
144
- end
145
-
146
136
  vbuf = view.buffer
147
137
  itr = vbuf.get_iter_at(:offset => pos)
148
138
  itr2 = vbuf.get_iter_at(:offset => pos + 1)
149
139
  vbuf.delete(itr, itr2)
150
- vbuf.insert(itr, pixbuf)
140
+ anchor = vbuf.create_child_anchor(itr)
141
+
142
+ da = ResizableImage.new(imgpath, view)
143
+ view.add_child_at_anchor(da, anchor)
144
+ da.signal_connect "draw" do |widget, cr|
145
+ da.do_draw(widget, cr)
146
+ end
147
+
148
+ da.scale_image
149
+
150
+ vma.gui.handle_image_resize
151
+ @images << { :path => imgpath, :obj => da }
152
+
153
+ gui_set_current_buffer(@id)
151
154
  end
152
155
 
153
156
  def is_legal_pos(pos, op = :read)
@@ -179,6 +182,7 @@ class Buffer < String
179
182
  b = " \n"
180
183
  txt = a + b
181
184
  insert_txt_at(txt, lr.end + 1)
185
+ buf.view.handle_deltas
182
186
  imgpos = lr.end + 1 + a.size
183
187
  add_image(fname, imgpos)
184
188
  end
@@ -251,7 +255,7 @@ class Buffer < String
251
255
  if str[0..10] == "VMACRYPT001"
252
256
  @encrypted_str = str[11..-1]
253
257
  callback = proc { |x| decrypt_cur_buffer(x) }
254
- gui_one_input_action("Decrypt", "Password:", "decrypt", callback)
258
+ gui_one_input_action("Decrypt", "Password:", "decrypt", callback, { :hide => true })
255
259
  str = "ENCRYPTED"
256
260
  else
257
261
  # @crypt = nil
@@ -301,6 +305,8 @@ class Buffer < String
301
305
  @update_hl_endpos = self.size - 1
302
306
 
303
307
  gui_set_buffer_contents(@id, self.to_s)
308
+ @images = [] #TODO: if reload
309
+ hpt_scan_images(self)
304
310
 
305
311
  # add_hl_update(@update_hl_startpos, @update_hl_endpos)
306
312
  end
@@ -786,6 +792,10 @@ class Buffer < String
786
792
  return @pos == self.size
787
793
  end
788
794
 
795
+ def jump_to_pos(new_pos)
796
+ set_pos(new_pos)
797
+ end
798
+
789
799
  def set_pos(new_pos)
790
800
  if new_pos >= self.size
791
801
  @pos = self.size - 1 # TODO:??right side of last char
@@ -1060,14 +1070,17 @@ class Buffer < String
1060
1070
  if wtype == :url
1061
1071
  open_url(word)
1062
1072
  elsif wtype == :linepointer
1063
- debug word.inspect
1064
- jump_to_file(word[0], word[1])
1073
+ jump_to_file(word[0], word[1], word[2])
1065
1074
  elsif wtype == :textfile
1066
1075
  open_existing_file(word)
1067
1076
  elsif wtype == :file
1068
1077
  open_with_default_program(word)
1069
1078
  elsif wtype == :hpt_link
1070
1079
  open_existing_file(word)
1080
+ elsif wtype == :help
1081
+ if word == "keybindings"
1082
+ call_action(:show_key_bindings)
1083
+ end
1071
1084
  else
1072
1085
  #TODO
1073
1086
  end
@@ -1128,7 +1141,7 @@ class Buffer < String
1128
1141
  word_end = pos if word_end == nil
1129
1142
  word = self[word_start..word_end]
1130
1143
  debug "'WORD: #{word}'"
1131
- message("'#{word}'")
1144
+ # message("Open link #{word}")
1132
1145
  linep = get_file_line_pointer(word)
1133
1146
  debug "linep'#{linep}'"
1134
1147
  path = File.expand_path(word)
@@ -1147,6 +1160,8 @@ class Buffer < String
1147
1160
  elsif linep != nil
1148
1161
  wtype = :linepointer
1149
1162
  word = linep
1163
+ elsif m = word.match(/⟦help:(.*)⟧/)
1164
+ return [m[1], :help]
1150
1165
  else
1151
1166
  fn = hpt_check_cur_word(word)
1152
1167
  if !fn.nil?
@@ -1163,19 +1178,6 @@ class Buffer < String
1163
1178
  handle_word(wnfo)
1164
1179
  end
1165
1180
 
1166
- def get_cur_word()
1167
- wem = get_word_end_marks(@pos, @pos + 200)
1168
- wsm = get_word_start_marks(@pos - 200, @pos)
1169
- word_start = wsm[-1]
1170
- word_end = wem[0]
1171
- word_start = pos if word_start == nil
1172
- word_end = pos if word_end == nil
1173
- word = self[word_start..word_end]
1174
- debug "'#{word}'"
1175
- message("'#{word}'")
1176
- #debug wm
1177
- end
1178
-
1179
1181
  def jump_to_next_instance_of_word()
1180
1182
  if $kbd.last_action == $kbd.cur_action and @current_word != nil
1181
1183
  # debug "REPEATING *"
@@ -1710,21 +1712,23 @@ class Buffer < String
1710
1712
  end
1711
1713
 
1712
1714
  Thread.new {
1713
- File.open(fpath, mode) do |io|
1714
- #io.set_encoding(self.encoding)
1715
-
1716
- begin
1717
- io.write(contents)
1718
- rescue Encoding::UndefinedConversionError => ex
1719
- # this might happen when trying to save UTF-8 as US-ASCII
1720
- # so just warn, try to save as UTF-8 instead.
1721
- warn("Saving as UTF-8 because of: #{ex.class}: #{ex}")
1722
- io.rewind
1723
-
1724
- io.set_encoding(Encoding::UTF_8)
1725
- io.write(contents)
1726
- #self.encoding = Encoding::UTF_8
1727
- end
1715
+ begin
1716
+ io = File.open(fpath, mode)
1717
+ io.set_encoding(self.encoding)
1718
+ io.write(contents)
1719
+ io.close
1720
+ rescue Encoding::UndefinedConversionError => ex
1721
+ puts "Encoding::UndefinedConversionError"
1722
+ # this might happen when trying to save UTF-8 as US-ASCII
1723
+ # so just warn, try to save as UTF-8 instead.
1724
+ warn("Saving as UTF-8 because of: #{ex.class}: #{ex}")
1725
+ io.rewind
1726
+
1727
+ io.set_encoding(Encoding::UTF_8)
1728
+ io.write(contents)
1729
+ rescue Errno::EACCES => ex
1730
+ message("File #{fpath} not writeable")
1731
+ #TODO: show message box
1728
1732
  end
1729
1733
  sleep 3
1730
1734
  }
data/lib/vimamsa/debug.rb CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  $log_messages = []
24
24
 
25
- def log_message(message,vlevel)
25
+ def log_message(message,vlevel=1)
26
26
  puts message if conf("log.verbose") >= vlevel
27
27
  $log_messages << message
28
28
  end
@@ -9,7 +9,6 @@ class EasyJump
9
9
  end
10
10
 
11
11
  def initialize()
12
- # message "EASY JUMP"
13
12
  visible_range = get_visible_area()
14
13
  visible_text = buf[visible_range[0]..visible_range[1]]
15
14
  wsmarks = scan_word_start_marks(visible_text)
@@ -17,12 +16,24 @@ class EasyJump
17
16
  lsh = Hash[line_starts.collect { |x| [x, true] }]
18
17
  wsmh = Hash[wsmarks.collect { |x| [x, true] }]
19
18
 
19
+ # Exclude work starts that are too close to start of line
20
20
  wsmarks.select! { |x|
21
21
  r = true
22
22
  r = false if lsh[x] or lsh[x - 1] or lsh[x - 2]
23
23
  r
24
24
  }
25
25
 
26
+ # Exclude those word start positions that are too close to each other
27
+ wsmarks.sort!
28
+ wsm2 = [wsmarks[0]]
29
+ for i in 1..(wsmarks.size - 1)
30
+ if (wsmarks[i] - wsm2[-1]) >= 4 or visible_text[wsm2[-1]..wsmarks[i]].include?("\n")
31
+
32
+ wsm2 << wsmarks[i]
33
+ end
34
+ end
35
+ wsmarks = wsm2
36
+
26
37
  linestart_buf = (line_starts).collect { |x| x + visible_range[0] }
27
38
  wsmarks_buf = (wsmarks).collect { |x| x + visible_range[0] }
28
39
 
@@ -63,25 +74,11 @@ class EasyJump
63
74
  end
64
75
 
65
76
  def easy_jump_draw()
66
- # debug @jump_sequence.inspect
67
- # debug @easy_jump_wsmarks.inspect
68
77
  vma.gui.start_overlay_draw
69
78
  for i in 0..(@easy_jump_wsmarks.size - 1)
70
- vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i])
79
+ vma.gui.overlay_draw_text(@jump_sequence[i], @easy_jump_wsmarks[i])
71
80
  end
72
81
  vma.gui.end_overlay_draw
73
-
74
- return
75
- return if @jump_sequence.empty?
76
- debug "EASY JUMP DRAW"
77
- screen_cord = cpp_function_wrapper(0, [@easy_jump_wsmarks])
78
- screen_cord = screen_cord[1..@jump_sequence.size]
79
- screen_cord.each_with_index { |point, i|
80
- mark_str = @jump_sequence[i]
81
- #debug "draw #{point[0]}x#{point[1]}"
82
- draw_text(mark_str, point[0] + 3, point[1])
83
- #break if m > @cpos
84
- }
85
82
  end
86
83
 
87
84
  def make_jump_sequence(num_items)
@@ -158,8 +155,6 @@ class EasyJump
158
155
  }
159
156
  }
160
157
 
161
- #printf("Size of sequence: %d\n",sequence.size)
162
- #debug sequence.inspect
163
158
  return sequence
164
159
  end
165
160
  end