* PATCH: edit-command-line
@ 2000-05-10 13:05 Peter Stephenson
2000-05-10 15:13 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2000-05-10 13:05 UTC (permalink / raw)
To: Zsh hackers list
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@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: PATCH: edit-command-line
2000-05-10 13:05 PATCH: edit-command-line Peter Stephenson
@ 2000-05-10 15:13 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2000-05-10 15:13 UTC (permalink / raw)
To: Zsh hackers list
On May 10, 2:05pm, Peter Stephenson wrote:
} Subject: PATCH: edit-command-line
}
} 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,
It looks like zrefresh() only reprints the line up to the previous cursor
position if it hasn't changed beyond that. The whole line gets redisplayed
correctly only if the cursor was at the start or end of the line when the
function began. So the call to redisplay is the right thing.
Fiddling with LBUFFER and RBUFFER causes CURSOR to change, though, so I
think we should take those out and explicitly set CURSOR instead.
And being me, I rewrote other stuff as well: Quote against shwordsplit,
use `print -R -' in case of backslashes or leading dashes in $BUFFER, and
don't let the user's alias for `rm' creep in.
Index: Functions/Zle/edit-command-line
===================================================================
@@ -7,12 +7,11 @@
local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$
-print $BUFFER >$tmpfile
+print -R - "$BUFFER" >$tmpfile
exec </dev/tty
${VISUAL:-${EDITOR:-vi}} $tmpfile
-LBUFFER=
-RBUFFER=
-BUFFER=$(<$tmpfile)
+BUFFER="$(<$tmpfile)"
+CURSOR=$#BUFFER
-rm -f $tmpfile
+command rm -f $tmpfile
zle redisplay
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2000-05-10 15:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-10 13:05 PATCH: edit-command-line Peter Stephenson
2000-05-10 15:13 ` Bart Schaefer
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).