Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Tweak to read-from-minibuffer
- X-seq: zsh-workers 20145
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: Tweak to read-from-minibuffer
- Date: Sat, 10 Jul 2004 13:03:29 -0700 (PDT)
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- Reply-to: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
The patch allows read-from-minibuffer to take two additional arguments
which are used as the values of LBUFFER and RBUFFER.
This in turn allows one to write a widget like the following:
self-accept () {
zle .self-insert "$@" && inserted=1
zle accept-line
}
show-matching-files () {
local SOFAR inserted
zle -N self-insert self-accept &&
{
while inserted=0; read-from-minibuffer "pattern: " "$SOFAR"
do
[[ -n "$REPLY" ]] && (( inserted )) || return 0
SOFAR="$REPLY"
zle -R "" *$~SOFAR*(N)
done
} always {
zle -A .self-insert self-insert
}
return 1
}
This is obviously a toy, but it shows the basic idea. I was tempted to
introduce LREPLY and RREPLY to get back the buffer state but decided to
let that pass pending further discussion.
Something like "self-accept" could be folded into read-from-minibuffer to
replace the somewhat ugly -k behavior (which I've clarified in the doc, as
it's unpleasant when N > 1).
Index: Doc/Zsh/contrib.yo
===================================================================
--- contrib.yo 3 Jul 2004 03:50:02 -0000 1.15
+++ contrib.yo 10 Jul 2004 19:24:28 -0000
@@ -742,12 +742,20 @@
returned to the calling function in the parameter tt($REPLY) and the
editing buffer restored to its previous state. If the read was aborted
by a keyboard break (typically tt(^G)), the function returns status 1
-and tt($REPLY) is not set. If an argument is supplied to the function
-it is taken as a prompt, otherwise `tt(? )' is used.
+and tt($REPLY) is not set.
+
+If one argument is supplied to the function it is taken as a prompt,
+otherwise `tt(? )' is used. If two arguments are supplied, they are the
+prompt and the initial value of tt($LBUFFER), and if a third argument is
+given it is the initial value of tt($RBUFFER). This provides a default
+value and starting cursor placement. Upon return the entire buffer is the
+value of tt($REPLY).
One option is available: `tt(-k) var(num)' specifies that var(num)
characters are to be read instead of a whole line. The line editor is not
-invoked recursively in this case. Note that unlike the tt(read) builtin
+invoked recursively in this case, so depending on the terminal settings
+the input may not be visible, and only the input keys are placed in
+tt($REPLY), not the entire buffer. Note that unlike the tt(read) builtin
var(num) must be given; there is no default.
The name is a slight misnomer, as in fact the shell's own minibuffer is
Index: Functions/Zle/read-from-minibuffer
===================================================================
--- read-from-minibuffer 31 Mar 2003 18:05:19 -0000 1.2
+++ read-from-minibuffer 10 Jul 2004 19:09:31 -0000
@@ -20,8 +20,8 @@
local savelbuffer=$LBUFFER saverbuffer=$RBUFFER
local savepredisplay=$PREDISPLAY savepostdisplay=$POSTDISPLAY
-LBUFFER=
-RBUFFER=
+LBUFFER="$2"
+RBUFFER="$3"
PREDISPLAY="$PREDISPLAY$savelbuffer$saverbuffer$POSTDISPLAY
${1:-? }"
POSTDISPLAY=
Messages sorted by:
Reverse Date,
Date,
Thread,
Author