about summary refs log tree commit diff
path: root/Functions/Zle/edit-command-line
diff options
context:
space:
mode:
authorDaniel Shahaf <d.s@daniel.shahaf.name>2015-07-07 20:30:15 +0000
committerDaniel Shahaf <d.s@daniel.shahaf.name>2015-07-13 23:21:54 +0000
commit35ffe36318955d03fca3df0d34a0997970cfc6a3 (patch)
tree505c4679b9ba33ba4970ed7c5d177b70e73ed786 /Functions/Zle/edit-command-line
parent5911aca85f200cb7621b65ff61d79919fd21cfcb (diff)
downloadzsh-35ffe36318955d03fca3df0d34a0997970cfc6a3.tar.gz
zsh-35ffe36318955d03fca3df0d34a0997970cfc6a3.tar.xz
zsh-35ffe36318955d03fca3df0d34a0997970cfc6a3.zip
35769: edit-command-line: Go to the right byte offset
Diffstat (limited to 'Functions/Zle/edit-command-line')
-rw-r--r--Functions/Zle/edit-command-line12
1 files changed, 11 insertions, 1 deletions
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 100af9601..2ad4825b7 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")