[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/rust-mode f1b6007 174/486: Merge pull request #71 from bir
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/rust-mode f1b6007 174/486: Merge pull request #71 from birkenfeld/doc-comments |
Date: |
Sat, 7 Aug 2021 09:25:13 -0400 (EDT) |
branch: elpa/rust-mode
commit f1b6007ab5c9acb5c2b07452f5f38caf85ec537f
Merge: 5ed4675 d1ed015
Author: Felix S Klock II <pnkfelix@pnkfx.org>
Commit: Felix S Klock II <pnkfelix@pnkfx.org>
Merge pull request #71 from birkenfeld/doc-comments
Distinguish face for doc-comments
---
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 1492106 232/486: Fix hook args for after-revert-hook, (continued)
- [nongnu] elpa/rust-mode 1492106 232/486: Fix hook args for after-revert-hook, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 2f42da8 228/486: Add rust-promote-module-into-dir, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 0914b48 234/486: Merge pull request #133 from kraai/avoid-cl, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 917503b 244/486: Fix failing tests, and add a test for the fix., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode a8a5e14 245/486: Fix for emacs24, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode ed0b390 246/486: Merge pull request #148 from bmastenbrook/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode b971c6d 247/486: Fix #151, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode abadab0 009/486: Update rust-mode.el with new keywords., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6275e8e 010/486: Add trait to emacs keyword table., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 9f21b28 024/486: change to 4-space indents everywhere, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f1b6007 174/486: Merge pull request #71 from birkenfeld/doc-comments,
ELPA Syncer <=
- [nongnu] elpa/rust-mode 07943f0 178/486: Perform syntactic angle bracket matching, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 54e24e6 200/486: Add basic license information, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e3c545e 252/486: imenu: don't add item defs in single-line comments, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 6886300 256/486: [master] Copy buffer only when format changes., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode e452995 261/486: rust--after-revert-hook should preserve point position., ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode d2e57a9 263/486: fix regex to account for `[E123]`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode bec3d0c 267/486: Test #169, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 7fb78d4 273/486: Bump version, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode f6cf013 275/486: Add instructions for version tag update requests, ELPA Syncer, 2021/08/07
- [nongnu] elpa/rust-mode 4935090 279/486: convert http links into https links, ELPA Syncer, 2021/08/07