help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Readline macro question


From: Robert E. Griffith
Subject: Re: Readline macro question
Date: Fri, 29 Jul 2022 18:44:52 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1

Thanks Koichi Murase,  This opens up a whole new set of possibilities for me. For some reason I thought -x only executed external commands and I would not be able to change the environment.

Is there a way to get readline to return from inside the rl_print_line_and_clear function? Like simulating a \n? I tried appending a \n to READLINE_LINE but that did not cause it to return

If not, I think I can use a macro that invokes a shell function and then has a \C-m to tell readline to return.  Is the only way to do that to bind -x the function to a keyseq and then use that keyseq in the macro?  Is that true for readline functions also -- i.e. I can only invoke a readline function from within a macro string if that function has a keyseq bound to it?

   $ bind -x '"<someObscureKey>": fooFn'
   $ bind '"\eOP": "<someObscureKey>\C-m"'


Are the key bindings from the emacs/VI mode different from those added with bind in that they can not be removed or replaced?  Is that why trying to remove or change the "TAB" binding did not work?

--BobG


On 7/29/22 17:52, Koichi Murase wrote:
2022年7月30日(土) 3:10 Robert E. Griffith<bobg@junga.com>:
Is it possible to prevent readline from echoing the text entered through
a macro?
It seems what you want to do is actually not to prevent the echoing
but just to print and clear the current commandline. In this case,
`bind -x' should be used rather than the readline string macros.

function rl_print_line_and_clear() {
   printf '\e[34m<up>:\e[m%s\n' "$READLINE_LINE"
   READLINE_LINE=
   READLINE_POINT=0
   READLINE_MARK=0
}
bind -x '"\eOP": rl_print_line_and_clear'

So I tried using the CSI conceal  code like ...

     $ bind '"\eOP": "\C-aecho \e34m'\''<up>'\'':\e0m\C-m"'
     $ echo mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm'<up>':hello
     mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm<up>:hello

But the default ESC binding is to metafy the next character. Removing or
replacing the ESC binding had no affect so a related question is "Is is
possible to embed CSI codes in a macro?
ESC (\e) and CSI (\e[) are different. The ANSI control sequence should
be started with CSI \e[ but not with ESC \e. In addition, the macro
string is treated as if the user inputs it from the keyboard, so if
you want to embed \e in the commandline, you need to insert control
characters by C-v or C-q, i.e., \e needs to be input by \C-v\e in the
macro string:

bind '"\eOP": "\C-aecho \C-v\e[34m'\''<up>'\'':\C-v\e[0m\C-m"'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]