Running previous commands in output pane

100 views
Skip to first unread message

Neil Hodgson

unread,
Jan 25, 2013, 4:53:50 PM1/25/13
to scite-i...@googlegroups.com
Command shells allow running previous commands by pressing the up key. I'd like to include something like this in SciTE's output pane by displaying an autocompletion box. It could include the last n lines that started with '>' but not if they contain '>Exit code'. Perhaps bound to Alt+Up or by starting the line with '>'.

Neil

Neil Hodgson

unread,
Jan 27, 2013, 9:37:50 PM1/27/13
to scite-i...@googlegroups.com
The previous commands feature can be implemented completely in Lua. Merge the attached file into the Lua Startup Script and connect it to Control+3 (for example) with

command.3.*=recentCommands()
command.name.3.*=Recent Commands
command.mode.3.*=subsystem:lua,savebefore:no

Neil

recentCommands.lua

zetah

unread,
Jan 29, 2013, 9:02:49 AM1/29/13
to scite-i...@googlegroups.com, nyama...@me.com
Works great Neil, thanks

command.30.*=recentCommands()
command.mode.30.*=subsystem:lua,savebefore:no
Alt+Up|1130|\

I found myself couple of times pressing up arrow in output pane, then quickly realize that I'm actually in output pane and do manual copy/paste :)

I've seen "shells" doings history on Ctrl+Up, but there is no distinction between shortcuts for editor pane and output pane, so Ctrl+Up can't be used comfortably.

zetah

unread,
Jan 29, 2013, 10:04:11 AM1/29/13
to scite-i...@googlegroups.com, nyama...@me.com
If splits command on question mark. For example `grep "something?else" .` is returned as `grep "something`

Neil Hodgson

unread,
Jan 29, 2013, 3:43:54 PM1/29/13
to scite-i...@googlegroups.com
zetah:

> If splits command on question mark. For example `grep "something?else" .` is returned as `grep "something`

That's the icon feature of autocompletion lists. Turn it off with output.AutoCTypeSeparator = string.byte('\0')

Fixed version attached.

Neil
recentCommands.lua

zetah

unread,
Jan 30, 2013, 3:41:45 AM1/30/13
to scite-i...@googlegroups.com, nyama...@me.com
That solves it.
I extended a bit more.
Most notably ">>" - if user run some tool with "command.input.*" then output pane command history is bloated with every line from input. I grepped also "SciTEWin.cxx" for other possibilities:

--- recentCommands.lua
+++ recentCommands_mod.lua
@@ -8,6 +8,12 @@
     for line = output.LineCount-1, 0, -1 do
         local text = output:GetLine(line)
         if text and string.starts(text, '>') and
+            not string.starts(text, '>>') and
+            not string.starts(text, '>Input pipe closed due to write failure') and
+            not string.starts(text, '>Process failed to respond; forcing abrupt termination') and
+            not string.starts(text, '>Attempting to cancel process') and
+            not string.starts(text, '>BREAK Failed') and
             not string.starts(text, '>Exit code:') and
             not string.starts(text, '>Lua:') then
             text = text:sub(2)

zetah

unread,
Feb 1, 2013, 4:24:06 PM2/1/13
to scite-i...@googlegroups.com
In addition to above script I made one to auto-complete files in working directory:

========================================
function pathComplete()
    local files = {}
    if string.match(props['SciteUserHome'], '\\') then
        ignore_case = true
        o = spawner.popen('dir "' .. props['FileDir'] .. '" /b')
    else
        ignore_case = false
        o = io.popen('ls -m1 "' .. props['FileDir'] .. '"')
    end
    local cur_pos = output.CurrentPos
    local beg_pos = output:WordStartPosition(cur_pos, true)
    part = output:textrange(beg_pos, cur_pos)
    local function helper(line)
        if ignore_case then line, part = line:lower(), part:lower() end
        if line:sub(1, cur_pos-beg_pos) == part then
            if line:match(' ') then line = '"' .. line .. '"' end
            table.insert(files, line)
        end
        return ''
    end
    helper((o:read('*a'):gsub('(.-)\r?\n', helper)))
    o:close()
    output.AutoCIgnoreCase = ignore_case
    output.AutoCSeparator = string.byte('\n')
    output:GrabFocus()
    output:AutoCShow(cur_pos-beg_pos, table.concat(files, '\n'))
end
========================================

Made on Windows, but I guess it should work fine on Linux too.

Neil Hodgson

unread,
Feb 1, 2013, 4:40:09 PM2/1/13
to scite-i...@googlegroups.com
zetah:

Made on Windows, but I guess it should work fine on Linux too.

   Works on OS X. There are properties for checking platform which may be more robust than looking at paths: props['PLAT_WIN'] is 1 on Windows and props['PLAT_UNIX'] is 1 for OS X or GTK+.

    print('WIN '..props['PLAT_WIN'])
    print('GTK '..props['PLAT_GTK'])
    print('MAC '..props['PLAT_MAC'])
    print('UNIX '..props['PLAT_UNIX'])

WIN 
GTK 
MAC 1
UNIX 1

   Neil

zetah

unread,
Feb 1, 2013, 5:07:33 PM2/1/13
to scite-i...@googlegroups.com, nyama...@me.com
Great, thanks for confirmation, and OS detection tip. I somehow forgot about it from properties.
Reply all
Reply to author
Forward
0 new messages