summaryrefslogtreecommitdiff
path: root/Functions/Zle/edit-command-line
diff options
context:
space:
mode:
authorAxel Beckert <abe@deuxchevaux.org>2015-08-22 01:55:58 +0200
committerAxel Beckert <abe@deuxchevaux.org>2015-08-22 01:55:58 +0200
commit02f6e25bfcd5feb9a093377dda0dd549cdf5c309 (patch)
tree9a25e61122b3fa0d0a1ff68b5ef05c775ff78b1e /Functions/Zle/edit-command-line
parente04a19735ffc8523b93b33074f685ad4e2c92e0c (diff)
parent881474edcb223ac22a08d81a824809c33ca3a9c9 (diff)
downloadzsh-02f6e25bfcd5feb9a093377dda0dd549cdf5c309.tar.gz
zsh-02f6e25bfcd5feb9a093377dda0dd549cdf5c309.zip
Merge tag 'zsh-5.0.8-test-2' into debian
Diffstat (limited to 'Functions/Zle/edit-command-line')
-rw-r--r--Functions/Zle/edit-command-line15
1 files changed, 14 insertions, 1 deletions
diff --git a/Functions/Zle/edit-command-line b/Functions/Zle/edit-command-line
index 100af9601..2c7f34b8b 100644
--- a/Functions/Zle/edit-command-line
+++ b/Functions/Zle/edit-command-line
@@ -8,7 +8,20 @@
() {
exec </dev/tty
- ${=${VISUAL:-${EDITOR:-vi}}} $1
+
+ # Compute the cursor's position in bytes, not characters.
+ setopt localoptions nomultibyte
+ integer byteoffset=$(( $#PREBUFFER + $#LBUFFER + 1 ))
+
+ # Open the editor, placing the cursor at the right place if we know how.
+ local editor=${${VISUAL:-${EDITOR:-vi}}}
+ 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")