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

Functions/Zle/edit-command-line



I wrote:
} I see that Clint's committed 13323, but I'm not convinced that it's the
} correct fix.

The problem with Clint's version is that it puts the entire multi-line
construct into the editor file:

print -R - "$PREBUFFER$BUFFER" >$tmpfile

But then it presumes that the user won't edit anything but the last line:

BUFFER=${"$(<$tmpfile)"/$PREBUFFER/}

If you actually do change anything that originated in $PREBUFFER, the whole
editor file will replace what used to be just the last line of the input,
leaving the original $PREBUFFER unchanged, which is clearly not correct.

The following "correct" solution unfortunately does not work:

    edit-command-line () {
        local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$
        zle push-input			# This line aborts the function
        read -r -z -E > $tmpfile 
        exec < /dev/tty
        ${VISUAL:-${EDITOR:-vi}} $tmpfile
        BUFFER="$(<$tmpfile)" 
        CURSOR=$#BUFFER
        command rm -f $tmpfile
    }

The reason that it doesn't work is that push-input (and push-line-or-edit)
must set errflag to force ZLE and the lexer to reset all the way to the PS1
prompt, and setting errflag causes ZLE to abort as if send-break were used.

That suggests the following alternate solution:

    edit-command-line () {
        local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$
        print -R - "$PREBUFFER$BUFFER" > $tmpfile 
        exec < /dev/tty
        ${VISUAL:-${EDITOR:-vi}} $tmpfile
        print -z - "$(<$tmpfile)" 
        command rm -f $tmpfile
        zle send-break
    }

This works exactly as desired except that it causes zsh to feep when the
editor exits.  Unless somebody has a better idea (e.g., to fix push-input
so it does not need to simulate an error), I propose using the above.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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