Scite Open Filename

lua-users home
wiki

Ctrl+Shift+O replacement for SciTE

SciTEOpenFilename is a replacement for the OpenFilename function in SciTE (Ctrl+Shift+O), which is used to quickly open files specified in the current document. The major advantage of this Lua extension version of OpenFilename is the opening of library or system header files of certain languages. SciTEOpenFilename can be downloaded from Files:wiki_insecure/editors/SciTE/SciTEOpenFilename.lua.

Instead of using the open.suffix and openpath properties, SciTEOpenFilename has custom handlers for opening the libraries and system header files of the following languages: C, C++, Perl and Python. Since it is a Lua extension, SciTEOpenFilename can be easily extended to handle other languages. Customizing search locations is a simple matter of editing and adding entries to the table of paths to be searched.

SciTEOpenFilename also checks the prefix to determine whether an appropriate keyword is present. This disables the more promiscuous behaviour of the default Ctrl+Shift+O function (to remove this feature, simply delete the relevant tests.) For property files, the script checks for import; for C/C++, the script checks for #include; for Perl, the script checks for use, require, do or no; for Python, the script checks for import and from.

SciTEOpenFilename is not an exact work-alike version of OpenFilename. It does not support Ctags (see SciteTags if you want Ctags, it is a more complete solution), it does not support the open.suffix and openpath properties, and it does not support the opening of http:, ftp: etc. kind of resources. But it is in Lua, and you can extend it any way you want without needing to recompile binaries.

If anyone extends SciTEOpenFilename, please update the appropriate stuff.

2007-03-29: fixed bug in lookupExt() comparing extensions

--khman--

Update 2010 by Hank

The above did not work for me and was too complicated to fix, so I wrote a simpler version that does what I want.

Does pretty much what the original did, I think, only this one opens all highlighted files at once.

I use it to highlight all the dofile("") entries in startup.lua and open them. It also works on lists of #include <> directives. If it can't find something, it uses the 'locate' command to try and find them.

function try_open(word)

	subd=string.gsub(word, '[#\*\t\r\n\"\'<> ]','')

	if(io.open(subd)) then

		scite.Open(subd)

	elseif(io.open("/usr/include/"..subd)) then

		scite.Open("/usr/include/"..subd)

	else

		local f = io.popen("locate -l 5 ".."/`basename "..subd.."`")

		local l = f:read("*a") -- read output of command

		print(l)

		f:close()

	end

end



function quick_open(sel)

	for word in string.gfind(sel, '[<\"\'].-[\'\">]') do 

		local subd=string.gsub(word, '[<>]','')

		try_open(subd)

	end

	if word == nil then

		try_open(sel)

	end

end

And in .SciTEUser.properties:


command.name.10.*=Open Filename

command.10.*=quick_open $(CurrentSelection)

command.shortcut.10.*=Ctrl+Shift+O

command.subsystem.10.*=3


RecentChanges · preferences
edit · history
Last edited October 31, 2010 8:05 pm GMT (diff)