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

ideasman42
  • 8,786
  • 1
  • 32
  • 114

2 Answers2

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)
ideasman42
  • 8,786
  • 1
  • 32
  • 114
amitp
  • 2,541
  • 14
  • 24
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"         . ?)
        ("->"         . ?→)
        ("=>"         . ?⇒)
        (">="         . ?≥)
        ("<="         . ?≤)
        ("=="         . ?≡)
        ("!="         . ?≢)
        (".."         . ?‥)
        ("..."        . ?…)

        ; ("*"          . ?×)
        ; ("/"          . ?÷)
        )
      )
     )
   )
  )
ideasman42
  • 8,786
  • 1
  • 32
  • 114
  • 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 '16 at 11:59