summaryrefslogtreecommitdiff
path: root/rust-mode.el
diff options
context:
space:
mode:
authorChristophe Troestler <Christophe.Troestler@umons.ac.be>2021-12-24 20:55:02 +0100
committerChristophe Troestler <Christophe.Troestler@umons.ac.be>2021-12-25 14:27:16 +0100
commit959bfce215c342c83d72650b2b35201de263edfe (patch)
tree2e26e653291a8820dcc3e863d21868320757e519 /rust-mode.el
parentb017f746503df27ccdca8ee6d2627529d64d76e1 (diff)
downloadrust-mode-959bfce215c342c83d72650b2b35201de263edfe.tar.gz
Enable the use of prettify-symbols-mode
Diffstat (limited to 'rust-mode.el')
-rw-r--r--rust-mode.el23
1 files changed, 23 insertions, 0 deletions
diff --git a/rust-mode.el b/rust-mode.el
index fca9e9f..3bb1f8d 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))