- 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-d3aeb78583b8master
parent
bf1a1e84e2
commit
1bc0c7e047
|
@ -2,6 +2,9 @@ CVS code -
|
||||||
- General
|
- General
|
||||||
- Add Meta-A as alternate keyystroke for ^^ for people with
|
- Add Meta-A as alternate keyystroke for ^^ for people with
|
||||||
non-US keyboards.
|
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:
|
- nano.c:
|
||||||
usage()
|
usage()
|
||||||
- Remove extra \n in --keypad description (Jordi).
|
- Remove extra \n in --keypad description (Jordi).
|
||||||
|
|
40
nano.c
40
nano.c
|
@ -1471,27 +1471,37 @@ int do_int_spell_fix(char *word)
|
||||||
|
|
||||||
edit_update(fileage, TOP);
|
edit_update(fileage, TOP);
|
||||||
|
|
||||||
/* make sure word is still mis-spelt (i.e. when multi-errors) */
|
while (1) {
|
||||||
if (findnextstr(TRUE, FALSE, fileage, beginx_top, prevanswer) != NULL) {
|
|
||||||
do_replace_highlight(TRUE, prevanswer);
|
|
||||||
|
|
||||||
/* allow replace word to be corrected */
|
/* make sure word is still mis-spelt (i.e. when multi-errors) */
|
||||||
i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace,
|
if (findnextstr(TRUE, FALSE, fileage, beginx_top, prevanswer) != NULL) {
|
||||||
_("Edit a replacement"));
|
|
||||||
|
|
||||||
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 */
|
do_replace_highlight(TRUE, prevanswer);
|
||||||
current = fileage;
|
|
||||||
current_x = beginx_top;
|
|
||||||
|
|
||||||
search_last_line = FALSE;
|
/* allow replace word to be corrected */
|
||||||
|
i = statusq(0, spell_list, SPELL_LIST_LEN, last_replace,
|
||||||
|
_("Edit a replacement"));
|
||||||
|
|
||||||
if (strcmp(prevanswer,answer) != 0) {
|
do_replace_highlight(FALSE, prevanswer);
|
||||||
j = i;
|
|
||||||
do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j);
|
/* start from the start of this line again */
|
||||||
|
current = fileage;
|
||||||
|
current_x = beginx_top;
|
||||||
|
|
||||||
|
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 */
|
/* restore the search/replace strings */
|
||||||
last_search = mallocstrcpy(last_search, save_search);
|
last_search = mallocstrcpy(last_search, save_search);
|
||||||
|
|
1
proto.h
1
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_writeout(char *path, int exiting, int append);
|
||||||
int do_gotoline(int line, int save_pos);
|
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 do_replace_loop(char *prevanswer, filestruct *begin, int *beginx,
|
||||||
int wholewords, int *i);
|
int wholewords, int *i);
|
||||||
int do_find_bracket(void);
|
int do_find_bracket(void);
|
||||||
|
|
31
search.c
31
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 */
|
int past_editbuff; /* search is now looking through lines not displayed */
|
||||||
|
|
||||||
filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx,
|
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;
|
break;
|
||||||
|
|
||||||
/* Make sure only whole words are found */
|
/* Make sure only whole words are found */
|
||||||
if (wholewords)
|
if ((wholewords) && (!is_whole_word(current_x, fileptr, prevanswer)))
|
||||||
{
|
continue;
|
||||||
/* 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 we're here, we've found the search string */
|
/* If we're here, we've found the search string */
|
||||||
if (!replaceall) {
|
if (!replaceall) {
|
||||||
|
|
Loading…
Reference in New Issue