File: kbstack.tf

package info (click to toggle)
tf5 5.0beta8-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,976 kB
  • sloc: ansic: 25,499; perl: 103; makefile: 79; sh: 70
file content (40 lines) | stat: -rw-r--r-- 1,223 bytes parent folder | download | duplicates (7)
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
38
39
40
;;;; Keyboard stack
;;;; This is useful when you're in the middle of typing a long line,
;;;; and want to execute another command without losing the current line.
;;;; Type ESC DOWN to save the current input line on a stack.
;;;; Type ESC UP to restore the saved line.  Any number of lines can
;;;; be saved and restored.

/loaded __TFLIB__/kbstack.tf

/purge -i key_esc_down
/purge -i key_esc_up
/def -i key_esc_down = /kb_push
/def -i key_esc_up = /kb_pop

/def -i kb_push = \
    /let n=$[+kbnum]%; \
    /if (n < 0) \
	/echo -A %% %0: illegal stack number %n.%; \
	/return 0%; \
    /endif%; \
    /let _line=$(/recall -i 1)%;\
    /if ( _line !~ "" ) \
        /eval \
	    /set _kb_stack_%{n}_top=$$[_kb_stack_%{n}_top + 1]%%;\
	    /set _kb_stack_%{n}_%%{_kb_stack_%{n}_top}=%%{_line}%;\
    /endif%;\
    /dokey dline

/def -i kb_pop = \
    /let n=$[+kbnum]%; \
    /if /test %{n} >= 0 & _kb_stack_%{n}_top > 0%; /then \
        /dokey dline%;\
        /eval \
	    /@test input(_kb_stack_%{n}_%%{_kb_stack_%{n}_top})%%;\
	    /unset _kb_stack_%{n}_%%{_kb_stack_%{n}_top}%%;\
	    /set _kb_stack_%{n}_top=$$[_kb_stack_%{n}_top - 1]%;\
    /else \
        /echo -A %% %0: Keyboard stack %n is empty.%;\
    /endif