Add unsetting capability to set-pretty-symbols!

+ Allows (set-pretty-symbols! 'some-mode nil)
+ Changes the semantics of +pretty-code-enabled-modes, which is now t by
  default (meaning enable all modes). It also supports '(not ...).
This commit is contained in:
Henrik Lissner 2018-06-21 13:05:29 +02:00
parent 1dd023cda1
commit d01f39d658
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -13,17 +13,10 @@ This requires the iosevka font!
Use the :iosevka property to enable (or disable) it regardless.") Use the :iosevka property to enable (or disable) it regardless.")
;;;###autoload ;;;###autoload
(defvar +pretty-code-enabled-modes (defvar +pretty-code-enabled-modes t
'(c++-mode-hook "List of major modes in which `prettify-symbols-mode' should not be enabled.
c-mode-hook If t, enable it everywhere. If the first element is 'not, enable it in any mode
elm-mode besides what is listed.")
emacs-lisp-mode
js2-mode
org-mode
python-mode
typescript-mode
web-mode)
"List of major modes in which `prettify-symbols-mode' should be enabled.")
;;;###autoload ;;;###autoload
(defvar +pretty-code-symbols (defvar +pretty-code-symbols
@ -296,9 +289,10 @@ Use the :iosevka property to enable (or disable) it regardless.")
"Associates string patterns with icons in certain major-modes. "Associates string patterns with icons in certain major-modes.
MODES is a major mode symbol or a list of them. MODES is a major mode symbol or a list of them.
PLIST is a property list whose keys must match keys in PLIST is a property list whose keys must match keys in `+pretty-code-symbols',
`+pretty-code-symbols', and whose values are strings representing the and whose values are strings representing the text to be replaced with that
text to be replaced with that symbol. symbol. If the car of PLIST is nil, then unset any pretty symbols previously
defined for MODES.
The following properties are special: The following properties are special:
@ -320,32 +314,43 @@ For example, the rule for emacs-lisp-mode is very simple:
:lambda \"lambda\") :lambda \"lambda\")
This will replace any instances of \"lambda\" in emacs-lisp-mode with the symbol This will replace any instances of \"lambda\" in emacs-lisp-mode with the symbol
assicated with :lambda in `+pretty-code-symbols'." 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 1)) (declare (indent 1))
(dolist (mode (doom-enlist modes)) (dolist (mode (doom-enlist modes))
(let ((fn (intern (format "+pretty-code|init-%s" mode)))) (let ((hook (intern (format "%s-hook" mode)))
(fset fn (fn (intern (format "+pretty-code|init-%s" mode))))
(lambda () (cond ((null (car-safe plist))
(when (and (eq major-mode mode) (remove-hook hook fn)
(memq major-mode +pretty-code-enabled-modes)) (unintern fn))
(unless (cadr (plist-member plist :merge)) ((or (eq +pretty-code-enabled-modes 't)
(setq prettify-symbols-alist nil)) (if (eq (car +pretty-code-enabled-modes) 'not)
(if-let ((alist (plist-get plist :alist))) (not (memq mode (cdr +pretty-code-enabled-modes)))
(setq prettify-symbols-alist (append alist prettify-symbols-alist)) (memq mode +pretty-code-enabled-modes)))
(let ((plist plist) (fset fn
results) (lambda ()
(while plist (when (eq major-mode mode)
(let ((prop (car plist)) (unless (cadr (plist-member plist :merge))
(sym (cadr plist))) (setq prettify-symbols-alist nil))
(when-let* ((icon (plist-get +pretty-code-symbols prop))) (if-let ((alist (plist-get plist :alist)))
(push (cons sym (+pretty-code--icon-to-char (append icon nil))) (setq prettify-symbols-alist (append alist prettify-symbols-alist))
results)) (let ((plist plist)
(setq plist (cddr plist)))) results)
(setq prettify-symbols-alist (append results prettify-symbols-alist)))) (while plist
(when (or (cadr (plist-member plist :iosevka)) (let ((prop (car plist))
+pretty-code-iosevka-ligatures-enabled-by-default) (sym (cadr plist)))
(+pretty-code-setup-iosevka-ligatures)) (when-let* ((icon (plist-get +pretty-code-symbols prop)))
(when prettify-symbols-mode (push (cons sym (+pretty-code--icon-to-char (append icon nil)))
(prettify-symbols-mode -1)) results))
(prettify-symbols-mode +1)))) (setq plist (cddr plist))))
(add-hook (intern (format "%s-hook" mode)) fn)))) (setq prettify-symbols-alist (append results prettify-symbols-alist))))
(when (or (cadr (plist-member plist :iosevka))
+pretty-code-iosevka-ligatures-enabled-by-default)
(+pretty-code-setup-iosevka-ligatures))
(when prettify-symbols-mode
(prettify-symbols-mode -1))
(prettify-symbols-mode +1))))
(add-hook hook fn))))))