From 959bfce215c342c83d72650b2b35201de263edfe Mon Sep 17 00:00:00 2001 From: Christophe Troestler Date: Fri, 24 Dec 2021 20:55:02 +0100 Subject: 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 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 "\\(?:\\ Date: Sun, 26 Dec 2021 19:21:01 +0100 Subject: Add an entry to the README to mention prettifying --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 46c48ea..e20d7e4 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,21 @@ on save: (setq rust-format-on-save t) ``` +### Prettifying + +You can toggle prettification of your code by running `M-x +prettify-symbols-mode`. If you'd like to automatically enable this +for all rust files, add the following to your init.el. + +```elisp +(add-hook 'rust-mode-hook + (lambda () (prettify-symbols-mode))) +``` + +You can add your own prettifications to `rust-prettify-symbols-alist`. +For example, to display `x.add(y)` as `x∔(y)`, simply add to your init +file `(push '(".add" . ?∔) rust-prettify-symbols-alist)`. + ### Running / testing / compiling code The `rust-run`, `rust-test`, `rust-compile` and `rust-check` functions -- cgit v1.2.3