From: David Lawrence Ramsey Date: Fri, 6 Jan 2006 21:51:10 +0000 (+0000) Subject: allow specifying matching bracket characters other than the default via X-Git-Tag: v1.3.11~67 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=d89617fb1712b281802d0a8c9d7d978c47363a11;p=nano.git allow specifying matching bracket characters other than the default via the "matchbrackets" rcfile option git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3259 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index f9e48836..083e1ec8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -8,10 +8,12 @@ CVS code - ASCII. Changes to main(), nano.1, nanorc.5, and nanorc.sample. (DLR) - Rework the bracket searching code to handle multibyte bracket - characters. New functions mbstrpbrk() and mbrevstrpbrk(); - changes to find_statusbar_bracket_match(), - do_statusbar_find_bracket(), find_bracket_match(), and - do_find_bracket(). (DLR) + characters, and allow specifying matching bracket characters + other than the default via the "matchbrackets" rcfile option. + New functions mbstrpbrk() and mbrevstrpbrk(); changes to + find_statusbar_bracket_match(), do_statusbar_find_bracket(), + find_bracket_match(), do_find_bracket(), main(), + nanorc.5, and nanorc.sample. (DLR) - chars.c: mbstrchr() - Make parameter c const. (DLR) diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 6cc11e67..7cbbef40 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -6,7 +6,7 @@ .\" Public License for copying conditions. There is NO warranty. .\" .\" $Id$ -.TH NANORC 5 "version 1.3.10" "January 02, 2006" +.TH NANORC 5 "version 1.3.10" "January 06, 2006" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -77,6 +77,11 @@ default value is -8. Enable \fI~/.nano_history\fP for saving and reading search/replace 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". +.TP .B set/unset morespace Allow use of the blank line below the titlebar as extra editing space. .TP diff --git a/doc/nanorc.sample b/doc/nanorc.sample index 623e34bd..f3e0623e 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -45,6 +45,12 @@ ## Enable ~/.nano_history for saving and reading search/replace strings. # 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. +## +# set matchbrackets "(<[{)>]}" + ## Use the blank line below the titlebar as extra editing space. # set morespace @@ -331,7 +337,7 @@ ## highlight possible errors and parameters # icolor brightwhite "^[[:space:]]*(set|unset|syntax|i?color).*$" ## set, unset and syntax -# icolor cyan "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|brackets|casesensitive|const|cut|fill|historylog|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct|quickblank)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>" +# icolor cyan "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|brackets|casesensitive|const|cut|fill|historylog|matchbrackets|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct|quickblank)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>" # icolor green "^[[:space:]]*(set|unset|syntax)\>" ## colors # icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" diff --git a/src/global.c b/src/global.c index 384a0a3d..43f4bb6a 100644 --- a/src/global.c +++ b/src/global.c @@ -3,7 +3,7 @@ * global.c * * * * Copyright (C) 1999-2004 Chris Allegretta * - * Copyright (C) 2005 David Lawrence Ramsey * + * Copyright (C) 2005-2006 David Lawrence Ramsey * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2, or (at your option) * @@ -65,6 +65,12 @@ partition *filepart = NULL; openfilestruct *openfile = NULL; /* The list of all open file buffers. */ +#ifndef NANO_TINY +char *matchbrackets = NULL; + /* The opening and closing brackets that can be found by bracket + * searches. */ +#endif + #if !defined(NANO_TINY) && defined(ENABLE_NANORC) char *whitespace = NULL; /* The characters used when displaying the first characters of diff --git a/src/nano.c b/src/nano.c index a4f486a7..408a7dc0 100644 --- a/src/nano.c +++ b/src/nano.c @@ -3,7 +3,7 @@ * nano.c * * * * Copyright (C) 1999-2004 Chris Allegretta * - * Copyright (C) 2005 David Lawrence Ramsey * + * Copyright (C) 2005-2006 David Lawrence Ramsey * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2, or (at your option) * @@ -1955,12 +1955,15 @@ int main(int argc, char **argv) #endif #ifndef DISABLE_JUSTIFY + /* If punct wasn't specified, set its default value. */ if (punct == NULL) punct = mallocstrcpy(NULL, "!.?"); + /* If brackets wasn't specified, set its default value. */ if (brackets == NULL) brackets = mallocstrcpy(NULL, "\"')>]}"); + /* If quotestr wasn't specified, set its default value. */ if (quotestr == NULL) quotestr = mallocstrcpy(NULL, #ifdef HAVE_REGEX_H @@ -2000,6 +2003,12 @@ int main(int argc, char **argv) } #endif +#ifndef NANO_TINY + /* If matchbrackets wasn't specified, set its default value. */ + if (matchbrackets == NULL) + matchbrackets = mallocstrcpy(NULL, "(<[{)>]}"); +#endif + #if !defined(NANO_TINY) && defined(ENABLE_NANORC) /* If whitespace wasn't specified, set its default value. */ if (whitespace == NULL) { diff --git a/src/prompt.c b/src/prompt.c index cfb1d2a1..820800ab 100644 --- a/src/prompt.c +++ b/src/prompt.c @@ -711,22 +711,20 @@ bool find_statusbar_bracket_match(bool reverse, const char void do_statusbar_find_bracket(void) { size_t statusbar_x_save, pww_save; - const char *bracket_list = "(<[{)>]}"; - /* The list of brackets we can find matches to. */ const char *ch; - /* The location in bracket_list of the bracket at the current + /* 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 bracket_list of the bracket complementing the - * bracket at the current cursor position. */ + /* 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 bracket_halflist; - /* The number of characters in one half of bracket_list. */ + size_t matchhalf; + /* The number of characters in one half of matchbrackets. */ size_t count = 1; /* The initial bracket count. */ bool reverse; @@ -734,11 +732,11 @@ void do_statusbar_find_bracket(void) char *found_ch; /* The character we find. */ - assert(mbstrlen(bracket_list) % 2 == 0); + assert(mbstrlen(matchbrackets) % 2 == 0); ch = answer + statusbar_x; - if (ch == '\0' || (ch = mbstrchr(bracket_list, ch)) == NULL) + if (ch == '\0' || (ch = mbstrchr(matchbrackets, ch)) == NULL) return; /* Save where we are. */ @@ -746,27 +744,27 @@ void do_statusbar_find_bracket(void) pww_save = statusbar_pww; /* If we're on an opening bracket, which must be in the first half - * of bracket_list, we want to search forwards for a closing + * 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 bracket_list, we want to search backwards for an + * second half of matchbrackets, we want to search backwards for an * opening bracket. */ - bracket_halflist = mbstrlen(bracket_list) / 2; - reverse = ((ch - bracket_list) > bracket_halflist); + matchhalf = mbstrlen(matchbrackets) / 2; + reverse = ((ch - matchbrackets) > matchhalf); /* If we're on an opening bracket, set wanted_ch to the character - * that's bracket_halflist characters after ch. If we're on a - * closing bracket, set wanted_ch to the character that's - * bracket_halflist characters before ch. */ + * 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 (bracket_halflist > 0) { + while (matchhalf > 0) { if (reverse) - wanted_ch = bracket_list + move_mbleft(bracket_list, - wanted_ch - bracket_list); + wanted_ch = matchbrackets + move_mbleft(matchbrackets, + wanted_ch - matchbrackets); else wanted_ch += move_mbright(wanted_ch, 0); - bracket_halflist--; + matchhalf--; } ch_len = parse_mbchar(ch, NULL, NULL); diff --git a/src/proto.h b/src/proto.h index 29f76b2e..f93d56f2 100644 --- a/src/proto.h +++ b/src/proto.h @@ -48,6 +48,10 @@ extern filestruct *jusbuffer; extern partition *filepart; extern openfilestruct *openfile; +#ifndef NANO_TINY +extern char *matchbrackets; +#endif + #if !defined(NANO_TINY) && defined(ENABLE_NANORC) extern char *whitespace; extern int whitespace_len[2]; diff --git a/src/rcfile.c b/src/rcfile.c index fd58867a..7d56909b 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -3,7 +3,7 @@ * rcfile.c * * * * Copyright (C) 2001-2004 Chris Allegretta * - * Copyright (C) 2005 David Lawrence Ramsey * + * Copyright (C) 2005-2006 David Lawrence Ramsey * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2, or (at your option) * @@ -81,6 +81,7 @@ const static rcoption rcopts[] = { {"casesensitive", CASE_SENSITIVE}, {"cut", CUT_TO_END}, {"historylog", HISTORYLOG}, + {"matchbrackets", 0}, {"noconvert", NO_CONVERT}, {"quickblank", QUICK_BLANK}, {"smarthome", SMART_HOME}, @@ -144,13 +145,10 @@ char *parse_next_word(char *ptr) return ptr; } -/* The keywords operatingdir, backupdir, fill, tabsize, speller, punct, - * brackets, quotestr, and whitespace take an argument when set. Among - * these, operatingdir, backupdir, speller, punct, brackets, quotestr, - * and whitespace have to allow tabs and spaces in the argument. Thus, - * if the next word starts with a ", we say it ends with the last " of - * the line. Otherwise, the word is interpreted as usual. That is so - * the arguments can contain "s too. */ +/* Parse an argument, with optional quotes, after a keyword that takes + * one. If the next word starts with a ", we say that it ends with the + * last " of the line. Otherwise, we interpret it as usual, so that the + * arguments can contain "'s too. */ char *parse_argument(char *ptr) { const char *ptr_bak = ptr; diff --git a/src/search.c b/src/search.c index b80a4e89..4a4f46fc 100644 --- a/src/search.c +++ b/src/search.c @@ -1130,22 +1130,20 @@ void do_find_bracket(void) { filestruct *current_save; size_t current_x_save, pww_save; - const char *bracket_list = "(<[{)>]}"; - /* The list of brackets we can find matches to. */ const char *ch; - /* The location in bracket_list of the bracket at the current + /* 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 bracket_list of the bracket complementing the - * bracket at the current cursor position. */ + /* 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 bracket_halflist; - /* The number of characters in one half of bracket_list. */ + size_t matchhalf; + /* The number of characters in one half of matchbrackets. */ size_t count = 1; /* The initial bracket count. */ bool reverse; @@ -1153,11 +1151,11 @@ void do_find_bracket(void) char *found_ch; /* The character we find. */ - assert(mbstrlen(bracket_list) % 2 == 0); + assert(mbstrlen(matchbrackets) % 2 == 0); ch = openfile->current->data + openfile->current_x; - if (ch == '\0' || (ch = mbstrchr(bracket_list, ch)) == NULL) { + if (ch == '\0' || (ch = mbstrchr(matchbrackets, ch)) == NULL) { statusbar(_("Not a bracket")); return; } @@ -1168,27 +1166,27 @@ void do_find_bracket(void) pww_save = openfile->placewewant; /* If we're on an opening bracket, which must be in the first half - * of bracket_list, we want to search forwards for a closing + * 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 bracket_list, we want to search backwards for an + * second half of matchbrackets, we want to search backwards for an * opening bracket. */ - bracket_halflist = mbstrlen(bracket_list) / 2; - reverse = ((ch - bracket_list) > bracket_halflist); + matchhalf = mbstrlen(matchbrackets) / 2; + reverse = ((ch - matchbrackets) > matchhalf); /* If we're on an opening bracket, set wanted_ch to the character - * that's bracket_halflist characters after ch. If we're on a - * closing bracket, set wanted_ch to the character that's - * bracket_halflist characters before ch. */ + * 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 (bracket_halflist > 0) { + while (matchhalf > 0) { if (reverse) - wanted_ch = bracket_list + move_mbleft(bracket_list, - wanted_ch - bracket_list); + wanted_ch = matchbrackets + move_mbleft(matchbrackets, + wanted_ch - matchbrackets); else wanted_ch += move_mbright(wanted_ch, 0); - bracket_halflist--; + matchhalf--; } ch_len = parse_mbchar(ch, NULL, NULL);