Skip to content

Commit 959bfce

Browse files
committed
Enable the use of prettify-symbols-mode
1 parent b017f74 commit 959bfce

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

rust-mode.el

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ This variable might soon be remove again.")
4141
:type 'function
4242
:group 'rust-mode)
4343

44+
(defvar rust-prettify-symbols-alist
45+
'(("&&" . ?∧) ("||" . ?∨)
46+
("<=" . ?≤) (">=" . ?≥) ("!=" . ?≠)
47+
("INFINITY" . ?∞) ("->" . ?→) ("=>" . ?⇒))
48+
"Alist of symbol prettifications used for `prettify-symbols-alist'.")
49+
4450
;;; Customization
4551

4652
(defgroup rust-mode nil
@@ -204,6 +210,20 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
204210
table)
205211
"Syntax definitions and helpers.")
206212

213+
;;; Prettify
214+
215+
(defun rust--prettify-symbols-compose-p (start end match)
216+
"Return true iff the symbol MATCH should be composed.
217+
See `prettify-symbols-compose-predicate'."
218+
(and (fboundp 'prettify-symbols-default-compose-p)
219+
(prettify-symbols-default-compose-p start end match)
220+
;; Make sure there is a space before || as it is also used for
221+
;; functions with 0 arguments.
222+
(not (and (string= match "||")
223+
(save-excursion
224+
(goto-char start)
225+
(looking-back "\\(?:\\<move\\|=\\) *"))))))
226+
207227
;;; Mode
208228

209229
(defvar rust-mode-map
@@ -273,6 +293,9 @@ Use idomenu (imenu with `ido-mode') for best mileage.")
273293
(setq-local electric-pair-inhibit-predicate
274294
'rust-electric-pair-inhibit-predicate-wrap)
275295
(setq-local electric-pair-skip-self 'rust-electric-pair-skip-self-wrap)
296+
;; Configure prettify
297+
(setq prettify-symbols-alist rust-prettify-symbols-alist)
298+
(setq prettify-symbols-compose-predicate #'rust--prettify-symbols-compose-p)
276299

277300
(add-hook 'before-save-hook rust-before-save-hook nil t)
278301
(add-hook 'after-save-hook rust-after-save-hook nil t))

0 commit comments

Comments
 (0)