forked from rgieseke/ta-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filename.lua
33 lines (29 loc) · 902 Bytes
/
filename.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
-- Inserts a filename with a (if possible) relative path
-- from a file select dialog.
module('_m.common.filename', package.seeall)
-- ## Commands
-- Opens a file select dialog and inserts filename in the buffer.
function insert_filename()
local current_dir = (buffer.filename or ''):match('.+[/\\]')
if not current_dir then
current_dir = _HOME
end
filename =
gui.dialog('fileselect',
'--title', "Insert filename",
'--select-multiple',
'--with-directory', current_dir)
if filename then
filename = filename:gsub('\n', '')
filename = filename:gsub(current_dir, '')
if buffer:get_sel_text() == '' then
buffer:add_text(filename)
else
buffer:replace_sel(filename)
end
end
end
-- ## Key commands
local keys = _G.keys
-- `Ctrl`+`Alt/⌘`+`Shift`+`O` Insert a filename.
keys.caO = { insert_filename }