Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: edit-command-line



This adds a zle function for editing the command line using an ordinary
editor, based on what Bart suggested (except being me I rewrote it without
looking at that again).

I think the LBUFFER= and RBUFFER= are redundant, I put them there while I
was wondering why the display didn't appear properly after the function,
which is why I eventually added the `zle redisplay'.  The answer must be
that zle doesn't know that what was on the line already was removed by the
editor, so this is a perfectly resonable solution and I don't think there's
a problem.

As written, this doesn't execute the line edited.

Index: Functions/Zle/.distfiles
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zle/.distfiles,v
retrieving revision 1.1.1.3
diff -u -r1.1.1.3 .distfiles
--- Functions/Zle/.distfiles	1999/09/22 12:36:25	1.1.1.3
+++ Functions/Zle/.distfiles	2000/05/10 12:59:52
@@ -1,4 +1,4 @@
 DISTFILES_SRC='
-    .distfiles history-search-end incremental-complete-word
+    .distfiles history-search-end edit-command-line incremental-complete-word
     incarg insert-files predict-on
 '
Index: Functions/Zle/edit-command-line
===================================================================
RCS file: edit-command-line
diff -N edit-command-line
--- /dev/null	Tue May  5 13:32:27 1998
+++ edit-command-line	Wed May 10 05:59:52 2000
@@ -0,0 +1,18 @@
+# Edit the command line using your usual editor.
+# Binding this to 'v' in the vi command mode map,
+#   autoload edit-command-line
+#   zle -N edit-command-line
+#   bindkey -M vicmd v edit-command-line
+# will give ksh-like behaviour for that key.
+
+local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$
+
+print $BUFFER >$tmpfile
+exec </dev/tty
+${VISUAL:-${EDITOR:-vi}} $tmpfile
+LBUFFER=
+RBUFFER=
+BUFFER=$(<$tmpfile)
+
+rm -f $tmpfile
+zle redisplay

-- 
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



Messages sorted by: Reverse Date, Date, Thread, Author