commit 1bc0c7e047be162d946e7e6ba4567d1ae2f9f58a
parent bf1a1e84e284d4d088ea26cbe4d58aa49bd14500
Author: Chris Allegretta <chrisa@asty.org>
Date: Tue, 8 Jan 2002 15:00:24 +0000
- Better partial word checking code. New function search.c:is_whole_word(), changes to findnextstr(), and nano.c:do_int_spell_fix() (Rocco Corsi)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@989 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
Diffstat:
4 files changed, 45 insertions(+), 30 deletions(-)
diff --git a/ChangeLog b/ChangeLog
@@ -2,6 +2,9 @@ CVS code -
- General
- Add Meta-A as alternate keyystroke for ^^ for people with
non-US keyboards.
+ - Better partial word checking code. New function
+ search.c:is_whole_word(), changes to findnextstr(),
+ and nano.c:do_int_spell_fix() (Rocco Corsi).
- nano.c:
usage()
- Remove extra \n in --keypad description (Jordi).
diff --git a/nano.c b/nano.c
@@ -1471,27 +1471,37 @@ 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, FALSE, 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,
- _("Edit a replacement"));
+ /* make sure word is still mis-spelt (i.e. when multi-errors) */
+ if (findnextstr(TRUE, FALSE, fileage, beginx_top, prevanswer) != NULL) {
- do_replace_highlight(FALSE, prevanswer);
+ /* find wholewords only */
+ if (!is_whole_word(current_x, current, prevanswer))
+ continue;
- /* start from the start of this line again */
- current = fileage;
- current_x = beginx_top;
+ 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);
- search_last_line = FALSE;
+ /* start from the start of this line again */
+ current = fileage;
+ current_x = beginx_top;
- if (strcmp(prevanswer,answer) != 0) {
- j = i;
- do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j);
+ search_last_line = FALSE;
+
+ if (strcmp(prevanswer,answer) != 0) {
+ j = i;
+ do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j);
+ }
}
- }
+
+ break;
+ }
/* restore the search/replace strings */
last_search = mallocstrcpy(last_search, save_search);
diff --git a/proto.h b/proto.h
@@ -114,6 +114,7 @@ int check_operating_dir(char *currpath, int allow_tabcomp);
int do_writeout(char *path, int exiting, int append);
int do_gotoline(int line, int save_pos);
+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);
int do_find_bracket(void);
diff --git a/search.c b/search.c
@@ -226,6 +226,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;
+}
+
int past_editbuff; /* search is now looking through lines not displayed */
filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx,
@@ -611,21 +625,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) {