In this video (time-linked, only a few seconds) the word function
is displayed as f
, but can still be edited so the underlying text remains as-is.
How can this be done in emacs? (using plugins or built in features).
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityIn this video (time-linked, only a few seconds) the word function
is displayed as f
, but can still be edited so the underlying text remains as-is.
How can this be done in emacs? (using plugins or built in features).
Prettify-symbols-mode comes with emacs; here's a blog post about it. You need to add the substitution to prettify-symbols-alist
in whatever mode you want it in. Here's an example for javascript-mode:
(add-hook 'javascript-mode-hook
(lambda ()
(push '("function" . ?λ) prettify-symbols-alist)))
and then M-x
prettify-symbols-mode
To avoid having to set this manually, it can be enabled globally from your init file:
(global-prettify-symbols-mode t)
While the current answer is useful, this example shows how to set many characters at once and enable globally when in graphical mode.
(when local-cfg/use-prettify-symbols
(add-hook
'rust-mode-hook
(lambda ()
(setq
prettify-symbols-alist
'(
("fn" . ?ƒ)
("Fn" . ?𝘍)
("->" . ?→)
("=>" . ?⇒)
(">=" . ?≥)
("<=" . ?≤)
("==" . ?≡)
("!=" . ?≢)
(".." . ?‥)
("..." . ?…)
; ("*" . ?×)
; ("/" . ?÷)
)
)
)
)
)