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))
|
||||
"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
|
||||
"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")
|
||||
|
@ -72,15 +76,6 @@ font.")
|
|||
(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
|
||||
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
|
||||
"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.
|
||||
|
||||
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
|
||||
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)
|
||||
"Return t if ligatures should be enabled in this buffer depending on MODES."
|
||||
(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)))
|
||||
(apply #'derived-mode-p modes)))))
|
||||
|
||||
(defun +ligatures-init-buffer-h ()
|
||||
"Set up ligatures for the current buffer.
|
||||
(defun +ligatures-init-extra-symbols-h ()
|
||||
"Set up `prettify-symbols-mode' for the current buffer.
|
||||
|
||||
Extra ligatures are mode-specific substituions, defined in
|
||||
`+ligatures-extra-symbols', assigned with `set-ligatures!', and made possible
|
||||
with `prettify-symbols-mode'. This variable controls where these are enabled.
|
||||
See `+ligatures-extras-in-modes' to control what major modes this function can
|
||||
and cannot run in."
|
||||
(when after-init-time
|
||||
(let ((in-mode-p
|
||||
(+ligatures--enable-p +ligatures-in-modes))
|
||||
(in-mode-extras-p
|
||||
(and (modulep! +extra)
|
||||
(+ligatures--enable-p +ligatures-extras-in-modes))))
|
||||
(when in-mode-p
|
||||
;; If ligature-mode has been installed, there's no
|
||||
;; need to do anything, we activate global-ligature-mode
|
||||
;; later and handle all settings from `set-ligatures!' later.
|
||||
(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)))))
|
||||
(when (and after-init-time (+ligatures--enable-p +ligatures-extras-in-modes))
|
||||
(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 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
|
||||
(setq prettify-symbols-unprettify-at-point 'right-edge)
|
||||
|
||||
(add-hook! 'doom-init-ui-hook :append
|
||||
(defun +ligatures-init-h ()
|
||||
(add-hook 'after-change-major-mode-hook #'+ligatures-init-buffer-h)))
|
||||
(when (modulep! +extra)
|
||||
(add-hook 'after-change-major-mode-hook #'+ligatures-init-extra-symbols-h))
|
||||
|
||||
(cond
|
||||
;; 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