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>
master
David Lawrence Ramsey 2017-07-02 01:46:59 -05:00 committed by Benno Schulenberg
parent bf72cdd814
commit 2abe7c03fe
3 changed files with 10 additions and 3 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;
}