[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode d1ed015 173/486: Distinguish face for doc-commen
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode d1ed015 173/486: Distinguish face for doc-comments |
Date: |
Sat, 7 Aug 2021 09:25:13 -0400 (EDT) |
branch: elpa/rust-mode
commit d1ed01519655b6b262d6d21cdfb29f166b697eb3
Author: Georg Brandl <georg@python.org>
Commit: Georg Brandl <georg@python.org>
Distinguish face for doc-comments
Using the syntactic-face-function, we can assign the proper
`font-lock-doc-face' to doc comments ("///", "//!", "/**", "/*!").
Test changes graciously copied from
https://github.com/rust-lang/rust-mode/pull/64
---
rust-mode-tests.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
rust-mode.el | 16 +++++++++++++-
2 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/rust-mode-tests.el b/rust-mode-tests.el
index b40aed0..58fcaaf 100644
--- a/rust-mode-tests.el
+++ b/rust-mode-tests.el
@@ -1085,6 +1085,70 @@ this_is_not_a_string();)"
(should (equal nil (get-text-property 28 'face))) ;; Semicolon--should not
be part of the string
))
+;;; Documentation comments
+
+(ert-deftest font-lock-doc-line-comment-parent ()
+ (rust-test-font-lock
+ "//! doc"
+ '("//! doc" font-lock-doc-face)))
+
+(ert-deftest font-lock-doc-line-comment-item ()
+ (rust-test-font-lock
+ "/// doc"
+ '("/// doc" font-lock-doc-face)))
+
+(ert-deftest font-lock-nondoc-line ()
+ (rust-test-font-lock
+ "////// doc"
+ '("////// " font-lock-comment-delimiter-face
+ "doc" font-lock-comment-face)))
+
+(ert-deftest font-lock-doc-line-in-string ()
+ (rust-test-font-lock
+ "\"/// doc\""
+ '("\"/// doc\"" font-lock-string-face))
+
+ (rust-test-font-lock
+ "\"//! doc\""
+ '("\"//! doc\"" font-lock-string-face)))
+
+(ert-deftest font-lock-doc-line-in-nested-comment ()
+ (rust-test-font-lock
+ "/* /// doc */"
+ '("/* " font-lock-comment-delimiter-face
+ "/// doc */" font-lock-comment-face))
+
+ (rust-test-font-lock
+ "/* //! doc */"
+ '("/* " font-lock-comment-delimiter-face
+ "//! doc */" font-lock-comment-face)))
+
+
+(ert-deftest font-lock-doc-block-comment-parent ()
+ (rust-test-font-lock
+ "/*! doc */"
+ '("/*! doc */" font-lock-doc-face)))
+
+(ert-deftest font-lock-doc-block-comment-item ()
+ (rust-test-font-lock
+ "/** doc */"
+ '("/** doc */" font-lock-doc-face)))
+
+(ert-deftest font-lock-nondoc-block-comment-item ()
+ (rust-test-font-lock
+ "/***** doc */"
+ '("/**" font-lock-comment-delimiter-face
+ "*** doc */" font-lock-comment-face)))
+
+(ert-deftest font-lock-doc-block-in-string ()
+ (rust-test-font-lock
+ "\"/** doc */\""
+ '("\"/** doc */\"" font-lock-string-face))
+ (rust-test-font-lock
+ "\"/*! doc */\""
+ '("\"/*! doc */\"" font-lock-string-face)))
+
+
(ert-deftest indent-method-chains-no-align ()
(let ((rust-indent-method-chain nil)) (test-indent
"
diff --git a/rust-mode.el b/rust-mode.el
index c45d5c1..7fcc09e 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -480,6 +480,16 @@
;; Handle raw strings:
`((rust-look-for-raw-string (1 "|") (4 "_" nil t) (5 "|" nil t) (6 "|" nil
t)))))
+(defun rust-mode-syntactic-face-function (state)
+ "Syntactic face function to distinguish doc comments from other comments."
+ (if (nth 3 state) 'font-lock-string-face
+ (save-excursion
+ (goto-char (nth 8 state))
+ (if (looking-at "/\\([*][*!][^*!]\\|/[/!][^/!]\\)")
+ 'font-lock-doc-face
+ 'font-lock-comment-face
+ ))))
+
(defun rust-fill-prefix-for-comment-start (line-start)
"Determine what to use for `fill-prefix' based on what is at the beginning
of a line."
(let ((result
@@ -740,7 +750,11 @@ This is written mainly to be used as
`end-of-defun-function' for Rust."
;; Fonts
(add-to-list 'font-lock-extend-region-functions
'rust-extend-region-raw-string)
- (setq-local font-lock-defaults '(rust-mode-font-lock-keywords nil nil nil
nil (font-lock-syntactic-keywords . rust-mode-font-lock-syntactic-keywords)))
+ (setq-local font-lock-defaults '(rust-mode-font-lock-keywords
+ nil nil nil nil
+ (font-lock-syntactic-keywords .
rust-mode-font-lock-syntactic-keywords)
+ (font-lock-syntactic-face-function .
rust-mode-syntactic-face-function)
+ ))
;; Misc
(setq-local comment-start "// ")
- [nongnu] elpa/rust-mode 9672625 066/486: Added more scripts to tidy check, (continued)
- [nongnu] elpa/rust-mode 9672625 066/486: Added more scripts to tidy check, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7cb68f7 088/486: Add new keywords (particularly `where` & `virtual`) to editor modes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode efbc810 089/486: Replaced some TODO by FIXME, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 13c7e25 105/486: Ignore byte-compiled files, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 3878cc6 107/486: Allow user to override which emacs is used in run_rust_emacs_tests.sh, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6b57bbf 117/486: Make features (and their tests) work on emacs 23, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4d633fc 125/486: Merge pull request #32 from MicahChalmer/raw-string-handling, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 8d99bf8 126/486: Merge pull request #31 from pnkfelix/more-robust-test-driver, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e16c37c 161/486: Remove Marmalade from the README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee171df 172/486: test $EMACS directly rather than using "which", ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d1ed015 173/486: Distinguish face for doc-comments,
ELPA Syncer <=
- [nongnu] elpa/rust-mode c9c7871 179/486: Merge pull request #79 from MicahChalmer/angle-bracket-madness, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ee564d5 185/486: Merge pull request #85 from talchas/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 99b128c 187/486: Fix slowness in angle bracket matching, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e77aed 191/486: Correcting highlighting of capitals in function names., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 5e51aaa 194/486: Merge pull request #69 from tromey/safe-local-variables, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 012537b 195/486: remove byte-compiler warnings and prevent future ones, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 866df37 196/486: make rust-mode use lexical binding, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6252cf1 217/486: Fix indentation of closing delimiters, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode dd6d417 215/486: Fix type annotations incorrectly highlighted as modules., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 86d636a 223/486: Remove duplicate keywords, ELPA Syncer, 2021/08/07