summaryrefslogtreecommitdiff
path: root/lisp/progmodes/cc-mode.el
diff options
context:
space:
mode:
authorAlan Mackenzie <acm@muc.de>2019-04-20 11:30:55 +0000
committerAlan Mackenzie <acm@muc.de>2019-04-20 11:30:55 +0000
commita85befa4aa52033bd6d9927144b358529ec2b360 (patch)
tree2c536fc9d7bd53809984e55b52efb945b8951f36 /lisp/progmodes/cc-mode.el
parent6f334b6bc0f0c343bbf34c3fee0848aadb5d1d84 (diff)
downloademacs-a85befa4aa52033bd6d9927144b358529ec2b360.tar.gz
Fix Pike Mode's autodoc doc comments style's continued lines.
* lisp/progmodes/cc-engine.el (c-forward-sws, c-backward-sws): Recognize matches of c-doc-line-join-re as syntactic whitespace. (c-find-decl-prefix-search): Recognize and move over matches of c-doc-line-join-re as whitespace. (c-find-decl-spots): Before moving backward a char, check (bobp). Before moving forward over a comment, check it isn't possibly a "bright" comment. * lisp/progmodes/cc-fonts.el (c-get-doc-comment-style): New function, extracted from c-compose-keywords-list. (c-compose-keywords-list): Call the above new function. (pike-font-lock-keywords, pike-font-lock-keywords-2) (pike-font-lock-keywords-3): Call c-set-doc-comment-res. (c-doc-line-join-re, c-doc-bright-comment-start-re, c-doc-line-join-end-ch): New variables. (c-set-doc-comment-re-element, c-set-doc-comment-char-list): New macros. (c-set-doc-comment-res): New function. (c-font-lock-doc-comments): For consistency and repeatability, in a sequence of C++ style doc comments, don't fontify the region between BOL and the comment marker. (autodoc-line-join-re, autodoc-bright-comment-start-re) (autodoc-line-join-end-ch): New variables. * lisp/progmodes/cc-mode.el (c-doc-fl-decl-start, c-doc-fl-decl-end): New functions. (c-change-expand-fl-region, c-context-expand-fl-region): Call the above two new functions for extra possibilities for the start and end of a construct. * doc/misc/cc-mode.texi (Doc Comments): Add a sentence drawing attention to the possibility of fontifying constructs within a doc comment.
Diffstat (limited to 'lisp/progmodes/cc-mode.el')
-rw-r--r--lisp/progmodes/cc-mode.el39
1 files changed, 35 insertions, 4 deletions
diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el
index fc4ba8f5891..aea9c7f3ed1 100644
--- a/lisp/progmodes/cc-mode.el
+++ b/lisp/progmodes/cc-mode.el
@@ -1797,6 +1797,34 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
(funcall fn beg end old-len))
c-before-font-lock-functions)))))))
+(defun c-doc-fl-decl-start (pos)
+ ;; If the line containing POS is in a doc comment continued line (as defined
+ ;; by `c-doc-line-join-re'), return the position of the first line of the
+ ;; sequence. Otherwise, return nil. Point has no significance at entry to
+ ;; and exit from this function.
+ (goto-char pos)
+ (back-to-indentation)
+ (and (or (looking-at c-comment-start-regexp)
+ (memq (c-literal-type (c-literal-limits)) '(c c++)))
+ (progn
+ (end-of-line)
+ (let ((here (point)))
+ (while (re-search-backward c-doc-line-join-re (c-point 'bopl) t))
+ (and (not (eq (point) here))
+ (c-point 'bol))))))
+
+(defun c-doc-fl-decl-end (pos)
+ ;; If the line containing POS is continued by a doc comment continuation
+ ;; marker (as defined by `c-doc-line-join-re), return the position of
+ ;; the BOL at the end of the sequence. Otherwise, return nil. Point has no
+ ;; significance at entry to and exit from this function.
+ (goto-char pos)
+ (back-to-indentation)
+ (let ((here (point)))
+ (while (re-search-forward c-doc-line-join-re (c-point 'eonl) t))
+ (and (not (eq (point) here))
+ (c-point 'bonl))))
+
(defun c-fl-decl-start (pos)
;; If the beginning of the line containing POS is in the middle of a "local"
;; declaration, return the beginning of that declaration. Otherwise return
@@ -1912,9 +1940,10 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
;; and OLD-LEN are not used.
(if font-lock-mode
(setq c-new-BEG
- (or (c-fl-decl-start c-new-BEG) (c-point 'bol c-new-BEG))
+ (or (c-fl-decl-start c-new-BEG) (c-doc-fl-decl-start c-new-BEG)
+ (c-point 'bol c-new-BEG))
c-new-END
- (or (c-fl-decl-end c-new-END)
+ (or (c-fl-decl-end c-new-END) (c-doc-fl-decl-end c-new-END)
(c-point 'bonl c-new-END)))))
(defun c-context-expand-fl-region (beg end)
@@ -1922,8 +1951,10 @@ Note that this is a strict tail, so won't match, e.g. \"0x....\".")
;; "local" declaration containing BEG (see `c-fl-decl-start') or BOL BEG is
;; in. NEW-END is beginning of the line after the one END is in.
(c-save-buffer-state ()
- (cons (or (c-fl-decl-start beg) (c-point 'bol beg))
- (or (c-fl-decl-end end) (c-point 'bonl (1- end))))))
+ (cons (or (c-fl-decl-start beg) (c-doc-fl-decl-start beg)
+ (c-point 'bol beg))
+ (or (c-fl-decl-end end) (c-doc-fl-decl-end end)
+ (c-point 'bonl (1- end))))))
(defun c-before-context-fl-expand-region (beg end)
;; Expand the region (BEG END) as specified by