zsh-workers
 help / color / mirror / code / Atom feed
* Improvement (?) to spell-word and correct/correctall
@ 1996-11-19 11:55 Bart Schaefer
  0 siblings, 0 replies; only message in thread
From: Bart Schaefer @ 1996-11-19 11:55 UTC (permalink / raw)
  To: zsh-workers; +Cc: Matthew Braun

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-11-19 12:13 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-19 11:55 Improvement (?) to spell-word and correct/correctall Bart Schaefer

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).