common/ctags.lua |
|
---|---|
For supported filetypes, displays a filtered list dialog with symbols
in the current document using
Exuberant Ctags.
Written by Mitchell. |
local M = {}
|
Fields |
|
Path and options for the ctags utility can be defined in the |
if WIN32 then
M.CTAGS = '"c:\\program files\\ctags\\ctags.exe" --sort=yes --fields=+K-f'
else
M.CTAGS = 'ctags --sort=yes --fields=+K-f'
end
|
Commands |
|
Goes to the selected symbol in a filtered list dialog. Requires ctags to be installed. |
function M.goto_symbol()
local buffer = buffer
if not buffer.filename then return end
local symbols = {}
local p = io.popen(M.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)
buffer:vertical_centre_caret()
end
end
p:close()
end
return M
|