Zsh ZLE widget "edit-command-line" returns with an error

647 Views Asked by At

When I invoke this widget with ^x^e and then exit the visual editor (vim), the current command is aborted with an error and the command contents is put on the next command line to be executed.

What I expect is that the command content should be put back on the current command line, just like in bash. And I suspect the error is because of the non-zero editor exit status.

I even start zsh fresh like:

zsh -f
autoload -U edit-command-line && zle -N edit-command-line
bindkey '^x^e' edit-command-line

But still got the same problem.

1

There are 1 best solutions below

1
On BEST ANSWER

This seems intended. He said that at the time on the zsh mailing list:

As written, this doesn't execute the line edited.

-- Peter Stephenson (http://www.zsh.org/mla/workers/2000/msg02123.html)

The error might be triggered by using send-break at the end of the function these days.

Indeed, it could be extended like this patch for the edit-command-line file:
(The file might be found by % echo ${^fpath}/edit-command-line(N))

diff --git a/edit-command-line b/edit-command-line
index 250cac6..592fd07 100644
--- a/edit-command-line
+++ b/edit-command-line
@@ -11,7 +11,7 @@ local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$
 print -R - "$PREBUFFER$BUFFER" >$tmpfile
 exec </dev/tty
 ${=${VISUAL:-${EDITOR:-vi}}} $tmpfile
-print -Rz - "$(<$tmpfile)" 
+BUFFER="$(<$tmpfile)"

 command rm -f $tmpfile
-zle send-break     # Force reload from the buffer stack
+zle accept-line

With this patch, it puts back the edited contents on the current command line then executes.