From ef142fc913d0ef1f37b4e73c8d155434537cbf00 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 19 Aug 2024 16:43:22 -0400 Subject: [PATCH] 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). --- modules/ui/ligatures/autoload/ligatures.el | 18 +++--- modules/ui/ligatures/config.el | 65 ++++++++++++---------- 2 files changed, 44 insertions(+), 39 deletions(-) diff --git a/modules/ui/ligatures/autoload/ligatures.el b/modules/ui/ligatures/autoload/ligatures.el index 6c8194681..26ae08892 100644 --- a/modules/ui/ligatures/autoload/ligatures.el +++ b/modules/ui/ligatures/autoload/ligatures.el @@ -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 - (dolist (mode (ensure-list modes)) - (setq ligature-ignored-major-modes (delq mode ligature-ignored-major-modes)) - (ligature-set-ligatures mode ligatures))))) - - + (let ((package? (featurep 'ligature))) + (dolist (mode (ensure-list modes)) + (if package? + (ligature-set-ligatures mode ligatures) + (setf (alist-get mode +ligatures-alist) ligatures)))))) diff --git a/modules/ui/ligatures/config.el b/modules/ui/ligatures/config.el index ad8baab5e..d2bcdcec7 100644 --- a/modules/ui/ligatures/config.el +++ b/modules/ui/ligatures/config.el @@ -44,29 +44,34 @@ 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-alist + '((prog-mode "|||>" "<|||" "<==>" "" "---" "-<<" + "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->" + "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "" "###" "#_(" "..<" + "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~=" + "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|" + "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:" + ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:" + "<$" "<=" "<>" "<-" "<<" "<+" "" "++" "?:" + "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)" + "\\\\" "://") + (t)) + "A alist of ligatures to enable in specific modes.") + +(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-prog-mode-list - '("|||>" "<|||" "<==>" "" "---" "-<<" - "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->" - "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "" "###" "#_(" "..<" - "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~=" - "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|" - "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:" - ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:" - "<$" "<=" "<>" "<-" "<<" "<+" "" "++" "?:" - "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)" - "\\\\" "://") - "A list of ligatures to enable in all `prog-mode' buffers.") - -(defvar +ligatures-all-modes-list - '() - "A list of ligatures to enable in all buffers.") - (defvar +ligatures-in-modes '(not special-mode comint-mode eshell-mode term-mode vterm-mode Info-mode elfeed-search-mode elfeed-show-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)))