zsh-workers
 help / color / mirror / code / Atom feed
From: Clint Adams <clint@zsh.org>
To: zsh-workers@sunsite.dk
Subject: correction hook
Date: Mon, 11 Feb 2002 03:08:23 -0500	[thread overview]
Message-ID: <20020211080823.GA9961@dman.com> (raw)

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';


             reply	other threads:[~2002-02-11  8:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-11  8:08 Clint Adams [this message]
2002-02-11 13:04 ` Oliver Kiddle
2002-02-11 16:38   ` Clint Adams
2002-02-11 19:14     ` Bart Schaefer
2002-02-11 13:48 ` Peter Stephenson
2002-02-11 13:55   ` Peter Stephenson
2002-04-07 16:51 Felix Rosencrantz

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=20020211080823.GA9961@dman.com \
    --to=clint@zsh.org \
    --cc=zsh-workers@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).