emacs-diffs
[Top][All Lists]
Advanced

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

master e686fb9de39: Add prettify-symbols configuration to 'rust-ts-mode'


From: Eli Zaretskii
Subject: master e686fb9de39: Add prettify-symbols configuration to 'rust-ts-mode'
Date: Sun, 17 Sep 2023 05:58:08 -0400 (EDT)

branch: master
commit e686fb9de39657ac97b33c1fe74c3328d0fb90fd
Author: Christophe Troestler <Christophe.Troestler@umons.ac.be>
Commit: Eli Zaretskii <eliz@gnu.org>

    Add prettify-symbols configuration to 'rust-ts-mode'
    
    * lisp/progmodes/rust-ts-mode.el
    (rust-ts-mode-prettify-symbols-alist): New variable.
    (rust-ts-mode--prettify-symbols-compose-p): New function.
    (rust-ts-mode): Use it.
---
 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 @@
   :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 @@ delimiters < and >'s."
                             (?< '(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 @@ delimiters < and >'s."
                     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)



reply via email to

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