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)
.\" 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
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
## 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
## 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))?\>"
* 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) *
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
* 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) *
#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
}
#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) {
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;
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. */
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);
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];
* 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) *
{"casesensitive", CASE_SENSITIVE},
{"cut", CUT_TO_END},
{"historylog", HISTORYLOG},
+ {"matchbrackets", 0},
{"noconvert", NO_CONVERT},
{"quickblank", QUICK_BLANK},
{"smarthome", SMART_HOME},
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;
{
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;
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;
}
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);