refactor the statusbar prompt's bracket searching code to be closer to

the edit window's bracket searching code


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3194 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-11-16 13:45:41 +00:00
parent 45d344b72c
commit 5ab56eaa8d
3 changed files with 43 additions and 23 deletions

View File

@ -106,8 +106,9 @@ CVS code -
and find_bracket_match(); changes to shortcut_init() and
do_find_bracket(). (DLR)
- Add the ability to do bracket searches at the statusbar
prompt. New function do_statusbar_find_bracket(); changes to
do_statusbar_input(). (DLR)
prompt. New functions find_statusbar_bracket_match() and
do_statusbar_find_bracket(); changes to do_statusbar_input().
(DLR)
- chars.c:
mbwidth()
- If wcwidth() returns -1 for the character passed in, treat the

View File

@ -644,10 +644,46 @@ void do_statusbar_verbatim_input(bool *got_enter)
}
#ifndef NANO_TINY
/* Search for a match to one of the two characters in bracket_set. If
* reverse is TRUE, search backwards. Otherwise, search forwards. */
bool find_statusbar_bracket_match(bool reverse, const char
*bracket_set)
{
const char *rev_start = NULL, *found = NULL;
assert(strlen(bracket_set) == 2);
/* rev_start might end up 1 character before the start or after the
* end of the line. This won't be a problem because we'll skip over
* it below in that case. */
rev_start = reverse ? answer + (statusbar_x - 1) : answer +
(statusbar_x + 1);
while (TRUE) {
/* Look for either of the two characters in bracket_set.
* rev_start can be 1 character before the start or after the
* end of the line. In either case, just act as though no match
* is found. */
found = ((rev_start > answer && *(rev_start - 1) == '\0') ||
rev_start < answer) ? NULL : (reverse ?
revstrpbrk(answer, bracket_set, rev_start) :
strpbrk(rev_start, bracket_set));
/* We've found a potential match. */
if (found != NULL)
break;
}
/* We've definitely found something. */
statusbar_x = found - answer;
statusbar_pww = statusbar_xplustabs();
return TRUE;
}
void do_statusbar_find_bracket(void)
{
size_t statusbar_x_save, pww_save;
const char *rev_start = NULL, *found = NULL;
const char *bracket_list = "()<>[]{}";
/* The list of brackets we can find matches to. */
const char *pos;
@ -686,26 +722,7 @@ void do_statusbar_find_bracket(void)
bracket_set[2] = '\0';
while (TRUE) {
/* rev_start might end up 1 character before the start or after
* the end of the line. This won't be a problem because we'll
* skip over it below in that case. */
rev_start = reverse ? answer + (statusbar_x - 1) : answer +
(statusbar_x + 1);
/* Look for either of the two characters in bracket_set.
* rev_start can be 1 character before the start or after the
* end of the line. In either case, just act as though no match
* is found. */
found = ((rev_start > answer && *(rev_start - 1) == '\0') ||
rev_start < answer) ? NULL : (reverse ?
revstrpbrk(answer, bracket_set, rev_start) :
strpbrk(rev_start, bracket_set));
if (found != NULL) {
/* We've definitely found something. */
statusbar_x = found - answer;
statusbar_pww = statusbar_xplustabs();
if (find_statusbar_bracket_match(reverse, bracket_set)) {
/* If we found an identical bracket, increment count. If we
* found a complementary bracket, decrement it. */
count += (answer[statusbar_x] == ch) ? 1 : -1;

View File

@ -446,6 +446,8 @@ bool do_statusbar_prev_word(bool allow_punct);
#endif
void do_statusbar_verbatim_input(bool *got_enter);
#ifndef NANO_TINY
bool find_statusbar_bracket_match(bool reverse, const char
*bracket_set);
void do_statusbar_find_bracket(void);
#endif
size_t statusbar_xplustabs(void);