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 +4 -4
- data/exe/vimamsa +4 -2
- data/lib/vimamsa/ack.rb +0 -4
- data/lib/vimamsa/actions.rb +26 -38
- data/lib/vimamsa/buffer.rb +117 -60
- data/lib/vimamsa/buffer_list.rb +27 -3
- data/lib/vimamsa/buffer_manager.rb +83 -0
- data/lib/vimamsa/conf.rb +21 -0
- data/lib/vimamsa/debug.rb +9 -8
- data/lib/vimamsa/easy_jump.rb +129 -125
- data/lib/vimamsa/editor.rb +66 -48
- data/lib/vimamsa/file_finder.rb +7 -8
- data/lib/vimamsa/file_history.rb +15 -8
- data/lib/vimamsa/file_manager.rb +9 -8
- data/lib/vimamsa/gui.rb +560 -0
- data/lib/vimamsa/gui_menu.rb +110 -0
- data/lib/vimamsa/gui_select_window.rb +177 -0
- data/lib/vimamsa/gui_sourceview.rb +294 -0
- data/lib/vimamsa/hyper_plain_text.rb +8 -10
- data/lib/vimamsa/{default_key_bindings.rb → key_actions.rb} +71 -190
- data/lib/vimamsa/key_binding_tree.rb +48 -36
- data/lib/vimamsa/key_bindings_vimlike.rb +260 -0
- data/lib/vimamsa/macro.rb +6 -6
- data/lib/vimamsa/main.rb +1 -2
- data/lib/vimamsa/rbvma.rb +25 -1031
- data/lib/vimamsa/search.rb +1 -5
- data/lib/vimamsa/search_replace.rb +4 -6
- data/lib/vimamsa/version.rb +1 -1
- data/vimamsa.gemspec +1 -1
- metadata +12 -5
@@ -0,0 +1,177 @@
|
|
1
|
+
def gui_select_update_window(item_list, jump_keys, select_callback, update_callback, opt={})
|
2
|
+
$selup = SelectUpdateWindow.new(nil, item_list, jump_keys, select_callback, update_callback, opt)
|
3
|
+
$selup.run
|
4
|
+
end
|
5
|
+
|
6
|
+
class SelectUpdateWindow
|
7
|
+
COLUMN_JUMP_KEY = 0
|
8
|
+
COLUMN_DESCRIPTION = 1
|
9
|
+
|
10
|
+
def update_item_list(item_list)
|
11
|
+
# debug item_list.inspect
|
12
|
+
@model.clear
|
13
|
+
for item in item_list
|
14
|
+
iter = @model.append
|
15
|
+
if !@opt[:columns].nil?
|
16
|
+
v = item
|
17
|
+
else
|
18
|
+
v = ["", item[0]]
|
19
|
+
end
|
20
|
+
debug v.inspect
|
21
|
+
iter.set_values(v)
|
22
|
+
end
|
23
|
+
|
24
|
+
set_selected_row(0)
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_selected_row(rownum)
|
28
|
+
rownum = 0 if rownum < 0
|
29
|
+
@selected_row = rownum
|
30
|
+
|
31
|
+
if @model.count > 0
|
32
|
+
path = Gtk::TreePath.new(@selected_row.to_s)
|
33
|
+
iter = @model.get_iter(path)
|
34
|
+
@tv.selection.select_iter(iter)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(main_window, item_list, jump_keys, select_callback, update_callback, opt = {})
|
39
|
+
@window = Gtk::Window.new(:toplevel)
|
40
|
+
# @window.screen = main_window.screen
|
41
|
+
@window.title = ""
|
42
|
+
if !opt[:title].nil?
|
43
|
+
@window.title = opt[:title]
|
44
|
+
end
|
45
|
+
|
46
|
+
@selected_row = 0
|
47
|
+
@opt = opt
|
48
|
+
|
49
|
+
debug item_list.inspect
|
50
|
+
@update_callback = method(update_callback)
|
51
|
+
@select_callback = method(select_callback)
|
52
|
+
# debug @update_callback_m.call("").inspect
|
53
|
+
|
54
|
+
vbox = Gtk::Box.new(:vertical, 8)
|
55
|
+
vbox.margin = 8
|
56
|
+
@window.add(vbox)
|
57
|
+
|
58
|
+
@entry = Gtk::SearchEntry.new
|
59
|
+
@entry.width_chars = 45
|
60
|
+
container = Gtk::Box.new(:horizontal, 10)
|
61
|
+
# container.halign = :start
|
62
|
+
container.halign = :center
|
63
|
+
container.pack_start(@entry,
|
64
|
+
:expand => false, :fill => false, :padding => 0)
|
65
|
+
|
66
|
+
# create tree view
|
67
|
+
@model = Gtk::ListStore.new(String, String)
|
68
|
+
treeview = Gtk::TreeView.new(@model)
|
69
|
+
treeview.search_column = COLUMN_DESCRIPTION
|
70
|
+
@tv = treeview
|
71
|
+
# item_list = @update_callback.call("")
|
72
|
+
update_item_list(item_list)
|
73
|
+
|
74
|
+
@window.signal_connect("key-press-event") do |_widget, event|
|
75
|
+
# debug "KEYPRESS 1"
|
76
|
+
@entry.handle_event(event)
|
77
|
+
end
|
78
|
+
|
79
|
+
@entry.signal_connect("key_press_event") do |widget, event|
|
80
|
+
# debug "KEYPRESS 2"
|
81
|
+
if event.keyval == Gdk::Keyval::KEY_Down
|
82
|
+
debug "DOWN"
|
83
|
+
set_selected_row(@selected_row + 1)
|
84
|
+
# fixed = iter[COLUMN_FIXED]
|
85
|
+
|
86
|
+
true
|
87
|
+
elsif event.keyval == Gdk::Keyval::KEY_Up
|
88
|
+
set_selected_row(@selected_row - 1)
|
89
|
+
debug "UP"
|
90
|
+
true
|
91
|
+
elsif event.keyval == Gdk::Keyval::KEY_Return
|
92
|
+
path = Gtk::TreePath.new(@selected_row.to_s)
|
93
|
+
iter = @model.get_iter(path)
|
94
|
+
ret = iter[1]
|
95
|
+
@select_callback.call(ret, @selected_row)
|
96
|
+
@window.destroy
|
97
|
+
# debug iter[1].inspect
|
98
|
+
true
|
99
|
+
elsif event.keyval == Gdk::Keyval::KEY_Escape
|
100
|
+
@window.destroy
|
101
|
+
true
|
102
|
+
else
|
103
|
+
false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
@entry.signal_connect("search-changed") do |widget|
|
108
|
+
debug "search changed: #{widget.text || ""}"
|
109
|
+
item_list = @update_callback.call(widget.text)
|
110
|
+
|
111
|
+
update_item_list(item_list)
|
112
|
+
# label.text = widget.text || ""
|
113
|
+
end
|
114
|
+
@entry.signal_connect("changed") { debug "[changed] " }
|
115
|
+
@entry.signal_connect("next-match") { debug "[next-match] " }
|
116
|
+
|
117
|
+
if !opt[:desc].nil?
|
118
|
+
descl = Gtk::Label.new(opt[:desc])
|
119
|
+
vbox.pack_start(descl, :expand => false, :fill => false, :padding => 0)
|
120
|
+
end
|
121
|
+
|
122
|
+
# label = Gtk::Label.new(<<-EOF)
|
123
|
+
# Search:
|
124
|
+
# EOF
|
125
|
+
|
126
|
+
# label = Gtk::Label.new("Input:")
|
127
|
+
# vbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
|
128
|
+
|
129
|
+
vbox.pack_start(container, :expand => false, :fill => false, :padding => 0)
|
130
|
+
sw = Gtk::ScrolledWindow.new(nil, nil)
|
131
|
+
sw.shadow_type = :etched_in
|
132
|
+
sw.set_policy(:never, :automatic)
|
133
|
+
vbox.pack_start(sw, :expand => true, :fill => true, :padding => 0)
|
134
|
+
|
135
|
+
sw.add(treeview)
|
136
|
+
|
137
|
+
if !opt[:columns].nil?
|
138
|
+
for col in opt[:columns]
|
139
|
+
renderer = Gtk::CellRendererText.new
|
140
|
+
column = Gtk::TreeViewColumn.new(col[:title],
|
141
|
+
renderer,
|
142
|
+
"text" => col[:id])
|
143
|
+
column.sort_column_id = col[:id]
|
144
|
+
treeview.append_column(column)
|
145
|
+
end
|
146
|
+
else
|
147
|
+
renderer = Gtk::CellRendererText.new
|
148
|
+
column = Gtk::TreeViewColumn.new("JMP",
|
149
|
+
renderer,
|
150
|
+
"text" => COLUMN_JUMP_KEY)
|
151
|
+
column.sort_column_id = COLUMN_JUMP_KEY
|
152
|
+
treeview.append_column(column)
|
153
|
+
|
154
|
+
renderer = Gtk::CellRendererText.new
|
155
|
+
column = Gtk::TreeViewColumn.new("Description",
|
156
|
+
renderer,
|
157
|
+
"text" => COLUMN_DESCRIPTION)
|
158
|
+
column.sort_column_id = COLUMN_DESCRIPTION
|
159
|
+
treeview.append_column(column)
|
160
|
+
end
|
161
|
+
|
162
|
+
@window.set_default_size(280, 500)
|
163
|
+
debug "SelectUpdateWindow"
|
164
|
+
end
|
165
|
+
|
166
|
+
def run
|
167
|
+
if !@window.visible?
|
168
|
+
@window.show_all
|
169
|
+
# add_spinner
|
170
|
+
else
|
171
|
+
@window.destroy
|
172
|
+
# GLib::Source.remove(@tiemout) unless @timeout.zero?
|
173
|
+
@timeout = 0
|
174
|
+
end
|
175
|
+
@window
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,294 @@
|
|
1
|
+
|
2
|
+
class VSourceView < GtkSource::View
|
3
|
+
def initialize(title = nil)
|
4
|
+
# super(:toplevel)
|
5
|
+
super()
|
6
|
+
debug "vsource init"
|
7
|
+
@last_keyval = nil
|
8
|
+
@last_event = [nil, nil]
|
9
|
+
|
10
|
+
signal_connect "button-press-event" do |_widget, event|
|
11
|
+
if event.button == Gdk::BUTTON_PRIMARY
|
12
|
+
# debug "Gdk::BUTTON_PRIMARY"
|
13
|
+
false
|
14
|
+
elsif event.button == Gdk::BUTTON_SECONDARY
|
15
|
+
# debug "Gdk::BUTTON_SECONDARY"
|
16
|
+
true
|
17
|
+
else
|
18
|
+
true
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
signal_connect("key_press_event") do |widget, event|
|
23
|
+
handle_key_event(event, :key_press_event)
|
24
|
+
true
|
25
|
+
end
|
26
|
+
|
27
|
+
signal_connect("key_release_event") do |widget, event|
|
28
|
+
handle_key_event(event, :key_release_event)
|
29
|
+
true
|
30
|
+
end
|
31
|
+
|
32
|
+
signal_connect("move-cursor") do |widget, event|
|
33
|
+
$update_cursor = true
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
signal_connect "button-release-event" do |widget, event|
|
38
|
+
$buffer.set_pos(buffer.cursor_position)
|
39
|
+
false
|
40
|
+
end
|
41
|
+
@curpos_mark = nil
|
42
|
+
end
|
43
|
+
|
44
|
+
def handle_key_event(event, sig)
|
45
|
+
if $update_cursor
|
46
|
+
curpos = buffer.cursor_position
|
47
|
+
debug "MOVE CURSOR: #{curpos}"
|
48
|
+
buf.set_pos(curpos)
|
49
|
+
$update_cursor = false
|
50
|
+
end
|
51
|
+
debug $view.visible_rect.inspect
|
52
|
+
|
53
|
+
debug "key event"
|
54
|
+
debug event
|
55
|
+
|
56
|
+
key_name = event.string
|
57
|
+
if event.state.control_mask?
|
58
|
+
key_name = Gdk::Keyval.to_name(event.keyval)
|
59
|
+
# Gdk::Keyval.to_name()
|
60
|
+
end
|
61
|
+
|
62
|
+
keyval_trans = {}
|
63
|
+
keyval_trans[Gdk::Keyval::KEY_Control_L] = "ctrl"
|
64
|
+
keyval_trans[Gdk::Keyval::KEY_Control_R] = "ctrl"
|
65
|
+
|
66
|
+
keyval_trans[Gdk::Keyval::KEY_Escape] = "esc"
|
67
|
+
|
68
|
+
keyval_trans[Gdk::Keyval::KEY_Return] = "enter"
|
69
|
+
keyval_trans[Gdk::Keyval::KEY_ISO_Enter] = "enter"
|
70
|
+
keyval_trans[Gdk::Keyval::KEY_KP_Enter] = "enter"
|
71
|
+
keyval_trans[Gdk::Keyval::KEY_Alt_L] = "alt"
|
72
|
+
keyval_trans[Gdk::Keyval::KEY_Alt_R] = "alt"
|
73
|
+
|
74
|
+
keyval_trans[Gdk::Keyval::KEY_BackSpace] = "backspace"
|
75
|
+
keyval_trans[Gdk::Keyval::KEY_KP_Page_Down] = "pagedown"
|
76
|
+
keyval_trans[Gdk::Keyval::KEY_KP_Page_Up] = "pageup"
|
77
|
+
keyval_trans[Gdk::Keyval::KEY_Page_Down] = "pagedown"
|
78
|
+
keyval_trans[Gdk::Keyval::KEY_Page_Up] = "pageup"
|
79
|
+
keyval_trans[Gdk::Keyval::KEY_Left] = "left"
|
80
|
+
keyval_trans[Gdk::Keyval::KEY_Right] = "right"
|
81
|
+
keyval_trans[Gdk::Keyval::KEY_Down] = "down"
|
82
|
+
keyval_trans[Gdk::Keyval::KEY_Up] = "up"
|
83
|
+
keyval_trans[Gdk::Keyval::KEY_space] = "space"
|
84
|
+
|
85
|
+
keyval_trans[Gdk::Keyval::KEY_Shift_L] = "shift"
|
86
|
+
keyval_trans[Gdk::Keyval::KEY_Shift_R] = "shift"
|
87
|
+
keyval_trans[Gdk::Keyval::KEY_Tab] = "tab"
|
88
|
+
|
89
|
+
key_trans = {}
|
90
|
+
key_trans["\e"] = "esc"
|
91
|
+
tk = keyval_trans[event.keyval]
|
92
|
+
key_name = tk if !tk.nil?
|
93
|
+
|
94
|
+
key_str_parts = []
|
95
|
+
key_str_parts << "ctrl" if event.state.control_mask? and key_name != "ctrl"
|
96
|
+
key_str_parts << "alt" if event.state.mod1_mask? and key_name != "alt"
|
97
|
+
|
98
|
+
key_str_parts << key_name
|
99
|
+
key_str = key_str_parts.join("-")
|
100
|
+
keynfo = { :key_str => key_str, :key_name => key_name, :keyval => event.keyval }
|
101
|
+
debug keynfo.inspect
|
102
|
+
# $kbd.match_key_conf(key_str, nil, :key_press)
|
103
|
+
# debug "key_str=#{key_str} key_"
|
104
|
+
|
105
|
+
if key_str != "" # or prefixed_key_str != ""
|
106
|
+
if sig == :key_release_event and event.keyval == @last_keyval
|
107
|
+
$kbd.match_key_conf(key_str + "!", nil, :key_release)
|
108
|
+
@last_event = [event, :key_release]
|
109
|
+
elsif sig == :key_press_event
|
110
|
+
$kbd.match_key_conf(key_str, nil, :key_press)
|
111
|
+
@last_event = [event, key_str, :key_press]
|
112
|
+
end
|
113
|
+
@last_keyval = event.keyval #TODO: outside if?
|
114
|
+
end
|
115
|
+
|
116
|
+
handle_deltas
|
117
|
+
|
118
|
+
# set_focus(5)
|
119
|
+
# false
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
def pos_to_coord(i)
|
124
|
+
b = buffer
|
125
|
+
iter = b.get_iter_at(:offset => i)
|
126
|
+
iterxy = get_iter_location(iter)
|
127
|
+
winw = parent_window.width
|
128
|
+
view_width = visible_rect.width
|
129
|
+
gutter_width = winw - view_width
|
130
|
+
|
131
|
+
x = iterxy.x + gutter_width
|
132
|
+
y = iterxy.y
|
133
|
+
|
134
|
+
# buffer_to_window_coords(Gtk::TextWindowType::TEXT, iterxy.x, iterxy.y).inspect
|
135
|
+
# debug buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y).inspect
|
136
|
+
(x, y) = buffer_to_window_coords(Gtk::TextWindowType::TEXT, x, y)
|
137
|
+
# Ripl.start :binding => binding
|
138
|
+
|
139
|
+
return [x, y]
|
140
|
+
end
|
141
|
+
|
142
|
+
def handle_deltas()
|
143
|
+
any_change = false
|
144
|
+
while d = buf.deltas.shift
|
145
|
+
any_change = true
|
146
|
+
pos = d[0]
|
147
|
+
op = d[1]
|
148
|
+
num = d[2]
|
149
|
+
txt = d[3]
|
150
|
+
if op == DELETE
|
151
|
+
startiter = buffer.get_iter_at(:offset => pos)
|
152
|
+
enditer = buffer.get_iter_at(:offset => pos + num)
|
153
|
+
buffer.delete(startiter, enditer)
|
154
|
+
elsif op == INSERT
|
155
|
+
startiter = buffer.get_iter_at(:offset => pos)
|
156
|
+
buffer.insert(startiter, txt)
|
157
|
+
end
|
158
|
+
end
|
159
|
+
if any_change
|
160
|
+
gui_set_cursor_pos($buffer.id, $buffer.pos) #TODO: only when necessary
|
161
|
+
end
|
162
|
+
|
163
|
+
# sanity_check #TODO
|
164
|
+
end
|
165
|
+
|
166
|
+
def sanity_check()
|
167
|
+
a = buffer.text
|
168
|
+
b = buf.to_s
|
169
|
+
# debug "===================="
|
170
|
+
# debug a.lines[0..10].join()
|
171
|
+
# debug "===================="
|
172
|
+
# debug b.lines[0..10].join()
|
173
|
+
# debug "===================="
|
174
|
+
if a == b
|
175
|
+
debug "Buffers match"
|
176
|
+
else
|
177
|
+
debug "ERROR: Buffer's don't match."
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def set_cursor_pos(pos)
|
182
|
+
# return
|
183
|
+
itr = buffer.get_iter_at(:offset => pos)
|
184
|
+
itr2 = buffer.get_iter_at(:offset => pos + 1)
|
185
|
+
buffer.place_cursor(itr)
|
186
|
+
|
187
|
+
# $view.signal_emit("extend-selection", Gtk::MovementStep.new(:PAGES), -1, false)
|
188
|
+
|
189
|
+
within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
|
190
|
+
use_align = false
|
191
|
+
xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
|
192
|
+
yalign = 0.5
|
193
|
+
|
194
|
+
if @curpos_mark.nil?
|
195
|
+
@curpos_mark = buffer.create_mark("cursor", itr, false)
|
196
|
+
else
|
197
|
+
buffer.move_mark(@curpos_mark, itr)
|
198
|
+
end
|
199
|
+
scroll_to_mark(@curpos_mark, within_margin, use_align, xalign, yalign)
|
200
|
+
$idle_scroll_to_mark = true
|
201
|
+
ensure_cursor_visible
|
202
|
+
|
203
|
+
# scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
|
204
|
+
|
205
|
+
# $view.signal_emit("extend-selection", Gtk::TextExtendSelection.new, itr,itr,itr2)
|
206
|
+
# Ripl.start :binding => binding
|
207
|
+
draw_cursor
|
208
|
+
|
209
|
+
return true
|
210
|
+
end
|
211
|
+
|
212
|
+
def cursor_visible_idle_func
|
213
|
+
debug "cursor_visible_idle_func"
|
214
|
+
# From https://picheta.me/articles/2013/08/gtk-plus--a-method-to-guarantee-scrolling.html
|
215
|
+
# vr = visible_rect
|
216
|
+
|
217
|
+
# b = $view.buffer
|
218
|
+
# iter = buffer.get_iter_at(:offset => buffer.cursor_position)
|
219
|
+
# iterxy = get_iter_location(iter)
|
220
|
+
|
221
|
+
sleep(0.01)
|
222
|
+
# intr = iterxy.intersect(vr)
|
223
|
+
if is_cursor_visible == false
|
224
|
+
# set_cursor_pos(buffer.cursor_position)
|
225
|
+
|
226
|
+
itr = buffer.get_iter_at(:offset => buffer.cursor_position)
|
227
|
+
|
228
|
+
within_margin = 0.075 #margin as a [0.0,0.5) fraction of screen size
|
229
|
+
use_align = false
|
230
|
+
xalign = 0.5 #0.0=top 1.0=bottom, 0.5=center
|
231
|
+
yalign = 0.5
|
232
|
+
|
233
|
+
scroll_to_iter(itr, within_margin, use_align, xalign, yalign)
|
234
|
+
|
235
|
+
# return true # Call this func again
|
236
|
+
else
|
237
|
+
return false # Don't call this idle func again
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def is_cursor_visible
|
242
|
+
vr = visible_rect
|
243
|
+
iter = buffer.get_iter_at(:offset => buffer.cursor_position)
|
244
|
+
iterxy = get_iter_location(iter)
|
245
|
+
iterxy.width = 1 if iterxy.width == 0
|
246
|
+
iterxy.height = 1 if iterxy.height == 0
|
247
|
+
|
248
|
+
intr = iterxy.intersect(vr)
|
249
|
+
if intr.nil?
|
250
|
+
debug iterxy.inspect
|
251
|
+
debug vr.inspect
|
252
|
+
# Ripl.start :binding => binding
|
253
|
+
|
254
|
+
# exit!
|
255
|
+
return false
|
256
|
+
else
|
257
|
+
return true
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def ensure_cursor_visible
|
262
|
+
if is_cursor_visible == false
|
263
|
+
Thread.new {
|
264
|
+
sleep 0.01
|
265
|
+
GLib::Idle.add(proc { cursor_visible_idle_func })
|
266
|
+
}
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def draw_cursor
|
271
|
+
if is_command_mode
|
272
|
+
itr = buffer.get_iter_at(:offset => buf.pos)
|
273
|
+
itr2 = buffer.get_iter_at(:offset => buf.pos + 1)
|
274
|
+
$view.buffer.select_range(itr, itr2)
|
275
|
+
elsif buf.visual_mode?
|
276
|
+
debug "VISUAL MODE"
|
277
|
+
(_start, _end) = buf.get_visual_mode_range2
|
278
|
+
debug "#{_start}, #{_end}"
|
279
|
+
itr = buffer.get_iter_at(:offset => _start)
|
280
|
+
itr2 = buffer.get_iter_at(:offset => _end + 1)
|
281
|
+
$view.buffer.select_range(itr, itr2)
|
282
|
+
else # Insert mode
|
283
|
+
itr = buffer.get_iter_at(:offset => buf.pos)
|
284
|
+
$view.buffer.select_range(itr, itr)
|
285
|
+
debug "INSERT MODE"
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# def quit
|
290
|
+
# destroy
|
291
|
+
# true
|
292
|
+
# end
|
293
|
+
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
|
-
|
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
|
-
|
16
|
-
|
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,22 +35,23 @@ def hpt_check_cur_word(w)
|
|
38
35
|
return nil
|
39
36
|
end
|
40
37
|
|
38
|
+
# Scan images inserted with ⟦img:filepath⟧ syntax
|
41
39
|
def hpt_scan_images()
|
42
40
|
return if !buf.fname
|
43
41
|
return if !buf.fname.match(/.*txt$/)
|
44
42
|
imgpos = scan_indexes(buf, /⟦img:.+?⟧/)
|
45
43
|
imgtags = buf.scan(/(⟦img:(.+?)⟧)/)
|
46
|
-
# i = 0
|
47
44
|
c = 0
|
48
45
|
imgpos.each.with_index { |x, i|
|
49
46
|
a = imgpos[i]
|
50
47
|
t = imgtags[i]
|
51
48
|
insert_pos = a + t[0].size + c
|
52
49
|
imgfn = File.expand_path(t[1])
|
53
|
-
# Ripl.start :binding => binding
|
54
50
|
next if !File.exist?(imgfn)
|
51
|
+
# Show as image in gui, handle as empty space in txt file
|
55
52
|
if buf[insert_pos..(insert_pos + 2)] != "\n \n"
|
56
53
|
buf.insert_txt_at("\n \n", insert_pos)
|
54
|
+
buf.view.handle_deltas
|
57
55
|
c += 3
|
58
56
|
end
|
59
57
|
buf.add_image(imgfn, insert_pos + 1)
|