fix(ligatures): no prettify-symbols-mode w/o +extra
Also removes unused variables and functions, and obsoletes `+ligatures-in-modes`, since it is no longer used. Fix: #7440
This commit is contained in:
parent
5a4aa916bc
commit
5ad99220b8
1 changed files with 19 additions and 53 deletions
|
@ -61,6 +61,10 @@ font.")
|
||||||
(t))
|
(t))
|
||||||
"A alist of ligatures to enable in specific modes.")
|
"A alist of ligatures to enable in specific modes.")
|
||||||
|
|
||||||
|
(defvar +ligatures-in-modes nil
|
||||||
|
"List of major modes where ligatures should be enabled.")
|
||||||
|
(make-obsolete-variable '+ligatures-in-modes "Use `ligature-ignored-major-modes' instead" "24.10.0")
|
||||||
|
|
||||||
(defvar +ligatures-prog-mode-list nil
|
(defvar +ligatures-prog-mode-list nil
|
||||||
"A list of ligatures to enable in all `prog-mode' buffers.")
|
"A list of ligatures to enable in all `prog-mode' buffers.")
|
||||||
(make-obsolete-variable '+ligatures-prog-mode-list "Use `+ligatures-alist' instead" "24.09.0")
|
(make-obsolete-variable '+ligatures-prog-mode-list "Use `+ligatures-alist' instead" "24.09.0")
|
||||||
|
@ -72,15 +76,6 @@ font.")
|
||||||
(defvar +ligatures-extra-alist '((t))
|
(defvar +ligatures-extra-alist '((t))
|
||||||
"A map of major modes to symbol lists (for `prettify-symbols-alist').")
|
"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
|
|
||||||
elfeed-search-mode elfeed-show-mode)
|
|
||||||
"List of major modes where ligatures should be enabled.
|
|
||||||
|
|
||||||
If t, enable it everywhere (except `fundamental-mode').
|
|
||||||
If the first element is 'not, enable it in any mode besides what is listed.
|
|
||||||
If nil, don't enable ligatures anywhere.")
|
|
||||||
|
|
||||||
(defvar +ligatures-extras-in-modes t
|
(defvar +ligatures-extras-in-modes t
|
||||||
"List of major modes where extra ligatures should be enabled.
|
"List of major modes where extra ligatures should be enabled.
|
||||||
|
|
||||||
|
@ -89,24 +84,10 @@ Extra ligatures are mode-specific substituions, defined in
|
||||||
controls where these are enabled.
|
controls where these are enabled.
|
||||||
|
|
||||||
If t, enable it everywhere (except `fundamental-mode').
|
If t, enable it everywhere (except `fundamental-mode').
|
||||||
If the first element is 'not, enable it in any mode besides what is listed.
|
If the first element is not, enable it in any mode besides what is listed.
|
||||||
If nil, don't enable these extra ligatures anywhere (though it's more
|
If nil, don't enable these extra ligatures anywhere (though it's more
|
||||||
efficient to remove the `+extra' flag from the :ui ligatures module instead).")
|
efficient to remove the `+extra' flag from the :ui ligatures module instead).")
|
||||||
|
|
||||||
(defvar +ligatures--init-font-hook nil)
|
|
||||||
|
|
||||||
(defun +ligatures--correct-symbol-bounds (ligature-alist)
|
|
||||||
"Prepend non-breaking spaces to a ligature.
|
|
||||||
|
|
||||||
This way `compose-region' (called by `prettify-symbols-mode') will use the
|
|
||||||
correct width of the symbols instead of the width measured by `char-width'."
|
|
||||||
(let ((len (length (car ligature-alist)))
|
|
||||||
(acc (list (cdr ligature-alist))))
|
|
||||||
(while (> len 1)
|
|
||||||
(setq acc (cons #X00a0 (cons '(Br . Bl) acc))
|
|
||||||
len (1- len)))
|
|
||||||
(cons (car ligature-alist) acc)))
|
|
||||||
|
|
||||||
(defun +ligatures--enable-p (modes)
|
(defun +ligatures--enable-p (modes)
|
||||||
"Return t if ligatures should be enabled in this buffer depending on MODES."
|
"Return t if ligatures should be enabled in this buffer depending on MODES."
|
||||||
(unless (eq major-mode 'fundamental-mode)
|
(unless (eq major-mode 'fundamental-mode)
|
||||||
|
@ -115,38 +96,24 @@ correct width of the symbols instead of the width measured by `char-width'."
|
||||||
(not (apply #'derived-mode-p (cdr modes)))
|
(not (apply #'derived-mode-p (cdr modes)))
|
||||||
(apply #'derived-mode-p modes)))))
|
(apply #'derived-mode-p modes)))))
|
||||||
|
|
||||||
(defun +ligatures-init-buffer-h ()
|
(defun +ligatures-init-extra-symbols-h ()
|
||||||
"Set up ligatures for the current buffer.
|
"Set up `prettify-symbols-mode' for the current buffer.
|
||||||
|
|
||||||
Extra ligatures are mode-specific substituions, defined in
|
Extra ligatures are mode-specific substituions, defined in
|
||||||
`+ligatures-extra-symbols', assigned with `set-ligatures!', and made possible
|
`+ligatures-extra-symbols', assigned with `set-ligatures!', and made possible
|
||||||
with `prettify-symbols-mode'. This variable controls where these are enabled.
|
with `prettify-symbols-mode'. This variable controls where these are enabled.
|
||||||
See `+ligatures-extras-in-modes' to control what major modes this function can
|
See `+ligatures-extras-in-modes' to control what major modes this function can
|
||||||
and cannot run in."
|
and cannot run in."
|
||||||
(when after-init-time
|
(when (and after-init-time (+ligatures--enable-p +ligatures-extras-in-modes))
|
||||||
(let ((in-mode-p
|
(prependq! prettify-symbols-alist
|
||||||
(+ligatures--enable-p +ligatures-in-modes))
|
(or (alist-get major-mode +ligatures-extra-alist)
|
||||||
(in-mode-extras-p
|
(cl-loop for (mode . symbols) in +ligatures-extra-alist
|
||||||
(and (modulep! +extra)
|
if (derived-mode-p mode)
|
||||||
(+ligatures--enable-p +ligatures-extras-in-modes))))
|
return symbols)))
|
||||||
(when in-mode-p
|
(when prettify-symbols-alist
|
||||||
;; If ligature-mode has been installed, there's no
|
(when prettify-symbols-mode
|
||||||
;; need to do anything, we activate global-ligature-mode
|
(prettify-symbols-mode -1))
|
||||||
;; later and handle all settings from `set-ligatures!' later.
|
(prettify-symbols-mode +1))))
|
||||||
(unless (fboundp #'ligature-mode-turn-on)
|
|
||||||
(run-hooks '+ligatures--init-font-hook)
|
|
||||||
(setq +ligatures--init-font-hook nil)))
|
|
||||||
(when in-mode-extras-p
|
|
||||||
(prependq! prettify-symbols-alist
|
|
||||||
(or (alist-get major-mode +ligatures-extra-alist)
|
|
||||||
(cl-loop for (mode . symbols) in +ligatures-extra-alist
|
|
||||||
if (derived-mode-p mode)
|
|
||||||
return symbols))))
|
|
||||||
(when (and (or in-mode-p in-mode-extras-p)
|
|
||||||
prettify-symbols-alist)
|
|
||||||
(when prettify-symbols-mode
|
|
||||||
(prettify-symbols-mode -1))
|
|
||||||
(prettify-symbols-mode +1)))))
|
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
@ -156,9 +123,8 @@ and cannot run in."
|
||||||
;; When you get to the right edge, it goes back to how it normally prints
|
;; When you get to the right edge, it goes back to how it normally prints
|
||||||
(setq prettify-symbols-unprettify-at-point 'right-edge)
|
(setq prettify-symbols-unprettify-at-point 'right-edge)
|
||||||
|
|
||||||
(add-hook! 'doom-init-ui-hook :append
|
(when (modulep! +extra)
|
||||||
(defun +ligatures-init-h ()
|
(add-hook 'after-change-major-mode-hook #'+ligatures-init-extra-symbols-h))
|
||||||
(add-hook 'after-change-major-mode-hook #'+ligatures-init-buffer-h)))
|
|
||||||
|
|
||||||
(cond
|
(cond
|
||||||
;; The emacs-mac build of Emacs appears to have built-in support for ligatures,
|
;; The emacs-mac build of Emacs appears to have built-in support for ligatures,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue