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,14 +314,25 @@ 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)))
(fn (intern (format "+pretty-code|init-%s" mode))))
(cond ((null (car-safe plist))
(remove-hook hook fn)
(unintern fn))
((or (eq +pretty-code-enabled-modes 't)
(if (eq (car +pretty-code-enabled-modes) 'not)
(not (memq mode (cdr +pretty-code-enabled-modes)))
(memq mode +pretty-code-enabled-modes)))
(fset fn (fset fn
(lambda () (lambda ()
(when (and (eq major-mode mode) (when (eq major-mode mode)
(memq major-mode +pretty-code-enabled-modes))
(unless (cadr (plist-member plist :merge)) (unless (cadr (plist-member plist :merge))
(setq prettify-symbols-alist nil)) (setq prettify-symbols-alist nil))
(if-let ((alist (plist-get plist :alist))) (if-let ((alist (plist-get plist :alist)))
@ -348,4 +353,4 @@ assicated with :lambda in `+pretty-code-symbols'."
(when prettify-symbols-mode (when prettify-symbols-mode
(prettify-symbols-mode -1)) (prettify-symbols-mode -1))
(prettify-symbols-mode +1)))) (prettify-symbols-mode +1))))
(add-hook (intern (format "%s-hook" mode)) fn)))) (add-hook hook fn))))))