From: Mikael Magnusson <mikachu@gmail.com>
To: zsh-workers@zsh.org
Subject: PATCH: edit-command-line: when possible, set $BUFFER directly
Date: Sat, 8 Aug 2020 11:51:48 +0200 [thread overview]
Message-ID: <20200808095148.21555-1-mikachu@gmail.com> (raw)
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.
---
See also: 23588 and 47295
Functions/Zle/edit-command-line | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 991775ea50..1103ca556c 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")
--
2.15.1
next reply other threads:[~2020-08-08 9:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-08 9:51 Mikael Magnusson [this message]
2020-08-08 10:17 ` PATCH: edit-command-line: add editor style Mikael Magnusson
2020-08-08 10:18 ` PATCH: edit-command-line: restrict editing to region if it is active Mikael Magnusson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200808095148.21555-1-mikachu@gmail.com \
--to=mikachu@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public 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).