User strip - Lua command line - problems with focus

140 views
Skip to first unread message

Gavin Holt

unread,
Oct 27, 2015, 2:00:20 PM10/27/15
to scite-interest
Hi,

I am trying to create a Lua prompt with history - as a user strip defined in my lua startup script:

--global history
run_lua_hist = [[print("Hello World")]]

function run_lua_strip()
-- Enter lua code in a command line, with history and execute on enter
    scite.StripShow("!' Lua:> '{}((OK))(Cancel)")
    scite.StripSetList(1, run_lua_hist)

    function OnStrip(control, change)
if control == 1 then -- Action in the combo box

elseif control == 2 then -- Enter or OK
   local cmd=scite.StripValue(1)
   assert(loadstring("do Selection = editor:GetSelText() "..cmd.." end"))()
   run_lua_hist = cmd.."\n"..run_lua_hist
   scite.StripSetList(1, run_lua_hist)
   scite.StripSet(1, cmd)
elseif control == 3 then -- Escape or cancel
   scite.StripShow("") -- Just hide the dialog
end
    end
end

e.g. Lua:> editor:InsertText(-1,"Hello World")
       Lua:> editor:InsertText(-1,"You highlighted: "..Selection)
       Lua:> for i,v in pairs(_G.scite) do print(i,tostring(v)) end

When I use this strip all is well, until I move away to another editor tab(buffer). I cannot then get the user strip to work in the newly selected editor or even if I then go back to the original editor. Activity in the output pane does not cause this behavior. 

I am running Version 3.6.1 (Sep 15 2015 09:00:58) under windows, without extman or similar.

I have read "Open requires special care. When the buffer changes in SciTE, the Lua global namespace is reset to its initial state, and any extension script associated with the new buffer is loaded. Thus, when you call Open, this may change the environment in which your current script is running. When possible, you can avoid confusion by simply returning after scite.Open, but when that is not possible, just bear in mind that there are side effects. Local variables, unlike globals, will be retained after the buffer change until your script returns."

Q1. Is there any way to make my user strip behave like the inbuilt find replace strip which will act upon which ever editor tab(buffer) has focus? Would a clever OnSwitchFile() function help?

Q2. Is there any easy way to get syntax highlighting for my user strip?

Kind Regards

Gavin

Neil Hodgson

unread,
Oct 27, 2015, 6:02:08 PM10/27/15
to scite-i...@googlegroups.com
Gavin Holt:

When I use this strip all is well, until I move away to another editor tab(buffer). I cannot then get the user strip to work in the newly selected editor or even if I then go back to the original editor. Activity in the output pane does not cause this behaviour. 

   IIRC there was some technique for saving values between buffers, possibly involving props, but I can’t remember how.


Q1. Is there any way to make my user strip behave like the inbuilt find replace strip which will act upon which ever editor tab(buffer) has focus? Would a clever OnSwitchFile() function help?

   You can ask whether the output pane has focus with output.focus.

Q2. Is there any easy way to get syntax highlighting for my user strip?

   Strips have only the most basic controls with no styling.

   Neil

Reply all
Reply to author
Forward
0 new messages