vimamsa 0.1.7 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,9 @@
1
1
  def gui_select_update_window(item_list, jump_keys, select_callback, update_callback, opt={})
2
2
  $selup = SelectUpdateWindow.new(nil, item_list, jump_keys, select_callback, update_callback, opt)
3
3
  $selup.run
4
+ # opt fields:
5
+ # :title
6
+ # :desc
4
7
  end
5
8
 
6
9
  class SelectUpdateWindow
@@ -8,7 +11,7 @@ class SelectUpdateWindow
8
11
  COLUMN_DESCRIPTION = 1
9
12
 
10
13
  def update_item_list(item_list)
11
- # puts item_list.inspect
14
+ # debug item_list.inspect
12
15
  @model.clear
13
16
  for item in item_list
14
17
  iter = @model.append
@@ -17,7 +20,7 @@ class SelectUpdateWindow
17
20
  else
18
21
  v = ["", item[0]]
19
22
  end
20
- puts v.inspect
23
+ debug v.inspect
21
24
  iter.set_values(v)
22
25
  end
23
26
 
@@ -46,10 +49,10 @@ class SelectUpdateWindow
46
49
  @selected_row = 0
47
50
  @opt = opt
48
51
 
49
- puts item_list.inspect
52
+ debug item_list.inspect
50
53
  @update_callback = method(update_callback)
51
54
  @select_callback = method(select_callback)
52
- # puts @update_callback_m.call("").inspect
55
+ # debug @update_callback_m.call("").inspect
53
56
 
54
57
  vbox = Gtk::Box.new(:vertical, 8)
55
58
  vbox.margin = 8
@@ -72,21 +75,21 @@ class SelectUpdateWindow
72
75
  update_item_list(item_list)
73
76
 
74
77
  @window.signal_connect("key-press-event") do |_widget, event|
75
- # puts "KEYPRESS 1"
78
+ # debug "KEYPRESS 1"
76
79
  @entry.handle_event(event)
77
80
  end
78
81
 
79
82
  @entry.signal_connect("key_press_event") do |widget, event|
80
- # puts "KEYPRESS 2"
83
+ # debug "KEYPRESS 2"
81
84
  if event.keyval == Gdk::Keyval::KEY_Down
82
- puts "DOWN"
85
+ debug "DOWN"
83
86
  set_selected_row(@selected_row + 1)
84
87
  # fixed = iter[COLUMN_FIXED]
85
88
 
86
89
  true
87
90
  elsif event.keyval == Gdk::Keyval::KEY_Up
88
91
  set_selected_row(@selected_row - 1)
89
- puts "UP"
92
+ debug "UP"
90
93
  true
91
94
  elsif event.keyval == Gdk::Keyval::KEY_Return
92
95
  path = Gtk::TreePath.new(@selected_row.to_s)
@@ -94,7 +97,7 @@ class SelectUpdateWindow
94
97
  ret = iter[1]
95
98
  @select_callback.call(ret, @selected_row)
96
99
  @window.destroy
97
- # puts iter[1].inspect
100
+ # debug iter[1].inspect
98
101
  true
99
102
  elsif event.keyval == Gdk::Keyval::KEY_Escape
100
103
  @window.destroy
@@ -105,14 +108,14 @@ class SelectUpdateWindow
105
108
  end
106
109
 
107
110
  @entry.signal_connect("search-changed") do |widget|
108
- puts "search changed: #{widget.text || ""}"
111
+ debug "search changed: #{widget.text || ""}"
109
112
  item_list = @update_callback.call(widget.text)
110
113
 
111
114
  update_item_list(item_list)
112
115
  # label.text = widget.text || ""
113
116
  end
114
- @entry.signal_connect("changed") { puts "[changed] " }
115
- @entry.signal_connect("next-match") { puts "[next-match] " }
117
+ @entry.signal_connect("changed") { debug "[changed] " }
118
+ @entry.signal_connect("next-match") { debug "[next-match] " }
116
119
 
117
120
  if !opt[:desc].nil?
118
121
  descl = Gtk::Label.new(opt[:desc])
@@ -160,7 +163,7 @@ class SelectUpdateWindow
160
163
  end
161
164
 
162
165
  @window.set_default_size(280, 500)
163
- puts "SelectUpdateWindow"
166
+ debug "SelectUpdateWindow"
164
167
  end
165
168
 
166
169
  def run
@@ -1,24 +1,58 @@
1
1
 
2
+
3
+ # class VSourceView < Gtk::TextView
2
4
  class VSourceView < GtkSource::View
3
- def initialize(title = nil)
5
+ attr_accessor :bufo
6
+ # :highlight_matching_brackets
7
+
8
+ # def set_highlight_current_line(vbool)
9
+ # end
10
+
11
+ # def set_show_line_numbers(vbool)
12
+ # end
13
+
14
+ # def highlight_matching_brackets=(vbool)
15
+ # end
16
+
17
+
18
+ # def initialize(title = nil,bufo=nil)
19
+ def initialize(title,bufo)
4
20
  # super(:toplevel)
21
+ @highlight_matching_brackets = true
5
22
  super()
6
- puts "vsource init"
23
+ @bufo = bufo #object of Buffer class buffer.rb
24
+ debug "vsource init"
7
25
  @last_keyval = nil
8
26
  @last_event = [nil, nil]
27
+ self.drag_dest_add_image_targets
28
+ self.drag_dest_add_uri_targets
9
29
 
10
30
  signal_connect "button-press-event" do |_widget, event|
11
31
  if event.button == Gdk::BUTTON_PRIMARY
12
- # puts "Gdk::BUTTON_PRIMARY"
32
+ # debug "Gdk::BUTTON_PRIMARY"
13
33
  false
14
34
  elsif event.button == Gdk::BUTTON_SECONDARY
15
- # puts "Gdk::BUTTON_SECONDARY"
35
+ # debug "Gdk::BUTTON_SECONDARY"
16
36
  true
17
37
  else
18
38
  true
19
39
  end
20
40
  end
21
41
 
42
+ signal_connect("drag-data-received") do |widget, event, x, y, data, info, time|
43
+ puts "drag-data-received"
44
+ puts
45
+ if data.uris.size >= 1
46
+ imgpath = CGI.unescape(data.uris[0])
47
+ m = imgpath.match(/^file:\/\/(.*)/)
48
+ if m
49
+ fp = m[1]
50
+ handle_drag_and_drop(fp)
51
+ end
52
+ end
53
+ true
54
+ end
55
+
22
56
  signal_connect("key_press_event") do |widget, event|
23
57
  handle_key_event(event, :key_press_event)
24
58
  true
@@ -35,7 +69,7 @@ class VSourceView < GtkSource::View
35
69
  end
36
70
 
37
71
  signal_connect "button-release-event" do |widget, event|
38
- $buffer.set_pos(buffer.cursor_position)
72
+ vma.buf.set_pos(buffer.cursor_position)
39
73
  false
40
74
  end
41
75
  @curpos_mark = nil
@@ -44,14 +78,14 @@ class VSourceView < GtkSource::View
44
78
  def handle_key_event(event, sig)
45
79
  if $update_cursor
46
80
  curpos = buffer.cursor_position
47
- puts "MOVE CURSOR: #{curpos}"
81
+ debug "MOVE CURSOR: #{curpos}"
48
82
  buf.set_pos(curpos)
49
83
  $update_cursor = false
50
84
  end
51
- puts $view.visible_rect.inspect
85
+ debug $view.visible_rect.inspect
52
86
 
53
- puts "key event"
54
- puts event
87
+ debug "key event"
88
+ debug event
55
89
 
56
90
  key_name = event.string
57
91
  if event.state.control_mask?
@@ -98,9 +132,9 @@ class VSourceView < GtkSource::View
98
132
  key_str_parts << key_name
99
133
  key_str = key_str_parts.join("-")
100
134
  keynfo = { :key_str => key_str, :key_name => key_name, :keyval => event.keyval }
101
- puts keynfo.inspect
135
+ debug keynfo.inspect
102
136
  # $kbd.match_key_conf(key_str, nil, :key_press)
103
- # puts "key_str=#{key_str} key_"
137
+ # debug "key_str=#{key_str} key_"
104
138
 
105
139
  if key_str != "" # or prefixed_key_str != ""
106
140
  if sig == :key_release_event and event.keyval == @last_keyval
@@ -132,7 +166,7 @@ class VSourceView < GtkSource::View
132
166
  y = iterxy.y
133
167
 
134
168
  # buffer_to_window_coords(Gtk::TextWindowType::TEXT, iterxy.x, iterxy.y).inspect
135
- # puts buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
169
+ # debug buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
136
170
  (x, y) = buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y)
137
171
  # Ripl.start :binding => binding
138
172
 
@@ -141,7 +175,7 @@ class VSourceView < GtkSource::View
141
175
 
142
176
  def handle_deltas()
143
177
  any_change = false
144
- while d = buf.deltas.shift
178
+ while d = @bufo.deltas.shift
145
179
  any_change = true
146
180
  pos = d[0]
147
181
  op = d[1]
@@ -157,7 +191,7 @@ class VSourceView < GtkSource::View
157
191
  end
158
192
  end
159
193
  if any_change
160
- gui_set_cursor_pos($buffer.id, $buffer.pos) #TODO: only when necessary
194
+ gui_set_cursor_pos(@bufo.id, @bufo.pos) #TODO: only when necessary
161
195
  end
162
196
 
163
197
  # sanity_check #TODO
@@ -166,15 +200,15 @@ class VSourceView < GtkSource::View
166
200
  def sanity_check()
167
201
  a = buffer.text
168
202
  b = buf.to_s
169
- # puts "===================="
170
- # puts a.lines[0..10].join()
171
- # puts "===================="
172
- # puts b.lines[0..10].join()
173
- # puts "===================="
203
+ # debug "===================="
204
+ # debug a.lines[0..10].join()
205
+ # debug "===================="
206
+ # debug b.lines[0..10].join()
207
+ # debug "===================="
174
208
  if a == b
175
- puts "Buffers match"
209
+ debug "Buffers match"
176
210
  else
177
- puts "ERROR: Buffer's don't match."
211
+ debug "ERROR: Buffer's don't match."
178
212
  end
179
213
  end
180
214
 
@@ -210,7 +244,7 @@ class VSourceView < GtkSource::View
210
244
  end
211
245
 
212
246
  def cursor_visible_idle_func
213
- puts "cursor_visible_idle_func"
247
+ debug "cursor_visible_idle_func"
214
248
  # From https://picheta.me/articles/2013/08/gtk-plus--a-method-to-guarantee-scrolling.html
215
249
  # vr = visible_rect
216
250
 
@@ -247,8 +281,8 @@ class VSourceView < GtkSource::View
247
281
 
248
282
  intr = iterxy.intersect(vr)
249
283
  if intr.nil?
250
- puts iterxy.inspect
251
- puts vr.inspect
284
+ debug iterxy.inspect
285
+ debug vr.inspect
252
286
  # Ripl.start :binding => binding
253
287
 
254
288
  # exit!
@@ -269,26 +303,20 @@ class VSourceView < GtkSource::View
269
303
 
270
304
  def draw_cursor
271
305
  if is_command_mode
272
- itr = buffer.get_iter_at(:offset => buf.pos)
273
- itr2 = buffer.get_iter_at(:offset => buf.pos + 1)
306
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
307
+ itr2 = buffer.get_iter_at(:offset => @bufo.pos + 1)
274
308
  $view.buffer.select_range(itr, itr2)
275
- elsif buf.visual_mode?
276
- puts "VISUAL MODE"
277
- (_start, _end) = buf.get_visual_mode_range2
278
- puts "#{_start}, #{_end}"
309
+ elsif @bufo.visual_mode?
310
+ debug "VISUAL MODE"
311
+ (_start, _end) = @bufo.get_visual_mode_range2
312
+ debug "#{_start}, #{_end}"
279
313
  itr = buffer.get_iter_at(:offset => _start)
280
314
  itr2 = buffer.get_iter_at(:offset => _end + 1)
281
315
  $view.buffer.select_range(itr, itr2)
282
316
  else # Insert mode
283
- itr = buffer.get_iter_at(:offset => buf.pos)
317
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
284
318
  $view.buffer.select_range(itr, itr)
285
- puts "INSERT MODE"
319
+ debug "INSERT MODE"
286
320
  end
287
321
  end
288
-
289
- # def quit
290
- # destroy
291
- # true
292
- # end
293
322
  end
294
-
@@ -1,19 +1,16 @@
1
-
2
-
3
- def hpt_open_link()
4
- end
5
-
6
1
  def hpt_check_cur_word(w)
7
- puts "check_cur_word(w)"
2
+ debug "check_cur_word(w)"
8
3
  m = w.match(/⟦(.*)⟧/)
9
4
  if m
10
5
  fpfx = m[1]
11
- if $buffer.fname
12
- dn = File.dirname($buffer.fname)
6
+ if vma.buf.fname
7
+ dn = File.dirname(vma.buf.fname)
13
8
 
14
9
  fcands = []
15
- fcands << "#{dn}/#{fpfx}"
16
- fcands << "#{dn}/#{fpfx}.txt"
10
+ if fpfx[0] != "/"
11
+ fcands << "#{dn}/#{fpfx}"
12
+ fcands << "#{dn}/#{fpfx}.txt"
13
+ end
17
14
  fcands << File.expand_path("#{fpfx}")
18
15
  fcands << File.expand_path("#{fpfx}.txt")
19
16
 
@@ -38,24 +35,46 @@ def hpt_check_cur_word(w)
38
35
  return nil
39
36
  end
40
37
 
41
- def hpt_scan_images()
42
- return if !buf.fname
43
- return if !buf.fname.match(/.*txt$/)
44
- imgpos = scan_indexes(buf, /⟦img:.+?⟧/)
45
- imgtags = buf.scan(/(⟦img:(.+?)⟧)/)
46
- # i = 0
38
+ def translate_path(fn, bf)
39
+ if File.exist?(fn)
40
+ outfn = fn
41
+ elsif fn[0] == "$"
42
+ outfn = ppath(fn[1..-1]) # Path to source location
43
+ elsif fn[0] == "~"
44
+ outfn = File.expand_path(fn)
45
+ elsif !bf.fname.nil?
46
+ pd = File.dirname(bf.fname)
47
+ outfn = "#{pd}/#{fn}"
48
+ else
49
+ outfn = File.expand_path(fn)
50
+ end
51
+ return outfn
52
+ end
53
+
54
+ # Scan images inserted with ⟦img:filepath⟧ syntax
55
+ def hpt_scan_images(bf = nil)
56
+ bf = buf() if bf.nil?
57
+ return if bf.nil?
58
+ return if !bf.fname
59
+ return if !bf.fname.match(/.*txt$/)
60
+ imgpos = scan_indexes(bf, /⟦img:.+?⟧/)
61
+ imgtags = bf.scan(/(⟦img:(.+?)⟧)/)
47
62
  c = 0
48
63
  imgpos.each.with_index { |x, i|
49
64
  a = imgpos[i]
50
65
  t = imgtags[i]
51
66
  insert_pos = a + t[0].size + c
52
- imgfn = File.expand_path(t[1])
53
- # Ripl.start :binding => binding
67
+ fn = t[1]
68
+ imgfn = translate_path(fn, bf)
54
69
  next if !File.exist?(imgfn)
55
- if buf[insert_pos..(insert_pos + 2)] != "\n \n"
56
- buf.insert_txt_at("\n \n", insert_pos)
70
+ # Show as image in gui, handle as empty space in txt file
71
+
72
+ if bf[insert_pos..(insert_pos + 2)] != "\n \n"
73
+ bf.insert_txt_at("\n \n", insert_pos)
74
+ bf.view.handle_deltas
57
75
  c += 3
58
76
  end
59
- buf.add_image(imgfn, insert_pos + 1)
77
+ bf.add_image(imgfn, insert_pos + 1)
60
78
  }
79
+ vma.gui.delex.run
61
80
  end
@@ -28,13 +28,16 @@ def is_visual_mode()
28
28
  return 0
29
29
  end
30
30
 
31
+ reg_act(:enable_debug, proc { $debug = true }, "Enable debug")
32
+ reg_act(:disable_debug, proc { $debug = false }, "Disable debug")
33
+
31
34
  reg_act(:easy_jump, proc { EasyJump.start }, "Easy jump")
32
35
  reg_act(:savedebug, "savedebug", "Save debug info", { :group => :debug })
33
36
  reg_act(:open_file_dialog, "open_file_dialog", "Open file", { :group => :file })
34
37
  reg_act(:create_new_file, "create_new_file", "Create new file", { :group => :file })
35
- reg_act(:backup_all_buffers, proc{backup_all_buffers}, "Backup all buffers", { :group => :file })
36
- reg_act(:e_move_forward_char, "e_move_forward_char", "", { :group => :move })
37
- reg_act(:e_move_backward_char, "e_move_backward_char", "", { :group => :move })
38
+ reg_act(:backup_all_buffers, proc { backup_all_buffers }, "Backup all buffers", { :group => :file })
39
+ reg_act(:e_move_forward_char, "e_move_forward_char", "", { :group => [:move, :basic] })
40
+ reg_act(:e_move_backward_char, "e_move_backward_char", "", { :group => [:move, :basic] })
38
41
  reg_act(:history_switch_backwards, "history_switch_backwards", "", { :group => :file })
39
42
  reg_act(:history_switch_forwards, "history_switch_forwards", "", { :group => :file })
40
43
  reg_act(:center_on_current_line, "center_on_current_line", "", { :group => :view })
@@ -52,7 +55,7 @@ reg_act(:set_executable, proc { buf.set_executable }, "Set current file permissi
52
55
  reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
53
56
  reg_act(:close_current_buffer, proc { bufs.close_current_buffer(true) }, "Close current buffer")
54
57
  reg_act(:comment_selection, proc { buf.comment_selection }, "")
55
- reg_act(:delete_char_forward, proc { buf.delete(CURRENT_CHAR_FORWARD) }, "Delete char forward")
58
+ reg_act(:delete_char_forward, proc { buf.delete(CURRENT_CHAR_FORWARD) }, "Delete char forward", { :group => [:edit, :basic] })
56
59
  reg_act(:load_theme, proc { load_theme }, "Load theme")
57
60
  reg_act(:gui_file_finder, proc { vma.FileFinder.start_gui }, "Fuzzy file finder")
58
61
  reg_act(:gui_file_history_finder, proc { vma.FileHistory.start_gui }, "Fuzzy file history finder")
@@ -78,19 +81,19 @@ reg_act(:diff_buffer, "diff_buffer", "")
78
81
  reg_act(:invoke_grep_search, proc { gui_grep }, "Grep current buffer")
79
82
  reg_act(:ack_search, proc { gui_ack }, "") #invoke_ack_search
80
83
  reg_act :update_file_index, proc { update_file_index }, "Update file index"
81
- reg_act :delete_to_word_end, proc { buf.delete2(:to_word_end) }, "Delete to file end"
82
- reg_act :delete_to_line_start, proc { buf.delete2(:to_line_start) }, "Delete to line start"
84
+ reg_act :delete_to_word_end, proc { buf.delete2(:to_word_end) }, "Delete to file end", { :group => [:edit, :basic] }
85
+ reg_act :delete_to_line_start, proc { buf.delete2(:to_line_start) }, "Delete to line start", { :group => [:edit, :basic] }
83
86
  reg_act :start_browse_mode, proc { $kbd.set_mode(:browse); $kbd.set_default_mode(:browse) }, "Start browse mode"
84
87
  reg_act :exit_browse_mode, proc {
85
88
  bufs.add_current_buf_to_history(); $kbd.set_mode(:command); $kbd.set_default_mode(:command)
86
89
  }, "Exit browse mode"
87
90
 
88
- reg_act :page_down, proc { page_down }
89
- reg_act :page_up, proc { page_up }
91
+ reg_act :page_down, proc { page_down }, "Page down", :group => [:move, :basic]
92
+ reg_act :page_up, proc { page_up }, "Page up", :group => [:move, :basic]
90
93
  reg_act :jump_to_start_of_buffer, proc { buf.jump(START_OF_BUFFER) }, "Jump to start of buffer"
91
94
  reg_act :jump_to_end_of_buffer, proc { buf.jump(END_OF_BUFFER) }, "Jump to end of buffer"
92
95
  reg_act(:auto_indent_buffer, proc { buf.indent }, "Auto format buffer")
93
- reg_act(:execute_current_line_in_terminal, proc { buf.execute_current_line_in_terminal }, "Execute current line in terminalL")
96
+ reg_act(:execute_current_line_in_terminal, proc { buf.execute_current_line_in_terminal }, "Execute current line in terminal")
94
97
  reg_act(:execute_current_line_in_terminal_autoclose, proc { buf.execute_current_line_in_terminal(true) }, "Execute current line in terminal. Close after execution.")
95
98
  reg_act(:show_images, proc { hpt_scan_images() }, "Show images inserted with ⟦img:file.png⟧ syntax")
96
99
  reg_act(:delete_current_file, proc { bufs.delete_current_buffer() }, "Delete current file")
@@ -114,8 +117,28 @@ act_list = {
114
117
  :desc => "Undo edit", :group => :edit },
115
118
 
116
119
  :find_in_buffer => { :proc => proc { invoke_search },
117
- :desc => "Find", :group => :edit },
120
+ :desc => "Find", :group => :edit },
121
+
122
+ :selection_upcase => { :proc => proc { buf.transform_selection(:upcase) },
123
+ :desc => "Transform text: upcase", :group => :edit },
124
+
125
+ :selection_downcase => { :proc => proc { buf.transform_selection(:downcase) },
126
+ :desc => "Transform text: downcase", :group => :edit },
127
+
128
+ :selection_capitalize => { :proc => proc { buf.transform_selection(:capitalize) },
129
+ :desc => "Transform text: capitalize", :group => :edit },
130
+
131
+ :selection_swapcase => { :proc => proc { buf.transform_selection(:swapcase) },
132
+ :desc => "Transform text: swapcase", :group => :edit },
118
133
 
134
+ :selection_reverse => { :proc => proc { buf.transform_selection(:reverse) },
135
+ :desc => "Transform text: reverse", :group => :edit },
136
+
137
+ :forward_line => { :proc => proc { buf.move(FORWARD_LINE) },
138
+ :desc => "Move one line forward", :group => [:move, :basic] },
139
+
140
+ :backward_line => { :proc => proc { buf.move(BACKWARD_LINE) },
141
+ :desc => "Move one line backward", :group => [:move, :basic] },
119
142
 
120
143
  # { :proc => proc { },
121
144
  # :desc => "", :group => : },
@@ -123,6 +146,9 @@ act_list = {
123
146
  :search_actions => { :proc => proc { search_actions },
124
147
  :desc => "Search actions", :group => :search },
125
148
 
149
+ :content_search => { :proc => proc { FileContentSearch.start_gui },
150
+ :desc => "Search content of files", :group => :search },
151
+
126
152
  :quit => { :proc => proc { _quit },
127
153
  :desc => "Quit", :group => :app },
128
154
 
@@ -145,14 +171,13 @@ act_list_todo = {
145
171
  :desc => "Close current file", :group => :file },
146
172
  #"C , b" => '$kbd.set_mode("S");gui_select_buffer',
147
173
 
148
-
149
174
  # MOVING
150
175
  # 'VC h' => 'buf.move(BACKWARD_CHAR)',
151
176
  :m_forward_char => { :proc => proc { buf.move(FORWARD_CHAR) },
152
177
  :desc => "Move cursor one char forward",
153
178
  :group => :move },
154
- "VC j" => "buf.move(FORWARD_LINE)",
155
- "VC k" => "buf.move(BACKWARD_LINE)",
179
+ # "VC j" => "buf.move(FORWARD_LINE)",
180
+ # "VC k" => "buf.move(BACKWARD_LINE)",
156
181
 
157
182
  "VC pagedown" => "page_down",
158
183
  "VC pageup" => "page_up",