From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: zsh-workers-request@euclid.skiles.gatech.edu Received: from euclid.skiles.gatech.edu (list@euclid.skiles.gatech.edu [130.207.146.50]) by coral.primenet.com.au (8.7.6/8.7.3) with ESMTP id XAA04910 for ; Tue, 19 Nov 1996 23:13:38 +1100 (EST) Received: (from list@localhost) by euclid.skiles.gatech.edu (8.7.3/8.7.3) id GAA26434; Tue, 19 Nov 1996 06:51:17 -0500 (EST) Resent-Date: Tue, 19 Nov 1996 06:51:17 -0500 (EST) From: "Bart Schaefer" Message-Id: <961119035517.ZM2419@candle.brasslantern.com> Date: Tue, 19 Nov 1996 03:55:17 -0800 Reply-To: schaefer@nbn.com X-Mailer: Z-Mail (4.0b.820 20aug96) To: zsh-workers@math.gatech.edu Subject: Improvement (?) to spell-word and correct/correctall Cc: Matthew Braun MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Resent-Message-ID: <"ceJmM2.0.yS6.ryPao"@euclid> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/2429 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu The following simple patch to spname() causes spell-word and correction prompts to fix up as much of a path as possible. spname() was already computing the best-guess corrections for every element of the path prefix, but then would give up on the entire path as soon as it encountered any single element that was "too far off" to be corrected. All this patch does is record the intermediate results and, if any reasonable match has been found so far, return the corrected prefix with the still-incorrect suffix. This may actually be wrong in some cases, e.g. two very similar prefixes exist, one of which "contains" the suffix and the other does not; without this patch, correction simply fails in that case. Ideally, any time two or more close matches are found on the prefix, each of those would be compared against the suffix, and the overall best chosen; but that needs a much more significant rewrite of spname() and mindist(). If you're willing to ignore that particular glitch, this patch enables zsh to perform tcsh-style autocorrections via something like: bindkey ^X^I expand-or-complete bindkey -s \\t \\es^X^I (that is, rebind tab to first attempt spelling and then perform completion). Unfortunately, this still doesn't work with expand-or-complete-prefix or completeinword, because spell-word always moves the cursor to the end of the word. I think I have a fix for that, too, but right now it's bedtime. *** Src/utils.c.1 Wed Nov 13 08:36:13 1996 --- Src/utils.c Tue Nov 19 03:20:50 1996 *************** *** 2583,2588 **** --- 2583,2589 ---- char *p, spnameguess[PATH_MAX + 1], spnamebest[PATH_MAX + 1]; static char newname[PATH_MAX + 1]; char *new = newname, *old; + int bestdist = 200, thisdist; old = oldname; for (;;) { *************** *** 2596,2603 **** if (p < spnameguess + PATH_MAX) *p++ = *old; *p = '\0'; ! if (mindist(newname, spnameguess, spnamebest) >= 3) ! return NULL; for (p = spnamebest; (*new = *p++);) new++; } --- 2597,2611 ---- if (p < spnameguess + PATH_MAX) *p++ = *old; *p = '\0'; ! if ((thisdist = mindist(newname, spnameguess, spnamebest)) >= 3) { ! if (bestdist < 3) { ! strcpy(new, spnameguess); ! strcat(new, old); ! return newname; ! } else ! return NULL; ! } else ! bestdist = thisdist; for (p = spnamebest; (*new = *p++);) new++; } -- Bart Schaefer Brass Lantern Enterprises http://www.well.com/user/barts http://www.nbn.com/people/lantern