tweaks: shorten and improve some comments, and reshuffle a few lines
parent
691eb1145c
commit
81bee1f5fd
38
src/search.c
38
src/search.c
|
@ -925,25 +925,19 @@ void do_find_bracket(void)
|
||||||
linestruct *current_save;
|
linestruct *current_save;
|
||||||
size_t current_x_save;
|
size_t current_x_save;
|
||||||
const char *ch;
|
const char *ch;
|
||||||
/* The location in matchbrackets of the bracket at the current
|
/* The location in matchbrackets of the bracket under the cursor. */
|
||||||
* cursor position. */
|
|
||||||
int ch_len;
|
int ch_len;
|
||||||
/* The length of ch in bytes. */
|
/* The length of ch in bytes. */
|
||||||
const char *wanted_ch;
|
const char *wanted_ch;
|
||||||
/* The location in matchbrackets of the bracket complementing
|
/* The location in matchbrackets of the complementing bracket. */
|
||||||
* the bracket at the current cursor position. */
|
|
||||||
int wanted_ch_len;
|
int wanted_ch_len;
|
||||||
/* The length of wanted_ch in bytes. */
|
/* The length of wanted_ch in bytes. */
|
||||||
char bracket_set[MAXCHARLEN * 2 + 1];
|
char bracket_set[MAXCHARLEN * 2 + 1];
|
||||||
/* The pair of characters in ch and wanted_ch. */
|
/* The pair of characters in ch and wanted_ch. */
|
||||||
size_t i;
|
|
||||||
/* Generic loop variable. */
|
|
||||||
size_t matchhalf;
|
size_t matchhalf;
|
||||||
/* The number of single-byte characters in one half of
|
/* The number of bytes in the first half of matchbrackets. */
|
||||||
* matchbrackets. */
|
|
||||||
size_t mbmatchhalf;
|
size_t mbmatchhalf;
|
||||||
/* The number of multibyte characters in one half of
|
/* Half the number of characters in matchbrackets. */
|
||||||
* matchbrackets. */
|
|
||||||
size_t count = 1;
|
size_t count = 1;
|
||||||
/* The initial bracket count. */
|
/* The initial bracket count. */
|
||||||
bool reverse;
|
bool reverse;
|
||||||
|
@ -951,44 +945,40 @@ void do_find_bracket(void)
|
||||||
|
|
||||||
assert(mbstrlen(matchbrackets) % 2 == 0);
|
assert(mbstrlen(matchbrackets) % 2 == 0);
|
||||||
|
|
||||||
ch = openfile->current->data + openfile->current_x;
|
ch = mbstrchr(matchbrackets, openfile->current->data + openfile->current_x);
|
||||||
|
|
||||||
if ((ch = mbstrchr(matchbrackets, ch)) == NULL) {
|
if (ch == NULL) {
|
||||||
statusbar(_("Not a bracket"));
|
statusbar(_("Not a bracket"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save where we are. */
|
/* Remember the current position in case we don't find a complement. */
|
||||||
current_save = openfile->current;
|
current_save = openfile->current;
|
||||||
current_x_save = openfile->current_x;
|
current_x_save = openfile->current_x;
|
||||||
|
|
||||||
/* 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;
|
matchhalf = 0;
|
||||||
mbmatchhalf = mbstrlen(matchbrackets) / 2;
|
mbmatchhalf = mbstrlen(matchbrackets) / 2;
|
||||||
|
|
||||||
for (i = 0; i < mbmatchhalf; i++)
|
/* Find the halfway point in matchbrackets, where the closing ones start. */
|
||||||
|
for (size_t i = 0; i < mbmatchhalf; i++)
|
||||||
matchhalf += parse_mbchar(matchbrackets + matchhalf, NULL, NULL);
|
matchhalf += parse_mbchar(matchbrackets + matchhalf, NULL, NULL);
|
||||||
|
|
||||||
|
/* When on a closing bracket, we have to search backwards for a matching
|
||||||
|
* opening bracket; otherwise, forward for a matching closing bracket. */
|
||||||
reverse = ((ch - matchbrackets) >= matchhalf);
|
reverse = ((ch - matchbrackets) >= matchhalf);
|
||||||
|
|
||||||
/* If we're on an opening bracket, set wanted_ch to the character
|
/* 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
|
* that's mbmatchhalf characters after ch. If we're on a closing
|
||||||
* bracket, set wanted_ch to the character that's matchhalf
|
* bracket, set wanted_ch to the character that's mbmatchhalf
|
||||||
* characters before ch. */
|
* characters before ch. */
|
||||||
wanted_ch = ch;
|
wanted_ch = ch;
|
||||||
|
|
||||||
while (mbmatchhalf > 0) {
|
while (mbmatchhalf-- > 0) {
|
||||||
if (reverse)
|
if (reverse)
|
||||||
wanted_ch = matchbrackets + move_mbleft(matchbrackets,
|
wanted_ch = matchbrackets + move_mbleft(matchbrackets,
|
||||||
wanted_ch - matchbrackets);
|
wanted_ch - matchbrackets);
|
||||||
else
|
else
|
||||||
wanted_ch += move_mbright(wanted_ch, 0);
|
wanted_ch += move_mbright(wanted_ch, 0);
|
||||||
|
|
||||||
mbmatchhalf--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ch_len = parse_mbchar(ch, NULL, NULL);
|
ch_len = parse_mbchar(ch, NULL, NULL);
|
||||||
|
|
Loading…
Reference in New Issue