nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 2abe7c03fe25e3291a0aaeddffcb24df1b09d8c2
parent bf72cdd81451ba9fa70a64c90077e268b669651e
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date:   Sun,  2 Jul 2017 01:46:59 -0500

text: make sure commenting is disabled when comment "" was specified

When the active syntax contains a comment command that specifies the
empty string, this should override the default comment of "#" and
should disable the Meta-3 keystroke.

To achieve this, the comment string is now set by default to "#" for
all syntaxes, so that it will be set when no comment command is given
(including for the "none" syntax), and is unset only by explicitly
specifying «comment ""» in a syntax file.

This fixes https://savannah.gnu.org/bugs/?51355.
Reported-by: David Lawrence Ramsey <pooka109@gmail.com>

Diffstat:
Msrc/nano.h | 3+++
Msrc/rcfile.c | 4++++
Msrc/text.c | 6+++---
3 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/nano.h b/src/nano.h @@ -597,6 +597,9 @@ enum /* The default width of a tab in spaces. */ #define WIDTH_OF_TAB 8 +/* The default comment character when a syntax does not specify any. */ +#define GENERAL_COMMENT_CHARACTER "#" + /* The maximum number of search/replace history strings saved, not * counting the blank lines at their ends. */ #define MAX_SEARCH_HISTORY 100 diff --git a/src/rcfile.c b/src/rcfile.c @@ -315,7 +315,11 @@ void parse_syntax(char *ptr) live_syntax->magics = NULL; live_syntax->linter = NULL; live_syntax->formatter = NULL; +#ifdef ENABLE_COMMENT + live_syntax->comment = mallocstrcpy(NULL, GENERAL_COMMENT_CHARACTER); +#else live_syntax->comment = NULL; +#endif live_syntax->color = NULL; lastcolor = NULL; live_syntax->nmultis = 0; diff --git a/src/text.c b/src/text.c @@ -458,7 +458,7 @@ bool white_string(const char *s) /* Comment or uncomment the current line or the marked lines. */ void do_comment() { - const char *comment_seq = "#"; + const char *comment_seq = GENERAL_COMMENT_CHARACTER; undo_type action = UNCOMMENT; filestruct *top, *bot, *f; size_t top_x, bot_x; @@ -467,11 +467,11 @@ void do_comment() assert(openfile->current != NULL && openfile->current->data != NULL); #ifndef DISABLE_COLOR - if (openfile->syntax && openfile->syntax->comment) + if (openfile->syntax) comment_seq = openfile->syntax->comment; /* Does the syntax not allow comments? */ - if (strlen(comment_seq) == 0) { + if (comment_seq == NULL) { statusbar(_("Commenting is not supported for this file type")); return; }