--▽▽UTF-8▽▽ -- SciteFuncList.lua -- by 2011.04.22 lee.sheen@gmail.com scite_Command { 'Function List|functionList|Ctrl+/', } local outPutLineNum local editorLineNum scite_OnDoubleClick(function() if output.Focus then local outLineNum = output:LineFromPosition(output.CurrentPos) local outLine = output:GetLine(outLineNum):sub(1, -2) local lineNum, content = string.match(outLine, "%[(%d+),.%]%S+%s+.*/^(.*)$/") if lineNum then local editLine = editor:GetLine(lineNum-1) if editLine then editLine = string.sub(editLine, 1, -2) editLine = string.gsub(editLine, "\r", "") if content == editLine then --print(lineNum) lineNum = tonumber(lineNum) editor:GotoLine(lineNum) ctags_center_pos() if outPutLineNum then output:MarkerDeleteAll(0) end outPutLineNum = outLineNum output:MarkerDefine(0, SC_MARK_SMALLRECT) output:MarkerSetFore(0, colour_parse('red')) output:MarkerSetBack(0, colour_parse('yellow')) output:MarkerAdd(outPutLineNum, 0) if editorLineNum then editor:MarkerDeleteAll(0) end editorLineNum = lineNum-1 editor:MarkerDefine(0, SC_MARK_CIRCLE) editor:MarkerSetFore(0, colour_parse('red')) editor:MarkerSetBack(0, colour_parse('yellow')) editor:MarkerAdd(editorLineNum, 0) return true end end end end end) function functionList() local sourceFilename = props["FilePath"] local ctagsFilename = sourceFilename .. '.ctags' output:BeginUndoAction() makeCtagsFile('"'..sourceFilename..'"', '"'..ctagsFilename..'"') --readCtagsFile(ctagsFilename) removeCtagsFile(ctagsFilename) print("------------------------------------") output:EndUndoAction() end function makeCtagsFile(sourceFilename, ctagsFilename) local makeCtagsCommand = '""'.. lua_Path()..'/ctags" --fields=kn -u -f ' .. ctagsFilename .. ' ' .. sourceFilename ..' && type '..ctagsFilename..'"' --local makeCtagsCommand = default_path .."/script/scite_lua/ctags -u -x " .. sourceFilename .. " > " .. ctagsFilename --print(makeCtagsCommand) print("============================") print(string.gsub(sourceFilename, '"', '').. ":0:") print("------------------------------------") --os.execute(makeCtagsCommand) local f = scite_Popen(makeCtagsCommand) for line in f:lines()do if not isCommentLine(line)then local funcName, str = getFunctionName(line) print(funcName..'\t\t'..str) end end f:close() end --[[ function readCtagsFile(ctagsFilename) print() io.input(ctagsFilename) while true do local line = io.read("*line") if line == nil then break end if not isCommentLine(line) then print(getFunctionName(line)) end end io.input():close() end ]]-- function isCommentLine(line) return '!' == string.sub(line, 0, 1) end function getFunctionName(line) local ctagsTable = {} ctagsTable = splitCtagsLine(line) local functionName = makeFunctionName(ctagsTable) local searchString = makeSearchString(ctagsTable) return functionName, searchString end function splitCtagsLine(line) local t = {} local c = 0 local l = 0 local r = 0 d = string.find(line, "$/", l) while true do c = c + 1 if d == nil or c ~= 3 then r = string.find(line, "\t", l) else r = string.find(line, "\t", d) end if r == nil then r = #line + 1 end local name = string.sub(line, l, r - 1) t[#t + 1] = name l = r + 1 if #line <= l then break end end return t end function makeFunctionName(ctagsTable) local functionName = ctagsTable[1] local funType = ctagsTable[4] --exg line:6646 local lineNumber = string.sub(ctagsTable[5], 6, #ctagsTable[5]) functionName = "["..lineNumber..","..funType.."]"..functionName --[[ -- with it's class name if not(ctagsTable[5] == nil) then local isClass = not(string.find(ctagsTable[5], "class:", 0) == nil) if isClass then local className = string.sub(ctagsTable[5], 7) functionName = className.."::"..functionName end end --]] return functionName end function makeSearchString(ctagsTable) local searchString = nil local s = string.sub(ctagsTable[3], 0, #ctagsTable[3] - 2) local l = 0 local r = 0 while true do r = string.find(s, "\\", l) if r == nil then r = #s + 1 elseif string.sub(s, r + 1, r + 1) == "\\" then r = r + 1 end local name = string.sub(s, l, r - 1) if searchString == nil then searchString = name else searchString = searchString..name end l = r + 1 if #s <= l then break end end return searchString end function removeCtagsFile(ctagsFilename) os.remove(ctagsFilename) end