forked from rgieseke/ta-common
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctags.lua
63 lines (59 loc) · 2.36 KB
/
ctags.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
-- For supported filetypes, displays a filtered list dialog with symbols
-- in the current document using
-- [Exuberant Ctags](http://ctags.sourceforge.net/).<br>
-- Note that it is possible to add support for additional filetypes, for
-- example for Latex:<br>
-- In `~/.ctags`:
--
-- --langdef=latex
-- --langmap=latex:.tex
-- --regex-latex=/\\label\{([^}]*)\}/\1/l,label/
-- --regex-latex=/\\section\{([^}]*)\}/\1/s,section/
-- --regex-latex=/\\subsection\{([^}]*)\}/\1/t,subsection/
-- --regex-latex=/\\subsubsection\{([^}]*)\}/\1/u,subsubsection/
-- --regex-latex=/\\section\*\{([^}]*)\}/\1/s,section/
-- --regex-latex=/\\subsection\*\{([^}]*)\}/\1/t,subsection/
-- --regex-latex=/\\subsubsection\*\{([^}]*)\}/\1/u,subsubsection/
--
-- Written by
-- [Mitchell](http://caladbolg.net/textadeptwiki/index.php?n=Main.Gotosymbol).
module('_m.common.ctags', package.seeall)
-- ## Fields
-- Path and options for the ctags utility can be defined in the `CTAGS`
-- field.
if WIN32 then
CTAGS = '"c:\\program files\\ctags\\ctags.exe" --sort=yes --fields=+K-f'
else
CTAGS = 'ctags --sort=yes --fields=+K-f'
end
-- ## Commands
-- Goes to the selected symbol in a filtered list dialog.
-- Requires [ctags]((http://ctags.sourceforge.net/)) to be installed.
function goto_symbol()
local buffer = buffer
if not buffer.filename then return end
local symbols = {}
local p = io.popen(CTAGS..' --excmd=number -f - "'..buffer.filename..'"')
for line in p:read('*all'):gmatch('[^\r\n]+') do
local name, line, ext = line:match('^(%S+)\t[^\t]+\t([^;]+);"\t(.+)$')
if name and line and ext then
symbols[#symbols + 1] = name
symbols[#symbols + 1] = ext
symbols[#symbols + 1] = line
end
end
if #symbols > 0 then
local response = gui.dialog('filteredlist',
'--title', 'Goto Symbol',
'--button1', 'gtk-ok',
'--button2', 'gtk-cancel',
'--string-output',
'--no-newline',
'--columns', 'Name', 'Type', 'Line',
'--output-column', '3',
'--items', symbols)
local ok, line = response:match('(%S+)\n(%d+)$')
if ok == 'gtk-ok' then buffer:goto_line(tonumber(line) - 1) end
end
p:close()
end