diff -u -r nano/nano.c nano-spel/nano.c --- nano/nano.c Wed Aug 7 13:33:47 2002 +++ nano-spel/nano.c Sat Aug 10 13:46:11 2002 @@ -790,13 +790,15 @@ int wrap_loc = -1; /* index of inptr->data where we wrap */ int word_back = -1; #ifndef NANO_SMALL - char *indentation = NULL; /* indentation to prepend to the new line */ + const char *indentation = NULL; + /* indentation to prepend to the new line */ int indent_len = 0; /* strlen(indentation) */ #endif - char *after_break; /* text after the wrap point */ + const char *after_break; /* text after the wrap point */ int after_break_len; /* strlen(after_break) */ int wrapping = 0; /* do we prepend to the next line? */ - char *wrap_line = NULL; /* the next line, minus indentation */ + const char *wrap_line = NULL; + /* the next line, minus indentation */ int wrap_line_len = 0; /* strlen(wrap_line) */ char *newline = NULL; /* the line we create */ int new_line_len = 0; /* eventual length of newline */ @@ -804,10 +806,6 @@ /* There are three steps. First, we decide where to wrap. Then, we * create the new wrap line. Finally, we clean up. */ - /* Is it necessary to do anything? */ - if (strlenpt(inptr->data) <= fill) - return 0; - /* Step 1, finding where to wrap. We are going to replace a white-space * character with a new-line. In this step, we set wrap_loc as the * location of this replacement. @@ -825,32 +823,28 @@ * Note that the initial indentation does not count as a legal wrap * point if we are going to auto-indent! * - * Note that the code below could be optimised, by not calling strlenpt - * so often, and by not calling isspace(inptr->data[i+1]) and then in - * the next loop calling isspace(inptr->data[i]). Oh well, fixing the - * first point would entail expanding the definition of strnlenpt, which - * I won't do since it will probably change soon. Fixing the second - * point would entail nested loops. */ + * Note that the code below could be optimised, by not calling strnlenpt() + * so often. */ #ifndef NANO_SMALL if (ISSET(AUTOINDENT)) i = indent_length(inptr->data); #endif - for(; i < len; i++) { + wrap_line = inptr->data + i; + for(; i < len; i++, wrap_line++) { /* record where the last word ended */ - if (!isspace((int)inptr->data[i])) + if (*wrap_line != ' ' && *wrap_line != '\t') word_back = i; /* if we have found a "legal wrap point" and the current word * extends too far, then we stop */ - if (wrap_loc != -1 && strnlenpt(inptr->data,word_back) > fill) + if (wrap_loc != -1 && strnlenpt(inptr->data, word_back + 1) > fill) break; /* we record the latest "legal wrap point" */ - if (i != (current_x - 1) && isspace((int)inptr->data[i]) && - (i == (len - 1) || !isspace((int)inptr->data[i + 1]))) { + if (i != current_x - 1 && word_back != i && + wrap_line[1] != ' ' && wrap_line[1] != '\t') wrap_loc = i; - } } - if (wrap_loc < 0 || wrap_loc == len - 1 || i == len) + if (wrap_loc < 0 || i == len) return 0; /* Step 2, making the new wrap line. It will consist of indentation + @@ -906,7 +900,6 @@ } #endif strcat(newline, after_break); - after_break = NULL; /* We end the old line at wrap_loc. Note this eats the space. */ null_at(&inptr->data, wrap_loc); if (wrapping) { @@ -1354,17 +1347,22 @@ { int alt_spell_status, lineno_cur = current->lineno; int x_cur = current_x, y_cur = current_y, pww_cur = placewewant; -#ifndef NANO_SMALL - int mark_set; -#endif pid_t pid_spell; char *ptr; static int arglen = 3; static char **spellargs = (char **) NULL; - #ifndef NANO_SMALL - mark_set = ISSET(MARK_ISSET); - UNSET(MARK_ISSET); + int mark_set = ISSET(MARK_ISSET); + int mbb_lineno_cur = 0; + /* We're going to close the current file, and open the output of + the alternate spell command. The line that mark_beginbuf + points to will be freed, so we save the line number and restore + afterwards. */ + + if (mark_set) { + mbb_lineno_cur = mark_beginbuf->lineno; + UNSET(MARK_ISSET); + } #endif endwin(); @@ -1408,8 +1406,13 @@ open_file(file_name, 0, 1); #ifndef NANO_SMALL - if (mark_set) + if (mark_set) { + do_gotopos(mbb_lineno_cur, mark_beginx, y_cur, 0); + mark_beginbuf = current; + mark_beginx = current_x; + /* In case the line got shorter, assign mark_beginx. */ SET(MARK_ISSET); + } #endif /* go back to the old position, mark the file as modified, and make