zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: [PATCH] edit-command-line: Go to the right byte offset
Date: Fri, 10 Jul 2015 18:32:21 +0000	[thread overview]
Message-ID: <20150710183221.GK1869@tarsus.local2> (raw)

---
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


                 reply	other threads:[~2015-07-10 18:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20150710183221.GK1869@tarsus.local2 \
    --to=d.s@daniel.shahaf.name \
    --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).