emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

emacs-29 fbaf113bf38: rust-ts-mode: appropriately fontify doc strings


From: Dmitry Gutov
Subject: emacs-29 fbaf113bf38: rust-ts-mode: appropriately fontify doc strings
Date: Fri, 1 Dec 2023 18:55:20 -0500 (EST)

branch: emacs-29
commit fbaf113bf38ee7db8416f0c0581d479c40b2d69c
Author: Christophe Troestler <Christophe.Troestler@umons.ac.be>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    rust-ts-mode: appropriately fontify doc strings
    
    * 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 | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 999c1d7ae96..a07634199ff 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -147,7 +147,7 @@
 
    :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
@@ -287,6 +287,17 @@
    '((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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]