Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: prepopulate BUFFER



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@xxxxxxxxxxxx> ha scritto:
> On 29 April 2022 at 15:18 Pier Paolo Grassi <pierpaolog@xxxxxxxxx> 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


Messages sorted by: Reverse Date, Date, Thread, Author