From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 526 invoked from network); 11 Feb 2002 08:08:35 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 11 Feb 2002 08:08:35 -0000 Received: (qmail 11825 invoked by alias); 11 Feb 2002 08:08:28 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 16597 Received: (qmail 11814 invoked from network); 11 Feb 2002 08:08:27 -0000 Date: Mon, 11 Feb 2002 03:08:23 -0500 From: Clint Adams To: zsh-workers@sunsite.dk Subject: correction hook Message-ID: <20020211080823.GA9961@dman.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.27i Someone complained to me that when he mistyped "make" as "mak", zsh would spell-correct it to "mawk" instead of "make". I had asked him for a proposed algorithm to solve this, but he had none. The thought then occurred to me that a hook function might be a bit more flexible. With the following patch, one can now do something like correctword() { [[ "$1" == mak ]] && CORRECT_GUESS=make } or potentially something more sophisticated that couldn't be accomplished as effectively as by alias mak=make. I'll refrain from committing the patch. Does anyone have a better way of solving this problem? Index: Src/utils.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/utils.c,v retrieving revision 1.39 diff -u -r1.39 utils.c --- Src/utils.c 6 Jan 2002 01:07:23 -0000 1.39 +++ Src/utils.c 11 Feb 2002 07:54:28 -0000 @@ -1536,6 +1536,7 @@ char ic = '\0'; int ne; int preflen = 0; + Eprog prog; if ((histdone & HISTFLAG_NOEXEC) || **s == '-' || **s == '%') return; @@ -1632,6 +1633,27 @@ guess = *s; *guess = *best = ztokens[ic - Pound]; } + + if ((prog = getshfunc("correctword")) != &dummy_eprog) { + + char *correct_guess; + int osc = sfcontext; + LinkList args = NULL; + + args = newlinklist(); + addlinknode(args, "correctword"); + addlinknode(args, dupstring(guess)); + addlinknode(args, dupstring(best)); + + sfcontext = SFC_HOOK; + doshfunc("correctword", prog, args, 0, 1); + sfcontext = osc; + + correct_guess = ztrdup(getsparam("CORRECT_GUESS")); + if (correct_guess) + best = correct_guess; + } + if (ask) { if (noquery(0)) { x = 'n';