zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] edit-command-line: Go to the right byte offset
@ 2015-07-10 18:32 Daniel Shahaf
  0 siblings, 0 replies; only message in thread
From: Daniel Shahaf @ 2015-07-10 18:32 UTC (permalink / raw)
  To: zsh-workers

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-07-10 18:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-10 18:32 [PATCH] edit-command-line: Go to the right byte offset Daniel Shahaf

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