refactor(ligatures): defer ligature.el & combine variables

This combines `+ligatures-prog-mode-list` and `+ligatures-all-mode-list`
into `+ligatures-alist` (and deprecates the former).
This commit is contained in:
Henrik Lissner 2024-08-19 16:43:22 -04:00
parent dff6c36ab5
commit ef142fc913
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 44 additions and 39 deletions

View file

@ -67,15 +67,15 @@ Font ligatures can be unset for emacs-lisp-mode with:
Note that this will keep all ligatures in `+ligatures-prog-mode-list' active, as
`emacs-lisp-mode' is derived from `prog-mode'."
(declare (indent defun))
;; NOTE: Doom enforces `ligature-composition-table' to have a single mode per key in the alist.
;; This is less efficient than what ligature.el can do (i.e. use a list of modes, or `t' as a key),
;; but holding this invariant allows resetting with `(set-font-ligatures! 'mode nil)` to work reliably.
;; NOTE: Doom enforces `ligature-composition-table' to have a single mode per
;; key in the alist. This is less efficient than what ligature.el can do
;; (i.e. use a list of modes, or `t' as a key), but holding this invariant
;; allows resetting with `(set-font-ligatures! 'mode nil)` to work reliably.
(if (or (null ligatures) (equal ligatures '(nil)))
(dolist (mode (ensure-list modes))
(delq! mode ligature-composition-table 'assq))
(after! ligature
(let ((package? (featurep 'ligature)))
(dolist (mode (ensure-list modes))
(setq ligature-ignored-major-modes (delq mode ligature-ignored-major-modes))
(ligature-set-ligatures mode ligatures)))))
(if package?
(ligature-set-ligatures mode ligatures)
(setf (alist-get mode +ligatures-alist) ligatures))))))

View file

@ -44,11 +44,8 @@ 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.")
(defvar +ligatures-extra-alist '((t))
"A map of major modes to symbol lists (for `prettify-symbols-alist').")
(defvar +ligatures-prog-mode-list
'("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
(defvar +ligatures-alist
'((prog-mode "|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
"!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
"<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
@ -61,11 +58,19 @@ font.")
"##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
"?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
"\\\\" "://")
"A list of ligatures to enable in all `prog-mode' buffers.")
(t))
"A alist of ligatures to enable in specific modes.")
(defvar +ligatures-all-modes-list
'()
(defvar +ligatures-prog-mode-list nil
"A list of ligatures to enable in all `prog-mode' buffers.")
(make-obsolete-variable '+ligatures-prog-mode-list "Use `+ligatures-alist' instead" "v3.0.0")
(defvar +ligatures-all-modes-list nil
"A list of ligatures to enable in all buffers.")
(make-obsolete-variable '+ligatures-all-modes-list "Use `+ligatures-alist' instead" "v3.0.0")
(defvar +ligatures-extra-alist '((t))
"A map of major modes to symbol lists (for `prettify-symbols-alist').")
(defvar +ligatures-in-modes
'(not special-mode comint-mode eshell-mode term-mode vterm-mode Info-mode
@ -169,14 +174,14 @@ and cannot run in."
(featurep 'harfbuzz))
(featurep 'composite)) ; Emacs loads `composite' at startup
(use-package! ligature
:config
;; Enable all `+ligatures-prog-mode-list' ligatures in programming modes
(ligature-set-ligatures 'prog-mode +ligatures-prog-mode-list)
(ligature-set-ligatures 't +ligatures-all-modes-list))
(after! ligature
;; DEPRECATED: For backwards compatibility. Remove later.
(with-no-warnings
(when +ligatures-prog-mode-list
(setf (alist-get 'prog-mode +ligatures-alist) +ligatures-prog-mode-list))
(when +ligatures-all-modes-list
(setf (alist-get t +ligatures-alist) +ligatures-all-modes-list)))
(dolist (lig +ligatures-alist)
(ligature-set-ligatures (car lig) (cdr lig))))
(add-hook! 'doom-init-ui-hook :append
(defun +ligature-enable-globally-h ()
"Enables ligature checks globally in all buffers.
You can also do it per mode with `ligature-mode'."
(global-ligature-mode t)))))
(add-hook 'doom-init-ui-hook #'global-ligature-mode 'append)))