emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] emacs-25 326ffcc: Allow line comments ending with escaped


From: Alan Mackenzie
Subject: [Emacs-diffs] emacs-25 326ffcc: Allow line comments ending with escaped NL to be continued to the next line.
Date: Mon, 28 Dec 2015 16:00:35 +0000

branch: emacs-25
commit 326ffcce5fbbb0ca368cfa08a33101dbbcaa2ace
Author: Alan Mackenzie <address@hidden>
Commit: Alan Mackenzie <address@hidden>

    Allow line comments ending with escaped NL to be continued to the next line.
    
    Use this in C, C++, and Objective C Modes.  Fixes bug#22246
    
    * src/syntax.c (comment-end-can-be-escaped): New buffer local variable.
    (forw-comment, back-comment): On encountering an end of comment character,
    test whether it is escaped when `comment-end-can-be-escaped' is non-nil.
    
    * doc/lispref/syntax.texi (Control Parsing): Describe
    `comment-end-can-be-escaped'.
    
    * etc/NEWS (Lisp Changes): Describe `comment-end-can-be-escaped'.
    
    * lisp/progmodes/cc-langs.el: New c-lang-setvar 
`comment-end-can-be-escaped'.
---
 doc/lispref/syntax.texi    |    8 ++++++++
 etc/NEWS                   |    5 +++++
 lisp/progmodes/cc-langs.el |    8 ++++++++
 src/syntax.c               |   15 ++++++++++++---
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi
index 7a984e3..831ebd1 100644
--- a/doc/lispref/syntax.texi
+++ b/doc/lispref/syntax.texi
@@ -945,6 +945,14 @@ whitespace by the functions in this section and by 
@code{forward-sexp},
 The behavior of @code{parse-partial-sexp} is also affected by
 @code{parse-sexp-lookup-properties} (@pxref{Syntax Properties}).
 
address@hidden comment-end-can-be-escaped
+If this buffer local variable is address@hidden, a single character
+which usually terminates a comment doesn't do so when that character
+is escaped.  This is used in C and C++ Modes, where line comments
+starting with @samp{//} can be continued onto the next line by
+escaping the newline with @samp{\}.
address@hidden defvar
+
 You can use @code{forward-comment} to move forward or backward over
 one comment or several comments.
 
diff --git a/etc/NEWS b/etc/NEWS
index 1aeab35..3b86a88 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1268,6 +1268,11 @@ Area.  The output is still logged to the *Messages* 
buffer.
 buffers to allow certain parts of the text to be writable.
 
 +++
+** A new variable `comment-end-can-be-escaped' is useful in languages
+   such as C and C++ where line comments with escaped newlines are
+   continued to the next line.
+
++++
 ** New macro `define-advice'.
 
 ** `read-buffer' takes a new `predicate' argument.
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el
index 5b67083..1a07c4c 100644
--- a/lisp/progmodes/cc-langs.el
+++ b/lisp/progmodes/cc-langs.el
@@ -1433,6 +1433,14 @@ properly."
            "\\)\\s *"))
 (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip))
 
+(c-lang-defconst comment-end-can-be-escaped
+  "When non-nil, escaped EOLs inside comments are valid.
+This works in Emacs >= 25.1."
+  t nil
+  (c c++ objc) t)
+(c-lang-setvar comment-end-can-be-escaped
+              (c-lang-const comment-end-can-be-escaped))
+
 (c-lang-defconst c-syntactic-ws-start
   ;; Regexp matching any sequence that can start syntactic whitespace.
   ;; The only uncertain case is '#' when there are cpp directives.
diff --git a/src/syntax.c b/src/syntax.c
index 5b0ec6d..2acbd41 100644
--- a/src/syntax.c
+++ b/src/syntax.c
@@ -790,8 +790,10 @@ back_comment (ptrdiff_t from, ptrdiff_t from_byte, 
ptrdiff_t stop,
                   || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested))
        continue;
 
-      /* Ignore escaped characters, except comment-enders.  */
-      if (code != Sendcomment && char_quoted (from, from_byte))
+      /* Ignore escaped characters, except comment-enders which cannot
+         be escaped.  */
+      if ((Vcomment_end_can_be_escaped || code != Sendcomment)
+          && char_quoted (from, from_byte))
        continue;
 
       switch (code)
@@ -2346,7 +2348,8 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, 
ptrdiff_t stop,
       if (code == Sendcomment
          && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style
          && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ?
-             (nesting > 0 && --nesting == 0) : nesting < 0))
+             (nesting > 0 && --nesting == 0) : nesting < 0)
+          && !(Vcomment_end_can_be_escaped && char_quoted (from, from_byte)))
        /* We have encountered a comment end of the same style
           as the comment sequence which began this comment
           section.  */
@@ -3702,6 +3705,12 @@ character of that word.
 In both cases, LIMIT bounds the search. */);
   Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil);
 
+  DEFVAR_BOOL ("comment-end-can-be-escaped", Vcomment_end_can_be_escaped,
+               doc: /* Non-nil means an escaped ender inside a comment 
doesn'tend the comment.  */);
+  Vcomment_end_can_be_escaped = 0;
+  DEFSYM (Qcomment_end_can_be_escaped, "comment-end-can-be-escaped");
+  Fmake_variable_buffer_local (Qcomment_end_can_be_escaped);
+
   defsubr (&Ssyntax_table_p);
   defsubr (&Ssyntax_table);
   defsubr (&Sstandard_syntax_table);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]