[-- Attachment #1: Type: text/plain, Size: 226 bytes --] hello, I was wondering if it is possible to prepopulate $BUFFER before rendering the prompt. I tried doing so in preexec, but it didn't work. Is there some other function I can override to do this? regards Pier Paolo Grassi [-- Attachment #2: Type: text/html, Size: 476 bytes --]
> On 29 April 2022 at 14:21 Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> hello, I was wondering if it is possible to prepopulate $BUFFER before
> rendering the prompt.
> I tried doing so in preexec, but it didn't work. Is there some other
> function I can override to do this?
You need "print -z" --- it has all the usual options of print but the result
ends up in the line buffer when the line editor starts.
pws
[-- Attachment #1: Type: text/plain, Size: 587 bytes --] perfect, thanks! Pier Paolo Grassi Il giorno ven 29 apr 2022 alle ore 15:29 Peter Stephenson < p.w.stephenson@ntlworld.com> ha scritto: > > On 29 April 2022 at 14:21 Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > > hello, I was wondering if it is possible to prepopulate $BUFFER before > > rendering the prompt. > > I tried doing so in preexec, but it didn't work. Is there some other > > function I can override to do this? > > You need "print -z" --- it has all the usual options of print but the > result > ends up in the line buffer when the line editor starts. > > pws > > [-- Attachment #2: Type: text/html, Size: 1201 bytes --]
[-- Attachment #1: Type: text/plain, Size: 881 bytes --] actually I have another question, is there a similar way of setting the initial cursor position like I would do setting the CURSOR var in zle widgets? Pier Paolo Grassi Il giorno ven 29 apr 2022 alle ore 16:16 Pier Paolo Grassi < pierpaolog@gmail.com> ha scritto: > perfect, thanks! > > Pier Paolo Grassi > > > Il giorno ven 29 apr 2022 alle ore 15:29 Peter Stephenson < > p.w.stephenson@ntlworld.com> ha scritto: > >> > On 29 April 2022 at 14:21 Pier Paolo Grassi <pierpaolog@gmail.com> >> wrote: >> > hello, I was wondering if it is possible to prepopulate $BUFFER before >> > rendering the prompt. >> > I tried doing so in preexec, but it didn't work. Is there some other >> > function I can override to do this? >> >> You need "print -z" --- it has all the usual options of print but the >> result >> ends up in the line buffer when the line editor starts. >> >> pws >> >> [-- Attachment #2: Type: text/html, Size: 1904 bytes --]
> On 29 April 2022 at 15:18 Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> actually I have another question, is there a similar way of setting the
> initial cursor position like I would do setting the CURSOR var in zle
> widgets?
As long as something else hasn't already taken over zle-line-init, you
can do something like
zle-line-init() {
if (( set_cursor )); then
(( CURSOR = set_cursor ))
set_cursor=0
fi
}
zle -N zle-line-init
then you can use it like
print -z "foo bar"; typeset -gi set_cursor=4
pws
[-- Attachment #1: Type: text/plain, Size: 1080 bytes --] thanks, I ended doing it like this: zle-line-init(){ [[ -n $__precmd_buffer ]] && { BUFFER=$__precmd_buffer CURSOR=$__precmd_cursor } } and storing the current line and cursor position with: set_precmd_buffer() { __precmd_buffer=$BUFFER __precmd_cursor=$CURSOR } zle -N set_precmd_buffer set_precmd_buffer bindkey "^X^[e" set_precmd_buffer best regards! Pier Paolo Grassi Il giorno ven 29 apr 2022 alle ore 16:25 Peter Stephenson < p.w.stephenson@ntlworld.com> ha scritto: > > On 29 April 2022 at 15:18 Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > > actually I have another question, is there a similar way of setting the > > initial cursor position like I would do setting the CURSOR var in zle > > widgets? > > As long as something else hasn't already taken over zle-line-init, you > can do something like > > zle-line-init() { > if (( set_cursor )); then > (( CURSOR = set_cursor )) > set_cursor=0 > fi > } > zle -N zle-line-init > > then you can use it like > > print -z "foo bar"; typeset -gi set_cursor=4 > > pws > [-- Attachment #2: Type: text/html, Size: 1925 bytes --]
On 4/29/22, Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
> thanks, I ended doing it like this:
>
> zle-line-init(){
> [[ -n $__precmd_buffer ]] && {
> BUFFER=$__precmd_buffer
> CURSOR=$__precmd_cursor
> }
> }
>
> and storing the current line and cursor position with:
>
> set_precmd_buffer() {
> __precmd_buffer=$BUFFER
> __precmd_cursor=$CURSOR
> }
> zle -N set_precmd_buffer set_precmd_buffer
> bindkey "^X^[e" set_precmd_buffer
>
> best regards!
Perhaps you would like to know about the accept-and-hold widget (bound
to alt-a by default)?
--
Mikael Magnusson
[-- Attachment #1: Type: text/plain, Size: 1097 bytes --] Hi, thanks, I already use that, I even have a widget that rebinds enter so I can switch it temporarily to accept-and-hold. This use case is a bit different, since I return always to the original (incomplete) version of the command line, and I have only to complete it instead of deleting what I don't need anymore and fill the blanks Pier Paolo Grassi Il giorno ven 29 apr 2022 alle ore 17:25 Mikael Magnusson <mikachu@gmail.com> ha scritto: > On 4/29/22, Pier Paolo Grassi <pierpaolog@gmail.com> wrote: > > thanks, I ended doing it like this: > > > > zle-line-init(){ > > [[ -n $__precmd_buffer ]] && { > > BUFFER=$__precmd_buffer > > CURSOR=$__precmd_cursor > > } > > } > > > > and storing the current line and cursor position with: > > > > set_precmd_buffer() { > > __precmd_buffer=$BUFFER > > __precmd_cursor=$CURSOR > > } > > zle -N set_precmd_buffer set_precmd_buffer > > bindkey "^X^[e" set_precmd_buffer > > > > best regards! > > Perhaps you would like to know about the accept-and-hold widget (bound > to alt-a by default)? > > -- > Mikael Magnusson > [-- Attachment #2: Type: text/html, Size: 1835 bytes --]
On Fri, Apr 29, 2022 at 8:57 AM Pier Paolo Grassi <pierpaolog@gmail.com> wrote:
>
> This use case is a bit different, since I return always to the original (incomplete) version of the command line, and I have only to complete it instead of deleting what I don't need anymore and fill the blanks
How does that differ from push-line ?
[-- Attachment #1: Type: text/plain, Size: 911 bytes --] push-line (^Q ESC-Q ESC-q) (unbound) (unbound) Push the current buffer onto the buffer stack and clear the buffer. Next time the editor starts up, the buffer will be popped off the top of the buffer stack and loaded into the editing buffer. the difference is in the fact that the stack will return a pushed line just once, not for each subsequent prompt, and it will not save cursor position. Pier Paolo Grassi Il giorno ven 29 apr 2022 alle ore 18:21 Bart Schaefer < schaefer@brasslantern.com> ha scritto: > On Fri, Apr 29, 2022 at 8:57 AM Pier Paolo Grassi <pierpaolog@gmail.com> > wrote: > > > > This use case is a bit different, since I return always to the original > (incomplete) version of the command line, and I have only to complete it > instead of deleting what I don't need anymore and fill the blanks > > How does that differ from push-line ? > [-- Attachment #2: Type: text/html, Size: 1543 bytes --]