Function: prettify-symbols-mode

prettify-symbols-mode is an interactive and byte-compiled function defined in prog-mode.el.gz.

Signature

(prettify-symbols-mode &optional ARG)

Documentation

Toggle Prettify Symbols mode.

When Prettify Symbols mode and font-locking are enabled, symbols are prettified (displayed as composed characters) according to the rules in prettify-symbols-alist (which see), which are locally defined by major modes supporting prettifying. To add further customizations for a given major mode, you can modify prettify-symbols-alist thus:

  (add-hook 'emacs-lisp-mode-hook
            (lambda ()
              (push '("<=" . ?≤) prettify-symbols-alist)))

You can enable this mode locally in desired buffers, or use global-prettify-symbols-mode(var)/global-prettify-symbols-mode(fun) to enable it for all modes that support it.

This is a minor mode. If called interactively, toggle the Prettify-Symbols mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable prettify-symbols-mode(var)/prettify-symbols-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

View in manual

Probably introduced at or before Emacs version 24.4.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/prog-mode.el.gz
;;;###autoload
(define-minor-mode prettify-symbols-mode
  "Toggle Prettify Symbols mode.

When Prettify Symbols mode and font-locking are enabled, symbols are
prettified (displayed as composed characters) according to the rules
in `prettify-symbols-alist' (which see), which are locally defined
by major modes supporting prettifying.  To add further customizations
for a given major mode, you can modify `prettify-symbols-alist' thus:

  (add-hook \\='emacs-lisp-mode-hook
            (lambda ()
              (push \\='(\"<=\" . ?≤) prettify-symbols-alist)))

You can enable this mode locally in desired buffers, or use
`global-prettify-symbols-mode' to enable it for all modes that
support it."
  :init-value nil
  (when prettify-symbols--keywords
    (font-lock-remove-keywords nil prettify-symbols--keywords)
    (setq prettify-symbols--keywords nil))
  (if prettify-symbols-mode
      ;; Turn on
      (when (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
        (font-lock-add-keywords nil prettify-symbols--keywords)
        (setq-local font-lock-extra-managed-props
                    (append font-lock-extra-managed-props
                            '(composition
                              prettify-symbols-start
                              prettify-symbols-end)))
        (when prettify-symbols-unprettify-at-point
          (add-hook 'post-command-hook
                    #'prettify-symbols--post-command-hook nil t))
        (font-lock-flush))
    ;; Turn off
    (remove-hook 'post-command-hook #'prettify-symbols--post-command-hook t)
    (when (memq 'composition font-lock-extra-managed-props)
      (setq font-lock-extra-managed-props (delq 'composition
                                                font-lock-extra-managed-props))
      (with-silent-modifications
        (remove-text-properties (point-min) (point-max) '(composition nil))))))