]> git.eshelyaron.com Git - emacs.git/commitdiff
rust-ts-mode: appropriately fontify doc strings
authorChristophe Troestler <Christophe.Troestler@umons.ac.be>
Wed, 29 Nov 2023 23:13:10 +0000 (00:13 +0100)
committerDmitry Gutov <dmitry@gutov.dev>
Fri, 1 Dec 2023 23:55:02 +0000 (01:55 +0200)
* lisp/progmodes/rust-ts-mode.el
(rust-ts-mode--comment-docstring): New function.
(rust-ts-mode--font-lock-settings): Use it
(https://lists.gnu.org/archive/html/emacs-devel/2023-12/msg00019.html).

lisp/progmodes/rust-ts-mode.el

index 999c1d7ae9628e689c1d5b843859dd440f9c991c..a07634199ffe4b53af7314033f465fb91233fbaf 100644 (file)
 
    :language 'rust
    :feature 'comment
-   '(([(block_comment) (line_comment)]) @font-lock-comment-face)
+   '(([(block_comment) (line_comment)]) @rust-ts-mode--comment-docstring)
 
    :language 'rust
    :feature 'delimiter
    '((ERROR) @font-lock-warning-face))
   "Tree-sitter font-lock settings for `rust-ts-mode'.")
 
+(defun rust-ts-mode--comment-docstring (node override start end &rest _args)
+  "Use the comment or documentation face appropriately for comments."
+  (let* ((beg (treesit-node-start node))
+         (end (treesit-node-end node))
+         (face (save-excursion
+                 (goto-char beg)
+                 (if (looking-at "///")
+                     'font-lock-doc-face
+                   'font-lock-comment-face))))
+    (treesit-fontify-with-override beg end face override start end)))
+
 (defun rust-ts-mode--fontify-scope (node override start end &optional tail-p)
   (let* ((case-fold-search nil)
          (face