Scite 開啟檔案名稱 |
|
SciTEOpenFilename
是 SciTE (Ctrl+Shift+O
) 中 OpenFilename
函式的取代版本,用於快速開啟正在處理的文件中指定的檔案。此 Lua
延伸函式的最大優點是可以開啟特定語言的函式庫或系統標頭檔案。SciTEOpenFilename
可從 Files:wiki_insecure/editors/SciTE/SciTEOpenFilename.lua 下載。
SciTEOpenFilename
未使用 open.suffix
和 openpath
屬性,而是有自訂處理常式來開啟下列語言的函式庫和系統標頭檔案:C、C++、Perl 和 Python。由於 SciTEOpenFilename
是 Lua
延伸函式,因此可以輕鬆延伸以處理其他語言。自訂搜尋位置只是編輯並加入路徑表到搜尋中即可。
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