vimamsa 0.1.7 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -4
- data/custom_example.rb +47 -0
- data/demo.txt +25 -0
- data/lang/hyperplaintext.lang +9 -25
- data/lib/vimamsa/ack.rb +55 -9
- data/lib/vimamsa/actions.rb +27 -8
- data/lib/vimamsa/buffer.rb +120 -82
- data/lib/vimamsa/buffer_list.rb +48 -30
- data/lib/vimamsa/buffer_manager.rb +83 -0
- data/lib/vimamsa/conf.rb +21 -0
- data/lib/vimamsa/debug.rb +11 -10
- data/lib/vimamsa/easy_jump.rb +15 -20
- data/lib/vimamsa/editor.rb +100 -85
- data/lib/vimamsa/encrypt.rb +3 -3
- data/lib/vimamsa/file_finder.rb +6 -9
- data/lib/vimamsa/file_history.rb +3 -3
- data/lib/vimamsa/file_manager.rb +16 -13
- data/lib/vimamsa/gui.rb +95 -90
- data/lib/vimamsa/gui_image.rb +43 -0
- data/lib/vimamsa/gui_menu.rb +11 -2
- data/lib/vimamsa/gui_select_window.rb +16 -13
- data/lib/vimamsa/gui_sourceview.rb +66 -38
- data/lib/vimamsa/hyper_plain_text.rb +40 -21
- data/lib/vimamsa/key_actions.rb +38 -13
- data/lib/vimamsa/key_binding_tree.rb +50 -126
- data/lib/vimamsa/key_bindings_vimlike.rb +26 -24
- data/lib/vimamsa/macro.rb +5 -5
- data/lib/vimamsa/main.rb +3 -3
- data/lib/vimamsa/rbvma.rb +22 -18
- data/lib/vimamsa/search.rb +2 -2
- data/lib/vimamsa/search_replace.rb +25 -22
- data/lib/vimamsa/text_transforms.rb +3 -1
- data/lib/vimamsa/util.rb +34 -0
- data/lib/vimamsa/version.rb +1 -1
- data/lib/vimamsa.rb +5 -0
- data/sheep.jpg +0 -0
- data/styles/dark.xml +1 -0
- data/styles/molokai_edit.xml +1 -1
- data/vimamsa.gemspec +2 -2
- metadata +16 -11
- data/lib/vimamsa/gui_gtk_sourceview.rb +0 -294
data/lib/vimamsa/buffer.rb
CHANGED
@@ -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,11 +26,12 @@ 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)
|
31
|
-
|
33
|
+
gui_create_buffer(@id, self)
|
34
|
+
debug "NEW BUFFER fn=#{fname} ID:#{@id}"
|
32
35
|
|
33
36
|
@module = nil
|
34
37
|
|
@@ -71,6 +74,15 @@ class Buffer < String
|
|
71
74
|
@active_kbd_mode = nil
|
72
75
|
end
|
73
76
|
|
77
|
+
def list_str()
|
78
|
+
if @fname.nil?
|
79
|
+
x = @title
|
80
|
+
else
|
81
|
+
x = @fname
|
82
|
+
end
|
83
|
+
return x
|
84
|
+
end
|
85
|
+
|
74
86
|
def set_active
|
75
87
|
if !@active_kbd_mode.nil?
|
76
88
|
$kbd.set_mode(@active_kbd_mode)
|
@@ -104,7 +116,7 @@ class Buffer < String
|
|
104
116
|
# lang.get_metadata("block-comment-end")
|
105
117
|
@lang_nfo = lang
|
106
118
|
if !lang.nil? and !lang.id.nil?
|
107
|
-
|
119
|
+
debug "Guessed LANG: #{lang.id}"
|
108
120
|
@lang = lang.id
|
109
121
|
end
|
110
122
|
|
@@ -113,10 +125,32 @@ class Buffer < String
|
|
113
125
|
end
|
114
126
|
end
|
115
127
|
|
128
|
+
def view()
|
129
|
+
# Get the VSourceView < GtkSource::View object corresponding to this buffer
|
130
|
+
return vma.gui.buffers[@id]
|
131
|
+
end
|
132
|
+
|
116
133
|
def add_image(imgpath, pos)
|
117
134
|
return if !is_legal_pos(pos)
|
118
|
-
|
119
|
-
|
135
|
+
|
136
|
+
vbuf = view.buffer
|
137
|
+
itr = vbuf.get_iter_at(:offset => pos)
|
138
|
+
itr2 = vbuf.get_iter_at(:offset => pos + 1)
|
139
|
+
vbuf.delete(itr, itr2)
|
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)
|
120
154
|
end
|
121
155
|
|
122
156
|
def is_legal_pos(pos, op = :read)
|
@@ -148,6 +182,7 @@ class Buffer < String
|
|
148
182
|
b = " \n"
|
149
183
|
txt = a + b
|
150
184
|
insert_txt_at(txt, lr.end + 1)
|
185
|
+
buf.view.handle_deltas
|
151
186
|
imgpos = lr.end + 1 + a.size
|
152
187
|
add_image(fname, imgpos)
|
153
188
|
end
|
@@ -197,20 +232,20 @@ class Buffer < String
|
|
197
232
|
ok = true
|
198
233
|
@bt.each_line { |r|
|
199
234
|
if lines[i] != r #or true
|
200
|
-
|
201
|
-
|
202
|
-
#
|
203
|
-
#
|
204
|
-
|
205
|
-
|
206
|
-
|
235
|
+
debug "NO MATCH FOR LINE:"
|
236
|
+
debug "i=#{i}["
|
237
|
+
# debug "[orig]pos=#{leaf.pos} |#{leaf.data}|"
|
238
|
+
# debug "spos=#{spos} nchar=#{leaf.nchar} epos=#{epos} a[]=\nr=|#{r}|"
|
239
|
+
debug "fromtree:|#{r}|"
|
240
|
+
debug "frombuf:|#{lines[i]}"
|
241
|
+
debug "]"
|
207
242
|
ok = false
|
208
243
|
end
|
209
244
|
i += 1
|
210
245
|
}
|
211
246
|
|
212
|
-
|
213
|
-
|
247
|
+
debug "BT: NO ERRORS" if ok
|
248
|
+
debug "BT: ERRORS" if !ok
|
214
249
|
end
|
215
250
|
|
216
251
|
def set_content(str)
|
@@ -220,7 +255,7 @@ class Buffer < String
|
|
220
255
|
if str[0..10] == "VMACRYPT001"
|
221
256
|
@encrypted_str = str[11..-1]
|
222
257
|
callback = proc { |x| decrypt_cur_buffer(x) }
|
223
|
-
gui_one_input_action("Decrypt", "Password:", "decrypt", callback)
|
258
|
+
gui_one_input_action("Decrypt", "Password:", "decrypt", callback, { :hide => true })
|
224
259
|
str = "ENCRYPTED"
|
225
260
|
else
|
226
261
|
# @crypt = nil
|
@@ -270,6 +305,8 @@ class Buffer < String
|
|
270
305
|
@update_hl_endpos = self.size - 1
|
271
306
|
|
272
307
|
gui_set_buffer_contents(@id, self.to_s)
|
308
|
+
@images = [] #TODO: if reload
|
309
|
+
hpt_scan_images(self)
|
273
310
|
|
274
311
|
# add_hl_update(@update_hl_startpos, @update_hl_endpos)
|
275
312
|
end
|
@@ -283,6 +320,7 @@ class Buffer < String
|
|
283
320
|
@dirname = File.dirname(@fname)
|
284
321
|
userhome = File.expand_path("~")
|
285
322
|
@subtitle = @dirname.gsub(/^#{userhome}/, "~")
|
323
|
+
vma.buffers.last_dir = @dirname
|
286
324
|
|
287
325
|
detect_file_language
|
288
326
|
end
|
@@ -429,11 +467,11 @@ class Buffer < String
|
|
429
467
|
end
|
430
468
|
|
431
469
|
def update_index(pos, changeamount)
|
432
|
-
#
|
470
|
+
# debug "pos #{pos}, changeamount #{changeamount}, @pos #{@pos}"
|
433
471
|
@edit_pos_history.collect! { |x| r = x if x <= pos; r = x + changeamount if x > pos; r }
|
434
472
|
# TODO: handle between removal case
|
435
473
|
for k in @marks.keys
|
436
|
-
#
|
474
|
+
# debug "change(?): pos=#{pos}, k=#{k}, #{@marks[k]}, #{changeamount}"
|
437
475
|
if @marks[k] > pos
|
438
476
|
@marks[k] = @marks[k] + changeamount
|
439
477
|
end
|
@@ -537,8 +575,7 @@ class Buffer < String
|
|
537
575
|
|
538
576
|
def comment_linerange(r)
|
539
577
|
com_str = get_com_str()
|
540
|
-
|
541
|
-
lines = $buffer[r].lines
|
578
|
+
lines = self[r].lines
|
542
579
|
mod = ""
|
543
580
|
lines.each { |line|
|
544
581
|
m = line.match(/^(\s*)(\S.*)/)
|
@@ -574,7 +611,7 @@ class Buffer < String
|
|
574
611
|
ls = nil
|
575
612
|
ls = @line_ends[a] if a != nil
|
576
613
|
# if a != nil and ls != @line_ends[a]
|
577
|
-
#
|
614
|
+
# debug "NO MATCH @line_ends[a]"
|
578
615
|
# end
|
579
616
|
|
580
617
|
if ls == nil
|
@@ -600,14 +637,14 @@ class Buffer < String
|
|
600
637
|
elsif op == :uncomment
|
601
638
|
uncomment_linerange(first..last)
|
602
639
|
end
|
603
|
-
|
640
|
+
self.end_visual_mode
|
604
641
|
end
|
605
642
|
end
|
606
643
|
|
607
644
|
def uncomment_linerange(r)
|
608
645
|
com_str = get_com_str()
|
609
|
-
#r
|
610
|
-
lines =
|
646
|
+
#r=self.line_range(self.lpos, 2)
|
647
|
+
lines = self[r].split(/(\n)/).each_slice(2).map { |x| x[0] }
|
611
648
|
mod = lines.collect { |x| x.sub(/^(\s*)(#{com_str}\s?)/, '\1') + "\n" }.join()
|
612
649
|
replace_range(r, mod)
|
613
650
|
end
|
@@ -679,7 +716,7 @@ class Buffer < String
|
|
679
716
|
end
|
680
717
|
|
681
718
|
debug "Scan line_end time: #{Time.now - t1}"
|
682
|
-
#
|
719
|
+
#debug @line_ends
|
683
720
|
end
|
684
721
|
|
685
722
|
def sanity_check_line_ends()
|
@@ -696,7 +733,7 @@ class Buffer < String
|
|
696
733
|
end
|
697
734
|
|
698
735
|
def update_bufpos_on_change(positions, xpos, changeamount)
|
699
|
-
#
|
736
|
+
# debug "xpos=#{xpos} changeamount=#{changeamount}"
|
700
737
|
positions.collect { |x|
|
701
738
|
r = nil
|
702
739
|
r = x if x < xpos
|
@@ -731,7 +768,7 @@ class Buffer < String
|
|
731
768
|
i_nl = scan_indexes(changestr, /\n/)
|
732
769
|
i_nl.collect! { |x| x + pos }
|
733
770
|
end
|
734
|
-
#
|
771
|
+
# debug "change:#{changeamount}"
|
735
772
|
#TODO: this is the bottle neck in insert_txt action
|
736
773
|
@line_ends.collect! { |x|
|
737
774
|
r = nil
|
@@ -755,6 +792,10 @@ class Buffer < String
|
|
755
792
|
return @pos == self.size
|
756
793
|
end
|
757
794
|
|
795
|
+
def jump_to_pos(new_pos)
|
796
|
+
set_pos(new_pos)
|
797
|
+
end
|
798
|
+
|
758
799
|
def set_pos(new_pos)
|
759
800
|
if new_pos >= self.size
|
760
801
|
@pos = self.size - 1 # TODO:??right side of last char
|
@@ -879,10 +920,10 @@ class Buffer < String
|
|
879
920
|
range = @pos..wmarks[0]
|
880
921
|
end
|
881
922
|
elsif range_id == :to_line_end
|
882
|
-
|
923
|
+
debug "TO LINE END"
|
883
924
|
range = @pos..(@line_ends[@lpos] - 1)
|
884
925
|
elsif range_id == :to_line_start
|
885
|
-
|
926
|
+
debug "TO LINE START: #{@lpos}"
|
886
927
|
|
887
928
|
if @cpos == 0
|
888
929
|
range = nil
|
@@ -918,15 +959,15 @@ class Buffer < String
|
|
918
959
|
end
|
919
960
|
|
920
961
|
def move(direction)
|
921
|
-
|
962
|
+
debug "cpos:#{@cpos} lpos:#{@lpos} @larger_cpos:#{@larger_cpos}"
|
922
963
|
if direction == :forward_page
|
923
|
-
|
964
|
+
debug "FORWARD PAGE"
|
924
965
|
visible_range = get_visible_area()
|
925
966
|
set_pos(visible_range[1])
|
926
967
|
top_where_cursor()
|
927
968
|
end
|
928
969
|
if direction == :backward_page
|
929
|
-
|
970
|
+
debug "backward PAGE"
|
930
971
|
visible_range = get_visible_area()
|
931
972
|
set_pos(visible_range[0])
|
932
973
|
bottom_where_cursor()
|
@@ -1029,14 +1070,17 @@ class Buffer < String
|
|
1029
1070
|
if wtype == :url
|
1030
1071
|
open_url(word)
|
1031
1072
|
elsif wtype == :linepointer
|
1032
|
-
|
1033
|
-
jump_to_file(word[0], word[1])
|
1073
|
+
jump_to_file(word[0], word[1], word[2])
|
1034
1074
|
elsif wtype == :textfile
|
1035
1075
|
open_existing_file(word)
|
1036
1076
|
elsif wtype == :file
|
1037
1077
|
open_with_default_program(word)
|
1038
1078
|
elsif wtype == :hpt_link
|
1039
1079
|
open_existing_file(word)
|
1080
|
+
elsif wtype == :help
|
1081
|
+
if word == "keybindings"
|
1082
|
+
call_action(:show_key_bindings)
|
1083
|
+
end
|
1040
1084
|
else
|
1041
1085
|
#TODO
|
1042
1086
|
end
|
@@ -1096,10 +1140,10 @@ class Buffer < String
|
|
1096
1140
|
word_start = pos if word_start == nil
|
1097
1141
|
word_end = pos if word_end == nil
|
1098
1142
|
word = self[word_start..word_end]
|
1099
|
-
|
1100
|
-
message("
|
1143
|
+
debug "'WORD: #{word}'"
|
1144
|
+
# message("Open link #{word}")
|
1101
1145
|
linep = get_file_line_pointer(word)
|
1102
|
-
|
1146
|
+
debug "linep'#{linep}'"
|
1103
1147
|
path = File.expand_path(word)
|
1104
1148
|
wtype = nil
|
1105
1149
|
if is_url(word)
|
@@ -1112,10 +1156,12 @@ class Buffer < String
|
|
1112
1156
|
wtype = :file
|
1113
1157
|
end
|
1114
1158
|
# elsif hpt_check_cur_word(word) #TODO: check only
|
1115
|
-
#
|
1159
|
+
# debug word
|
1116
1160
|
elsif linep != nil
|
1117
1161
|
wtype = :linepointer
|
1118
1162
|
word = linep
|
1163
|
+
elsif m = word.match(/⟦help:(.*)⟧/)
|
1164
|
+
return [m[1], :help]
|
1119
1165
|
else
|
1120
1166
|
fn = hpt_check_cur_word(word)
|
1121
1167
|
if !fn.nil?
|
@@ -1132,22 +1178,9 @@ class Buffer < String
|
|
1132
1178
|
handle_word(wnfo)
|
1133
1179
|
end
|
1134
1180
|
|
1135
|
-
def get_cur_word()
|
1136
|
-
wem = get_word_end_marks(@pos, @pos + 200)
|
1137
|
-
wsm = get_word_start_marks(@pos - 200, @pos)
|
1138
|
-
word_start = wsm[-1]
|
1139
|
-
word_end = wem[0]
|
1140
|
-
word_start = pos if word_start == nil
|
1141
|
-
word_end = pos if word_end == nil
|
1142
|
-
word = self[word_start..word_end]
|
1143
|
-
puts "'#{word}'"
|
1144
|
-
message("'#{word}'")
|
1145
|
-
#puts wm
|
1146
|
-
end
|
1147
|
-
|
1148
1181
|
def jump_to_next_instance_of_word()
|
1149
1182
|
if $kbd.last_action == $kbd.cur_action and @current_word != nil
|
1150
|
-
#
|
1183
|
+
# debug "REPEATING *"
|
1151
1184
|
else
|
1152
1185
|
start_search = [@pos - 150, 0].max
|
1153
1186
|
|
@@ -1246,10 +1279,10 @@ class Buffer < String
|
|
1246
1279
|
|
1247
1280
|
if target == FIRST_NON_WHITESPACE
|
1248
1281
|
l = current_line()
|
1249
|
-
|
1282
|
+
debug l.inspect
|
1250
1283
|
@cpos = line(@lpos).size - 1
|
1251
1284
|
a = scan_indexes(l, /\S/)
|
1252
|
-
|
1285
|
+
debug a.inspect
|
1253
1286
|
if a.any?
|
1254
1287
|
@cpos = a[0]
|
1255
1288
|
else
|
@@ -1323,7 +1356,7 @@ class Buffer < String
|
|
1323
1356
|
d2 = [@pos, INSERT, 1, char]
|
1324
1357
|
add_delta(d1, true)
|
1325
1358
|
add_delta(d2, true)
|
1326
|
-
debug "DELTAS:#{
|
1359
|
+
debug "DELTAS:#{self.deltas.inspect} "
|
1327
1360
|
end
|
1328
1361
|
|
1329
1362
|
def insert_txt_at(c, pos)
|
@@ -1358,14 +1391,13 @@ class Buffer < String
|
|
1358
1391
|
if m
|
1359
1392
|
c = c + " " * m[1].size if m
|
1360
1393
|
end
|
1361
|
-
|
1362
1394
|
|
1363
1395
|
#if tab indent
|
1364
1396
|
m = /^(\t+)([^\t]+|$)/.match(last_line)
|
1365
1397
|
if m
|
1366
1398
|
c = c + "\t" * m[1].size if m
|
1367
1399
|
end
|
1368
|
-
|
1400
|
+
|
1369
1401
|
# debug m.inspect
|
1370
1402
|
end
|
1371
1403
|
if mode == BEFORE
|
@@ -1379,8 +1411,8 @@ class Buffer < String
|
|
1379
1411
|
|
1380
1412
|
#self.insert(insert_pos,c)
|
1381
1413
|
add_delta([insert_pos, INSERT, c.size, c], true)
|
1382
|
-
#
|
1383
|
-
#
|
1414
|
+
#debug("encoding: #{c.encoding}")
|
1415
|
+
#debug "c.size: #{c.size}"
|
1384
1416
|
#recalc_line_ends #TODO: optimize?
|
1385
1417
|
calculate_line_and_column_pos
|
1386
1418
|
#need_redraw!
|
@@ -1417,7 +1449,6 @@ class Buffer < String
|
|
1417
1449
|
for d in deltas
|
1418
1450
|
add_delta(d, true, true)
|
1419
1451
|
end
|
1420
|
-
# $buffer.update_content(IO.read('test.txt'))
|
1421
1452
|
end
|
1422
1453
|
|
1423
1454
|
def need_redraw!
|
@@ -1454,7 +1485,7 @@ class Buffer < String
|
|
1454
1485
|
text = $register[register]
|
1455
1486
|
end
|
1456
1487
|
end
|
1457
|
-
|
1488
|
+
debug "PASTE: #{text}"
|
1458
1489
|
|
1459
1490
|
return if text == ""
|
1460
1491
|
|
@@ -1511,7 +1542,7 @@ class Buffer < String
|
|
1511
1542
|
debug "COPY SELECTION"
|
1512
1543
|
s = self[get_visual_mode_range]
|
1513
1544
|
if x == :append
|
1514
|
-
|
1545
|
+
debug "APPEND"
|
1515
1546
|
s += "\n" + get_clipboard()
|
1516
1547
|
end
|
1517
1548
|
|
@@ -1653,7 +1684,7 @@ class Buffer < String
|
|
1653
1684
|
# If current file has fname, save to that fname
|
1654
1685
|
# Else search for previously open files and save to the directory of
|
1655
1686
|
# the last viewed file that has a filename
|
1656
|
-
#
|
1687
|
+
# selffers[$buffer_history.reverse[1]].fname
|
1657
1688
|
|
1658
1689
|
if @fname
|
1659
1690
|
savepath = File.dirname(@fname)
|
@@ -1680,21 +1711,23 @@ class Buffer < String
|
|
1680
1711
|
end
|
1681
1712
|
|
1682
1713
|
Thread.new {
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1714
|
+
begin
|
1715
|
+
io = File.open(fpath, mode)
|
1716
|
+
io.set_encoding(self.encoding)
|
1717
|
+
io.write(contents)
|
1718
|
+
io.close
|
1719
|
+
rescue Encoding::UndefinedConversionError => ex
|
1720
|
+
puts "Encoding::UndefinedConversionError"
|
1721
|
+
# this might happen when trying to save UTF-8 as US-ASCII
|
1722
|
+
# so just warn, try to save as UTF-8 instead.
|
1723
|
+
warn("Saving as UTF-8 because of: #{ex.class}: #{ex}")
|
1724
|
+
io.rewind
|
1725
|
+
|
1726
|
+
io.set_encoding(Encoding::UTF_8)
|
1727
|
+
io.write(contents)
|
1728
|
+
rescue Errno::EACCES => ex
|
1729
|
+
message("File #{fpath} not writeable")
|
1730
|
+
#TODO: show message box
|
1698
1731
|
end
|
1699
1732
|
sleep 3
|
1700
1733
|
}
|
@@ -1713,7 +1746,7 @@ class Buffer < String
|
|
1713
1746
|
def indent()
|
1714
1747
|
file = Tempfile.new("out")
|
1715
1748
|
infile = Tempfile.new("in")
|
1716
|
-
file.write(
|
1749
|
+
file.write(self.to_s)
|
1717
1750
|
file.flush
|
1718
1751
|
bufc = "FOO"
|
1719
1752
|
|
@@ -1739,12 +1772,17 @@ class Buffer < String
|
|
1739
1772
|
else
|
1740
1773
|
return
|
1741
1774
|
end
|
1742
|
-
|
1775
|
+
self.update_content(bufc)
|
1743
1776
|
center_on_current_line #TODO: needed?
|
1744
1777
|
file.close; file.unlink
|
1745
1778
|
infile.close; infile.unlink
|
1746
1779
|
end
|
1747
1780
|
|
1781
|
+
def close()
|
1782
|
+
idx = vma.buffers.get_buffer_by_id(@id)
|
1783
|
+
vma.buffers.close_buffer(idx)
|
1784
|
+
end
|
1785
|
+
|
1748
1786
|
def backup()
|
1749
1787
|
fname = @fname
|
1750
1788
|
return if !@fname
|
@@ -1765,7 +1803,7 @@ end
|
|
1765
1803
|
#TODO
|
1766
1804
|
def write_to_file(savepath, s)
|
1767
1805
|
if is_path_writable(savepath)
|
1768
|
-
IO.write(savepath,
|
1806
|
+
IO.write(savepath, self.to_s)
|
1769
1807
|
else
|
1770
1808
|
message("PATH NOT WRITABLE: #{savepath}")
|
1771
1809
|
end
|
@@ -1780,7 +1818,7 @@ def is_path_writable(fpath)
|
|
1780
1818
|
end
|
1781
1819
|
|
1782
1820
|
def backup_all_buffers()
|
1783
|
-
for buf in
|
1821
|
+
for buf in selffers
|
1784
1822
|
buf.backup
|
1785
1823
|
end
|
1786
1824
|
message("Backup all buffers")
|
data/lib/vimamsa/buffer_list.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
1
|
def save_buffer_list()
|
3
2
|
message("Save buffer list")
|
4
3
|
buffn = get_dot_path("buffers.txt")
|
5
4
|
f = File.open(buffn, "w")
|
6
|
-
bufstr =
|
5
|
+
bufstr = vma.buffers.collect { |buf| buf.fname }.inspect
|
7
6
|
f.write(bufstr)
|
8
7
|
f.close()
|
9
8
|
end
|
@@ -21,17 +20,23 @@ def load_buffer_list()
|
|
21
20
|
end
|
22
21
|
|
23
22
|
class BufferList < Array
|
24
|
-
attr_reader :current_buf
|
23
|
+
attr_reader :current_buf, :last_dir
|
24
|
+
|
25
|
+
def initialize()
|
26
|
+
@last_dir = File.expand_path(".")
|
27
|
+
super
|
28
|
+
end
|
25
29
|
|
30
|
+
# lastdir = File.expand_path(".") if lastdir.nil?
|
26
31
|
def <<(_buf)
|
27
32
|
super
|
28
|
-
|
33
|
+
vma.buf = _buf
|
29
34
|
@current_buf = self.size - 1
|
30
35
|
$buffer_history << @current_buf
|
31
36
|
@recent_ind = 0
|
32
|
-
$hook.call(:change_buffer,
|
33
|
-
gui_set_current_buffer(
|
34
|
-
gui_set_cursor_pos(
|
37
|
+
$hook.call(:change_buffer, vma.buf)
|
38
|
+
gui_set_current_buffer(vma.buf.id)
|
39
|
+
gui_set_cursor_pos(vma.buf.id, vma.buf.pos)
|
35
40
|
end
|
36
41
|
|
37
42
|
def switch()
|
@@ -58,6 +63,11 @@ class BufferList < Array
|
|
58
63
|
return buf_idx
|
59
64
|
end
|
60
65
|
|
66
|
+
def get_buffer_by_id(id)
|
67
|
+
buf_idx = self.index { |b| b.id == id }
|
68
|
+
return buf_idx
|
69
|
+
end
|
70
|
+
|
61
71
|
def add_current_buf_to_history()
|
62
72
|
@recent_ind = 0
|
63
73
|
$buffer_history << @current_buf
|
@@ -67,11 +77,11 @@ class BufferList < Array
|
|
67
77
|
def set_current_buffer(buffer_i, update_history = true)
|
68
78
|
buffer_i = self.size -1 if buffer_i > self.size
|
69
79
|
buffer_i = 0 if buffer_i < 0
|
70
|
-
|
71
|
-
return if
|
80
|
+
vma.buf = self[buffer_i]
|
81
|
+
return if !vma.buf
|
72
82
|
@current_buf = buffer_i
|
73
83
|
debug "SWITCH BUF2. bufsize:#{self.size}, curbuf: #{@current_buf}"
|
74
|
-
fpath =
|
84
|
+
fpath = vma.buf.fname
|
75
85
|
if fpath and fpath.size > 50
|
76
86
|
fpath = fpath[-50..-1]
|
77
87
|
end
|
@@ -80,31 +90,25 @@ class BufferList < Array
|
|
80
90
|
add_current_buf_to_history
|
81
91
|
end
|
82
92
|
|
83
|
-
$hook.call(:change_buffer,
|
84
|
-
|
93
|
+
$hook.call(:change_buffer, vma.buf)
|
94
|
+
vma.buf.set_active
|
95
|
+
|
96
|
+
gui_set_current_buffer(vma.buf.id)
|
97
|
+
gui_set_window_title(vma.buf.title, vma.buf.subtitle)
|
85
98
|
|
86
|
-
|
87
|
-
|
99
|
+
if vma.buf.fname
|
100
|
+
@last_dir = File.dirname(vma.buf.fname)
|
101
|
+
end
|
88
102
|
|
89
103
|
# hpt_scan_images() if $debug # experimental
|
90
104
|
end
|
91
105
|
|
106
|
+
def last_dir=(d)
|
107
|
+
@last_dir = d
|
108
|
+
end
|
109
|
+
|
92
110
|
def get_last_dir
|
93
|
-
|
94
|
-
if $buffer.fname
|
95
|
-
lastdir = File.dirname($buffer.fname)
|
96
|
-
else
|
97
|
-
for bufid in $buffer_history.reverse[1..-1]
|
98
|
-
bf = $buffers[bufid]
|
99
|
-
debug "FNAME:#{bf.fname}"
|
100
|
-
if bf.fname
|
101
|
-
lastdir = File.dirname(bf.fname)
|
102
|
-
break
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
lastdir = File.expand_path(".") if lastdir.nil?
|
107
|
-
return lastdir
|
111
|
+
return @last_dir
|
108
112
|
end
|
109
113
|
|
110
114
|
def get_recent_buffers()
|
@@ -138,9 +142,23 @@ class BufferList < Array
|
|
138
142
|
$buffer_history = bh.reverse
|
139
143
|
end
|
140
144
|
|
145
|
+
# Close buffer in the background
|
146
|
+
# TODO: if open in another widget
|
147
|
+
def close_other_buffer(buffer_i)
|
148
|
+
return if self.size <= buffer_i
|
149
|
+
return if @current_buf == buffer_i
|
150
|
+
|
151
|
+
bufname = self[buffer_i].basename
|
152
|
+
message("Closed buffer #{bufname}")
|
153
|
+
|
154
|
+
self.slice!(buffer_i)
|
155
|
+
$buffer_history = $buffer_history.collect { |x| r = x; r = x - 1 if x > buffer_i; r = nil if x == buffer_i; r }.compact
|
156
|
+
end
|
157
|
+
|
141
158
|
def close_buffer(buffer_i, from_recent = false)
|
159
|
+
return if buffer_i.nil?
|
142
160
|
return if self.size <= buffer_i
|
143
|
-
|
161
|
+
|
144
162
|
bufname = self[buffer_i].basename
|
145
163
|
message("Closed buffer #{bufname}")
|
146
164
|
recent = get_recent_buffers
|