File: histcompl.lua

package info (click to toggle)
notion 3%2B2014010901-1
  • links: PTS, VCS
  • area: non-free
  • in suites: jessie, jessie-kfreebsd
  • size: 4,940 kB
  • ctags: 6,104
  • sloc: ansic: 46,870; sh: 2,008; makefile: 598; perl: 270
file content (37 lines) | stat: -rw-r--r-- 715 bytes parent folder | download | duplicates (2)
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
36
37
-- Authors: Unknown
-- License: Unknown
-- Last Changed: Unknown
-- 
-- History completion support for the line editor

local function historyi()
    function gn(s)
	local i=s.i
	s.i=s.i+1
	return mod_query.history_get(i)
    end
    return gn, {i=0}
end

local function complhist(tocompl)
    local res={}
    local res2={}
    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 (#res>0 and res) or res2
end

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

defbindings("WEdln", {
    kpress("Shift+Tab", history_completor),
})