From 2abe7c03fe25e3291a0aaeddffcb24df1b09d8c2 Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sun, 2 Jul 2017 01:46:59 -0500 Subject: [PATCH] text: make sure commenting is disabled when comment "" was specified MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/nano.h | 3 +++ src/rcfile.c | 4 ++++ src/text.c | 6 +++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/nano.h b/src/nano.h index 1a030b62..fa38de14 100644 --- 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 index 2e71a05a..1b60addd 100644 --- 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 index 1355454d..c745e6ca 100644 --- 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; }