diff --git a/nano.c b/nano.c index 8715d76b..bb2e0f11 100644 --- a/nano.c +++ b/nano.c @@ -1297,27 +1297,36 @@ int do_int_spell_fix(char *word) edit_update(fileage, TOP); - /* make sure word is still mis-spelt (i.e. when multi-errors) */ - if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL) - { - do_replace_highlight(TRUE, prevanswer); + while (1) { - /* allow replace word to be corrected */ - i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace, + /* make sure word is still mis-spelt (i.e. when multi-errors) */ + if (findnextstr(TRUE, fileage, beginx_top, prevanswer) != NULL) { + + /* find wholewords only */ + if (!is_whole_word(current_x, current, prevanswer)) + continue; + + do_replace_highlight(TRUE, prevanswer); + + /* allow replace word to be corrected */ + i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace, _("Edit a replacement")); - do_replace_highlight(FALSE, prevanswer); + do_replace_highlight(FALSE, prevanswer); - /* start from the start of this line again */ - current = fileage; - current_x = beginx_top; + /* start from the start of this line again */ + current = fileage; + current_x = beginx_top; - search_last_line = FALSE; + search_last_line = FALSE; - if (strcmp(prevanswer,answer) != 0) { - j = i; - do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j); + if (strcmp(prevanswer,answer) != 0) { + j = i; + do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j); + } } + + break; } /* restore the search/replace strings */ diff --git a/proto.h b/proto.h index 2dc44312..24e749d2 100644 --- a/proto.h +++ b/proto.h @@ -83,6 +83,7 @@ int renumber_all(void); int open_file(char *filename, int insert, int quiet); int do_writeout(char *path, int exiting); int do_gotoline(long defline); +int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword); int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, int wholewords, int *i); /* Now in move.c */ diff --git a/search.c b/search.c index 3e6a18c6..e86a9d47 100644 --- a/search.c +++ b/search.c @@ -212,6 +212,20 @@ void not_found_msg(char *str) } } +int is_whole_word(int curr_pos, filestruct *fileptr, char *searchword) +{ + /* start of line or previous character not a letter */ + if ((curr_pos < 1) || (!isalpha((int) fileptr->data[curr_pos-1]))) + + /* end of line or next character not a letter */ + if (((curr_pos + strlen(searchword)) == strlen(fileptr->data)) + || (!isalpha((int) fileptr->data[curr_pos + strlen(searchword)]))) + + return TRUE; + + return FALSE; +} + filestruct *findnextstr(int quiet, filestruct * begin, int beginx, char *needle) { @@ -523,21 +537,8 @@ int do_replace_loop(char *prevanswer, filestruct *begin, int *beginx, break; /* Make sure only whole words are found */ - if (wholewords) - { - /* start of line or previous character not a letter */ - if ((current_x == 0) || (!isalpha((int) fileptr->data[current_x-1]))) - { - /* end of line or next character not a letter */ - if (((current_x + strlen(prevanswer)) == strlen(fileptr->data)) - || (!isalpha((int) fileptr->data[current_x + strlen(prevanswer)]))) - ; - else - continue; - } - else - continue; - } + if ((wholewords) && (!is_whole_word(current_x, fileptr, prevanswer))) + continue; /* If we're here, we've found the search string */ if (!replaceall) {