2018-07-05 19:37:06 -07:00
|
|
|
|
;;; ui/pretty-code/settings.el -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(defvar +pretty-code-symbols
|
|
|
|
|
'(;; org
|
|
|
|
|
:name "»"
|
|
|
|
|
:src_block "»"
|
2018-12-05 22:08:30 -05:00
|
|
|
|
:src_block_end "»"
|
2018-07-05 19:37:06 -07:00
|
|
|
|
;; Functional
|
|
|
|
|
:lambda "λ"
|
|
|
|
|
:def "ƒ"
|
|
|
|
|
:composition "∘"
|
|
|
|
|
:map "↦"
|
|
|
|
|
;; Types
|
|
|
|
|
:null "∅"
|
|
|
|
|
:true "𝕋"
|
|
|
|
|
:false "𝔽"
|
|
|
|
|
:int "ℤ"
|
|
|
|
|
:float "ℝ"
|
|
|
|
|
:str "𝕊"
|
|
|
|
|
:bool "𝔹"
|
|
|
|
|
;; Flow
|
|
|
|
|
:not "¬"
|
|
|
|
|
:in "∈"
|
|
|
|
|
:not-in "∉"
|
|
|
|
|
:and "∧"
|
|
|
|
|
:or "∨"
|
|
|
|
|
:for "∀"
|
|
|
|
|
:some "∃"
|
|
|
|
|
:return "⟼"
|
|
|
|
|
:yield "⟻"
|
|
|
|
|
;; Other
|
|
|
|
|
:tuple "⨂"
|
|
|
|
|
:pipe "" ;; FIXME: find a non-private char
|
|
|
|
|
:dot "•")
|
|
|
|
|
"Options plist for `set-pretty-symbols!'.
|
|
|
|
|
|
|
|
|
|
This should not contain any symbols from the Unicode Private Area! There is no
|
|
|
|
|
universal way of getting the correct symbol as that area varies from font to
|
|
|
|
|
font.")
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2018-07-06 19:59:16 +02:00
|
|
|
|
(defvar +pretty-code-symbols-alist '((t))
|
2018-07-05 19:37:06 -07:00
|
|
|
|
"An alist containing a mapping of major modes to its value for
|
|
|
|
|
`prettify-symbols-alist'.")
|
|
|
|
|
|
2018-07-07 17:55:26 -04:00
|
|
|
|
;;;###autodef
|
|
|
|
|
(defun +pretty-code--correct-symbol-bounds (ligature-alist)
|
|
|
|
|
"Prepend non-breaking spaces to a ligature.
|
|
|
|
|
|
|
|
|
|
This way `compose-region' (called by `prettify-symbols-mode') will use the
|
|
|
|
|
correct width of the symbols instead of the width measured by `char-width'."
|
|
|
|
|
(let ((len (length (car ligature-alist)))
|
|
|
|
|
(acc (list (cdr ligature-alist))))
|
|
|
|
|
(while (> len 1)
|
|
|
|
|
(setq acc (cons #X00a0 (cons '(Br . Bl) acc))
|
|
|
|
|
len (1- len)))
|
|
|
|
|
(cons (car ligature-alist) acc)))
|
|
|
|
|
|
2018-07-06 19:59:16 +02:00
|
|
|
|
;;;###autodef
|
2018-10-16 17:32:41 -04:00
|
|
|
|
(defun set-pretty-symbols! (modes &rest plist)
|
2018-07-06 19:59:16 +02:00
|
|
|
|
"Associates string patterns with icons in certain major-modes.
|
|
|
|
|
|
|
|
|
|
MODES is a major mode symbol or a list of them.
|
|
|
|
|
PLIST is a property list whose keys must match keys in `+pretty-code-symbols',
|
|
|
|
|
and whose values are strings representing the text to be replaced with that
|
|
|
|
|
symbol. If the car of PLIST is nil, then unset any pretty symbols previously
|
|
|
|
|
defined for MODES.
|
|
|
|
|
|
|
|
|
|
The following properties are special:
|
|
|
|
|
|
|
|
|
|
:alist ALIST
|
|
|
|
|
Appends ALIST to `prettify-symbols-alist' literally, without mapping text to
|
|
|
|
|
`+pretty-code-symbols'.
|
|
|
|
|
:merge BOOL
|
|
|
|
|
If non-nil, merge with previously defined `prettify-symbols-alist',
|
|
|
|
|
otherwise overwrite it.
|
|
|
|
|
|
|
|
|
|
For example, the rule for emacs-lisp-mode is very simple:
|
|
|
|
|
|
|
|
|
|
(set-pretty-symbols! 'emacs-lisp-mode
|
|
|
|
|
:lambda \"lambda\")
|
|
|
|
|
|
|
|
|
|
This will replace any instances of \"lambda\" in emacs-lisp-mode with the symbol
|
|
|
|
|
assicated with :lambda in `+pretty-code-symbols'.
|
|
|
|
|
|
|
|
|
|
Pretty symbols can be unset for emacs-lisp-mode with:
|
|
|
|
|
|
|
|
|
|
(set-pretty-symbols! 'emacs-lisp-mode nil)"
|
|
|
|
|
(declare (indent defun))
|
2018-10-16 17:32:41 -04:00
|
|
|
|
(if (null (car-safe plist))
|
2018-10-11 16:06:25 -04:00
|
|
|
|
(delq (assq mode +pretty-code-symbols-alist)
|
|
|
|
|
+pretty-code-symbols-alist)
|
|
|
|
|
(let (results merge key)
|
2018-10-16 17:32:41 -04:00
|
|
|
|
(while plist
|
|
|
|
|
(pcase (setq key (pop plist))
|
|
|
|
|
(:merge (setq merge (pop plist)))
|
|
|
|
|
(:alist (setq results (append (pop plist) results)))
|
2018-10-11 16:06:25 -04:00
|
|
|
|
(_
|
|
|
|
|
(when-let* ((char (plist-get +pretty-code-symbols key)))
|
2018-10-16 17:32:41 -04:00
|
|
|
|
(push (cons (pop plist) char) results)))))
|
2018-10-11 16:06:25 -04:00
|
|
|
|
(dolist (mode (doom-enlist modes))
|
2018-07-05 19:37:06 -07:00
|
|
|
|
(unless merge
|
2018-07-06 19:59:16 +02:00
|
|
|
|
(delq (assq mode +pretty-code-symbols-alist)
|
|
|
|
|
+pretty-code-symbols-alist))
|
2018-07-05 19:37:06 -07:00
|
|
|
|
(push (cons mode results) +pretty-code-symbols-alist)))))
|