diff options
author | Mikael Magnusson <mikachu@gmail.com> | 2012-06-08 07:55:27 +0200 |
---|---|---|
committer | Mikael Magnusson <mikachu@gmail.com> | 2020-08-16 18:04:43 +0200 |
commit | d877073959ba4b86da968f63be320875a0f0c2a7 (patch) | |
tree | 69f5e23bb7fe0a9ea086dcdb33599c8f7c189b56 /Functions/Zle | |
parent | b959ec790e7ee13725668d9917efe0a580619131 (diff) | |
download | zsh-d877073959ba4b86da968f63be320875a0f0c2a7.tar.gz zsh-d877073959ba4b86da968f63be320875a0f0c2a7.tar.xz zsh-d877073959ba4b86da968f63be320875a0f0c2a7.zip |
47305: edit-command-line: when possible, set $BUFFER directly
This avoids the send-break which is both visually unappealing and might break some use cases where the user wishes to wrap edit-command-line in another widget.
Diffstat (limited to 'Functions/Zle')
-rw-r--r-- | Functions/Zle/edit-command-line | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line index 991775ea5..1103ca556 100644 --- a/Functions/Zle/edit-command-line +++ b/Functions/Zle/edit-command-line @@ -7,6 +7,11 @@ # except that it will handle multi-line buffers properly. emulate -L zsh +local prebuffer +# see below comment for why this is needed +if (( ! ZLE_RECURSIVE )); then + prebuffer=$PREBUFFER +fi () { exec </dev/tty @@ -31,7 +36,21 @@ emulate -L zsh (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1] # Replace the buffer with the editor output. - print -Rz - "$(<$1)" -} =(<<<"$PREBUFFER$BUFFER") - -zle send-break # Force reload from the buffer stack + # avoid drawing a new prompt when we can: + # - in recursive-edit, the send-break will just cancel the recursive-edit + # rather than reload the line from print -z so in that case we want to + # just set $BUFFER (unfortunately, recursive-edit doesn't reset CONTEXT + # or PREBUFFER so we have to explicitly handle this case, which overrides + # the following point) + # - when we are at PS2 (CONTEXT == cont && ! ZLE_RECURSIVE) we do want the + # break or otherwise the text from PREBUFFER will be inserted twice + # - in all other cases (that I can think of) we also just want to set + # $BUFFER directly. + if [[ $CONTEXT != cont ]] || (( ZLE_RECURSIVE )); then + BUFFER="$(<$1)" + else + print -Rz - "$(<$1)" + zle send-break + fi + +} =(<<<"$prebuffer$BUFFER") |