Removing the ability to search for a matching bracket in a prompt input line.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5024 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2014-06-27 19:32:12 +00:00
parent 64fd3b8d0e
commit 29dfb68b6e
3 changed files with 4 additions and 166 deletions

View File

@ -8,6 +8,10 @@
* src/rcfile.c (is_universal): New function, returning TRUE for the
functions that are present in most menus but only listed in MMAIN.
* doc/man/nanorc.5, doc/texinfo/nano.texi: Update the docs for this.
* prompt.c (find_statusbar_bracket_match, do_statusbar_find_bracket):
Remove these functions and thus the ability to search for a matching
bracket in a prompt input line. The find_bracket function never had
a default keybinding outside MMAIN, so is unlikely to have been used.
2014-06-25 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (do_browser): Allow 'firstfile' and 'lastfile' to be

View File

@ -178,11 +178,6 @@ int do_statusbar_input(bool *meta_key, bool *func_key, bool *have_shortcut,
do_statusbar_home();
else if (s->scfunc == do_end)
do_statusbar_end();
#ifndef NANO_TINY
else if (s->scfunc == do_find_bracket)
do_statusbar_find_bracket();
#endif
else if (s->scfunc == do_verbatim_input) {
/* If we're using restricted mode, the filename
* isn't blank, and we're at the "Write File"
@ -650,162 +645,6 @@ void do_statusbar_verbatim_input(bool *got_enter)
free(output);
}
#ifndef NANO_TINY
/* Search for a match to one of the two characters in bracket_set. If
* reverse is TRUE, search backwards for the leftmost bracket.
* Otherwise, search forwards for the rightmost bracket. Return TRUE if
* we found a match, and FALSE otherwise. */
bool find_statusbar_bracket_match(bool reverse, const char
*bracket_set)
{
const char *rev_start = NULL, *found = NULL;
assert(mbstrlen(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 ?
mbrevstrpbrk(answer, bracket_set, rev_start) :
mbstrpbrk(rev_start, bracket_set));
/* We've found a potential match. */
if (found != NULL)
break;
/* We've reached the start or end of the statusbar text, so
* get out. */
return FALSE;
}
/* We've definitely found something. */
statusbar_x = found - answer;
statusbar_pww = statusbar_xplustabs();
return TRUE;
}
/* Search for a match to the bracket at the current cursor position, if
* there is one. */
void do_statusbar_find_bracket(void)
{
size_t statusbar_x_save, pww_save;
const char *ch;
/* The location in matchbrackets of the bracket at the current
* cursor position. */
int ch_len;
/* The length of ch in bytes. */
const char *wanted_ch;
/* The location in matchbrackets of the bracket complementing
* the bracket at the current cursor position. */
int wanted_ch_len;
/* The length of wanted_ch in bytes. */
char *bracket_set;
/* The pair of characters in ch and wanted_ch. */
size_t i;
/* Generic loop variable. */
size_t matchhalf;
/* The number of single-byte characters in one half of
* matchbrackets. */
size_t mbmatchhalf;
/* The number of multibyte characters in one half of
* matchbrackets. */
size_t count = 1;
/* The initial bracket count. */
bool reverse;
/* The direction we search. */
char *found_ch;
/* The character we find. */
assert(mbstrlen(matchbrackets) % 2 == 0);
ch = answer + statusbar_x;
if (ch == '\0' || (ch = mbstrchr(matchbrackets, ch)) == NULL)
return;
/* Save where we are. */
statusbar_x_save = statusbar_x;
pww_save = statusbar_pww;
/* If we're on an opening bracket, which must be in the first half
* of matchbrackets, we want to search forwards for a closing
* bracket. If we're on a closing bracket, which must be in the
* second half of matchbrackets, we want to search backwards for an
* opening bracket. */
matchhalf = 0;
mbmatchhalf = mbstrlen(matchbrackets) / 2;
for (i = 0; i < mbmatchhalf; i++)
matchhalf += parse_mbchar(matchbrackets + matchhalf, NULL,
NULL);
reverse = ((ch - matchbrackets) >= matchhalf);
/* If we're on an opening bracket, set wanted_ch to the character
* that's matchhalf characters after ch. If we're on a closing
* bracket, set wanted_ch to the character that's matchhalf
* characters before ch. */
wanted_ch = ch;
while (mbmatchhalf > 0) {
if (reverse)
wanted_ch = matchbrackets + move_mbleft(matchbrackets,
wanted_ch - matchbrackets);
else
wanted_ch += move_mbright(wanted_ch, 0);
mbmatchhalf--;
}
ch_len = parse_mbchar(ch, NULL, NULL);
wanted_ch_len = parse_mbchar(wanted_ch, NULL, NULL);
/* Fill bracket_set in with the values of ch and wanted_ch. */
bracket_set = charalloc((mb_cur_max() * 2) + 1);
strncpy(bracket_set, ch, ch_len);
strncpy(bracket_set + ch_len, wanted_ch, wanted_ch_len);
null_at(&bracket_set, ch_len + wanted_ch_len);
found_ch = charalloc(mb_cur_max() + 1);
while (TRUE) {
if (find_statusbar_bracket_match(reverse, bracket_set)) {
/* If we found an identical bracket, increment count. If we
* found a complementary bracket, decrement it. */
parse_mbchar(answer + statusbar_x, found_ch, NULL);
count += (strncmp(found_ch, ch, ch_len) == 0) ? 1 : -1;
/* If count is zero, we've found a matching bracket. Update
* the statusbar prompt and get out. */
if (count == 0) {
if (need_statusbar_horizontal_update(pww_save))
update_statusbar_line(answer, statusbar_x);
break;
}
} else {
/* We didn't find either an opening or closing bracket.
* Restore where we were, and get out. */
statusbar_x = statusbar_x_save;
statusbar_pww = pww_save;
break;
}
}
/* Clean up. */
free(bracket_set);
free(found_ch);
}
#endif /* !NANO_TINY */
/* Return the placewewant associated with statusbar_x, i.e. the
* zero-based column position of the cursor. The value will be no

View File

@ -514,11 +514,6 @@ bool do_statusbar_next_word(bool allow_punct);
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);
size_t get_statusbar_page_start(size_t start_col, size_t column);
void reset_statusbar_cursor(void);