* completion & read, vared @ 1998-07-13 11:10 Heinz Deinhart 1998-07-13 17:37 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Heinz Deinhart @ 1998-07-13 11:10 UTC (permalink / raw) To: zsh-users Hi, is there a way to use completion with any realine-like function ? vared uses completion, but i cant figure out how to change its behaviour. thanks for any tips, ciao Heinz ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completion & read, vared 1998-07-13 11:10 completion & read, vared Heinz Deinhart @ 1998-07-13 17:37 ` Bart Schaefer 1998-07-13 18:19 ` Heinz Deinhart 0 siblings, 1 reply; 4+ messages in thread From: Bart Schaefer @ 1998-07-13 17:37 UTC (permalink / raw) To: Heinz Deinhart, zsh-users On Jul 13, 1:10pm, Heinz Deinhart wrote: } Subject: completion & read, vared } } is there a way to use completion with any realine-like function ? Not directly; "read" inputs characters one at a time, for some reason, even when not in raw mode. } vared uses completion, but i cant figure out how to change its behaviour. Change its behavior how? Try the following; it should work exactly like the "read" builtin, except that when reading in the "ordinary" way from a terminal, it uses vared to provide access to completion and history. Note that this means you can't end the loop with an EOF character (ctrl-D) because vared doesn't interpret EOFs (it attempts completion instead). So you have to end the loop with an interrupt (ctrl-C), which in turn means it's not possible to interrupt any surrounding script or function when the vared is in progress. (There's probably some bindkey foolery that would fix this up.) The cryptic "${${(M)1%%\?*}#\?}" is peeling off the ?PROMPT part of the first NAME?PROMPT parameter (see the zsh doc for the "read" builtin). function zleread { emulate zsh setopt localoptions local input opt ropt n=0 ropt=() while getopts :AEe opt do case $opt in [?]) read $*; return $?;; *) ropt=($ropt -$opt); ((++n)); esac done if [[ -t 0 ]] then shift $n vared -hp "${${(M)1%%\?*}#\?}" input print -r $input | read $ropt ${1%%\?*} $*[2,-1] return $? fi read $* } I did notice one oddity while playing with this. From the PS1 prompt, read -eu0k1 reads a line from the terminal and echoes back the first character. However, if instead I redirect input to read like so: repeat 3 print x y z | read -eu0k1 then nothing is read. I have to use repeat 3 print x y z | read -eu0k 1 to get the desired behavior. Why does the source of the input affect the option parsing? -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.brasslantern.com ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completion & read, vared 1998-07-13 17:37 ` Bart Schaefer @ 1998-07-13 18:19 ` Heinz Deinhart 1998-07-14 1:45 ` Bart Schaefer 0 siblings, 1 reply; 4+ messages in thread From: Heinz Deinhart @ 1998-07-13 18:19 UTC (permalink / raw) To: Bart Schaefer; +Cc: zsh-users On Mon, 13 Jul 1998, Bart Schaefer wrote: > On Jul 13, 1:10pm, Heinz Deinhart wrote: > } Subject: completion & read, vared > } > } is there a way to use completion with any realine-like function ? > > Not directly; "read" inputs characters one at a time, for some reason, > even when not in raw mode. > > } vared uses completion, but i cant figure out how to change its behaviour. > > Change its behavior how? > hmm, maybe i'm missing something, but i want to do something like that: simple example: "compctl -u huhu" "huhu emp<TAB>" expands to "huhu emperor" well and now it would be cool if vared had a completion option (maybe -C) "vared -p 'enter a username> ' -C '-u' returnvar" "emp<TAB>" expands to "emperor" ^^^^ the compctl options that vared should use in input-line anyway, thanks for the script, i will try to understand it :) ciao, Heinz ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: completion & read, vared 1998-07-13 18:19 ` Heinz Deinhart @ 1998-07-14 1:45 ` Bart Schaefer 0 siblings, 0 replies; 4+ messages in thread From: Bart Schaefer @ 1998-07-14 1:45 UTC (permalink / raw) To: Heinz Deinhart; +Cc: zsh-users On Jul 13, 8:19pm, Heinz Deinhart wrote: > Subject: Re: completion & read, vared > > > On Mon, 13 Jul 1998, Bart Schaefer wrote: > > > On Jul 13, 1:10pm, Heinz Deinhart wrote: > > } Subject: completion & read, vared > > } > > } is there a way to use completion with any realine-like function ? > > > > Not directly; "read" inputs characters one at a time, for some reason, > > even when not in raw mode. > > hmm, maybe i'm missing something, but No, it is I that missed something. You meant "... use completion with _every_ readline-like function?" I parsed "... use completion with one of the readline-like functions?" The answer to the former question is, no, there isn't. The answer I gave was to invent a readline-like function that uses vared to perform completion, which may be interesting but isn't what you wanted. > > } vared uses completion, but i cant figure out how to change its behaviour. > > > > Change its behavior how? > > it would be cool if vared had a completion option (maybe -C) > > "vared -p 'enter a username> ' -C '-u' returnvar" > "emp<TAB>" expands to "emperor" > > ^^^^ the compctl options that vared > should use in input-line Completion within vared appears to work exactly as if it were parsing a command line; e.g. it completes commands in the leftmost word, then does the completions for those commands in succeeding words, etc. Arguably this isn't the most useful behavior. (For more fun, try invoking the binding for run-help while you're doing a vared; the results are not very helpful). To get the effect that you specifically asked for above, you need to change the default completion by using "compctl -T", then restore the default when vared has exited. E.g., compctl -Tx 'W[0,*]' -u vared whatever compctl -T As usual, one can't attempt something like this without running into another zsh oddity. In this case, compctl -T -u is accepted and appears in the "compctl -L" output, but is a no-op. There has to be a -x option and a pattern before -T will do anything at all. The manual says -T "is only useful when combined with extended completion" but here's a case where (a) it's useful WITHOUT extended completion and (b) it fails mysteriously when used in the obvious way. We should strive to prevent this sort of thing. Anyway, 'W[0,*]' means accept anything in word zero (the command position) which is the closest you can get to having no pattern at all. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1998-07-14 1:55 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 1998-07-13 11:10 completion & read, vared Heinz Deinhart 1998-07-13 17:37 ` Bart Schaefer 1998-07-13 18:19 ` Heinz Deinhart 1998-07-14 1:45 ` 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).