[net.sources.bugs] Word wrap fix for MicroEMACS

willcox@ccvaxa.UUCP (01/05/86)

The "wordwrap" routine in file word.c in the distribution of MicroEMACS
is broken.  In particular, it breaks if the last word you typed had only
one character.  Also, it used NULL, where FALSE was correct.  The following
works much better.

----------------- wrapword(n), from word.c ------------------
wrapword(n)
int n;
{
	register int cnt;
	register LINE *oldp;
	int onech;
        oldp = curwp->w_dotp;
        cnt = -1;
        do {                            
                cnt++;
                if (! backchar(FALSE, 1))
                        return(FALSE);
        } while (! inword());

	if (! backchar (FALSE, 1)) 	/* back over last char of word */
		return (FALSE);

	onech = !inword();		/* remember if one-char word */
	if (! forwchar (FALSE, 1))	/* return to end of word */
		return (FALSE);

	if (!onech) {			/* multi-letter word, back over
					   whole thing */
		if (! backword (FALSE, 1))
			return (FALSE);
	}

        if ((oldp == curwp->w_dotp) && curwp->w_doto) {
                if (! backdel(FALSE, 1))
                        return(FALSE);
                if (! newline(FALSE, 1))
                        return(FALSE);
        }
        return(forwword(FALSE, 1) && forwchar(FALSE, cnt)));
}
--------------------------- END --------------------------
David A. Willcox
Gould CSD-Urbana
1101 E. University Ave.
Urbana, IL 61801
217-384-8500
{decvax!pur-ee,ihnp4}!uiucdcs!ccvaxa!willcox

willcox@ccvaxa.UUCP (01/06/86)

Rats!  Two problems I've found with this since posting it:

   1) Somehow, in editing the posting, I added an extra parenthesis in
      the second-to-last line.

   2) While this works much better than the original, it still breaks
      the last word on the line is delimited by other than a space.
      If you type, for example "(stuff<space>" beyond the foll column,
      the parethesis will be deleted.  I haven't fixed this, yet.