6

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).

0

2 Answers 2

7

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)
2
3

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"         . ?𝘍)
        ("->"         . ?→)
        ("=>"         . ?⇒)
        (">="         . ?≥)
        ("<="         . ?≤)
        ("=="         . ?≡)
        ("!="         . ?≢)
        (".."         . ?‥)
        ("..."        . ?…)

        ; ("*"          . ?×)
        ; ("/"          . ?÷)
        )
      )
     )
   )
  )
1
  • If you have multiple frames some of them graphic some other not then this will not work completely as expected. for example if you're using the emacs daemon, I think the hook will not be added.
    – YoungFrog
    Dec 31, 2016 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.