Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Improving spelling correction prompt to generate aliases for future use
- X-seq: zsh-users 12074
- From: Gwern Branwen <gwern0@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Zsh-user <zsh-users@xxxxxxxxxx>
- Subject: Re: Improving spelling correction prompt to generate aliases for future use
- Date: Sun, 21 Oct 2007 18:22:26 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:received:date:from:to:subject:message-id:references:mime-version:content-type:content-disposition:in-reply-to:x-gnupg-keyid:x-gnupg-fingerprint:x-editor:x-operating-system:user-agent; bh=kMzB7Y7FlrAFKykmZr37yFx4PDvuVZW2loh9pECNVKc=; b=D0Dofsv1KR1MdjDNWcRvHBsmDieJnQ7T3RX5e8407T7t0hKUotgoh+RqGpB1L1SgvR4Zf+HApmQ6bqmT5sCYrCRDQF3/cVqwesdE095pcAdEZ1N4/Uvlp9Q/s59HUYXWLsksrOLwskFKq5/Y6F6HfJsH78Znf/yPrjtdUOW72/Q=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:date:from:to:subject:message-id:references:mime-version:content-type:content-disposition:in-reply-to:x-gnupg-keyid:x-gnupg-fingerprint:x-editor:x-operating-system:user-agent; b=p/+Vxf0ZpScKHdoH6GmLGRGSDsLuzwcEGnAkGcIQzO0EC3FuGnVoD+xa6jXBg5QLkC2jWsJirWFT+UweRwC8jO1sFNqN/FonLbGAgRq+yK8XUOc7Yvpt4w87jy/qSowBtp58VdoNjguW5rr66pSqeCaqkCntcBIAWxC2jwUIsT0=
- In-reply-to: <071021144511.ZM31240@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <200710211804.l9LI4w23004771@xxxxxxxxxxxxxxxxxxx> <071021144511.ZM31240@xxxxxxxxxxxxxxxxxxxxxx>
On 2007.10.21 14:45:11 -0700, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> scribbled 0 lines:
> On Oct 21, 7:04pm, Peter Stephenson wrote:
> }
> } You could "setopt promptsubst" and have typo output the prompt (as
> } well as whatever else it's doing)
>
> I don't think that'll do what Gwern is after. He wants to feed the
> results (original and suggested replacement) of spelling correction
> to "typo" as command-line arguments.
>
> E.g. he wants to do
>
> typo ${(%):-%R} ${(%):-%r}
>
> but he can't because prompt substitution in parameters doesn't have
> access to the SPROMPT escapes.
Yes, after quite a bit of frustrated and bemused experimentation I discovered I could only get '%R'/'%r' and not their values (which still amazes me just a little).
> The following works for simple commands but not loop constructs or other
> compound commands:
>
> accept-line() {
> emulate -L zsh
> local -a words
> words=(${(z)BUFFER})
> typeset -g ACCEPTED_CMD=$words[1]
> zle .accept-line "$@"
> }
> zle -N accept-line
>
> preexec() {
> emulate -L zsh
> local -a words
> words=(${(z)1})
> if [[ $words[1] != $ACCEPTED_CMD ]]
> then
> typo $ACCEPTED_CMD $words[1]
> fi
> }
Yes, that seems to work fine! Thanks, I hadn't realized that the pre* commands could be helpful in this case. In fact, this actually seems to be an even better solution compared to running out of the prompt, because a 'typo' in the prompt wouldn't know whether the user had answered yes or no - while this preexec thing has a conditional on just that.
--
gwern
Freeh Abbas warfare V fuses crypto AOL Mexico SNT friends
Attachment:
pgp244X6L2CnK.pgp
Description: PGP signature
Messages sorted by:
Reverse Date,
Date,
Thread,
Author