zsh-users
 help / color / mirror / code / Atom feed
* prepopulate BUFFER
@ 2022-04-29 13:21 Pier Paolo Grassi
  2022-04-29 13:28 ` Peter Stephenson
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2022-04-29 13:21 UTC (permalink / raw)
  To: Zsh-Users List

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 13:21 prepopulate BUFFER Pier Paolo Grassi
@ 2022-04-29 13:28 ` Peter Stephenson
  2022-04-29 14:16   ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2022-04-29 13:28 UTC (permalink / raw)
  To: Zsh-Users List

> 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 13:28 ` Peter Stephenson
@ 2022-04-29 14:16   ` Pier Paolo Grassi
  2022-04-29 14:18     ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2022-04-29 14:16 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh-Users List

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 14:16   ` Pier Paolo Grassi
@ 2022-04-29 14:18     ` Pier Paolo Grassi
  2022-04-29 14:25       ` Peter Stephenson
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2022-04-29 14:18 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh-Users List

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 14:18     ` Pier Paolo Grassi
@ 2022-04-29 14:25       ` Peter Stephenson
  2022-04-29 14:53         ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2022-04-29 14:25 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Zsh-Users List

> 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 14:25       ` Peter Stephenson
@ 2022-04-29 14:53         ` Pier Paolo Grassi
  2022-04-29 15:25           ` Mikael Magnusson
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2022-04-29 14:53 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh-Users List

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 14:53         ` Pier Paolo Grassi
@ 2022-04-29 15:25           ` Mikael Magnusson
  2022-04-29 15:56             ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2022-04-29 15:25 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Peter Stephenson, Zsh-Users List

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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 15:25           ` Mikael Magnusson
@ 2022-04-29 15:56             ` Pier Paolo Grassi
  2022-04-29 16:20               ` Bart Schaefer
  0 siblings, 1 reply; 10+ messages in thread
From: Pier Paolo Grassi @ 2022-04-29 15:56 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Peter Stephenson, Zsh-Users List

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 15:56             ` Pier Paolo Grassi
@ 2022-04-29 16:20               ` Bart Schaefer
  2022-04-29 19:34                 ` Pier Paolo Grassi
  0 siblings, 1 reply; 10+ messages in thread
From: Bart Schaefer @ 2022-04-29 16:20 UTC (permalink / raw)
  To: Pier Paolo Grassi; +Cc: Mikael Magnusson, Peter Stephenson, Zsh-Users List

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 ?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: prepopulate BUFFER
  2022-04-29 16:20               ` Bart Schaefer
@ 2022-04-29 19:34                 ` Pier Paolo Grassi
  0 siblings, 0 replies; 10+ messages in thread
From: Pier Paolo Grassi @ 2022-04-29 19:34 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Mikael Magnusson, Peter Stephenson, Zsh-Users List

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-04-29 19:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-29 13:21 prepopulate BUFFER Pier Paolo Grassi
2022-04-29 13:28 ` Peter Stephenson
2022-04-29 14:16   ` Pier Paolo Grassi
2022-04-29 14:18     ` Pier Paolo Grassi
2022-04-29 14:25       ` Peter Stephenson
2022-04-29 14:53         ` Pier Paolo Grassi
2022-04-29 15:25           ` Mikael Magnusson
2022-04-29 15:56             ` Pier Paolo Grassi
2022-04-29 16:20               ` Bart Schaefer
2022-04-29 19:34                 ` Pier Paolo Grassi

Code repositories for project(s) associated with this inbox:

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).