Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] edit-command-line: Go to the right byte offset
- X-seq: zsh-workers 35769
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] edit-command-line: Go to the right byte offset
- Date: Fri, 10 Jul 2015 18:32:21 +0000
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=mesmtp; bh=OKM vb6Bu4q7rCzourlwaD6398Ak=; b=Ws4p1n3nWbM9LTrd2/vnaqaRuXY4iMR7TmW q/O6HhamNsLveXgSUlk7MBuEhzdb6wSQRy2QRpTRjrB7CWmWZd2CCTuXqrxdrtyI jeEG9ubHSI9mNR2r5P7Q351HbEuFlFh18iZr51oHzvvKJxAqJZPXUNGbRu9wBb0s C7MXiWbY=
- Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:message-id :mime-version:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=OK Mvb6Bu4q7rCzourlwaD6398Ak=; b=FMdMx5NJZm3ia692ak1PRy3er36kZBMmZ0 Am+LiFcXvw0wQF5BeaSNevIZ/Amq4ejnnzgoV9GGgpNN5V6LNXvuAU1RLbWUGxGK J29obIKCqEmTE4R/2jkDxJJGnSaB7cObpll27Vluk0kxS5QVmzgaywwFXCGPaz3D /xIpwSzFo=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
---
I keep invoking <edit-command-line> and typing ahead editor commands
assuming $EDITOR's cursor is where zle's cursor is. This patch makes
the code match my expectation.
If there's a better way to open an arbitrary $EDITOR at a given byte offset...
Cheers,
Daniel
Functions/Zle/edit-command-line | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 100af96..44e590e 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -8,7 +8,17 @@
() {
exec </dev/tty
- ${=${VISUAL:-${EDITOR:-vi}}} $1
+
+ # Open the editor, placing the cursor at the right place if we know how.
+ local editor=${${VISUAL:-${EDITOR:-vi}}}
+ integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
+ case $editor in
+ (*vim*) ${=editor} -c "normal! ${byteoffset}go" -- $1;;
+ (*emacs*) ${=editor} $1 -eval "(goto-char ${byteoffset})";;
+ (*) ${=editor} $1;;
+ esac
+
+ # Replace the buffer with the editor output.
print -Rz - "$(<$1)"
} =(<<<"$PREBUFFER$BUFFER")
--
1.9.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author