diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 7cbbef4045fab9a25998f08f804d16d996631438..2de05bd97c946ff5a58cefeb8fdfeac8542eeb24 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -79,8 +79,9 @@ strings. .TP .B set matchbrackets "\fIstring\fP" Set the opening and closing brackets that can be found by bracket -searches. The former set must come before the latter set, and both must -be in the same order. The default value is "\fI(<[{)>]}\fP". +searches. They cannot contain blank characters. The former set must +come before the latter set, and both must be in the same order. The +default value is "\fI(<[{)>]}\fP". .TP .B set/unset morespace Allow use of the blank line below the titlebar as extra editing space. diff --git a/doc/nanorc.sample b/doc/nanorc.sample index f3e0623e75f446153edf6f7183f861f8afc3c78e..ecce99c447944c0a8a3a09bc9c8f6603a9e5d2bd 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -46,8 +46,8 @@ # set historylog ## The opening and closing brackets that can be found by bracket -## searches. The former set must come before the latter set, and both -## must be in the same order. +## searches. They cannot contain blank characters. The former set must +## come before the latter set, and both must be in the same order. ## # set matchbrackets "(<[{)>]}" diff --git a/src/prompt.c b/src/prompt.c index 820800ab39bec2b101ab3dae573ec3cd402209d5..18e41fb76904f6f428427ae7b62c2e87bcf724e2 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -723,8 +723,14 @@ void do_statusbar_find_bracket(void) /* 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 characters in one half of matchbrackets. */ + /* 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; @@ -748,7 +754,13 @@ void do_statusbar_find_bracket(void) * 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 = mbstrlen(matchbrackets) / 2; + 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 @@ -757,14 +769,14 @@ void do_statusbar_find_bracket(void) * characters before ch. */ wanted_ch = ch; - while (matchhalf > 0) { + while (mbmatchhalf > 0) { if (reverse) wanted_ch = matchbrackets + move_mbleft(matchbrackets, wanted_ch - matchbrackets); else wanted_ch += move_mbright(wanted_ch, 0); - matchhalf--; + mbmatchhalf--; } ch_len = parse_mbchar(ch, NULL, NULL); diff --git a/src/search.c b/src/search.c index 4a4f46fc4075f06f2f74615c4fcc7d9e25de4c2d..beab606308453dc4ce86b6cd7fa906fbdb29e6e4 100644 --- a/src/search.c +++ b/src/search.c @@ -1142,8 +1142,14 @@ void do_find_bracket(void) /* 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 characters in one half of matchbrackets. */ + /* 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; @@ -1170,7 +1176,13 @@ void do_find_bracket(void) * 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 = mbstrlen(matchbrackets) / 2; + 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 @@ -1179,14 +1191,14 @@ void do_find_bracket(void) * characters before ch. */ wanted_ch = ch; - while (matchhalf > 0) { + while (mbmatchhalf > 0) { if (reverse) wanted_ch = matchbrackets + move_mbleft(matchbrackets, wanted_ch - matchbrackets); else wanted_ch += move_mbright(wanted_ch, 0); - matchhalf--; + mbmatchhalf--; } ch_len = parse_mbchar(ch, NULL, NULL);