diff options
| author | Alan Mackenzie | 2015-12-28 16:01:05 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2015-12-28 16:01:05 +0000 |
| commit | 326ffcce5fbbb0ca368cfa08a33101dbbcaa2ace (patch) | |
| tree | 1b86615b5bed5089446aa9c5a8ae0619703aa3b0 | |
| parent | 17ab0d10e1db9cc4924ceb778e5c4e6bb9a90c3d (diff) | |
| download | emacs-326ffcce5fbbb0ca368cfa08a33101dbbcaa2ace.tar.gz emacs-326ffcce5fbbb0ca368cfa08a33101dbbcaa2ace.zip | |
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'.
| -rw-r--r-- | doc/lispref/syntax.texi | 8 | ||||
| -rw-r--r-- | etc/NEWS | 5 | ||||
| -rw-r--r-- | lisp/progmodes/cc-langs.el | 8 | ||||
| -rw-r--r-- | src/syntax.c | 15 |
4 files changed, 33 insertions, 3 deletions
diff --git a/doc/lispref/syntax.texi b/doc/lispref/syntax.texi index 7a984e3d87b..831ebd12f55 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}, | |||
| 945 | The behavior of @code{parse-partial-sexp} is also affected by | 945 | The behavior of @code{parse-partial-sexp} is also affected by |
| 946 | @code{parse-sexp-lookup-properties} (@pxref{Syntax Properties}). | 946 | @code{parse-sexp-lookup-properties} (@pxref{Syntax Properties}). |
| 947 | 947 | ||
| 948 | @defvar comment-end-can-be-escaped | ||
| 949 | If this buffer local variable is non-@code{nil}, a single character | ||
| 950 | which usually terminates a comment doesn't do so when that character | ||
| 951 | is escaped. This is used in C and C++ Modes, where line comments | ||
| 952 | starting with @samp{//} can be continued onto the next line by | ||
| 953 | escaping the newline with @samp{\}. | ||
| 954 | @end defvar | ||
| 955 | |||
| 948 | You can use @code{forward-comment} to move forward or backward over | 956 | You can use @code{forward-comment} to move forward or backward over |
| 949 | one comment or several comments. | 957 | one comment or several comments. |
| 950 | 958 | ||
| @@ -1268,6 +1268,11 @@ Area. The output is still logged to the *Messages* buffer. | |||
| 1268 | buffers to allow certain parts of the text to be writable. | 1268 | buffers to allow certain parts of the text to be writable. |
| 1269 | 1269 | ||
| 1270 | +++ | 1270 | +++ |
| 1271 | ** A new variable `comment-end-can-be-escaped' is useful in languages | ||
| 1272 | such as C and C++ where line comments with escaped newlines are | ||
| 1273 | continued to the next line. | ||
| 1274 | |||
| 1275 | +++ | ||
| 1271 | ** New macro `define-advice'. | 1276 | ** New macro `define-advice'. |
| 1272 | 1277 | ||
| 1273 | ** `read-buffer' takes a new `predicate' argument. | 1278 | ** `read-buffer' takes a new `predicate' argument. |
diff --git a/lisp/progmodes/cc-langs.el b/lisp/progmodes/cc-langs.el index 5b670833d45..1a07c4cd699 100644 --- a/lisp/progmodes/cc-langs.el +++ b/lisp/progmodes/cc-langs.el | |||
| @@ -1433,6 +1433,14 @@ properly." | |||
| 1433 | "\\)\\s *")) | 1433 | "\\)\\s *")) |
| 1434 | (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip)) | 1434 | (c-lang-setvar comment-start-skip (c-lang-const comment-start-skip)) |
| 1435 | 1435 | ||
| 1436 | (c-lang-defconst comment-end-can-be-escaped | ||
| 1437 | "When non-nil, escaped EOLs inside comments are valid. | ||
| 1438 | This works in Emacs >= 25.1." | ||
| 1439 | t nil | ||
| 1440 | (c c++ objc) t) | ||
| 1441 | (c-lang-setvar comment-end-can-be-escaped | ||
| 1442 | (c-lang-const comment-end-can-be-escaped)) | ||
| 1443 | |||
| 1436 | (c-lang-defconst c-syntactic-ws-start | 1444 | (c-lang-defconst c-syntactic-ws-start |
| 1437 | ;; Regexp matching any sequence that can start syntactic whitespace. | 1445 | ;; Regexp matching any sequence that can start syntactic whitespace. |
| 1438 | ;; The only uncertain case is '#' when there are cpp directives. | 1446 | ;; The only uncertain case is '#' when there are cpp directives. |
diff --git a/src/syntax.c b/src/syntax.c index 5b0ec6d071b..2acbd413858 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, | |||
| 790 | || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested)) | 790 | || SYNTAX_FLAGS_COMMENT_NESTED (syntax) != comnested)) |
| 791 | continue; | 791 | continue; |
| 792 | 792 | ||
| 793 | /* Ignore escaped characters, except comment-enders. */ | 793 | /* Ignore escaped characters, except comment-enders which cannot |
| 794 | if (code != Sendcomment && char_quoted (from, from_byte)) | 794 | be escaped. */ |
| 795 | if ((Vcomment_end_can_be_escaped || code != Sendcomment) | ||
| 796 | && char_quoted (from, from_byte)) | ||
| 795 | continue; | 797 | continue; |
| 796 | 798 | ||
| 797 | switch (code) | 799 | switch (code) |
| @@ -2346,7 +2348,8 @@ forw_comment (ptrdiff_t from, ptrdiff_t from_byte, ptrdiff_t stop, | |||
| 2346 | if (code == Sendcomment | 2348 | if (code == Sendcomment |
| 2347 | && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style | 2349 | && SYNTAX_FLAGS_COMMENT_STYLE (syntax, 0) == style |
| 2348 | && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? | 2350 | && (SYNTAX_FLAGS_COMMENT_NESTED (syntax) ? |
| 2349 | (nesting > 0 && --nesting == 0) : nesting < 0)) | 2351 | (nesting > 0 && --nesting == 0) : nesting < 0) |
| 2352 | && !(Vcomment_end_can_be_escaped && char_quoted (from, from_byte))) | ||
| 2350 | /* We have encountered a comment end of the same style | 2353 | /* We have encountered a comment end of the same style |
| 2351 | as the comment sequence which began this comment | 2354 | as the comment sequence which began this comment |
| 2352 | section. */ | 2355 | section. */ |
| @@ -3702,6 +3705,12 @@ character of that word. | |||
| 3702 | In both cases, LIMIT bounds the search. */); | 3705 | In both cases, LIMIT bounds the search. */); |
| 3703 | Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil); | 3706 | Vfind_word_boundary_function_table = Fmake_char_table (Qnil, Qnil); |
| 3704 | 3707 | ||
| 3708 | DEFVAR_BOOL ("comment-end-can-be-escaped", Vcomment_end_can_be_escaped, | ||
| 3709 | doc: /* Non-nil means an escaped ender inside a comment doesn'tend the comment. */); | ||
| 3710 | Vcomment_end_can_be_escaped = 0; | ||
| 3711 | DEFSYM (Qcomment_end_can_be_escaped, "comment-end-can-be-escaped"); | ||
| 3712 | Fmake_variable_buffer_local (Qcomment_end_can_be_escaped); | ||
| 3713 | |||
| 3705 | defsubr (&Ssyntax_table_p); | 3714 | defsubr (&Ssyntax_table_p); |
| 3706 | defsubr (&Ssyntax_table); | 3715 | defsubr (&Ssyntax_table); |
| 3707 | defsubr (&Sstandard_syntax_table); | 3716 | defsubr (&Sstandard_syntax_table); |