diff options
| author | brotzeit <brotzeitmacher@gmail.com> | 2021-12-26 19:24:38 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-26 19:24:38 +0100 |
| commit | eba544147aa6769f4f0e153e9f7373801dd2db89 (patch) | |
| tree | 2c3a43af7ece9eb5d1e7720d25eee79ac0237df1 /rust-mode.el | |
| parent | 65f96278b24b89c13e79b38a071a98824d108bb8 (diff) | |
| parent | f14fa86a5c0a3b8563a24437549693ee07b9a95f (diff) | |
| download | rust-mode-eba544147aa6769f4f0e153e9f7373801dd2db89.tar.gz | |
Merge pull request #429 from Chris00/prettify
Enable the use of prettify-symbols-mode
Diffstat (limited to 'rust-mode.el')
| -rw-r--r-- | rust-mode.el | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/rust-mode.el b/rust-mode.el index 57feaaa..eec6057 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 @@ -209,6 +215,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 @@ -278,6 +298,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)) |
