File: histcompl.lua

package info (click to toggle)
ion3-scripts 20050418-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 300 kB
  • ctags: 153
  • sloc: makefile: 18
file content (35 lines) | stat: -rw-r--r-- 736 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
-- History completion support for the line editor

local function historyi()
    function gn(s)
        local i=s.i
        s.i=s.i+1
        return query_history_get(i)
    end
    return gn, {i=0}
end
        
local function complhist(tocompl)
    local res={}
    local res2={}
    print(tocompl)
    for str in historyi() do
        local s, e=string.find(str, tocompl, 1, true)
        if s then
            table.insert(res2, str)
        end
	if s==1 and e>=1 then
            table.insert(res, str)
        end
    end
    return (table.getn(res)>0 and res) or res2
end

function history_completor(wedln)
    wedln:set_completions(complhist(wedln:contents()))
end

query_bindings{
    kpress("Shift+Tab", history_completor),
}