- 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
|
||||
- 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).
|
||||
|
|
40
nano.c
40
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);
|
||||
|
||||
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) {
|
||||
j = i;
|
||||
do_replace_loop(prevanswer, fileage, &beginx_top, TRUE, &j);
|
||||
do_replace_highlight(FALSE, prevanswer);
|
||||
|
||||
/* 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 */
|
||||
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_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);
|
||||
|
|
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 */
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Reference in New Issue