1;;; Commands that are useful when bound to keys. 2 3;;; /kb_backward_kill_line delete from cursor to beginning of line 4;;; /kb_kill_word delete from cursor to end of punctuated word 5;;; /kb_backward_kill_word delete from cursor to start of punctuated word 6;;; /kb_capitalize_word capitialize current word 7;;; /kb_downcase_word convert current word to lowercase 8;;; /kb_upcase_word convert current word to uppercase 9;;; /kb_transpose_chars swap current character with previous character 10;;; /kb_last_argument insert last word of previous line 11;;; /kb_expand_line /eval and replace current line 12;;; /kb_goto_match move cursor to matching parenthesis or bracket 13;;; /kb_up_or_recallb up within logical line or recallb to previous line 14;;; /kb_down_or_recallf down within logical line or recallf to next line 15 16/loaded __TFLIB__/kbfunc.tf 17 18;;; Don't give the warning if this file is reloaded 19/purge ~hook_redef_dokey 20 21/def -i -ag -mregexp -h'NOMACRO ^key_' no_named_key_macro = \ 22 /echo -p %% The key "@{B}%PR@{n}" is undefined; \ 23 you may use "@{B}/def key_%PR = <commands>@{n}" to define it. \ 24 See "@{B}/help keys@{n}". 25 26;;; /dokey functions. 27 28/def -i dokey_bspc = /@test kbdel(kbpoint() - (kbnum?:1)) 29/def -i dokey_bword = /@test regmatch("[^ ]* *$$", kbhead()), \ 30 kbdel(kbpoint() - strlen({P0})) 31/def -i dokey_dch = /@test kbdel(kbpoint() + (kbnum?:1)) 32/def -i dokey_deol = /@test kbdel(kblen()) 33/def -i dokey_dline = /@test kbgoto(0), kbdel(kblen()) 34/def -i dokey_down = /@test kbgoto(kbpoint() + wrapsize * (kbnum?:1)) 35/def -i dokey_dword = /kb_kill_word 36/def -i dokey_end = /@test kbgoto(kblen()) 37/def -i dokey_home = /@test kbgoto(0) 38/def -i dokey_left = /@test kbgoto(kbpoint() - (kbnum?:1)) 39/def -i dokey_lnext = /dokey lnext 40/def -i dokey_newline = /dokey newline 41/def -i dokey_pause = /dokey pause 42/def -i dokey_recallb = /dokey recallb 43/def -i dokey_recallbeg = /dokey recallbeg 44/def -i dokey_recallend = /dokey recallend 45/def -i dokey_recallf = /dokey recallf 46/def -i dokey_redraw = /dokey redraw 47/def -i dokey_right = /@test kbgoto(kbpoint() + (kbnum?:1)) 48/def -i dokey_searchb = /dokey searchb 49/def -i dokey_searchf = /dokey searchf 50/def -i dokey_socketb = /fg -c$[-kbnum?:-1] 51/def -i dokey_socketf = /fg -c$[+kbnum?:1] 52/def -i dokey_up = /@test kbgoto(kbpoint() - wrapsize * (kbnum?:1)) 53/def -i dokey_wleft = /test kbgoto(kb_nth_word(-(kbnum?:1))) 54/def -i dokey_wright = /test kbgoto(kb_nth_word(kbnum?:1)) 55/def -i dokey_page = /test morescroll(winlines() * (kbnum?:1)) 56/def -i dokey_pageback = /test morescroll(-winlines() * (kbnum?:1)) 57/def -i dokey_hpage = /test morescroll(winlines() * (kbnum?:1) / 2) 58/def -i dokey_hpageback = /test morescroll(-winlines() * (kbnum?:1) / 2) 59/def -i dokey_line = /test morescroll(kbnum?:1) 60/def -i dokey_lineback = /test morescroll(-(kbnum?:1)) 61/def -i dokey_flush = /dokey flush 62/def -i dokey_selflush = /dokey selflush 63 64/def -i dokey_pgup = /dokey_pageback 65/def -i dokey_pgdn = /dokey_page 66 67 68/def -i kb_backward_kill_line = /@test kbdel(0) 69 70/def -i kb_nth_word = \ 71 /let _i=%{1-1}%; \ 72 /let point=$[kbpoint()]%; \ 73 /while (_i<0) /@test point:=kbwordleft(point), ++_i%; /done%; \ 74 /while (_i>0) /@test point:=kbwordright(point), --_i%; /done%; \ 75 /return point 76 77/def -i kb_kill_word = /@test kbdel(kb_nth_word(kbnum?:1)) 78/def -i kb_backward_kill_word = /@test kbdel(kb_nth_word(-(kbnum?:1))) 79 80/def -i kb_capitalize_word = \ 81 /let _old_insert=$[+insert]%;\ 82 /set insert=0%;\ 83 /repeat -S $[kbnum>0?+kbnum:1] \ 84 /@test kbgoto(kbwordright()), kbgoto(kbwordleft()) %%;\ 85 /let end=$$[kbwordright()]%%;\ 86 /@test input(toupper(substr(kbtail(), 0, 1))) %%;\ 87 /@test input(tolower(substr(kbtail(), 0, end - kbpoint()))) %;\ 88 /set insert=%{_old_insert} 89 90/def -i kb_downcase_word = \ 91 /let _old_insert=$[+insert]%;\ 92 /set insert=0%;\ 93 /repeat -S $[kbnum>0?+kbnum:1] \ 94 /@test input(tolower(substr(kbtail(), 0, kbwordright() - kbpoint()))) %;\ 95 /set insert=%{_old_insert} 96 97/def -i kb_upcase_word = \ 98 /let _old_insert=$[+insert]%;\ 99 /set insert=0%;\ 100 /repeat -S $[kbnum>0?+kbnum:1] \ 101 /@test input(toupper(substr(kbtail(), 0, kbwordright() - kbpoint()))) %;\ 102 /set insert=%{_old_insert} 103 104/def -i kb_transpose_chars = \ 105 /if ( kbpoint() <= 0 ) /beep 1%; /return 0%; /endif%; \ 106 /let _old_insert=$[+insert]%;\ 107 /set insert=0%;\ 108; Can't use /dokey_left because it would use %kbnum. 109 /@test kbgoto(kbpoint() - (kbpoint()==kblen()) - 1)%; \ 110 /@test input(strcat(substr(kbtail(),1,kbnum>0?kbnum:1), \ 111 substr(kbtail(),0,1)))%; \ 112 /set insert=%{_old_insert} 113 114/def -i kb_last_argument = \ 115 /input $(/last $(/recall -i - -$[1 + (kbnum>0?kbnum:1)])) 116 117/def -i kb_expand_line = \ 118 /eval /grab $(/recall -i 1) 119 120/def -i kb_goto_match = \ 121 /let _match=$[kbmatch()]%; \ 122 /@test (_match < 0) ? beep() : kbgoto(_match) 123 124/def -i kb_collapse_space = \ 125 /if (regmatch("^ +", kbtail())) \ 126 /@test kbdel(kbpoint() + strlen({P0}) - 1)%; \ 127 /endif%; \ 128 /if (kbtail() =/ " *" & regmatch(" +$", kbhead())) \ 129 /@test kbdel(kbpoint() - strlen({P0}))%; \ 130 /endif 131 132/def -i kb_toggle_limit = \ 133 /if /limit%; /then /unlimit%; /else /relimit%; /endif 134 135/def -i kb_up_or_recallb = \ 136 /if (kbpoint() < wrapsize) \ 137 /dokey_recallb%; \ 138 /else \ 139 /dokey_up%; \ 140 /endif 141 142/def -i kb_down_or_recallf = \ 143 /if (mod(kbpoint(), wrapsize) == mod(kblen(), wrapsize)) \ 144 /dokey_recallf%; \ 145 /else \ 146 /dokey_down%; \ 147 /endif 148 149/eval /def -ip%maxpri -mregexp -h'REDEF macro (dokey|kb)_' ~hook_redef_dokey = \ 150 /echo -e %%% Warning: redefining the %%2 macro is not recommended; \ 151 instead, you should probably redefine the /key_* macro that calls it. \ 152 See /help keys. 153