vimamsa 0.1.5 → 0.1.8

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: 4f68b029a6b5f374740c9afa2cb7c4ac628db4c4b9295b7e64db8294dac89659
4
- data.tar.gz: c7c72c69ec7cd513e976caff3b0b1f2e619d890d8d84e616fcd747e4ab1193be
3
+ metadata.gz: 6000318b31060bff83029148c2cf47cc6ff8c5939d2fc1d54951a54e8b49a538
4
+ data.tar.gz: 500cd81fe9bd605276a0802f182980c5a93d77ab5d2221548586673e85a85832
5
5
  SHA512:
6
- metadata.gz: 892b4011a44310ad05becbf108fce73d4cdda3a25d6241435b03519ad0dd264daa856502956f02f47386bce251aef3e0296cc682fc35b01fefa375fbffd5ee4a
7
- data.tar.gz: 25c97fde0e225c7cb273bc0fa97d0db4d74376ea2ddca2baea8823dbb1e01d31334fabbaa8e319cc37d40eca23d37b3d64f2cbbbdcbbce88f7d30435cfb44a6f
6
+ metadata.gz: 8b687b1b72df46bd9bc35622b239e9525e2dc15884f1066557e82c474e99c280577a32a3a7f60a776f5b6be0866dc86c79e2b364780413821a491160ad73875f
7
+ data.tar.gz: d5e8da0e6263f74f27ee84781efdea5126411a68ace27d244da6c5b9203924196d10bbe91541319af91539089c6391dfadfde3f76cbac6f475b2002c1fbaa16c
data/exe/vimamsa CHANGED
@@ -16,7 +16,9 @@ listen_dir = File.expand_path("~/.vimamsa/listen")
16
16
  if File.exist?(listen_dir) and !ARGV[0].nil?
17
17
  tmpf = Tempfile.new("vmarun", listen_dir)
18
18
  fp = tmpf.path
19
- tmpf.write(ARGV[0])
19
+ paramfn = File.expand_path(ARGV[0])
20
+ puts paramfn
21
+ tmpf.write(paramfn)
20
22
  tmpf.close
21
23
  tstart = Time.new
22
24
  timeout = false
@@ -36,5 +38,5 @@ $LOAD_PATH.unshift(File.expand_path("ext"))
36
38
  require "vimamsa"
37
39
  # Ilib:ext
38
40
  # r rbvma -e "puts VMA.new.run"
39
- $vmag = VMAg.new()
41
+ $vmag = VMAgui.new()
40
42
  $vmag.run
data/lib/vimamsa/ack.rb CHANGED
@@ -16,10 +16,6 @@ def gui_ack()
16
16
  gui_one_input_action(nfo, "Search:", "search", callback)
17
17
  end
18
18
 
19
- def invoke_ack_search()
20
- start_minibuffer_cmd("", "", :ack_buffer)
21
- end
22
-
23
19
  def ack_buffer(instr, b = nil)
24
20
  instr = instr.gsub("'", ".") # TODO
25
21
  bufstr = ""
@@ -1,73 +1,62 @@
1
1
  class Action
2
- attr_accessor :id, :method_name, :method
2
+ attr_accessor :id, :method_name, :method, :opt
3
3
 
4
- def initialize(id, method_name, method, scope = [])
4
+ def initialize(id, method_name, method, opt = {})
5
5
  @method_name = method_name
6
6
  @id = id
7
7
  @method = method
8
+ @opt = opt
9
+
8
10
  $actions[id] = self
9
11
  end
10
12
  end
11
13
 
12
14
  $actions = {}
13
15
 
14
- # def reg_act(id, callfunc, name = "", scope = [])
15
- # if callfunc.class == Proc
16
- # a = Action.new(id, name, callfunc, scope)
17
- # else
18
- # a = Action.new(id, name, method(callfunc), scope)
19
- # end
20
- # end
21
-
22
- def reg_act(id, callfunc, name = "", scope = [])
16
+ def reg_act(id, callfunc, name = "", opt = {})
23
17
  if callfunc.class == Proc
24
- a = Action.new(id, name, callfunc, scope)
18
+ a = Action.new(id, name, callfunc, opt)
25
19
  else
26
20
  begin
27
21
  m = method(callfunc)
28
22
  rescue NameError
29
23
  m = method("missing_callfunc")
30
24
  end
31
- a = Action.new(id, name, m, scope)
25
+ a = Action.new(id, name, m, opt)
32
26
  end
27
+ return a
33
28
  end
34
29
 
35
30
  def missing_callfunc
36
- puts "missing_callfunc"
31
+ debug "missing_callfunc"
37
32
  end
38
33
 
39
-
34
+ #TODO: remove
40
35
  def call(id)
36
+ call_action(id)
37
+ end
38
+
39
+ def call_action(id)
41
40
  a = $actions[id]
42
41
  if a
43
- # Ripl.start :binding => binding
44
42
  a.method.call()
43
+ else
44
+ message("Unknown action: " + id.inspect)
45
45
  end
46
46
  end
47
47
 
48
48
  def search_actions()
49
49
  l = []
50
50
  $select_keys = ["h", "l", "f", "d", "s", "a", "g", "z"]
51
- qt_select_update_window(l, $select_keys.collect { |x| x.upcase },
52
- "search_actions_select_callback",
53
- "search_actions_update_callback")
51
+ gui_select_update_window(l, $select_keys.collect { |x| x.upcase },
52
+ "search_actions_select_callback",
53
+ "search_actions_update_callback")
54
54
  end
55
55
 
56
56
  $item_list = []
57
57
 
58
58
  def search_actions_update_callback(search_str = "")
59
- # item_list = $actions.collect {|x| x[1].id.to_s}
60
59
  return [] if search_str == ""
61
- # item_list = $action_list.collect { |x|
62
- # actname = x[:action].to_s
63
- # if x[:action].class == Symbol
64
- # mn = $actions[x[:action]].method_name
65
- # actname = mn if mn.size > 0
66
- # end
67
- # r = { :str => actname, :key => x[:key], :action => x[:action] }
68
- # }
69
-
70
- # => {:str=>"insert_new_line", :key=>"I return", :action=>:insert_new_line}
71
60
 
72
61
  item_list2 = []
73
62
  for act_id in $actions.keys
@@ -81,16 +70,15 @@ def search_actions_update_callback(search_str = "")
81
70
  end
82
71
  item_list2 << item
83
72
  end
84
- # Ripl.start :binding => binding
73
+
85
74
  item_list = item_list2
86
75
 
87
76
  a = filter_items(item_list, 0, search_str)
88
- puts a.inspect
77
+ debug a.inspect
89
78
 
90
79
  r = a.collect { |x| [x[0][0], 0, x] }
91
- puts r.inspect
80
+ debug r.inspect
92
81
  $item_list = r
93
- # Ripl.start :binding => binding
94
82
 
95
83
  r = a.collect { |x| ["[#{x[0][:key]}] #{x[0][:str]}", 0, x] }
96
84
  return r
@@ -100,13 +88,13 @@ def search_actions_select_callback(search_str, idx)
100
88
  item = $item_list[idx][2]
101
89
  acc = item[0][:action]
102
90
 
103
- puts "Selected:" + acc.to_s
104
- qt_select_window_close(0)
91
+ debug "Selected:" + acc.to_s
92
+ gui_select_window_close(0)
105
93
 
106
94
  if acc.class == String
107
95
  eval(acc)
108
96
  elsif acc.class == Symbol
109
- puts "Symbol"
97
+ debug "Symbol"
110
98
  call(acc)
111
99
  end
112
100
  end
@@ -118,7 +106,7 @@ def filter_items(item_list, item_key, search_str)
118
106
  [item, srn_dst(search_str, item[:str])]
119
107
  end
120
108
  scores.sort_by! { |x| -x[1] }
121
- puts scores.inspect
109
+ debug scores.inspect
122
110
  scores = scores[0..30]
123
111
 
124
112
  return scores
@@ -1,5 +1,6 @@
1
1
  require "digest"
2
2
  require "tempfile"
3
+ require "fileutils"
3
4
  require "pathname"
4
5
  require "openssl"
5
6
  require "ripl/multi_line"
@@ -15,7 +16,7 @@ class Buffer < String
15
16
 
16
17
  attr_reader :pos, :lpos, :cpos, :deltas, :edit_history, :fname, :call_func, :pathname, :basename, :update_highlight, :marks, :is_highlighted, :syntax_detect_failed, :id, :lang
17
18
  attr_writer :call_func, :update_highlight
18
- attr_accessor :qt_update_highlight, :update_hl_startpos, :update_hl_endpos, :hl_queue, :syntax_parser, :highlights, :qt_reset_highlight, :is_parsing_syntax, :line_ends, :bt, :line_action_handler, :module, :active_kbd_mode, :title, :subtitle
19
+ 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
19
20
 
20
21
  @@num_buffers = 0
21
22
 
@@ -26,8 +27,8 @@ class Buffer < String
26
27
  @lang = nil
27
28
  @id = @@num_buffers
28
29
  @@num_buffers += 1
29
- qt_create_buffer(@id)
30
- puts "NEW BUFFER fn=#{fname} ID:#{@id}"
30
+ gui_create_buffer(@id)
31
+ debug "NEW BUFFER fn=#{fname} ID:#{@id}"
31
32
 
32
33
  @module = nil
33
34
 
@@ -58,7 +59,7 @@ class Buffer < String
58
59
  end
59
60
 
60
61
  t1 = Time.now
61
- qt_set_current_buffer(@id)
62
+ gui_set_current_buffer(@id)
62
63
  gui_set_window_title(@title, @subtitle)
63
64
 
64
65
  set_content(str)
@@ -70,13 +71,29 @@ class Buffer < String
70
71
  @active_kbd_mode = nil
71
72
  end
72
73
 
74
+ def list_str()
75
+ if @fname.nil?
76
+ x = @title
77
+ else
78
+ x = @fname
79
+ end
80
+ return x
81
+ end
82
+
73
83
  def set_active
74
84
  if !@active_kbd_mode.nil?
75
85
  $kbd.set_mode(@active_kbd_mode)
76
86
  else
77
87
  $kbd.set_mode_to_default
78
88
  end
79
- # qt_set_current_buffer(@id)
89
+ # gui_set_current_buffer(@id)
90
+ end
91
+
92
+ def set_executable
93
+ if File.exists?(@fname)
94
+ FileUtils.chmod("+x", @fname)
95
+ message("Set executable: #{@fname}")
96
+ end
80
97
  end
81
98
 
82
99
  def detect_file_language
@@ -96,7 +113,7 @@ class Buffer < String
96
113
  # lang.get_metadata("block-comment-end")
97
114
  @lang_nfo = lang
98
115
  if !lang.nil? and !lang.id.nil?
99
- puts "Guessed LANG: #{lang.id}"
116
+ debug "Guessed LANG: #{lang.id}"
100
117
  @lang = lang.id
101
118
  end
102
119
 
@@ -105,11 +122,32 @@ class Buffer < String
105
122
  end
106
123
  end
107
124
 
125
+ def view()
126
+ # Get the VSourceView < GtkSource::View object corresponding to this buffer
127
+ return vma.gui.buffers[@id]
128
+ end
129
+
108
130
  def add_image(imgpath, pos)
109
131
  return if !is_legal_pos(pos)
110
- # insert_txt_at(" ", pos)
111
- qt_process_deltas
112
- qt_add_image(imgpath, pos)
132
+
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
+ vbuf = view.buffer
147
+ itr = vbuf.get_iter_at(:offset => pos)
148
+ itr2 = vbuf.get_iter_at(:offset => pos + 1)
149
+ vbuf.delete(itr, itr2)
150
+ vbuf.insert(itr, pixbuf)
113
151
  end
114
152
 
115
153
  def is_legal_pos(pos, op = :read)
@@ -141,7 +179,6 @@ class Buffer < String
141
179
  b = " \n"
142
180
  txt = a + b
143
181
  insert_txt_at(txt, lr.end + 1)
144
- qt_process_deltas
145
182
  imgpos = lr.end + 1 + a.size
146
183
  add_image(fname, imgpos)
147
184
  end
@@ -191,25 +228,25 @@ class Buffer < String
191
228
  ok = true
192
229
  @bt.each_line { |r|
193
230
  if lines[i] != r #or true
194
- puts "NO MATCH FOR LINE:"
195
- puts "i=#{i}["
196
- # puts "[orig]pos=#{leaf.pos} |#{leaf.data}|"
197
- # puts "spos=#{spos} nchar=#{leaf.nchar} epos=#{epos} a[]=\nr=|#{r}|"
198
- puts "fromtree:|#{r}|"
199
- puts "frombuf:|#{lines[i]}"
200
- puts "]"
231
+ debug "NO MATCH FOR LINE:"
232
+ debug "i=#{i}["
233
+ # debug "[orig]pos=#{leaf.pos} |#{leaf.data}|"
234
+ # debug "spos=#{spos} nchar=#{leaf.nchar} epos=#{epos} a[]=\nr=|#{r}|"
235
+ debug "fromtree:|#{r}|"
236
+ debug "frombuf:|#{lines[i]}"
237
+ debug "]"
201
238
  ok = false
202
239
  end
203
240
  i += 1
204
241
  }
205
242
 
206
- puts "BT: NO ERRORS" if ok
207
- puts "BT: ERRORS" if !ok
243
+ debug "BT: NO ERRORS" if ok
244
+ debug "BT: ERRORS" if !ok
208
245
  end
209
246
 
210
247
  def set_content(str)
211
248
  @encrypted_str = nil
212
- @qt_update_highlight = true
249
+ @gui_update_highlight = true
213
250
  @ftype = nil
214
251
  if str[0..10] == "VMACRYPT001"
215
252
  @encrypted_str = str[11..-1]
@@ -263,7 +300,7 @@ class Buffer < String
263
300
  @update_hl_startpos = 0 #TODO
264
301
  @update_hl_endpos = self.size - 1
265
302
 
266
- qt_set_buffer_contents(@id, self.to_s)
303
+ gui_set_buffer_contents(@id, self.to_s)
267
304
 
268
305
  # add_hl_update(@update_hl_startpos, @update_hl_endpos)
269
306
  end
@@ -272,6 +309,12 @@ class Buffer < String
272
309
  @fname = filename
273
310
  @pathname = Pathname.new(fname) if @fname
274
311
  @basename = @pathname.basename if @fname
312
+
313
+ @title = File.basename(@fname)
314
+ @dirname = File.dirname(@fname)
315
+ userhome = File.expand_path("~")
316
+ @subtitle = @dirname.gsub(/^#{userhome}/, "~")
317
+
275
318
  detect_file_language
276
319
  end
277
320
 
@@ -417,11 +460,11 @@ class Buffer < String
417
460
  end
418
461
 
419
462
  def update_index(pos, changeamount)
420
- # puts "pos #{pos}, changeamount #{changeamount}, @pos #{@pos}"
463
+ # debug "pos #{pos}, changeamount #{changeamount}, @pos #{@pos}"
421
464
  @edit_pos_history.collect! { |x| r = x if x <= pos; r = x + changeamount if x > pos; r }
422
465
  # TODO: handle between removal case
423
466
  for k in @marks.keys
424
- # puts "change(?): pos=#{pos}, k=#{k}, #{@marks[k]}, #{changeamount}"
467
+ # debug "change(?): pos=#{pos}, k=#{k}, #{@marks[k]}, #{changeamount}"
425
468
  if @marks[k] > pos
426
469
  @marks[k] = @marks[k] + changeamount
427
470
  end
@@ -447,7 +490,6 @@ class Buffer < String
447
490
  return if @edit_pos_history.empty?
448
491
  @edit_pos_history_i -= 1
449
492
  @edit_pos_history_i = @edit_pos_history.size - 1 if @edit_pos_history_i < 0
450
- # Ripl.start :binding => binding
451
493
  debug "@edit_pos_history_i=#{@edit_pos_history_i}"
452
494
  set_pos(@edit_pos_history[-@edit_pos_history_i])
453
495
  center_on_current_line
@@ -563,8 +605,7 @@ class Buffer < String
563
605
  ls = nil
564
606
  ls = @line_ends[a] if a != nil
565
607
  # if a != nil and ls != @line_ends[a]
566
- # puts "NO MATCH @line_ends[a]"
567
- # Ripl.start :binding => binding
608
+ # debug "NO MATCH @line_ends[a]"
568
609
  # end
569
610
 
570
611
  if ls == nil
@@ -576,7 +617,6 @@ class Buffer < String
576
617
  end
577
618
 
578
619
  def get_line_end(pos)
579
- #Ripl.start :binding => binding
580
620
  return @line_ends.select { |x| x > pos }.min
581
621
  end
582
622
 
@@ -670,7 +710,7 @@ class Buffer < String
670
710
  end
671
711
 
672
712
  debug "Scan line_end time: #{Time.now - t1}"
673
- #puts @line_ends
713
+ #debug @line_ends
674
714
  end
675
715
 
676
716
  def sanity_check_line_ends()
@@ -687,7 +727,7 @@ class Buffer < String
687
727
  end
688
728
 
689
729
  def update_bufpos_on_change(positions, xpos, changeamount)
690
- # puts "xpos=#{xpos} changeamount=#{changeamount}"
730
+ # debug "xpos=#{xpos} changeamount=#{changeamount}"
691
731
  positions.collect { |x|
692
732
  r = nil
693
733
  r = x if x < xpos
@@ -722,7 +762,7 @@ class Buffer < String
722
762
  i_nl = scan_indexes(changestr, /\n/)
723
763
  i_nl.collect! { |x| x + pos }
724
764
  end
725
- # puts "change:#{changeamount}"
765
+ # debug "change:#{changeamount}"
726
766
  #TODO: this is the bottle neck in insert_txt action
727
767
  @line_ends.collect! { |x|
728
768
  r = nil
@@ -752,7 +792,7 @@ class Buffer < String
752
792
  elsif new_pos >= 0
753
793
  @pos = new_pos
754
794
  end
755
- qt_set_cursor_pos(@id, @pos)
795
+ gui_set_cursor_pos(@id, @pos)
756
796
  calculate_line_and_column_pos
757
797
  end
758
798
 
@@ -870,10 +910,10 @@ class Buffer < String
870
910
  range = @pos..wmarks[0]
871
911
  end
872
912
  elsif range_id == :to_line_end
873
- puts "TO LINE END"
913
+ debug "TO LINE END"
874
914
  range = @pos..(@line_ends[@lpos] - 1)
875
915
  elsif range_id == :to_line_start
876
- puts "TO LINE START: #{@lpos}"
916
+ debug "TO LINE START: #{@lpos}"
877
917
 
878
918
  if @cpos == 0
879
919
  range = nil
@@ -909,15 +949,15 @@ class Buffer < String
909
949
  end
910
950
 
911
951
  def move(direction)
912
- puts "cpos:#{@cpos} lpos:#{@lpos} @larger_cpos:#{@larger_cpos}"
952
+ debug "cpos:#{@cpos} lpos:#{@lpos} @larger_cpos:#{@larger_cpos}"
913
953
  if direction == :forward_page
914
- puts "FORWARD PAGE"
954
+ debug "FORWARD PAGE"
915
955
  visible_range = get_visible_area()
916
956
  set_pos(visible_range[1])
917
957
  top_where_cursor()
918
958
  end
919
959
  if direction == :backward_page
920
- puts "backward PAGE"
960
+ debug "backward PAGE"
921
961
  visible_range = get_visible_area()
922
962
  set_pos(visible_range[0])
923
963
  bottom_where_cursor()
@@ -1020,7 +1060,7 @@ class Buffer < String
1020
1060
  if wtype == :url
1021
1061
  open_url(word)
1022
1062
  elsif wtype == :linepointer
1023
- puts word.inspect
1063
+ debug word.inspect
1024
1064
  jump_to_file(word[0], word[1])
1025
1065
  elsif wtype == :textfile
1026
1066
  open_existing_file(word)
@@ -1087,10 +1127,10 @@ class Buffer < String
1087
1127
  word_start = pos if word_start == nil
1088
1128
  word_end = pos if word_end == nil
1089
1129
  word = self[word_start..word_end]
1090
- puts "'WORD: #{word}'"
1130
+ debug "'WORD: #{word}'"
1091
1131
  message("'#{word}'")
1092
1132
  linep = get_file_line_pointer(word)
1093
- puts "linep'#{linep}'"
1133
+ debug "linep'#{linep}'"
1094
1134
  path = File.expand_path(word)
1095
1135
  wtype = nil
1096
1136
  if is_url(word)
@@ -1103,7 +1143,7 @@ class Buffer < String
1103
1143
  wtype = :file
1104
1144
  end
1105
1145
  # elsif hpt_check_cur_word(word) #TODO: check only
1106
- # puts word
1146
+ # debug word
1107
1147
  elsif linep != nil
1108
1148
  wtype = :linepointer
1109
1149
  word = linep
@@ -1131,14 +1171,14 @@ class Buffer < String
1131
1171
  word_start = pos if word_start == nil
1132
1172
  word_end = pos if word_end == nil
1133
1173
  word = self[word_start..word_end]
1134
- puts "'#{word}'"
1174
+ debug "'#{word}'"
1135
1175
  message("'#{word}'")
1136
- #puts wm
1176
+ #debug wm
1137
1177
  end
1138
1178
 
1139
1179
  def jump_to_next_instance_of_word()
1140
1180
  if $kbd.last_action == $kbd.cur_action and @current_word != nil
1141
- # puts "REPEATING *"
1181
+ # debug "REPEATING *"
1142
1182
  else
1143
1183
  start_search = [@pos - 150, 0].max
1144
1184
 
@@ -1237,10 +1277,10 @@ class Buffer < String
1237
1277
 
1238
1278
  if target == FIRST_NON_WHITESPACE
1239
1279
  l = current_line()
1240
- puts l.inspect
1280
+ debug l.inspect
1241
1281
  @cpos = line(@lpos).size - 1
1242
1282
  a = scan_indexes(l, /\S/)
1243
- puts a.inspect
1283
+ debug a.inspect
1244
1284
  if a.any?
1245
1285
  @cpos = a[0]
1246
1286
  else
@@ -1324,9 +1364,9 @@ class Buffer < String
1324
1364
  calculate_line_and_column_pos
1325
1365
  end
1326
1366
 
1327
- def execute_current_line_in_terminal()
1367
+ def execute_current_line_in_terminal(autoclose = false)
1328
1368
  s = get_current_line
1329
- exec_in_terminal(s)
1369
+ exec_in_terminal(s, autoclose)
1330
1370
  end
1331
1371
 
1332
1372
  def insert_new_line()
@@ -1346,8 +1386,17 @@ class Buffer < String
1346
1386
  # Indent start of new line based on last line
1347
1387
  last_line = line(@lpos)
1348
1388
  m = /^( +)([^ ]+|$)/.match(last_line)
1349
- debug m.inspect
1350
- c = c + " " * m[1].size if m
1389
+ if m
1390
+ c = c + " " * m[1].size if m
1391
+ end
1392
+
1393
+ #if tab indent
1394
+ m = /^(\t+)([^\t]+|$)/.match(last_line)
1395
+ if m
1396
+ c = c + "\t" * m[1].size if m
1397
+ end
1398
+
1399
+ # debug m.inspect
1351
1400
  end
1352
1401
  if mode == BEFORE
1353
1402
  insert_pos = @pos
@@ -1360,8 +1409,8 @@ class Buffer < String
1360
1409
 
1361
1410
  #self.insert(insert_pos,c)
1362
1411
  add_delta([insert_pos, INSERT, c.size, c], true)
1363
- #puts("encoding: #{c.encoding}")
1364
- #puts "c.size: #{c.size}"
1412
+ #debug("encoding: #{c.encoding}")
1413
+ #debug "c.size: #{c.size}"
1365
1414
  #recalc_line_ends #TODO: optimize?
1366
1415
  calculate_line_and_column_pos
1367
1416
  #need_redraw!
@@ -1435,7 +1484,7 @@ class Buffer < String
1435
1484
  text = $register[register]
1436
1485
  end
1437
1486
  end
1438
- puts "PASTE: #{text}"
1487
+ debug "PASTE: #{text}"
1439
1488
 
1440
1489
  return if text == ""
1441
1490
 
@@ -1481,7 +1530,6 @@ class Buffer < String
1481
1530
  def start_visual_mode()
1482
1531
  @visual_mode = true
1483
1532
  @selection_start = @pos
1484
- qt_set_selection_start(@id, selection_start)
1485
1533
  $kbd.set_mode(:visual)
1486
1534
  end
1487
1535
 
@@ -1491,7 +1539,13 @@ class Buffer < String
1491
1539
  return if !@visual_mode
1492
1540
 
1493
1541
  debug "COPY SELECTION"
1494
- set_clipboard(self[get_visual_mode_range])
1542
+ s = self[get_visual_mode_range]
1543
+ if x == :append
1544
+ debug "APPEND"
1545
+ s += "\n" + get_clipboard()
1546
+ end
1547
+
1548
+ set_clipboard(s)
1495
1549
  end_visual_mode
1496
1550
  return true
1497
1551
  end
@@ -1636,10 +1690,14 @@ class Buffer < String
1636
1690
  else
1637
1691
  savepath = buflist.get_last_dir
1638
1692
  end
1639
- # Ripl.start :binding => binding
1640
- qt_file_saveas(savepath)
1693
+ gui_file_saveas(savepath)
1641
1694
  # calls back to file_saveas
1642
- # TODO:?
1695
+ end
1696
+
1697
+ def save_as_callback(fpath)
1698
+ set_filename(fpath)
1699
+ save()
1700
+ gui_set_window_title(@title, @subtitle) #TODO: if not active buffer?
1643
1701
  end
1644
1702
 
1645
1703
  def write_contents_to_file(fpath)
@@ -1720,14 +1778,13 @@ class Buffer < String
1720
1778
  def backup()
1721
1779
  fname = @fname
1722
1780
  return if !@fname
1723
- message("Backup buffer #{fname}")
1724
1781
  spfx = fname.gsub("=", "==").gsub("/", "=:")
1725
- spath = File.expand_path("~/autosave")
1782
+ spath = File.expand_path("~/.vimamsa/backup")
1726
1783
  return false if !can_save_to_directory?(spath)
1727
1784
  datetime = DateTime.now().strftime("%d%m%Y:%H%M%S")
1728
1785
  savepath = "#{spath}/#{spfx}_#{datetime}"
1786
+ message("Backup buffer #{fname} TO: #{savepath}")
1729
1787
  if is_path_writable(savepath)
1730
- debug "BACKUP BUFFER TO: #{savepath}"
1731
1788
  write_contents_to_file(savepath)
1732
1789
  else
1733
1790
  message("PATH NOT WRITABLE: #{savepath}")
@@ -23,6 +23,7 @@ end
23
23
  class BufferList < Array
24
24
  attr_reader :current_buf
25
25
 
26
+
26
27
  def <<(_buf)
27
28
  super
28
29
  $buffer = _buf
@@ -30,8 +31,8 @@ class BufferList < Array
30
31
  $buffer_history << @current_buf
31
32
  @recent_ind = 0
32
33
  $hook.call(:change_buffer, $buffer)
33
- qt_set_current_buffer($buffer.id)
34
- qt_set_cursor_pos($buffer.id, $buffer.pos)
34
+ gui_set_current_buffer($buffer.id)
35
+ gui_set_cursor_pos($buffer.id, $buffer.pos)
35
36
  end
36
37
 
37
38
  def switch()
@@ -57,6 +58,12 @@ class BufferList < Array
57
58
  buf_idx = self.index { |b| b.fname == fname }
58
59
  return buf_idx
59
60
  end
61
+
62
+ def get_buffer_by_id(id)
63
+ buf_idx = self.index { |b| b.id == id }
64
+ return buf_idx
65
+ end
66
+
60
67
 
61
68
  def add_current_buf_to_history()
62
69
  @recent_ind = 0
@@ -83,7 +90,7 @@ class BufferList < Array
83
90
  $hook.call(:change_buffer, $buffer)
84
91
  $buffer.set_active
85
92
 
86
- qt_set_current_buffer($buffer.id)
93
+ gui_set_current_buffer($buffer.id)
87
94
  gui_set_window_title($buffer.title,$buffer.subtitle)
88
95
 
89
96
  # hpt_scan_images() if $debug # experimental
@@ -138,7 +145,24 @@ class BufferList < Array
138
145
  $buffer_history = bh.reverse
139
146
  end
140
147
 
148
+
149
+ # Close buffer in the background
150
+ # TODO: if open in another widget
151
+ def close_other_buffer(buffer_i)
152
+ return if self.size <= buffer_i
153
+ return if @current_buf == buffer_i
154
+
155
+ bufname = self[buffer_i].basename
156
+ message("Closed buffer #{bufname}")
157
+
158
+ self.slice!(buffer_i)
159
+ $buffer_history = $buffer_history.collect { |x| r = x; r = x - 1 if x > buffer_i; r = nil if x == buffer_i; r }.compact
160
+
161
+ end
162
+
163
+
141
164
  def close_buffer(buffer_i, from_recent = false)
165
+ return if buffer_i.nil?
142
166
  return if self.size <= buffer_i
143
167
 
144
168
  bufname = self[buffer_i].basename