zsh-users
 help / color / mirror / code / Atom feed
From: Gwern Branwen <gwern0@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>,
	Zsh-user <zsh-users@sunsite.dk>
Subject: Re: Improving spelling correction prompt to generate aliases for future use
Date: Sun, 21 Oct 2007 18:22:26 -0400	[thread overview]
Message-ID: <20071021222226.GA25238@localhost> (raw)
In-Reply-To: <071021144511.ZM31240@torch.brasslantern.com>

[-- Attachment #1: Type: text/plain, Size: 1617 bytes --]

On 2007.10.21 14:45:11 -0700, Bart Schaefer <schaefer@brasslantern.com> 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 #2: Type: application/pgp-signature, Size: 189 bytes --]

      reply	other threads:[~2007-10-21 22:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-21  3:39 Gwern Branwen
2007-10-21 18:04 ` Peter Stephenson
2007-10-21 21:45   ` Bart Schaefer
2007-10-21 22:22     ` Gwern Branwen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20071021222226.GA25238@localhost \
    --to=gwern0@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).