refactor(ligatures): set-font-ligatures!: unsetting multiple modes

This changes set-font-ligature such that unsetting multiple modes will
properly manipulate multi-mode entries in ligature-composition-table.
This commit is contained in:
Henrik Lissner 2024-08-20 00:01:12 -04:00
parent ef142fc913
commit 0ce403d069
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -60,22 +60,24 @@ For example, the rule for emacs-lisp-mode is very simple:
This will ligate \"->\" into the arrow of choice according to your font.
Font ligatures can be unset for emacs-lisp-mode with:
All font ligatures for emacs-lisp-mode can be unset with:
(set-font-ligatures! \\='emacs-lisp-mode nil)
Note that this will keep all ligatures in `+ligatures-prog-mode-list' active, as
`emacs-lisp-mode' is derived from `prog-mode'."
However, ligatures for any parent modes (like `prog-mode') will still be in
effect, 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.
(after! ligature
(if (or (null ligatures) (equal ligatures '(nil)))
(dolist (mode (ensure-list modes))
(delq! mode ligature-composition-table 'assq))
(let ((package? (featurep 'ligature)))
(dolist (mode (ensure-list modes))
(if package?
(ligature-set-ligatures mode ligatures)
(setf (alist-get mode +ligatures-alist) ligatures))))))
(dolist (table ligature-composition-table)
(let ((modes (ensure-list modes))
(tmodes (car table)))
(cond ((and (listp tmodes) (cl-intersection modes tmodes))
(let ((tmodes (cl-nset-difference tmodes modes)))
(setq ligature-composition-table
(if tmodes
(cons tmodes (cdr table))
(delete table ligature-composition-table)))))
((memq tmodes modes)
(setq ligature-composition-table (delete table ligature-composition-table))))))
(ligature-set-ligatures modes ligatures))))