emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/rust-mode 959bfce215 1/3: Enable the use of prettify-symbo


From: ELPA Syncer
Subject: [nongnu] elpa/rust-mode 959bfce215 1/3: Enable the use of prettify-symbols-mode
Date: Sun, 26 Dec 2021 13:58:24 -0500 (EST)

branch: elpa/rust-mode
commit 959bfce215c342c83d72650b2b35201de263edfe
Author: Christophe Troestler <Christophe.Troestler@umons.ac.be>
Commit: Christophe Troestler <Christophe.Troestler@umons.ac.be>

    Enable the use of prettify-symbols-mode
---
 rust-mode.el | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/rust-mode.el b/rust-mode.el
index fca9e9f3fa..3bb1f8d41e 100644
--- a/rust-mode.el
+++ b/rust-mode.el
@@ -41,6 +41,12 @@ This variable might soon be remove again.")
   :type 'function
   :group 'rust-mode)
 
+(defvar rust-prettify-symbols-alist
+  '(("&&" . ?∧) ("||" . ?∨)
+    ("<=" . ?≤)  (">=" . ?≥) ("!=" . ?≠)
+    ("INFINITY" . ?∞) ("->" . ?→) ("=>" . ?⇒))
+  "Alist of symbol prettifications used for `prettify-symbols-alist'.")
+
 ;;; Customization
 
 (defgroup rust-mode nil
@@ -204,6 +210,20 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
     table)
   "Syntax definitions and helpers.")
 
+;;; Prettify
+
+(defun rust--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 there is a space before || as it is also used for
+       ;; functions with 0 arguments.
+       (not (and (string= match "||")
+                 (save-excursion
+                   (goto-char start)
+                   (looking-back "\\(?:\\<move\\|=\\) *"))))))
+
 ;;; Mode
 
 (defvar rust-mode-map
@@ -273,6 +293,9 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
   (setq-local electric-pair-inhibit-predicate
               'rust-electric-pair-inhibit-predicate-wrap)
   (setq-local electric-pair-skip-self 'rust-electric-pair-skip-self-wrap)
+  ;; Configure prettify
+  (setq prettify-symbols-alist rust-prettify-symbols-alist)
+  (setq prettify-symbols-compose-predicate #'rust--prettify-symbols-compose-p)
 
   (add-hook 'before-save-hook rust-before-save-hook nil t)
   (add-hook 'after-save-hook rust-after-save-hook nil t))



reply via email to

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