dev: merge branch 'master' of github.com:doomemacs

This commit is contained in:
Matt Nish-Lapidus 2024-09-11 10:00:32 -04:00
commit 25a4356ba1
15 changed files with 172 additions and 165 deletions

View file

@ -1,8 +1,8 @@
#!/usr/bin/env sh #!/usr/bin/env sh
:; # -*- mode: emacs-lisp; lexical-binding: t -*- :; # -*- mode: emacs-lisp; lexical-binding: t -*-
:; case "$EMACS" in *term*) EMACS=emacs ;; *) EMACS="${EMACS:-emacs}" ;; esac :; case "$EMACS" in *term*) EMACS=emacs ;; *) EMACS="${EMACS:-emacs}" ;; esac
:; [ "$EMACS" = emacs ] && { type emacs >/dev/null 2>&1 || err=1; } :; [ "x$EMACS" = xemacs ] && { type emacs >/dev/null 2>&1 || err=1; }
:; [ -n "$err" ] && { echo "Error: failed to run Emacs with command '$EMACS'"; echo; echo "Are you sure Emacs is installed and in your \$PATH?"; exit 1; } >&2 :; [ "x$err" = x ] || { echo "Error: failed to run Emacs with command '$EMACS'"; echo; echo "Are you sure Emacs is installed and in your \$PATH?"; exit 1; } >&2
:; emacs="$EMACS ${DEBUG:+--debug-init} -q --no-site-file --batch" :; emacs="$EMACS ${DEBUG:+--debug-init} -q --no-site-file --batch"
:; export __DOOMPID="${__DOOMPID:-$$}" :; export __DOOMPID="${__DOOMPID:-$$}"
:; export __DOOMSTEP="${__DOOMSTEP:-0}" :; export __DOOMSTEP="${__DOOMSTEP:-0}"
@ -10,7 +10,7 @@
:; export __DOOMGPIPE=${__DOOMGPIPE:-$__DOOMPIPE} :; export __DOOMGPIPE=${__DOOMGPIPE:-$__DOOMPIPE}
:; export __DOOMPIPE=; [ -t 0 ] || __DOOMPIPE="${__DOOMPIPE}0"; [ -t 1 ] || __DOOMPIPE="${__DOOMPIPE}1" :; export __DOOMPIPE=; [ -t 0 ] || __DOOMPIPE="${__DOOMPIPE}0"; [ -t 1 ] || __DOOMPIPE="${__DOOMPIPE}1"
:; $emacs --load "$0" -- "$@" || exit=$? :; $emacs --load "$0" -- "$@" || exit=$?
:; [ "${exit:-0}" -eq 254 ] && { export TMPDIR="${TMPDIR:-${TEMP:-`$emacs -Q --eval '(princ (temporary-file-directory))' 2>/dev/null`}}"; sh "${TMPDIR}/doom.${__DOOMPID}.${__DOOMSTEP}.sh" "$0" "$@" && true; exit="$?"; } :; [ "${exit:-0}" -eq 254 ] && { export TMPDIR="${TMPDIR:-${TMP:-${TEMP:-`$emacs -Q --eval '(princ temporary-file-directory)' 2>/dev/null`}}}"; sh "${TMPDIR}/doom.${__DOOMPID}.${__DOOMSTEP}.sh" "$0" "$@" && true; exit="$?"; }
:; exit $exit :; exit $exit
;; This magical mess of a shebang is necessary for any script that relies on ;; This magical mess of a shebang is necessary for any script that relies on

View file

@ -405,7 +405,16 @@ Defaults to the profile at `doom-profile-default'."
(letf! ((defun module-loader (group name file &optional noerror) (letf! ((defun module-loader (group name file &optional noerror)
(doom-module-context-with (cons group name) (doom-module-context-with (cons group name)
`(let ((doom-module-context ,doom-module-context)) `(let ((doom-module-context ,doom-module-context))
(doom-load ,(abbreviate-file-name (file-name-sans-extension file)))))) (doom-load
,(pcase (cons group name)
('(:core . nil)
`(file-name-concat
doom-core-dir ,(file-name-nondirectory (file-name-sans-extension file))))
('(:user . nil)
`(file-name-concat
doom-user-dir ,(file-name-nondirectory (file-name-sans-extension file))))
(_ (abbreviate-file-name (file-name-sans-extension file))))
t))))
(defun module-list-loader (modules file &optional noerror) (defun module-list-loader (modules file &optional noerror)
(cl-loop for (cat . mod) in modules (cl-loop for (cat . mod) in modules
if (doom-module-locate-path cat mod file) if (doom-module-locate-path cat mod file)

View file

@ -247,7 +247,12 @@ the command instead."
(projectile-mode +1) (projectile-mode +1)
;; HACK: See bbatsov/projectile@3c92d28c056c ;; HACK: See bbatsov/projectile@3c92d28c056c
(remove-hook 'buffer-list-update-hook #'projectile-track-known-projects-find-file-hook) (remove-hook 'buffer-list-update-hook #'projectile-track-known-projects-find-file-hook)
(add-hook 'doom-switch-buffer-hook #'projectile-track-known-projects-find-file-hook t))) (add-hook 'doom-switch-buffer-hook #'projectile-track-known-projects-find-file-hook t)
(add-hook! 'dired-after-readin-hook
(defun doom-project-track-known-project-h ()
(when projectile-mode
(setq projectile-project-root-cache (make-hash-table :test 'equal))
(projectile-track-known-projects-find-file-hook))))))
;; ;;

View file

@ -590,8 +590,10 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(put 'doom-theme 'previous-themes (or last-themes 'none)) (put 'doom-theme 'previous-themes (or last-themes 'none))
;; DEPRECATED Hook into `enable-theme-functions' when we target 29 ;; DEPRECATED Hook into `enable-theme-functions' when we target 29
(doom-run-hooks 'doom-load-theme-hook) (doom-run-hooks 'doom-load-theme-hook)
(setf (alist-get 'foreground-color default-frame-alist) (face-foreground 'default nil t) (when-let* ((fg (face-foreground 'default nil t))
(alist-get 'background-color default-frame-alist) (face-background 'default nil t))))))) (bg (face-background 'default nil t)))
(setf (alist-get 'foreground-color default-frame-alist) fg
(alist-get 'background-color default-frame-alist) bg)))))))
;; ;;

View file

@ -198,13 +198,15 @@ Activate this advice with:
-q or -Q, for example: -q or -Q, for example:
emacs -Q -l init.el -f doom-run-all-startup-hooks-h" emacs -Q -l init.el -f doom-run-all-startup-hooks-h"
(setq after-init-time (current-time)) (setq after-init-time (current-time)
doom-init-time (current-time))
(let ((inhibit-startup-hooks nil)) (let ((inhibit-startup-hooks nil))
(doom-run-hooks 'after-init-hook (doom-run-hooks 'after-init-hook
'delayed-warnings-hook 'delayed-warnings-hook
'emacs-startup-hook 'emacs-startup-hook
'tty-setup-hook 'tty-setup-hook
'window-setup-hook))) 'window-setup-hook
'doom-after-init-hook)))
;; ;;

View file

@ -49,25 +49,28 @@
(defun doom--sandbox-run (&optional mode) (defun doom--sandbox-run (&optional mode)
"TODO" "TODO"
(letenv! (("DOOMDIR" (if (eq mode 'vanilla-doom+)
(expand-file-name "___does_not_exist___" temporary-file-directory)
doom-user-dir)))
(doom--sandbox-launch (doom--sandbox-launch
(unless (eq mode 'doom) '("-Q")) (unless (memq mode '(doom vanilla-doom+)) '("-Q"))
(let ((forms (let ((forms
(read (format "(progn\n%s\n)" (read (format "(progn\n%s\n)"
(buffer-substring-no-properties (buffer-substring-no-properties
(point-min) (point-min)
(point-max)))))) (point-max))))))
(if (eq mode 'doom) (if (memq mode '(doom vanilla-doom+))
forms forms
`(progn `(progn
;; doom variables ;; doom variables
(setq init-file-debug t (setq init-file-debug t
doom-log-level 2
doom-emacs-dir ,doom-emacs-dir doom-emacs-dir ,doom-emacs-dir
doom-cache-dir ,(expand-file-name "cache/" doom-sandbox-dir) doom-cache-dir ,(expand-file-name "cache/" doom-sandbox-dir)
doom-data-dir ,(expand-file-name "data/" doom-sandbox-dir)) doom-data-dir ,(expand-file-name "data/" doom-sandbox-dir))
(defun doom--write-to-etc-dir-a (fn &rest args) (define-advice locate-user-emacs-file (:around (fn &rest args) restrict-to-data-dir)
(let ((user-emacs-directory doom-data-dir)) (let ((user-emacs-directory doom-data-dir))
(apply fn args))) (apply fn args)))
(advice-add #'locate-user-emacs-file :around #'doom--write-to-etc-dir-a)
;; emacs essential variables ;; emacs essential variables
(setq before-init-time (current-time) (setq before-init-time (current-time)
after-init-time nil after-init-time nil
@ -81,11 +84,8 @@
(setq package--init-file-ensured t (setq package--init-file-ensured t
package-user-dir ,package-user-dir package-user-dir ,package-user-dir
package-archives ',package-archives) package-archives ',package-archives)
;; (add-hook 'kill-emacs-hook (with-eval-after-load 'doom
;; (lambda () (run-hooks 'doom-before-init-hook))
;; (delete-file user-init-file)
;; (when (file-equal-p user-emacs-directory ,doom-sandbox-dir)
;; (delete-directory user-emacs-directory 'recursive))))
(with-eval-after-load 'undo-tree (with-eval-after-load 'undo-tree
;; HACK `undo-tree' sometimes throws errors because ;; HACK `undo-tree' sometimes throws errors because
;; `buffer-undo-tree' isn't correctly initialized. ;; `buffer-undo-tree' isn't correctly initialized.
@ -93,55 +93,30 @@
;; Then launch as much about Emacs as we can ;; Then launch as much about Emacs as we can
(defun --run-- () ,forms) (defun --run-- () ,forms)
,(pcase mode ,(pcase mode
(`doom
'(--run--))
(`vanilla-doom+ ; Doom core + modules - private config
`(progn
(load-file ,(expand-file-name "doom.el" doom-core-dir))
(setq doom-modules-dirs (list doom-modules-dir))
(let ((doom-init-modules-p t))
(doom-initialize)
(doom-initialize-core-modules))
(setq doom-modules ',doom-modules)
(maphash (lambda (key plist)
(doom-module-put
(car key) (cdr key)
:path (doom-module-locate-path (car key) (cdr key))))
doom-modules)
(--run--)
(doom-run-hooks 'doom-before-modules-init-hook)
(maphash (doom-module-loader doom-module-init-file) doom-modules)
(doom-run-hooks 'doom-after-modules-init-hook)
(doom-run-hooks 'doom-before-modules-config-hook)
(maphash (doom-module-loader doom-module-config-file) doom-modules)
(doom-run-hooks 'doom-after-modules-config-hook)))
(`vanilla-doom ; only Doom core (`vanilla-doom ; only Doom core
`(progn `(let ((doom-user-dir "/tmp/does/not/exist"))
(load-file ,(expand-file-name "doom.el" doom-core-dir)) (require 'doom ,(expand-file-name "doom.el" doom-core-dir))
(let ((doom-init-modules-p t)) (let ((doom-module-init-file "__does-not-exist__"))
(doom-initialize) (require 'doom-start))
(doom-initialize-core-modules)) (setq doom-modules (make-hash-table :test 'equal))
(--run--))) (--run--)))
(`vanilla ; nothing loaded (`vanilla ; nothing loaded
`(progn `(progn
(if (boundp 'comp-deferred-compilation)
;; REVIEW Remove me after a month
(setq comp-deferred-compilation nil
comp-deferred-compilation-deny-list ',(bound-and-true-p native-comp-async-env-modifier-form)
comp-async-env-modifier-form ',(bound-and-true-p native-comp-async-env-modifier-form)
comp-eln-load-path ',(bound-and-true-p native-comp-eln-load-path))
(setq native-comp-deferred-compilation nil (setq native-comp-deferred-compilation nil
native-comp-deferred-compilation-deny-list ',(bound-and-true-p native-comp-async-env-modifier-form) native-comp-deferred-compilation-deny-list ',(bound-and-true-p native-comp-async-env-modifier-form)
native-comp-async-env-modifier-form ',(bound-and-true-p native-comp-async-env-modifier-form) native-comp-async-env-modifier-form ',(bound-and-true-p native-comp-async-env-modifier-form)
native-comp-eln-load-path ',(bound-and-true-p native-comp-eln-load-path))) native-comp-eln-load-path ',(bound-and-true-p native-comp-eln-load-path))
(package-initialize t) (package-initialize t)
(--run--)))) (--run--))))
(with-eval-after-load 'doom
;; Then rerun Emacs' startup hooks to simulate a fresh Emacs session, ;; Then rerun Emacs' startup hooks to simulate a fresh Emacs session,
;; because they've already fired. ;; because they've already fired.
(fset 'doom-run-hook #',(symbol-function #'doom-run-hook)) (fset 'doom-run-hook #',(symbol-function #'doom-run-hook))
(fset 'doom-run-hooks #',(symbol-function #'doom-run-hooks)) (fset 'doom-run-hooks #',(symbol-function #'doom-run-hooks))
(fset 'doom-run-all-startup-hooks-h #',(symbol-function #'doom-run-all-startup-hooks-h)) (fset 'doom-run-all-startup-hooks-h #',(symbol-function #'doom-run-all-startup-hooks-h))
(doom-run-all-startup-hooks-h)))))) ;; (doom-run-all-startup-hooks-h)
(unless (default-toplevel-value 'mode-line-format)
(setq-default mode-line-format (get 'mode-line-format 'initial-value))))))))))
(fset 'doom--run-vanilla-emacs (cmd! (doom--sandbox-run 'vanilla))) (fset 'doom--run-vanilla-emacs (cmd! (doom--sandbox-run 'vanilla)))
(fset 'doom--run-vanilla-doom (cmd! (doom--sandbox-run 'vanilla-doom))) (fset 'doom--run-vanilla-doom (cmd! (doom--sandbox-run 'vanilla-doom)))

View file

@ -62,7 +62,9 @@
(_ (doom-log "Spell checker not found. Either install `aspell', `hunspell' or `enchant'"))) (_ (doom-log "Spell checker not found. Either install `aspell', `hunspell' or `enchant'")))
(ispell-check-version)) (if (executable-find ispell-program-name)
(ispell-check-version)
(warn "Can't find %s in your $PATH" ispell-program-name)))
;; ;;

View file

@ -61,8 +61,7 @@
:before #'company-begin-backend :before #'company-begin-backend
(company-abort))) (company-abort)))
(add-hook 'after-change-major-mode-hook #'+company-init-backends-h 'append) (add-hook 'company-mode-hook #'+company-init-backends-h 'append)
;; NOTE Fix #1335: ensure `company-emulation-alist' is the first item of ;; NOTE Fix #1335: ensure `company-emulation-alist' is the first item of
;; `emulation-mode-map-alists', thus higher priority than keymaps of ;; `emulation-mode-map-alists', thus higher priority than keymaps of

View file

@ -15,7 +15,7 @@
(dired-git-info-mode 1))) (dired-git-info-mode 1)))
;;;###autoload ;;;###autoload
(defun +dired/dirvish-side-or-follow (&optional arg) (defun +dired/dirvish-side-and-follow (&optional arg)
"Open `dirvish-side' then find the currently focused file. "Open `dirvish-side' then find the currently focused file.
If dirvish is already open, remotely jump to the file in Dirvish. If dirvish is already open, remotely jump to the file in Dirvish.

View file

@ -24,6 +24,11 @@
(add-to-list 'doom-debug-variables 'mu4e-debug) (add-to-list 'doom-debug-variables 'mu4e-debug)
;; mu4e now uses `display-buffer-alist' so we need to add some rules of our own ;; mu4e now uses `display-buffer-alist' so we need to add some rules of our own
(set-popup-rule! "^\\*mu4e-\\(main\\|headers\\)\\*" :ignore t) (set-popup-rule! "^\\*mu4e-\\(main\\|headers\\)\\*" :ignore t)
(set-popup-rule! "^\\*mu4e-log\\*" :select nil)
;; Treat mu4e main menu buffer as real, so it can be switched to or fallen
;; back to when killing other buffers.
(add-hook 'mu4e-main-mode-hook #'doom-mark-buffer-as-real-h)
;; Ensures backward/forward compatibility for mu4e, which is prone to breaking ;; Ensures backward/forward compatibility for mu4e, which is prone to breaking
;; updates, and also cannot be pinned, because it's bundled with mu (which you ;; updates, and also cannot be pinned, because it's bundled with mu (which you

View file

@ -10,7 +10,9 @@ This module adds rudimentary [[https://www.idris-lang.org/][Idris]] support to D
*This module needs a maintainer.* [[doom-contrib-maintainer:][Become a maintainer?]] *This module needs a maintainer.* [[doom-contrib-maintainer:][Become a maintainer?]]
** Module flags ** Module flags
/This module has no flags./ - +lsp ::
Enable LSP support for ~idris-mode~. Requires [[doom-module::tools lsp]] and
[[https://github.com/idris-community/idris2-lsp][idris2-lsp]].
** Packages ** Packages
- [[doom-package:idris-mode]] - [[doom-package:idris-mode]]
@ -25,6 +27,8 @@ This module adds rudimentary [[https://www.idris-lang.org/][Idris]] support to D
* TODO Installation * TODO Installation
[[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]] [[id:01cffea4-3329-45e2-a892-95a384ab2338][Enable this module in your ~doom!~ block.]]
For [[doom-module:+lsp]], [[https://github.com/idris-community/idris2-lsp][idris2-lsp]] is required.
#+begin_quote #+begin_quote
󱌣 /No installation steps have been documented./ [[doom-contrib-module:][Document them?]] 󱌣 /No installation steps have been documented./ [[doom-contrib-module:][Document them?]]
#+end_quote #+end_quote
@ -34,14 +38,27 @@ This module adds rudimentary [[https://www.idris-lang.org/][Idris]] support to D
󱌣 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]] 󱌣 /This module's usage documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
#+end_quote #+end_quote
In addition to ~idris-mode~ goodness, adds frequently used functions under the In addition to ~idris-mode~ goodness, this module adds frequently used functions
[[kbd:][<localleader>]] key. under the [[kbd:][<localleader>]] key.
* TODO Configuration * TODO Configuration
#+begin_quote #+begin_quote
󱌣 This module has no configuration documentation yet. [[doom-contrib-module:][Write some?]] 󱌣 /This module's configuration documentation is incomplete./ [[doom-contrib-module:][Complete it?]]
#+end_quote #+end_quote
** Support for Idris 2
While [[doom-package:idris-mode]] was designed for v1 of the IDE-Protocol of Idris,
it tries to maintain compatibility with v2. However, not all the features have
been realized, so expect a little jank.
To get this working, simply set [[var:idris-interpreter-path]] to the path of the
=idris2= executable. E.g.
#+begin_src emacs-lisp
;;; add to $DOODMIR/config.el
(after! idris-mode
(setq idris-interpreter-path "idris2"))
#+end_src
* Troubleshooting * Troubleshooting
/There are no known problems with this module./ [[doom-report:][Report one?]] /There are no known problems with this module./ [[doom-report:][Report one?]]

View file

@ -1,10 +1,12 @@
;;; lang/idris/config.el -*- lexical-binding: t; -*- ;;; lang/idris/config.el -*- lexical-binding: t; -*-
(after! idris-mode (after! idris-mode
(add-to-list 'completion-ignored-extensions ".ibc")
(add-hook 'idris-mode-hook #'turn-on-idris-simple-indent) (add-hook 'idris-mode-hook #'turn-on-idris-simple-indent)
(when (modulep! +lsp) (when (modulep! +lsp)
(add-hook 'idris-mode-hook #'lsp! 'append)) (add-hook 'idris-mode-hook #'lsp! 'append))
(set-repl-handler! 'idris-mode 'idris-pop-to-repl) (set-popup-rule! "^\\*idris-\\(notes\\|holes\\|info\\)" :select nil :ttl nil)
(set-repl-handler! 'idris-mode #'idris-pop-to-repl)
(set-lookup-handlers! 'idris-mode (set-lookup-handlers! 'idris-mode
:documentation #'idris-docs-at-point) :documentation #'idris-docs-at-point)
(map! :localleader (map! :localleader
@ -18,3 +20,9 @@
"m" #'idris-add-missing "m" #'idris-add-missing
"p" #'idris-proof-search "p" #'idris-proof-search
"h" #'idris-docs-at-point)) "h" #'idris-docs-at-point))
(use-package! flycheck-idris
:when (modulep! :checkers syntax)
:when (not (modulep! :checkers syntax +flymake))
:after idris-mode)

View file

@ -85,7 +85,7 @@ Can be a list of backends; accepts any value `company-backends' accepts.")
:type-definition #'lsp-find-type-definition) :type-definition #'lsp-find-type-definition)
;; HACK: See emacs-lsp/lsp-mode#3577 ;; HACK: See emacs-lsp/lsp-mode#3577
(unless (modulep! :lang terraform) (unless (modulep! :tools terraform)
(setq lsp-client-packages (delete 'lsp-terraform lsp-client-packages))) (setq lsp-client-packages (delete 'lsp-terraform lsp-client-packages)))
(defadvice! +lsp--respect-user-defined-checkers-a (fn &rest args) (defadvice! +lsp--respect-user-defined-checkers-a (fn &rest args)

View file

@ -63,6 +63,23 @@ be enabled. If any function returns non-nil, the mode will not be activated."
(defun +indent-guides-in-childframe-p () (defun +indent-guides-in-childframe-p ()
(frame-parameter nil 'parent-frame))) (frame-parameter nil 'parent-frame)))
;; HACK: The way `indent-bars-display-on-blank-lines' functions, it places
;; text properties with a display property containing a newline, which
;; confuses `move-to-column'. This breaks `next-line' and `evil-next-line'
;; without this advice (See jdtsmith/indent-bars#22). Advising
;; `line-move-to-column' isn't enough for `move-to-column' calls in various
;; Evil operators (`evil-delete', `evil-change', etc).
(defadvice! +indent-guides--prevent-passing-newline-a (fn col &rest args)
:around #'move-to-column
(if-let* ((indent-bars-mode)
(indent-bars-display-on-blank-lines)
(nlp (line-end-position))
(dprop (get-text-property nlp 'display))
((seq-contains-p dprop ?\n))
((> col (- nlp (point)))))
(goto-char nlp)
(apply fn col args)))
;; HACK: `indent-bars-mode' interactions with some packages poorly, often ;; HACK: `indent-bars-mode' interactions with some packages poorly, often
;; flooding whole sections of the buffer with indent guides. This section is ;; flooding whole sections of the buffer with indent guides. This section is
;; dedicated to fixing interop with those packages. ;; dedicated to fixing interop with those packages.

View file

@ -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
(+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 (prependq! prettify-symbols-alist
(or (alist-get major-mode +ligatures-extra-alist) (or (alist-get major-mode +ligatures-extra-alist)
(cl-loop for (mode . symbols) in +ligatures-extra-alist (cl-loop for (mode . symbols) in +ligatures-extra-alist
if (derived-mode-p mode) if (derived-mode-p mode)
return symbols)))) return symbols)))
(when (and (or in-mode-p in-mode-extras-p) (when prettify-symbols-alist
prettify-symbols-alist)
(when prettify-symbols-mode (when prettify-symbols-mode
(prettify-symbols-mode -1)) (prettify-symbols-mode -1))
(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,