Scite 打开文件名 |
|
SciTEOpenFilename 是 SciTE 中 OpenFilename 函数 (Ctrl+Shift+O) 的替代品,用于快速打开当前文档中指定的文件。此 Lua 扩展版本的 OpenFilename 的主要优点是可以打开某些语言的库或系统头文件。SciTEOpenFilename 可从 Files:wiki_insecure/editors/SciTE/SciTEOpenFilename.lua 下载。
SciTEOpenFilename 使用自定义的处理程序来打开 C、C++、Perl 和 Python 语言的库和系统头文件,而不是使用 open.suffix 和 openpath 属性。由于它是一个 Lua 扩展,SciTEOpenFilename 可以轻松地扩展以处理其他语言。自定义搜索位置只需编辑并向要搜索的路径表中添加条目即可。
SciTEOpenFilename 还会检查前缀以确定是否存在合适的关键字。这可以禁用默认 Ctrl+Shift+O 函数更广泛的匹配行为(要删除此功能,只需删除相关测试)。对于属性文件,脚本会检查 import;对于 C/C++,脚本会检查 #include;对于 Perl,脚本会检查 use、require、do 或 no;对于 Python,脚本会检查 import 和 from。
SciTEOpenFilename 并非 OpenFilename 的精确复制品。它不支持 Ctags(如果您想要 Ctags,它是一个更完整的解决方案,请参阅 SciteTags),不支持 open.suffix 和 openpath 属性,也不支持打开 http:、ftp: 等类型的资源。但它是用 Lua 编写的,您可以以任何您想要的方式扩展它,而无需重新编译二进制文件。
如果有人扩展了 SciTEOpenFilename,请更新相关内容。
2007-03-29:修复了 lookupExt() 中比较扩展名的错误
--khman--
这个替代方案可以打开多个高亮显示文件的列表。它还可以滚动编辑器到由冒号分隔的行号,例如编译器错误输出的列表。只需高亮显示要打开的文件组,然后按 Ctrl+Shift+O。
我使用它来高亮显示 startup.lua 中所有的 dofile("") 条目并打开它们。它也适用于 #include <> 指令列表。它会尽力确定文件而非非文件。如果找不到,它会使用 'locate' 命令尝试查找它们。
-- Compatibility: Lua 5.3 function try_open(txt) local x local words = split(txt,"\n") for k, word in pairs(words) do local line=tonumber(word:gsub(".-:([^:]*).*","%1"),10) local col =tonumber(word:gsub(".-:.-:([^:]+).*", "%1"),10) if col then col = col - 1 else col = 0 end if line then line = line- 1 end local subd=word:gsub(":.*","") subd = subd:gsub(".*[[(<\"' ](.*)[])>\"' ].*", "%1") if(io.open(subd)) then io.close() scite.Open(subd) elseif(io.open("/usr/include/"..subd)) then io.close() scite.Open("/usr/include/"..subd) else print("other possible candidates") local f = io.popen("locate -l 5 ".. "/`basename "..subd.."`") local l = f:read("*a") -- get locate output print(l) -- print possible search candidates file = split(l, "\n")[1] -- open first one if file then scite.Open(file) end f:close() return end if line then if not col then col = 0 end marker_define(1,1,'black','blue') editor:MarkerAdd(line, 1) editor:GotoLine(line) editor.SelectionStart = editor.CurrentPos + col editor.SelectionEnd = editor.LineEndPosition[line] end end end local colours = {red = "#FF0000", blue = '#0000FF', green = '#00FF00',pink ="#FFAAAA" , black = '#000000', lightblue = '#AAAAFF',lightgreen = '#AAFFAA', yellow = '#FFFF00' } function color_parse(str) if string.sub(str,1,1) ~= '#' then str = colours[str] end return tonumber(string.sub(str,6,7)..string.sub(str,4,5)..string.sub(str,2,4),16) end function marker_define(idx,typ,fore,back) editor:MarkerDefine(idx,typ) if fore then editor.MarkerFore[idx]=color_parse(fore) end if back then editor.MarkerFore[idx]=color_parse(back) end end -- Compatibility: Lua-5.1 function split(str, pat) local t = {} -- NOTE: use {n = 0} in Lua-5.0 local fpat = "(.-)" .. pat local last_end = 1 local s, e, cap = str:find(fpat, 1) while s do if s ~= 1 or cap ~= "" then table.insert(t,cap) end last_end = e+1 s, e, cap = str:find(fpat, last_end) end if last_end <= #str then cap = str:sub(last_end) table.insert(t, cap) end return t end
并且在 .SciTEUser.properties 中
command.name.10.*=Open Filename command.10.*=quick_open $(CurrentSelection) command.shortcut.10.*=Ctrl+Shift+O command.subsystem.10.*=3