branch: elpa/rust-mode commit 959bfce215c342c83d72650b2b35201de263edfe Author: Christophe Troestler <christophe.troest...@umons.ac.be> Commit: Christophe Troestler <christophe.troest...@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))