Doyle Whisenant wrote:
Dan Anderson wrote:
Neil Hodgson wrote:
Dan Anderson:
Does anyone know if there any way within a LUA script to
access each open buffer and the text it contains? Read
only access is sufficient. I would like to iterate through each
buffer, retrieve the text, and perform some additional
processing with the text.
This is not well supported. There is some code for switching
buffers at
http://lua-users.org/wiki/SciteBufferSwitch
Neil
Thanks. I did come across that, but it doesn't really satisfy my
needs. As far as I can tell, the script keeps track of all files
opened since Scite was started regardless of whether or not they have
been subsequently closed. I do have an idea. Basically, I was
thinking that I could use scite.SendEditor() to send IDM_NEXTFILE to
switch through all the buffers. I would have to keep track of the
original buffer somehow so that I know when it is complete. Maybe the
buffer file path. Not sure if it will work but the idea seams sound.
The biggest issue I see with this approach is that it will be pretty
ugly with the screen flashing through all of the buffers.
It would be nice if an array of open buffers was exposed to the LUA
scripting interface. Each buffer object in the array could have the
basic properties & functions of the editor object.
You can grab each of the buffer file names using OnOpen. Save the
following and put in your lua startup script.
--cut--
local ses_buffers = {}
function load_buffer(bufferpath)
--fill global buffers with the names of the loaded files
if string.len(bufferpath) > 0 then
table.insert(ses_buffers,bufferpath)
--print(bufferpath)
end
end
--print out the lua table file names
function get_files(filename)
local i, file
for i,file in ipairs(ses_buffers) do
print(file)
end
end
function OnOpen(f)
load_buffer(f)
end
--cut--
Add the following to SciTEUser.properties:
ext.lua.startup.script=$(SciteUserHome)/mystartupscript.lua
Restart SciTE and the table 'ses_buffers' will have a list of all files
opened on startup. It will add each opened file to the list.
What you do with them is up to you. ;-)
I am not an expert with lua but this should help get you started.
Thanks for the help. The code that Neil referred to
(http://lua-users.org/wiki/SciteBufferSwitch) uses the same method to build the
list of buffers. Unfortunately, that list does not remove buffers when they
are closed. It is really a list of files that have been opened since Scite was
last started, not a list of active/open buffers. Maybe I'm missing something
(it's been known to happen :) ), but looking at the code, that's what I see.
That method could work with a little modification if an OnClose() event existed
which AFAIK does not. Even so, it would still suffer the same issue as my
proposed method. Namely, there is no way AFAIK to get the contents of the
buffer w/o activating/focusing it (which is ugly).
_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest