-- TIME_STAMP 2019-08-16 20:44:06 v 0.6 local Require = {} Require.sortTable = function(self, _t) local tSort, tRet = {}, {} for k, v in pairs(_t) do tSort[#tSort+1] = k end table.sort(tSort) for k = 1, #tSort do tRet[k] = {tSort[k], _t[tSort[k]]} end return tRet end Require.getFile = function(self) local pos = editor.CurrentPos local linenum = editor:LineFromPosition(pos) local line = editor:GetLine(linenum) local home = editor:PositionFromLine(linenum) local tReq, file, tIndex, index = {}, '', {} for s, t, e in line:gmatch("()require%s-%(-(%b'')()") do table.insert(tReq, {home+s-1, home+e-1, t:sub(2,-2)}) tIndex[s] = #tReq end for s, t, e in line:gmatch('()require%s-%(-(%b"")()') do table.insert(tReq, {home+s-1, home+e-1, t:sub(2,-2)}) tIndex[s] = #tReq end if #tReq > 0 then for i=1, #tReq do if pos >= tReq[i][1] and pos <= tReq[i][2] then file = tReq[i][3] break end end if file == '' then -- cursor outside the require command, use 1st match tIndex = self:sortTable(tIndex) file = tReq[tIndex[1][2]][3] end file = file:gsub('%.', '/') return file, linenum +1 end return nil, linenum +1 end Require.createPathes = function(self, _file) local pathes = package.path local tPathes, bBreak = {}, false while pathes:len() do local pos = pathes:find(';') local fullpath if pos then local path = pathes:sub(1,pos-1) pathes = pathes:sub(pos+1) fullpath = path else fullpath = pathes bBreak = true end if not (fullpath:sub(-8) == 'init.lua') then fullpath = fullpath:gsub('%?',_file) -- print(fullpath) table.insert(tPathes, fullpath) end if bBreak then break end end return tPathes end Require.openFile = function(self) local s_require, linenum = self:getFile() if not s_require then print('@_NONE_REQUIRE__LINE\t\t'..tostring(linenum)) return end local tPathes = self:createPathes(s_require) local shell = require "shell" local s_open for i = 1, #tPathes do if shell.fileexists(tPathes[i]) then s_open = tPathes[i] break end end if s_open then print('@_REQUIRE_OPENED__LINE\t\t'..tostring(linenum)..' ['..s_open..']') scite.Open(s_open) else print('@_REQUIRE_IS_DLL_FILE__CAN\'T_OPEN__LINE\t\t'..tostring(linenum)) end end Require:openFile()