all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Christophe TROESTLER <Christophe.TROESTLER@umons.ac.be>
To: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Add prettify configuration to the rust-ts-mode
Date: Mon, 11 Sep 2023 14:24:59 +0000	[thread overview]
Message-ID: <87msxshjnp.fsf@poincare.umons.ac.be> (raw)

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

Hi,

I noticed that the rust-ts-mode does not have a configuration for the prettify-symbols-mode.  The attached patch aims to add that.

On another note, is it planned to have compile support for Rust?

Best regards,
Christophe

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-prettify-configuration-to-rust-ts-mode.patch --]
[-- Type: text/x-diff; name="0001-Add-prettify-configuration-to-rust-ts-mode.patch", Size: 2470 bytes --]

From b9d3549810465aae90c5917b943e0393d6519485 Mon Sep 17 00:00:00 2001
From: Christophe Troestler <Christophe.Troestler@umons.ac.be>
Date: Mon, 11 Sep 2023 15:32:57 +0200
Subject: [PATCH] Add prettify configuration to rust-ts-mode
Content-Type: text/plain; charset="utf-8"

* lisp/progmodes/rust-ts-mode.el: Add prettify configuration to the mode.
---
 lisp/progmodes/rust-ts-mode.el | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 999c1d7ae96..88344934e49 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -48,6 +48,12 @@ rust-ts-mode-indent-offset
   :safe 'integerp
   :group 'rust)
 
+(defvar rust-ts-mode-prettify-symbols-alist
+  '(("&&" . ?∧) ("||" . ?∨)
+    ("<=" . ?≤)  (">=" . ?≥) ("!=" . ?≠)
+    ("INFINITY" . ?∞) ("->" . ?→) ("=>" . ?⇒))
+  "Value for `prettify-symbols-alist' in `rust-ts-mode'.")
+
 (defvar rust-ts-mode--syntax-table
   (let ((table (make-syntax-table)))
     (modify-syntax-entry ?+   "."      table)
@@ -386,6 +392,19 @@ rust-ts-mode--syntax-propertize
                             (?< '(4 . ?>))
                             (?> '(5 . ?<))))))))
 
+(defun rust-ts-mode--prettify-symbols-compose-p (start end match)
+  "Return true iff the symbol MATCH should be composed.
+See `prettify-symbols-compose-predicate'."
+  (and (fboundp 'prettify-symbols-default-compose-p)
+       (prettify-symbols-default-compose-p start end match)
+       ;; Make sure || is not a closure with 0 arguments and && is not
+       ;; a double reference.
+       (pcase match
+         ((or "||" "&&")
+          (string= (treesit-node-field-name (treesit-node-at (point)))
+                   "operator"))
+         (_ t))))
+
 ;;;###autoload
 (define-derived-mode rust-ts-mode prog-mode "Rust"
   "Major mode for editing Rust, powered by tree-sitter."
@@ -411,6 +430,11 @@ rust-ts-mode
                     number type)
                   ( bracket delimiter error function operator property variable)))
 
+    ;; Prettify configuration
+    (setq prettify-symbols-alist rust-ts-mode-prettify-symbols-alist)
+    (setq prettify-symbols-compose-predicate
+          #'rust-ts-mode--prettify-symbols-compose-p)
+
     ;; Imenu.
     (setq-local treesit-simple-imenu-settings
                 `(("Module" "\\`mod_item\\'" nil nil)
-- 
2.40.1


             reply	other threads:[~2023-09-11 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11 14:24 Christophe TROESTLER [this message]
2023-09-12  0:15 ` Add prettify configuration to the rust-ts-mode Yuan Fu
2023-09-12  2:34   ` Eli Zaretskii
2023-09-17  9:58 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87msxshjnp.fsf@poincare.umons.ac.be \
    --to=christophe.troestler@umons.ac.be \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.