From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1460 invoked from network); 21 Oct 2007 22:57:17 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.3 (2007-08-08) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,SPF_HELO_PASS autolearn=ham version=3.2.3 Received: from ns2.primenet.com.au (HELO primenet.com.au) (@203.24.36.3) by ns1.primenet.com.au with (DHE-RSA-AES256-SHA encrypted) SMTP; 21 Oct 2007 22:57:17 -0000 Received: (qmail 25859 invoked from network); 21 Oct 2007 22:23:27 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by proxy.melb.primenet.com.au with SMTP; 21 Oct 2007 22:23:27 -0000 Received-SPF: none (proxy.melb.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 27347 invoked from network); 21 Oct 2007 22:23:20 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 21 Oct 2007 22:23:20 -0000 Received: (qmail 3479 invoked by alias); 21 Oct 2007 22:23:12 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12074 Received: (qmail 3463 invoked from network); 21 Oct 2007 22:23:12 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 21 Oct 2007 22:23:12 -0000 Received: (qmail 26104 invoked from network); 21 Oct 2007 22:23:12 -0000 Received: from wr-out-0506.google.com (64.233.184.226) by a.mx.sunsite.dk with SMTP; 21 Oct 2007 22:23:05 -0000 Received: by wr-out-0506.google.com with SMTP id c48so651834wra for ; Sun, 21 Oct 2007 15:23:03 -0700 (PDT) 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= Received: by 10.90.50.1 with SMTP id x1mr6085889agx.1193005383535; Sun, 21 Oct 2007 15:23:03 -0700 (PDT) Received: from localhost ( [85.25.141.60]) by mx.google.com with ESMTPS id 5sm10262805agc.2007.10.21.15.22.56 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 21 Oct 2007 15:23:02 -0700 (PDT) Received: by localhost (sSMTP sendmail emulation); Sun, 21 Oct 2007 18:22:26 -0400 Date: Sun, 21 Oct 2007 18:22:26 -0400 From: Gwern Branwen To: Bart Schaefer , Zsh-user Subject: Re: Improving spelling correction prompt to generate aliases for future use Message-ID: <20071021222226.GA25238@localhost> References: <200710211804.l9LI4w23004771@pws-pc.ntlworld.com> <071021144511.ZM31240@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="jI8keyz6grp/JLjh" Content-Disposition: inline In-Reply-To: <071021144511.ZM31240@torch.brasslantern.com> X-GnuPG-KeyID: F7E5D682 X-GnuPG-Fingerprint: 85F9 9FDE 8F20 898F 59BC DF32 BE90 E8E4 F7E5 D682 X-Editor: "GNU Emacs 23.0.50.1" X-Operating-System: "Gentoo x86_64 GNU/Linux" User-Agent: Mutt/1.5.16 (2007-06-09) --jI8keyz6grp/JLjh Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On 2007.10.21 14:45:11 -0700, Bart Schaefer 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 --jI8keyz6grp/JLjh Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.7 (GNU/Linux) iD8DBQFHG9EivpDo5Pfl1oIRCpxwAJ9rePzy/7k2PdpN9EASO4fbgh8RUQCdEk/0 zaVG8jNk4cMMhc/4YHB5a0k= =XL0h -----END PGP SIGNATURE----- --jI8keyz6grp/JLjh--