vimamsa 0.1.6 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,24 +1,57 @@
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)
4
19
  # super(:toplevel)
20
+ @highlight_matching_brackets = true
5
21
  super()
6
- puts "vsource init"
22
+ @bufo = bufo #object of Buffer class buffer.rb
23
+ debug "vsource init"
7
24
  @last_keyval = nil
8
25
  @last_event = [nil, nil]
26
+ self.drag_dest_add_image_targets
27
+ self.drag_dest_add_uri_targets
9
28
 
10
29
  signal_connect "button-press-event" do |_widget, event|
11
30
  if event.button == Gdk::BUTTON_PRIMARY
12
- # puts "Gdk::BUTTON_PRIMARY"
31
+ # debug "Gdk::BUTTON_PRIMARY"
13
32
  false
14
33
  elsif event.button == Gdk::BUTTON_SECONDARY
15
- # puts "Gdk::BUTTON_SECONDARY"
34
+ # debug "Gdk::BUTTON_SECONDARY"
16
35
  true
17
36
  else
18
37
  true
19
38
  end
20
39
  end
21
40
 
41
+ signal_connect("drag-data-received") do |widget, event, x, y, data, info, time|
42
+ puts "drag-data-received"
43
+ puts
44
+ if data.uris.size >= 1
45
+ imgpath = CGI.unescape(data.uris[0])
46
+ m = imgpath.match(/^file:\/\/(.*)/)
47
+ if m
48
+ fp = m[1]
49
+ handle_drag_and_drop(fp)
50
+ end
51
+ end
52
+ true
53
+ end
54
+
22
55
  signal_connect("key_press_event") do |widget, event|
23
56
  handle_key_event(event, :key_press_event)
24
57
  true
@@ -44,14 +77,14 @@ class VSourceView < GtkSource::View
44
77
  def handle_key_event(event, sig)
45
78
  if $update_cursor
46
79
  curpos = buffer.cursor_position
47
- puts "MOVE CURSOR: #{curpos}"
80
+ debug "MOVE CURSOR: #{curpos}"
48
81
  buf.set_pos(curpos)
49
82
  $update_cursor = false
50
83
  end
51
- puts $view.visible_rect.inspect
84
+ debug $view.visible_rect.inspect
52
85
 
53
- puts "key event"
54
- puts event
86
+ debug "key event"
87
+ debug event
55
88
 
56
89
  key_name = event.string
57
90
  if event.state.control_mask?
@@ -98,9 +131,9 @@ class VSourceView < GtkSource::View
98
131
  key_str_parts << key_name
99
132
  key_str = key_str_parts.join("-")
100
133
  keynfo = { :key_str => key_str, :key_name => key_name, :keyval => event.keyval }
101
- puts keynfo.inspect
134
+ debug keynfo.inspect
102
135
  # $kbd.match_key_conf(key_str, nil, :key_press)
103
- # puts "key_str=#{key_str} key_"
136
+ # debug "key_str=#{key_str} key_"
104
137
 
105
138
  if key_str != "" # or prefixed_key_str != ""
106
139
  if sig == :key_release_event and event.keyval == @last_keyval
@@ -132,7 +165,7 @@ class VSourceView < GtkSource::View
132
165
  y = iterxy.y
133
166
 
134
167
  # buffer_to_window_coords(Gtk::TextWindowType::TEXT, iterxy.x, iterxy.y).inspect
135
- # puts buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
168
+ # debug buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
136
169
  (x, y) = buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y)
137
170
  # Ripl.start :binding => binding
138
171
 
@@ -141,7 +174,7 @@ class VSourceView < GtkSource::View
141
174
 
142
175
  def handle_deltas()
143
176
  any_change = false
144
- while d = buf.deltas.shift
177
+ while d = @bufo.deltas.shift
145
178
  any_change = true
146
179
  pos = d[0]
147
180
  op = d[1]
@@ -157,7 +190,7 @@ class VSourceView < GtkSource::View
157
190
  end
158
191
  end
159
192
  if any_change
160
- gui_set_cursor_pos($buffer.id, $buffer.pos) #TODO: only when necessary
193
+ gui_set_cursor_pos(@bufo.id, @bufo.pos) #TODO: only when necessary
161
194
  end
162
195
 
163
196
  # sanity_check #TODO
@@ -166,15 +199,15 @@ class VSourceView < GtkSource::View
166
199
  def sanity_check()
167
200
  a = buffer.text
168
201
  b = buf.to_s
169
- # puts "===================="
170
- # puts a.lines[0..10].join()
171
- # puts "===================="
172
- # puts b.lines[0..10].join()
173
- # puts "===================="
202
+ # debug "===================="
203
+ # debug a.lines[0..10].join()
204
+ # debug "===================="
205
+ # debug b.lines[0..10].join()
206
+ # debug "===================="
174
207
  if a == b
175
- puts "Buffers match"
208
+ debug "Buffers match"
176
209
  else
177
- puts "ERROR: Buffer's don't match."
210
+ debug "ERROR: Buffer's don't match."
178
211
  end
179
212
  end
180
213
 
@@ -210,7 +243,7 @@ class VSourceView < GtkSource::View
210
243
  end
211
244
 
212
245
  def cursor_visible_idle_func
213
- puts "cursor_visible_idle_func"
246
+ debug "cursor_visible_idle_func"
214
247
  # From https://picheta.me/articles/2013/08/gtk-plus--a-method-to-guarantee-scrolling.html
215
248
  # vr = visible_rect
216
249
 
@@ -247,8 +280,8 @@ class VSourceView < GtkSource::View
247
280
 
248
281
  intr = iterxy.intersect(vr)
249
282
  if intr.nil?
250
- puts iterxy.inspect
251
- puts vr.inspect
283
+ debug iterxy.inspect
284
+ debug vr.inspect
252
285
  # Ripl.start :binding => binding
253
286
 
254
287
  # exit!
@@ -269,26 +302,20 @@ class VSourceView < GtkSource::View
269
302
 
270
303
  def draw_cursor
271
304
  if is_command_mode
272
- itr = buffer.get_iter_at(:offset => buf.pos)
273
- itr2 = buffer.get_iter_at(:offset => buf.pos + 1)
305
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
306
+ itr2 = buffer.get_iter_at(:offset => @bufo.pos + 1)
274
307
  $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}"
308
+ elsif @bufo.visual_mode?
309
+ debug "VISUAL MODE"
310
+ (_start, _end) = @bufo.get_visual_mode_range2
311
+ debug "#{_start}, #{_end}"
279
312
  itr = buffer.get_iter_at(:offset => _start)
280
313
  itr2 = buffer.get_iter_at(:offset => _end + 1)
281
314
  $view.buffer.select_range(itr, itr2)
282
315
  else # Insert mode
283
- itr = buffer.get_iter_at(:offset => buf.pos)
316
+ itr = buffer.get_iter_at(:offset => @bufo.pos)
284
317
  $view.buffer.select_range(itr, itr)
285
- puts "INSERT MODE"
318
+ debug "INSERT MODE"
286
319
  end
287
320
  end
288
-
289
- # def quit
290
- # destroy
291
- # true
292
- # end
293
321
  end
294
-
@@ -1,10 +1,5 @@
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]
@@ -12,8 +7,10 @@ def hpt_check_cur_word(w)
12
7
  dn = File.dirname($buffer.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 })
@@ -48,10 +51,11 @@ reg_act(:put_file_path_to_clipboard, proc { buf.put_file_path_to_clipboard }, "P
48
51
  # reg_act(:encrypt_file, proc{buf.set_encrypted},"Set current file to encrypt on save")
49
52
  reg_act(:encrypt_file, proc { encrypt_cur_buffer }, "Set current file to encrypt on save")
50
53
  reg_act(:set_unencrypted, proc { buf.set_unencrypted }, "Set current file to save unencrypted")
54
+ reg_act(:set_executable, proc { buf.set_executable }, "Set current file permissions to executable")
51
55
  reg_act(:close_all_buffers, proc { bufs.close_all_buffers() }, "Close all buffers")
52
56
  reg_act(:close_current_buffer, proc { bufs.close_current_buffer(true) }, "Close current buffer")
53
57
  reg_act(:comment_selection, proc { buf.comment_selection }, "")
54
- 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] })
55
59
  reg_act(:load_theme, proc { load_theme }, "Load theme")
56
60
  reg_act(:gui_file_finder, proc { vma.FileFinder.start_gui }, "Fuzzy file finder")
57
61
  reg_act(:gui_file_history_finder, proc { vma.FileHistory.start_gui }, "Fuzzy file history finder")
@@ -77,19 +81,20 @@ reg_act(:diff_buffer, "diff_buffer", "")
77
81
  reg_act(:invoke_grep_search, proc { gui_grep }, "Grep current buffer")
78
82
  reg_act(:ack_search, proc { gui_ack }, "") #invoke_ack_search
79
83
  reg_act :update_file_index, proc { update_file_index }, "Update file index"
80
- reg_act :delete_to_word_end, proc { buf.delete2(:to_word_end) }, "Delete to file end"
81
- 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] }
82
86
  reg_act :start_browse_mode, proc { $kbd.set_mode(:browse); $kbd.set_default_mode(:browse) }, "Start browse mode"
83
87
  reg_act :exit_browse_mode, proc {
84
88
  bufs.add_current_buf_to_history(); $kbd.set_mode(:command); $kbd.set_default_mode(:command)
85
89
  }, "Exit browse mode"
86
90
 
87
- reg_act :page_down, proc { page_down }
88
- 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]
89
93
  reg_act :jump_to_start_of_buffer, proc { buf.jump(START_OF_BUFFER) }, "Jump to start of buffer"
90
94
  reg_act :jump_to_end_of_buffer, proc { buf.jump(END_OF_BUFFER) }, "Jump to end of buffer"
91
95
  reg_act(:auto_indent_buffer, proc { buf.indent }, "Auto format buffer")
92
96
  reg_act(:execute_current_line_in_terminal, proc { buf.execute_current_line_in_terminal }, "Execute current line in terminal")
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.")
93
98
  reg_act(:show_images, proc { hpt_scan_images() }, "Show images inserted with ⟦img:file.png⟧ syntax")
94
99
  reg_act(:delete_current_file, proc { bufs.delete_current_buffer() }, "Delete current file")
95
100
 
@@ -112,8 +117,28 @@ act_list = {
112
117
  :desc => "Undo edit", :group => :edit },
113
118
 
114
119
  :find_in_buffer => { :proc => proc { invoke_search },
115
- :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 },
116
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] },
117
142
 
118
143
  # { :proc => proc { },
119
144
  # :desc => "", :group => : },
@@ -121,6 +146,9 @@ act_list = {
121
146
  :search_actions => { :proc => proc { search_actions },
122
147
  :desc => "Search actions", :group => :search },
123
148
 
149
+ :content_search => { :proc => proc { FileContentSearch.start_gui },
150
+ :desc => "Search content of files", :group => :search },
151
+
124
152
  :quit => { :proc => proc { _quit },
125
153
  :desc => "Quit", :group => :app },
126
154
 
@@ -143,14 +171,13 @@ act_list_todo = {
143
171
  :desc => "Close current file", :group => :file },
144
172
  #"C , b" => '$kbd.set_mode("S");gui_select_buffer',
145
173
 
146
-
147
174
  # MOVING
148
175
  # 'VC h' => 'buf.move(BACKWARD_CHAR)',
149
176
  :m_forward_char => { :proc => proc { buf.move(FORWARD_CHAR) },
150
177
  :desc => "Move cursor one char forward",
151
178
  :group => :move },
152
- "VC j" => "buf.move(FORWARD_LINE)",
153
- "VC k" => "buf.move(BACKWARD_LINE)",
179
+ # "VC j" => "buf.move(FORWARD_LINE)",
180
+ # "VC k" => "buf.move(BACKWARD_LINE)",
154
181
 
155
182
  "VC pagedown" => "page_down",
156
183
  "VC pageup" => "page_up",
@@ -256,7 +283,7 @@ act_list_todo = {
256
283
  # Visual mode only:
257
284
  "V esc" => "buf.end_visual_mode",
258
285
  "V ctrl!" => "buf.end_visual_mode",
259
- "V y" => "buf.copy_active_selection",
286
+ "V y" => "buf.copy_active_selection(:foo)",
260
287
  "V g U" => "buf.transform_selection(:upcase)",
261
288
  "V g u" => "buf.transform_selection(:downcase)",
262
289
  "V g c" => "buf.transform_selection(:capitalize)",