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