Roman Hubacek wrote:
Maybe you can use something like this lua function:

function open_cpp_or_h()
  ext = string.lower(props.FileExt)
  if ext == "cpp" then
    scite.Open(props.FileName .. ".h")
  else
    scite.Open(props.FileName .. ".cpp")
  end
end

You can assign this function into Tools menu.

Great! This works. Thanx.

Now, I only have one problem. When I already have both .cpp and .h files open, and I accidentally run it (I have many buffers so I oversee it), it opens another buffer, so I have .cpp or .h file opened twice, thrice, etc.

Is there some scite.Open_If_Not_Already_Open() function? Or can I somehow check the open buffers from Lua? I searched the docs, but don't see any function to get all open buffers.

It would be really nice if it could either: open new buffer or switch to it if it is already open.

I did try to make my own list of buffers (see script below), but there are problems:

- I don't know how to switch the current scite buffer from Lua. Is it possible?

- if user open other .h/.cpp file manually, I don't get that in buffer. This can be solved by using OnOpen.

- the most serious problem is that there is no OnClose event to catch. So user can simply close the file, but it would remain in my buffer. Neil, could we get OnClose same as we have OnOpen?

Here's the script. Please note that I wrote my first Lua code yesterday:

local buffers = {}

function open_cpp_or_h()
        local newfile
        local currfile = props.FileName .. "." .. props.FileExt
        local ext = string.lower(props.FileExt)
        if ext == "cpp" then
                newfile = props.FileName .. ".h"
        else
                newfile = props.FileName .. ".cpp"
        end
        
        local ni, ci;
        local n = table.getn(buffers)
        for i = 1, n do
                if buffers[i] == newfile then
                        ni = i
                end
                if buffers[i] == currfile then
                        ci = i
                end
        end
        
        if not ci then
                table.insert(buffers, currfile)
        end
        if ni then
                -- TODO: make that the current buffer in editor
                return
        end
        
        scite.Open(newfile)
        table.insert(buffers, newfile)
end

--
Milan Babuskov
http://www.flamerobin.org

_______________________________________________
Scite-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scite-interest

Reply via email to