vimamsa 0.1.6 → 0.1.9
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.
- checksums.yaml +4 -4
- data/custom_example.rb +47 -0
- data/demo.txt +25 -0
- data/lang/hyperplaintext.lang +9 -25
- data/lib/vimamsa/ack.rb +90 -7
- data/lib/vimamsa/actions.rb +27 -8
- data/lib/vimamsa/buffer.rb +130 -76
- data/lib/vimamsa/buffer_list.rb +24 -0
- data/lib/vimamsa/buffer_manager.rb +83 -0
- data/lib/vimamsa/conf.rb +21 -0
- data/lib/vimamsa/debug.rb +3 -2
- data/lib/vimamsa/easy_jump.rb +15 -20
- data/lib/vimamsa/editor.rb +93 -73
- data/lib/vimamsa/encrypt.rb +1 -1
- data/lib/vimamsa/file_finder.rb +6 -9
- data/lib/vimamsa/file_history.rb +3 -3
- data/lib/vimamsa/file_manager.rb +9 -8
- data/lib/vimamsa/gui.rb +89 -87
- 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 +64 -37
- data/lib/vimamsa/hyper_plain_text.rb +38 -19
- data/lib/vimamsa/key_actions.rb +40 -13
- data/lib/vimamsa/key_binding_tree.rb +52 -128
- data/lib/vimamsa/key_bindings_vimlike.rb +28 -25
- data/lib/vimamsa/macro.rb +5 -5
- data/lib/vimamsa/rbvma.rb +22 -18
- data/lib/vimamsa/search.rb +1 -1
- data/lib/vimamsa/search_replace.rb +11 -8
- data/lib/vimamsa/text_transforms.rb +2 -0
- 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 +1 -1
- metadata +13 -8
- data/lib/vimamsa/gui_gtk_sourceview.rb +0 -294
data/lib/vimamsa/buffer.rb
CHANGED
@@ -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"
|
@@ -9,11 +10,13 @@ $buffer_history = [0]
|
|
9
10
|
|
10
11
|
$update_highlight = false
|
11
12
|
|
13
|
+
$ifuncon = false
|
14
|
+
|
12
15
|
class Buffer < String
|
13
16
|
|
14
17
|
#attr_reader (:pos, :cpos, :lpos)
|
15
18
|
|
16
|
-
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
|
17
20
|
attr_writer :call_func, :update_highlight
|
18
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
|
19
22
|
|
@@ -23,11 +26,12 @@ class Buffer < String
|
|
23
26
|
debug "Buffer.rb: def initialize"
|
24
27
|
super(str)
|
25
28
|
|
29
|
+
@images = []
|
26
30
|
@lang = nil
|
27
31
|
@id = @@num_buffers
|
28
32
|
@@num_buffers += 1
|
29
|
-
gui_create_buffer(@id)
|
30
|
-
|
33
|
+
gui_create_buffer(@id, self)
|
34
|
+
debug "NEW BUFFER fn=#{fname} ID:#{@id}"
|
31
35
|
|
32
36
|
@module = nil
|
33
37
|
|
@@ -70,6 +74,15 @@ class Buffer < String
|
|
70
74
|
@active_kbd_mode = nil
|
71
75
|
end
|
72
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
|
+
|
73
86
|
def set_active
|
74
87
|
if !@active_kbd_mode.nil?
|
75
88
|
$kbd.set_mode(@active_kbd_mode)
|
@@ -79,6 +92,13 @@ class Buffer < String
|
|
79
92
|
# gui_set_current_buffer(@id)
|
80
93
|
end
|
81
94
|
|
95
|
+
def set_executable
|
96
|
+
if File.exists?(@fname)
|
97
|
+
FileUtils.chmod("+x", @fname)
|
98
|
+
message("Set executable: #{@fname}")
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
82
102
|
def detect_file_language
|
83
103
|
@lang = nil
|
84
104
|
@lang = "c" if @fname.match(/\.(c|h|cpp)$/)
|
@@ -96,7 +116,7 @@ class Buffer < String
|
|
96
116
|
# lang.get_metadata("block-comment-end")
|
97
117
|
@lang_nfo = lang
|
98
118
|
if !lang.nil? and !lang.id.nil?
|
99
|
-
|
119
|
+
debug "Guessed LANG: #{lang.id}"
|
100
120
|
@lang = lang.id
|
101
121
|
end
|
102
122
|
|
@@ -105,10 +125,32 @@ class Buffer < String
|
|
105
125
|
end
|
106
126
|
end
|
107
127
|
|
128
|
+
def view()
|
129
|
+
# Get the VSourceView < GtkSource::View object corresponding to this buffer
|
130
|
+
return vma.gui.buffers[@id]
|
131
|
+
end
|
132
|
+
|
108
133
|
def add_image(imgpath, pos)
|
109
134
|
return if !is_legal_pos(pos)
|
110
|
-
|
111
|
-
|
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)
|
112
154
|
end
|
113
155
|
|
114
156
|
def is_legal_pos(pos, op = :read)
|
@@ -140,6 +182,7 @@ class Buffer < String
|
|
140
182
|
b = " \n"
|
141
183
|
txt = a + b
|
142
184
|
insert_txt_at(txt, lr.end + 1)
|
185
|
+
buf.view.handle_deltas
|
143
186
|
imgpos = lr.end + 1 + a.size
|
144
187
|
add_image(fname, imgpos)
|
145
188
|
end
|
@@ -189,20 +232,20 @@ class Buffer < String
|
|
189
232
|
ok = true
|
190
233
|
@bt.each_line { |r|
|
191
234
|
if lines[i] != r #or true
|
192
|
-
|
193
|
-
|
194
|
-
#
|
195
|
-
#
|
196
|
-
|
197
|
-
|
198
|
-
|
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 "]"
|
199
242
|
ok = false
|
200
243
|
end
|
201
244
|
i += 1
|
202
245
|
}
|
203
246
|
|
204
|
-
|
205
|
-
|
247
|
+
debug "BT: NO ERRORS" if ok
|
248
|
+
debug "BT: ERRORS" if !ok
|
206
249
|
end
|
207
250
|
|
208
251
|
def set_content(str)
|
@@ -212,7 +255,7 @@ class Buffer < String
|
|
212
255
|
if str[0..10] == "VMACRYPT001"
|
213
256
|
@encrypted_str = str[11..-1]
|
214
257
|
callback = proc { |x| decrypt_cur_buffer(x) }
|
215
|
-
gui_one_input_action("Decrypt", "Password:", "decrypt", callback)
|
258
|
+
gui_one_input_action("Decrypt", "Password:", "decrypt", callback, { :hide => true })
|
216
259
|
str = "ENCRYPTED"
|
217
260
|
else
|
218
261
|
# @crypt = nil
|
@@ -262,6 +305,8 @@ class Buffer < String
|
|
262
305
|
@update_hl_endpos = self.size - 1
|
263
306
|
|
264
307
|
gui_set_buffer_contents(@id, self.to_s)
|
308
|
+
@images = [] #TODO: if reload
|
309
|
+
hpt_scan_images(self)
|
265
310
|
|
266
311
|
# add_hl_update(@update_hl_startpos, @update_hl_endpos)
|
267
312
|
end
|
@@ -421,11 +466,11 @@ class Buffer < String
|
|
421
466
|
end
|
422
467
|
|
423
468
|
def update_index(pos, changeamount)
|
424
|
-
#
|
469
|
+
# debug "pos #{pos}, changeamount #{changeamount}, @pos #{@pos}"
|
425
470
|
@edit_pos_history.collect! { |x| r = x if x <= pos; r = x + changeamount if x > pos; r }
|
426
471
|
# TODO: handle between removal case
|
427
472
|
for k in @marks.keys
|
428
|
-
#
|
473
|
+
# debug "change(?): pos=#{pos}, k=#{k}, #{@marks[k]}, #{changeamount}"
|
429
474
|
if @marks[k] > pos
|
430
475
|
@marks[k] = @marks[k] + changeamount
|
431
476
|
end
|
@@ -451,7 +496,6 @@ class Buffer < String
|
|
451
496
|
return if @edit_pos_history.empty?
|
452
497
|
@edit_pos_history_i -= 1
|
453
498
|
@edit_pos_history_i = @edit_pos_history.size - 1 if @edit_pos_history_i < 0
|
454
|
-
# Ripl.start :binding => binding
|
455
499
|
debug "@edit_pos_history_i=#{@edit_pos_history_i}"
|
456
500
|
set_pos(@edit_pos_history[-@edit_pos_history_i])
|
457
501
|
center_on_current_line
|
@@ -567,8 +611,7 @@ class Buffer < String
|
|
567
611
|
ls = nil
|
568
612
|
ls = @line_ends[a] if a != nil
|
569
613
|
# if a != nil and ls != @line_ends[a]
|
570
|
-
#
|
571
|
-
# Ripl.start :binding => binding
|
614
|
+
# debug "NO MATCH @line_ends[a]"
|
572
615
|
# end
|
573
616
|
|
574
617
|
if ls == nil
|
@@ -580,7 +623,6 @@ class Buffer < String
|
|
580
623
|
end
|
581
624
|
|
582
625
|
def get_line_end(pos)
|
583
|
-
#Ripl.start :binding => binding
|
584
626
|
return @line_ends.select { |x| x > pos }.min
|
585
627
|
end
|
586
628
|
|
@@ -674,7 +716,7 @@ class Buffer < String
|
|
674
716
|
end
|
675
717
|
|
676
718
|
debug "Scan line_end time: #{Time.now - t1}"
|
677
|
-
#
|
719
|
+
#debug @line_ends
|
678
720
|
end
|
679
721
|
|
680
722
|
def sanity_check_line_ends()
|
@@ -691,7 +733,7 @@ class Buffer < String
|
|
691
733
|
end
|
692
734
|
|
693
735
|
def update_bufpos_on_change(positions, xpos, changeamount)
|
694
|
-
#
|
736
|
+
# debug "xpos=#{xpos} changeamount=#{changeamount}"
|
695
737
|
positions.collect { |x|
|
696
738
|
r = nil
|
697
739
|
r = x if x < xpos
|
@@ -726,7 +768,7 @@ class Buffer < String
|
|
726
768
|
i_nl = scan_indexes(changestr, /\n/)
|
727
769
|
i_nl.collect! { |x| x + pos }
|
728
770
|
end
|
729
|
-
#
|
771
|
+
# debug "change:#{changeamount}"
|
730
772
|
#TODO: this is the bottle neck in insert_txt action
|
731
773
|
@line_ends.collect! { |x|
|
732
774
|
r = nil
|
@@ -750,6 +792,10 @@ class Buffer < String
|
|
750
792
|
return @pos == self.size
|
751
793
|
end
|
752
794
|
|
795
|
+
def jump_to_pos(new_pos)
|
796
|
+
set_pos(new_pos)
|
797
|
+
end
|
798
|
+
|
753
799
|
def set_pos(new_pos)
|
754
800
|
if new_pos >= self.size
|
755
801
|
@pos = self.size - 1 # TODO:??right side of last char
|
@@ -874,10 +920,10 @@ class Buffer < String
|
|
874
920
|
range = @pos..wmarks[0]
|
875
921
|
end
|
876
922
|
elsif range_id == :to_line_end
|
877
|
-
|
923
|
+
debug "TO LINE END"
|
878
924
|
range = @pos..(@line_ends[@lpos] - 1)
|
879
925
|
elsif range_id == :to_line_start
|
880
|
-
|
926
|
+
debug "TO LINE START: #{@lpos}"
|
881
927
|
|
882
928
|
if @cpos == 0
|
883
929
|
range = nil
|
@@ -913,15 +959,15 @@ class Buffer < String
|
|
913
959
|
end
|
914
960
|
|
915
961
|
def move(direction)
|
916
|
-
|
962
|
+
debug "cpos:#{@cpos} lpos:#{@lpos} @larger_cpos:#{@larger_cpos}"
|
917
963
|
if direction == :forward_page
|
918
|
-
|
964
|
+
debug "FORWARD PAGE"
|
919
965
|
visible_range = get_visible_area()
|
920
966
|
set_pos(visible_range[1])
|
921
967
|
top_where_cursor()
|
922
968
|
end
|
923
969
|
if direction == :backward_page
|
924
|
-
|
970
|
+
debug "backward PAGE"
|
925
971
|
visible_range = get_visible_area()
|
926
972
|
set_pos(visible_range[0])
|
927
973
|
bottom_where_cursor()
|
@@ -1024,14 +1070,17 @@ class Buffer < String
|
|
1024
1070
|
if wtype == :url
|
1025
1071
|
open_url(word)
|
1026
1072
|
elsif wtype == :linepointer
|
1027
|
-
|
1028
|
-
jump_to_file(word[0], word[1])
|
1073
|
+
jump_to_file(word[0], word[1], word[2])
|
1029
1074
|
elsif wtype == :textfile
|
1030
1075
|
open_existing_file(word)
|
1031
1076
|
elsif wtype == :file
|
1032
1077
|
open_with_default_program(word)
|
1033
1078
|
elsif wtype == :hpt_link
|
1034
1079
|
open_existing_file(word)
|
1080
|
+
elsif wtype == :help
|
1081
|
+
if word == "keybindings"
|
1082
|
+
call_action(:show_key_bindings)
|
1083
|
+
end
|
1035
1084
|
else
|
1036
1085
|
#TODO
|
1037
1086
|
end
|
@@ -1091,10 +1140,10 @@ class Buffer < String
|
|
1091
1140
|
word_start = pos if word_start == nil
|
1092
1141
|
word_end = pos if word_end == nil
|
1093
1142
|
word = self[word_start..word_end]
|
1094
|
-
|
1095
|
-
message("
|
1143
|
+
debug "'WORD: #{word}'"
|
1144
|
+
# message("Open link #{word}")
|
1096
1145
|
linep = get_file_line_pointer(word)
|
1097
|
-
|
1146
|
+
debug "linep'#{linep}'"
|
1098
1147
|
path = File.expand_path(word)
|
1099
1148
|
wtype = nil
|
1100
1149
|
if is_url(word)
|
@@ -1107,10 +1156,12 @@ class Buffer < String
|
|
1107
1156
|
wtype = :file
|
1108
1157
|
end
|
1109
1158
|
# elsif hpt_check_cur_word(word) #TODO: check only
|
1110
|
-
#
|
1159
|
+
# debug word
|
1111
1160
|
elsif linep != nil
|
1112
1161
|
wtype = :linepointer
|
1113
1162
|
word = linep
|
1163
|
+
elsif m = word.match(/⟦help:(.*)⟧/)
|
1164
|
+
return [m[1], :help]
|
1114
1165
|
else
|
1115
1166
|
fn = hpt_check_cur_word(word)
|
1116
1167
|
if !fn.nil?
|
@@ -1127,22 +1178,9 @@ class Buffer < String
|
|
1127
1178
|
handle_word(wnfo)
|
1128
1179
|
end
|
1129
1180
|
|
1130
|
-
def get_cur_word()
|
1131
|
-
wem = get_word_end_marks(@pos, @pos + 200)
|
1132
|
-
wsm = get_word_start_marks(@pos - 200, @pos)
|
1133
|
-
word_start = wsm[-1]
|
1134
|
-
word_end = wem[0]
|
1135
|
-
word_start = pos if word_start == nil
|
1136
|
-
word_end = pos if word_end == nil
|
1137
|
-
word = self[word_start..word_end]
|
1138
|
-
puts "'#{word}'"
|
1139
|
-
message("'#{word}'")
|
1140
|
-
#puts wm
|
1141
|
-
end
|
1142
|
-
|
1143
1181
|
def jump_to_next_instance_of_word()
|
1144
1182
|
if $kbd.last_action == $kbd.cur_action and @current_word != nil
|
1145
|
-
#
|
1183
|
+
# debug "REPEATING *"
|
1146
1184
|
else
|
1147
1185
|
start_search = [@pos - 150, 0].max
|
1148
1186
|
|
@@ -1241,10 +1279,10 @@ class Buffer < String
|
|
1241
1279
|
|
1242
1280
|
if target == FIRST_NON_WHITESPACE
|
1243
1281
|
l = current_line()
|
1244
|
-
|
1282
|
+
debug l.inspect
|
1245
1283
|
@cpos = line(@lpos).size - 1
|
1246
1284
|
a = scan_indexes(l, /\S/)
|
1247
|
-
|
1285
|
+
debug a.inspect
|
1248
1286
|
if a.any?
|
1249
1287
|
@cpos = a[0]
|
1250
1288
|
else
|
@@ -1328,9 +1366,9 @@ class Buffer < String
|
|
1328
1366
|
calculate_line_and_column_pos
|
1329
1367
|
end
|
1330
1368
|
|
1331
|
-
def execute_current_line_in_terminal()
|
1369
|
+
def execute_current_line_in_terminal(autoclose = false)
|
1332
1370
|
s = get_current_line
|
1333
|
-
exec_in_terminal(s)
|
1371
|
+
exec_in_terminal(s, autoclose)
|
1334
1372
|
end
|
1335
1373
|
|
1336
1374
|
def insert_new_line()
|
@@ -1350,8 +1388,17 @@ class Buffer < String
|
|
1350
1388
|
# Indent start of new line based on last line
|
1351
1389
|
last_line = line(@lpos)
|
1352
1390
|
m = /^( +)([^ ]+|$)/.match(last_line)
|
1353
|
-
|
1354
|
-
|
1391
|
+
if m
|
1392
|
+
c = c + " " * m[1].size if m
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
#if tab indent
|
1396
|
+
m = /^(\t+)([^\t]+|$)/.match(last_line)
|
1397
|
+
if m
|
1398
|
+
c = c + "\t" * m[1].size if m
|
1399
|
+
end
|
1400
|
+
|
1401
|
+
# debug m.inspect
|
1355
1402
|
end
|
1356
1403
|
if mode == BEFORE
|
1357
1404
|
insert_pos = @pos
|
@@ -1364,8 +1411,8 @@ class Buffer < String
|
|
1364
1411
|
|
1365
1412
|
#self.insert(insert_pos,c)
|
1366
1413
|
add_delta([insert_pos, INSERT, c.size, c], true)
|
1367
|
-
#
|
1368
|
-
#
|
1414
|
+
#debug("encoding: #{c.encoding}")
|
1415
|
+
#debug "c.size: #{c.size}"
|
1369
1416
|
#recalc_line_ends #TODO: optimize?
|
1370
1417
|
calculate_line_and_column_pos
|
1371
1418
|
#need_redraw!
|
@@ -1439,7 +1486,7 @@ class Buffer < String
|
|
1439
1486
|
text = $register[register]
|
1440
1487
|
end
|
1441
1488
|
end
|
1442
|
-
|
1489
|
+
debug "PASTE: #{text}"
|
1443
1490
|
|
1444
1491
|
return if text == ""
|
1445
1492
|
|
@@ -1494,7 +1541,13 @@ class Buffer < String
|
|
1494
1541
|
return if !@visual_mode
|
1495
1542
|
|
1496
1543
|
debug "COPY SELECTION"
|
1497
|
-
|
1544
|
+
s = self[get_visual_mode_range]
|
1545
|
+
if x == :append
|
1546
|
+
debug "APPEND"
|
1547
|
+
s += "\n" + get_clipboard()
|
1548
|
+
end
|
1549
|
+
|
1550
|
+
set_clipboard(s)
|
1498
1551
|
end_visual_mode
|
1499
1552
|
return true
|
1500
1553
|
end
|
@@ -1639,7 +1692,6 @@ class Buffer < String
|
|
1639
1692
|
else
|
1640
1693
|
savepath = buflist.get_last_dir
|
1641
1694
|
end
|
1642
|
-
# Ripl.start :binding => binding
|
1643
1695
|
gui_file_saveas(savepath)
|
1644
1696
|
# calls back to file_saveas
|
1645
1697
|
end
|
@@ -1660,21 +1712,23 @@ class Buffer < String
|
|
1660
1712
|
end
|
1661
1713
|
|
1662
1714
|
Thread.new {
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
|
1669
|
-
|
1670
|
-
|
1671
|
-
|
1672
|
-
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
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
|
1678
1732
|
end
|
1679
1733
|
sleep 3
|
1680
1734
|
}
|
data/lib/vimamsa/buffer_list.rb
CHANGED
@@ -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
|
@@ -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
|
@@ -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
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class BufferManager
|
2
|
+
attr_reader :buf
|
3
|
+
@@cur = nil # Current object of class
|
4
|
+
|
5
|
+
def self.cur()
|
6
|
+
return @@cur
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.init()
|
10
|
+
vma.kbd.add_minor_mode("bmgr", :buf_mgr, :command)
|
11
|
+
reg_act(:bmgr_select, proc { buf.module.select_line }, "")
|
12
|
+
reg_act(:bmgr_close, proc { buf.module.close_selected }, "")
|
13
|
+
|
14
|
+
reg_act(:start_buf_manager, proc { BufferManager.new.run; vma.kbd.set_mode(:buf_mgr) }, "Buffer manager")
|
15
|
+
|
16
|
+
bindkey "bmgr enter", :bmgr_select
|
17
|
+
bindkey "bmgr c", :bmgr_close
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize()
|
21
|
+
@buf = nil
|
22
|
+
@line_to_id = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
def buf_of_current_line()
|
26
|
+
l = @buf.lpos - @header.size
|
27
|
+
return nil if l < 0
|
28
|
+
bufid = @line_to_id[l]
|
29
|
+
buf_i = vma.buffers.get_buffer_by_id(bufid)
|
30
|
+
return buf_i
|
31
|
+
end
|
32
|
+
|
33
|
+
def close_selected
|
34
|
+
buf_i = buf_of_current_line()
|
35
|
+
if buf_i.nil?
|
36
|
+
message("buf already closed")
|
37
|
+
return
|
38
|
+
end
|
39
|
+
vma.buffers.close_other_buffer(buf_i)
|
40
|
+
end
|
41
|
+
|
42
|
+
def select_line
|
43
|
+
buf_i = buf_of_current_line()
|
44
|
+
return if buf_i.nil?
|
45
|
+
|
46
|
+
vma.buffers.close_current_buffer()
|
47
|
+
vma.buffers.set_current_buffer(buf_i)
|
48
|
+
@@cur = nil
|
49
|
+
end
|
50
|
+
|
51
|
+
def run
|
52
|
+
if !@@cur.nil? #One instance open already
|
53
|
+
#Close it
|
54
|
+
buf_i = vma.buffers.get_buffer_by_id(@@cur.buf.id)
|
55
|
+
vma.buffers.close_buffer(buf_i)
|
56
|
+
end
|
57
|
+
@@cur = self
|
58
|
+
@header = []
|
59
|
+
@header << "Current buffers:"
|
60
|
+
@header << "keys: <enter> to select, <c> to close buffer"
|
61
|
+
@header << "=" * 40
|
62
|
+
|
63
|
+
s = ""
|
64
|
+
s << @header.join("\n")
|
65
|
+
s << "\n"
|
66
|
+
i = 0
|
67
|
+
for b in vma.buffers.sort_by { |x| x.list_str }
|
68
|
+
x = b.list_str
|
69
|
+
s << "#{x}\n"
|
70
|
+
@line_to_id[i] = b.id
|
71
|
+
i += 1
|
72
|
+
end
|
73
|
+
|
74
|
+
if @buf.nil?
|
75
|
+
@buf = create_new_file(nil, s)
|
76
|
+
@buf.module = self
|
77
|
+
@buf.active_kbd_mode = :buf_mgr
|
78
|
+
else
|
79
|
+
@buf.set_content(s)
|
80
|
+
end
|
81
|
+
@buf.set_line_and_column_pos(@header.size, 0)
|
82
|
+
end
|
83
|
+
end
|
data/lib/vimamsa/conf.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$cnf = {} # TODO
|
2
|
+
|
3
|
+
def conf(id)
|
4
|
+
return $cnf[id]
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_conf(id, val)
|
8
|
+
$cnf[id] = val
|
9
|
+
end
|
10
|
+
|
11
|
+
def setcnf(id, val)
|
12
|
+
set_conf(id, val)
|
13
|
+
end
|
14
|
+
|
15
|
+
setcnf :indent_based_on_last_line, true
|
16
|
+
setcnf :extensions_to_open, [".txt", ".h", ".c", ".cpp", ".hpp", ".rb", ".inc", ".php", ".sh", ".m", ".gd", ".js"]
|
17
|
+
|
18
|
+
|
19
|
+
setcnf "log.verbose", 1
|
20
|
+
setcnf :tab_width, 4
|
21
|
+
|
data/lib/vimamsa/debug.rb
CHANGED