aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mackenzie2021-08-15 18:08:25 +0000
committerAlan Mackenzie2021-08-15 18:11:42 +0000
commitb3aec9ee483c82aa23e604ea61ce0777e9ef2ebd (patch)
treee1d7c89545b792a56d837821d1d682d362b4ba29
parentb77f6af24e9193a4f70622cda6d641c58e885c22 (diff)
downloademacs-b3aec9ee483c82aa23e604ea61ce0777e9ef2ebd.tar.gz
emacs-b3aec9ee483c82aa23e604ea61ce0777e9ef2ebd.zip
CC Mode: Fix unstable fontification of doc strings.
Also optimize a loop over several line doc-comments. * lisp/progmodes/cc-fonts.el (c-font-lock-doc-comments): New variable comment-mid, used as the starting point for applying c-doc-face-name in a line comments. In block comments, apply this face not from `comment-beg' but from `region-beg', no earlier than the start of the fontification region.
-rw-r--r--lisp/progmodes/cc-fonts.el15
1 files changed, 9 insertions, 6 deletions
diff --git a/lisp/progmodes/cc-fonts.el b/lisp/progmodes/cc-fonts.el
index fd00d65e335..5f3e2eaaf80 100644
--- a/lisp/progmodes/cc-fonts.el
+++ b/lisp/progmodes/cc-fonts.el
@@ -2733,13 +2733,14 @@ need for `pike-font-lock-extra-types'.")
2733 ;; 2733 ;;
2734 ;; This function might do hidden buffer changes. 2734 ;; This function might do hidden buffer changes.
2735 2735
2736 (let (comment-beg region-beg) 2736 (let (comment-beg region-beg comment-mid)
2737 (if (memq (get-text-property (point) 'face) 2737 (if (memq (get-text-property (point) 'face)
2738 '(font-lock-comment-face font-lock-comment-delimiter-face)) 2738 '(font-lock-comment-face font-lock-comment-delimiter-face))
2739 ;; Handle the case when the fontified region starts inside a 2739 ;; Handle the case when the fontified region starts inside a
2740 ;; comment. 2740 ;; comment.
2741 (let ((start (c-literal-start))) 2741 (let ((start (c-literal-start)))
2742 (setq region-beg (point)) 2742 (setq region-beg (point)
2743 comment-mid (point))
2743 (when start 2744 (when start
2744 (goto-char start)) 2745 (goto-char start))
2745 (when (looking-at prefix) 2746 (when (looking-at prefix)
@@ -2765,7 +2766,8 @@ need for `pike-font-lock-extra-types'.")
2765 (goto-char comment-beg) 2766 (goto-char comment-beg)
2766 (c-in-literal))))) 2767 (c-in-literal)))))
2767 (setq comment-beg nil)) 2768 (setq comment-beg nil))
2768 (setq region-beg comment-beg)) 2769 (setq region-beg comment-beg
2770 comment-mid comment-beg))
2769 2771
2770 (if (elt (parse-partial-sexp comment-beg (+ comment-beg 2)) 7) 2772 (if (elt (parse-partial-sexp comment-beg (+ comment-beg 2)) 7)
2771 ;; Collect a sequence of doc style line comments. 2773 ;; Collect a sequence of doc style line comments.
@@ -2773,15 +2775,16 @@ need for `pike-font-lock-extra-types'.")
2773 (goto-char comment-beg) 2775 (goto-char comment-beg)
2774 (while (and (progn 2776 (while (and (progn
2775 (c-forward-single-comment) 2777 (c-forward-single-comment)
2776 (c-put-font-lock-face comment-beg (point) 2778 (c-put-font-lock-face comment-mid (point)
2777 c-doc-face-name) 2779 c-doc-face-name)
2778 (skip-syntax-forward " ") 2780 (skip-syntax-forward " ")
2779 (setq comment-beg (point)) 2781 (setq comment-beg (point)
2782 comment-mid (point))
2780 (< (point) limit)) 2783 (< (point) limit))
2781 (looking-at prefix)))) 2784 (looking-at prefix))))
2782 (goto-char comment-beg) 2785 (goto-char comment-beg)
2783 (c-forward-single-comment) 2786 (c-forward-single-comment)
2784 (c-put-font-lock-face comment-beg (point) c-doc-face-name)) 2787 (c-put-font-lock-face region-beg (point) c-doc-face-name))
2785 (if (> (point) limit) (goto-char limit)) 2788 (if (> (point) limit) (goto-char limit))
2786 (setq comment-beg nil) 2789 (setq comment-beg nil)
2787 2790