Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: edit-command-line: when possible, set $BUFFER directly
- X-seq: zsh-workers 47305
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: edit-command-line: when possible, set $BUFFER directly
- Date: Sat, 8 Aug 2020 11:51:48 +0200
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-08/20200808095148.21555-1-mikachu%40gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-lj1-f175.google.com) smtp.remote-ip=209.85.208.175; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=AwGaMe2OxdyEt4+ydhuueF+DnWxXU9brr+g6vmCGf4M=; b=pc2pFpD3EWiZ8SvHrjBUyQh3/pt1r2WIs71G6eCOG42XWTTWMCq13QbChUygJIJSEk NwFiNA5fM+4Ughii+0LTpX9X07hwbtLUl/r4tvqdTp9G6SryQHtJlbMom43IXG/0ZNZp 6NLLdlug4W1GFrMlWHVcaLKGkv7Kj+eQGdoAFmEWizufxz+MwkLIMfTQ27AlgcF0KY+G BesKMh9oOMhp4JTjQ0YcloDIh9hK/WJ0o9wqv8KStIWsQ9iz3GREAfYC+WQe0/hnBhuY PNQrwhojKpqFNkVnrTM6//+fBA4pttOLOfL/fqz0sXlDoYOxtocKrg+2HnCoAZCgloB5 eKDQ==
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- Sender: Sympa Owner <sympa@xxxxxxx>
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author