unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* rust-ts-mode: appropriately fontify doc strings
@ 2023-11-29 23:21 Christophe TROESTLER
  2023-12-01  0:50 ` Dmitry Gutov
  0 siblings, 1 reply; 12+ messages in thread
From: Christophe TROESTLER @ 2023-11-29 23:21 UTC (permalink / raw)
  To: emacs-devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 201 bytes --]

Hi,

The attached patch for rust-ts-mode fontifies documentation comments with `font-lock-doc-face' instead of `font-lock-comment-face' (as it is the case right now).

Best regards,
Christophe


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: rust-ts-mode: appropriately fontify doc strings.patch --]
[-- Type: text/x-diff; name="0001-rust-ts-mode-appropriately-fontify-doc-strings.patch", Size: 1705 bytes --]

From 81020267812e57a94982f2620241c1ad69a0fc1b Mon Sep 17 00:00:00 2001
From: Christophe Troestler <Christophe.Troestler@umons.ac.be>
Date: Thu, 30 Nov 2023 00:13:10 +0100
Subject: [PATCH] rust-ts-mode: appropriately fontify doc strings
Content-Type: text/plain; charset="utf-8"

---
 lisp/progmodes/rust-ts-mode.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 88344934e49..aef6b5cb91a 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -153,7 +153,7 @@ rust-ts-mode--font-lock-settings
 
    :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
@@ -293,6 +293,16 @@ rust-ts-mode--font-lock-settings
    '((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))
+         (prefix (buffer-substring-no-properties beg (min (+ beg 3) end)))
+         (face (if (string-equal "///" prefix)
+                   '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
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-12-03 14:12 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-29 23:21 rust-ts-mode: appropriately fontify doc strings Christophe TROESTLER
2023-12-01  0:50 ` Dmitry Gutov
2023-12-01  8:25   ` Christophe TROESTLER
2023-12-01 21:38     ` Christophe TROESTLER
2023-12-01 23:58     ` Dmitry Gutov
2023-12-02  0:59       ` Christophe TROESTLER
2023-12-02  3:41       ` Yuan Fu
2023-12-02  7:55       ` Eli Zaretskii
2023-12-02 10:40         ` Christophe TROESTLER
2023-12-02 17:04           ` Dmitry Gutov
2023-12-02 20:57             ` Christophe TROESTLER
2023-12-03 14:12               ` Dmitry Gutov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).