From d317fa4667630df69f3adb6d2c1b8484f033b8d4 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 9 Apr 2024 12:29:22 -0400 Subject: [PATCH 1/8] refactor: menu-bar (re)initialization on MacOS Before this, it was non-trivial to *truly* disable the menu-bar in GUI frames on MacOS, unless you knew about the doom-restore-menu-bar-in-gui-frames-h hook and removed it. With this change, the hook will bow out if the user has tampered with/called menu-bar-mode at all. --- lisp/doom-start.el | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/lisp/doom-start.el b/lisp/doom-start.el index ce022d7cd..239a6f1d1 100644 --- a/lisp/doom-start.el +++ b/lisp/doom-start.el @@ -101,34 +101,40 @@ ;;; Disable UI elements early ;; PERF,UI: Doom strives to be keyboard-centric, so I consider these UI elements ;; clutter. Initializing them also costs a morsel of startup time. What's -;; more, the menu bar exposes functionality that Doom doesn't endorse. Perhaps -;; one day Doom will support these, but today is not that day. By disabling -;; them early, we save Emacs some time. +;; more, the menu bar exposes functionality that Doom doesn't endorse or +;; police. Perhaps one day Doom will support these, but today is not that day. +;; By disabling them early, we save Emacs some time. ;; HACK: I intentionally avoid calling `menu-bar-mode', `tool-bar-mode', and ;; `scroll-bar-mode' because their manipulation of frame parameters can ;; trigger/queue a superfluous (and expensive, depending on the window system) -;; frame redraw at startup. +;; frame redraw at startup. The variables must be set to `nil' as well so +;; users don't have to call the functions twice to re-enable them. (push '(menu-bar-lines . 0) default-frame-alist) (push '(tool-bar-lines . 0) default-frame-alist) (push '(vertical-scroll-bars) default-frame-alist) -;; And set these to nil so users don't have to toggle the modes twice to -;; reactivate them. (setq menu-bar-mode nil tool-bar-mode nil scroll-bar-mode nil) -;; FIX: On MacOS, disabling the menu bar makes MacOS treat Emacs as a -;; non-application window -- which means it doesn't automatically capture -;; focus when it is started, among other things, so enable the menu-bar for -;; GUI frames, but keep it disabled in terminal frames because there it -;; unavoidably activates an ugly, in-frame menu bar. -(eval-when! doom--system-macos-p - (add-hook! '(window-setup-hook after-make-frame-functions) - (defun doom-restore-menu-bar-in-gui-frames-h (&optional frame) - (when-let (frame (or frame (selected-frame))) - (when (display-graphic-p frame) - (set-frame-parameter frame 'menu-bar-lines 1)))))) +;; HACK: The menu-bar needs special treatment on MacOS. On Linux and Windows +;; (and TTY frames in MacOS), the menu-bar takes up valuable in-frame real +;; estate -- so we disable it -- but on MacOS (GUI frames only) the menu bar +;; lives outside of the frame, on the MacOS menu bar, which is acceptable, but +;; disabling Emacs' menu-bar also makes MacOS treat Emacs GUI frames like +;; non-application windows (e.g. it won't capture focus on activation, among +;; other things), so the menu-bar should be preserved there. +;; +(when doom--system-macos-p + ;; NOTE: The correct way to disable this hack is to toggle `menu-bar-mode' (or + ;; put it on a hook). Don't try to undo the hack below, as it may change + ;; without warning, but will always respect `menu-bar-mode'. + (setcdr (assq 'menu-bar-lines default-frame-alist) 'tty) + (add-hook! 'after-make-frame-functions + (defun doom--init-menu-bar-on-macos-h (&optional frame) + (if (eq (frame-parameter frame 'menu-bar-lines) 'tty) + (set-frame-parameter frame 'menu-bar-lines + (if (display-graphic-p frame) 1 0)))))) ;;; Encodings ;; Contrary to what many Emacs users have in their configs, you don't need more From 96e3255c330af96900437cee5a1ff3465b18d6b8 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 9 Apr 2024 12:39:51 -0400 Subject: [PATCH 2/8] nit: reformat+revise comments Includes minor refactors to appease the byte-compiler or use more succinct (but equivalent) syntax. --- lisp/doom-editor.el | 43 +++++++++++++------------- modules/checkers/syntax/config.el | 6 ++-- modules/completion/corfu/config.el | 15 +++++---- modules/lang/org/autoload/org-babel.el | 2 +- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/lisp/doom-editor.el b/lisp/doom-editor.el index 80696ac35..60f8a2bff 100644 --- a/lisp/doom-editor.el +++ b/lisp/doom-editor.el @@ -143,11 +143,11 @@ tell you about it. Very annoying. This prevents that." (letf! ((#'sit-for #'ignore)) (apply fn args))) -;; HACK Emacs generates long file paths for its auto-save files; long = -;; `auto-save-list-file-prefix' + `buffer-file-name'. If too long, the -;; filesystem will murder your family. To appease it, I compress -;; `buffer-file-name' to a stable 40 characters. -;; TODO PR this upstream; should be a universal issue! +;; HACK: Emacs generates long file paths for its auto-save files; long = +;; `auto-save-list-file-prefix' + `buffer-file-name'. If too long, the +;; filesystem will murder your family. To appease it, I compress +;; `buffer-file-name' to a stable 40 characters. +;; TODO: PR this upstream; should be a universal issue! (defadvice! doom-make-hashed-auto-save-file-name-a (fn) "Compress the auto-save file name so paths don't get too long." :around #'make-auto-save-file-name @@ -156,7 +156,7 @@ tell you about it. Very annoying. This prevents that." ;; Don't do anything for non-file-visiting buffers. Names ;; generated for those are short enough already. (null buffer-file-name) - ;; If an alternate handler exists for this path, bow out. Most of + ;; If an alternate handler exists for this path, bow out. Most of ;; them end up calling `make-auto-save-file-name' again anyway, so ;; we still achieve this advice's ultimate goal. (find-file-name-handler buffer-file-name @@ -165,8 +165,8 @@ tell you about it. Very annoying. This prevents that." (sha1 buffer-file-name)))) (funcall fn))) -;; HACK ...does the same for Emacs backup files, but also packages that use -;; `make-backup-file-name-1' directly (like undo-tree). +;; HACK: ...does the same for Emacs backup files, but also packages that use +;; `make-backup-file-name-1' directly (like undo-tree). (defadvice! doom-make-hashed-backup-file-name-a (fn file) "A few places use the backup file name so paths don't get too long." :around #'make-backup-file-name-1 @@ -191,7 +191,7 @@ tell you about it. Very annoying. This prevents that." ;; Favor spaces over tabs. Pls dun h8, but I think spaces (and 4 of them) is a ;; more consistent default than 8-space tabs. It can be changed on a per-mode -;; basis anyway (and is, where tabs are the canonical style, like go-mode). +;; basis anyway (and is, where tabs are the canonical style, like `go-mode'). (setq-default indent-tabs-mode nil tab-width 4) @@ -269,19 +269,20 @@ tell you about it. Very annoying. This prevents that." ;; Only prompts for confirmation when buffer is unsaved. revert-without-query (list ".")) - ;; `auto-revert-mode' and `global-auto-revert-mode' would, normally, abuse the - ;; heck out of file watchers _or_ aggressively poll your buffer list every X - ;; seconds. Too many watchers can grind Emacs to a halt if you preform - ;; expensive or batch processes on files outside of Emacs (e.g. their mtime - ;; changes), and polling your buffer list is terribly inefficient as your - ;; buffer list grows into the hundreds. + ;; PERF: `auto-revert-mode' and `global-auto-revert-mode' would, normally, + ;; abuse the heck out of file watchers _or_ aggressively poll your buffer + ;; list every X seconds. Too many watchers can grind Emacs to a halt if you + ;; preform expensive or batch processes on files outside of Emacs (e.g. + ;; their mtime changes), and polling your buffer list is terribly + ;; inefficient as your buffer list grows into the hundreds. ;; - ;; Doom does this lazily instead. i.e. All visible buffers are reverted - ;; immediately when a) a file is saved or b) Emacs is refocused (after using - ;; another app). Meanwhile, buried buffers are reverted only when they are - ;; switched to. This way, Emacs only ever has to operate on, at minimum, a - ;; single buffer and, at maximum, ~10 buffers (after all, when do you ever - ;; have more than 10 windows in any single frame?). + ;; Doom does this lazily instead. i.e. All visible buffers are reverted + ;; immediately when a) a file is saved or b) Emacs is refocused (after using + ;; another app). Meanwhile, buried buffers are reverted only when they are + ;; switched to. This way, Emacs only ever has to operate on, at minimum, a + ;; single buffer and, at maximum, ~10 x F buffers, where F = number of open + ;; frames (after all, when do you ever have more than 10 windows in any + ;; single frame?). (defun doom-auto-revert-buffer-h () "Auto revert current buffer, if necessary." (unless (or auto-revert-mode (active-minibuffer-window)) diff --git a/modules/checkers/syntax/config.el b/modules/checkers/syntax/config.el index faa1b730e..a458d8768 100644 --- a/modules/checkers/syntax/config.el +++ b/modules/checkers/syntax/config.el @@ -87,12 +87,10 @@ ;; ;;; Flymake + (use-package! flymake :when (modulep! +flymake) - :defer t - :init - ;; as flymakes fail silently there is no need to activate it on a per major mode basis - (add-hook! (prog-mode text-mode) #'flymake-mode) + :hook ((prog-mode text-mode) . flymake-mode) :config (setq flymake-fringe-indicator-position 'right-fringe)) diff --git a/modules/completion/corfu/config.el b/modules/completion/corfu/config.el index a65194aba..ccef3a811 100644 --- a/modules/completion/corfu/config.el +++ b/modules/completion/corfu/config.el @@ -44,12 +44,11 @@ use the minibuffer such as `query-replace'.") (setq corfu-auto t corfu-auto-delay 0.18 corfu-auto-prefix 2 - global-corfu-modes '((not - erc-mode - circe-mode - help-mode - gud-mode - vterm-mode) + global-corfu-modes '((not erc-mode + circe-mode + help-mode + gud-mode + vterm-mode) t) corfu-cycle t corfu-preselect 'prompt @@ -67,8 +66,8 @@ use the minibuffer such as `query-replace'.") (add-to-list 'corfu-continue-commands #'+corfu-smart-sep-toggle-escape) (add-hook 'evil-insert-state-exit-hook #'corfu-quit) - ;; If you want to update the visual hints after completing minibuffer commands - ;; with Corfu and exiting, you have to do it manually. + ;; HACK: If you want to update the visual hints after completing minibuffer + ;; commands with Corfu and exiting, you have to do it manually. (defadvice! +corfu--insert-before-exit-minibuffer-a () :before #'exit-minibuffer (when (or (and (frame-live-p corfu--frame) diff --git a/modules/lang/org/autoload/org-babel.el b/modules/lang/org/autoload/org-babel.el index de8ba79aa..60ed4e4f7 100644 --- a/modules/lang/org/autoload/org-babel.el +++ b/modules/lang/org/autoload/org-babel.el @@ -40,7 +40,7 @@ ((user-error "Definition lookup in SRC blocks isn't supported yet")))))) ;;;###autoload -(defun +org-lookup-references-handler (identifier) +(defun +org-lookup-references-handler (_identifier) "TODO" (when (org-in-src-block-p t) (user-error "References lookup in SRC blocks isn't supported yet"))) From ff4a0bc54a661f77bae8fe844fea3386c26bc594 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 9 Apr 2024 12:42:00 -0400 Subject: [PATCH 3/8] fix: doom-run-hook-on: check context & chain hooks unconditionally Consult the doom-context to determine if a transient hook should fire, rather than after-init-time (less reliable; there may be times we want them to fire post-init). Also ensures that they're chained to find-file hooks whether or not this is a daemon session (since they could concievably be triggered before the daemon finishes initializing, but after Doom initializes). --- lisp/doom-lib.el | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lisp/doom-lib.el b/lisp/doom-lib.el index fd6f34967..8f87b885b 100644 --- a/lisp/doom-lib.el +++ b/lisp/doom-lib.el @@ -246,29 +246,29 @@ TRIGGER-HOOK is a list of quoted hooks and/or sharp-quoted functions." (fset fn (lambda (&rest _) ;; Only trigger this after Emacs has initialized. - (when (and after-init-time - (not running?) + (when (and (not running?) + (not (doom-context-p 'init)) (or (daemonp) ;; In some cases, hooks may be lexically unset to ;; inhibit them during expensive batch operations on ;; buffers (such as when processing buffers - ;; internally). In these cases we should assume this - ;; hook wasn't invoked interactively. + ;; internally). In that case assume this hook was + ;; invoked non-interactively. (and (boundp hook) (symbol-value hook)))) (setq running? t) ; prevent infinite recursion (doom-run-hooks hook-var) (set hook-var nil)))) - (cond ((daemonp) - ;; In a daemon session we don't need all these lazy loading - ;; shenanigans. Just load everything immediately. - (add-hook 'after-init-hook fn 'append)) - ((eq hook 'find-file-hook) - ;; Advise `after-find-file' instead of using `find-file-hook' - ;; because the latter is triggered too late (after the file has - ;; opened and modes are all set up). - (advice-add 'after-find-file :before fn '((depth . -101)))) - ((add-hook hook fn -101))) + (when (daemonp) + ;; In a daemon session we don't need all these lazy loading shenanigans. + ;; Just load everything immediately. + (add-hook 'server-after-make-frame-hook fn 'append)) + (if (eq hook 'find-file-hook) + ;; Advise `after-find-file' instead of using `find-file-hook' because + ;; the latter is triggered too late (after the file has opened and + ;; modes are all set up). + (advice-add 'after-find-file :before fn '((depth . -101))) + (add-hook hook fn -101)) fn))) (defun doom-compile-functions (&rest fns) From fdeb8562109125f74edd04a9843db6e9094b69c2 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 11 Apr 2024 21:27:09 -0400 Subject: [PATCH 4/8] fix(spell): spell-fu: remove unneeded advice These issues were addressed upstream. Ref: emacsmirror/spell-fu@50be652a6ec8 Ref: emacsmirror/spell-fu@00af362af3e4 --- modules/checkers/spell/config.el | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/modules/checkers/spell/config.el b/modules/checkers/spell/config.el index 438bb8762..035452930 100644 --- a/modules/checkers/spell/config.el +++ b/modules/checkers/spell/config.el @@ -135,28 +135,6 @@ prog-mode-hook) #'spell-fu-mode)) :config - ;; TODO PR this fix upstream! - (defadvice! +spell--fix-face-detection-a (fn &rest args) - "`spell-fu--faces-at-point' uses face detection that won't penetrary -overlays (like `hl-line'). This makes `spell-fu-faces-exclude' demonstrably less -useful when it'll still spellcheck excluded faces on any line that `hl-line' is -displayed on, even momentarily." - :around #'spell-fu--faces-at-point - (letf! (defun get-char-property (pos prop &optional obj) - (or (plist-get (text-properties-at pos) prop) - (funcall get-char-property pos prop obj))) - (apply fn args))) - - (defadvice! +spell--create-word-dict-a (_word words-file _action) - "Prevent `spell-fu--word-add-or-remove' from throwing non-existant -directory errors when writing a personal dictionary file (by creating the -directory first)." - :before #'spell-fu--word-add-or-remove - (unless (file-exists-p words-file) - (make-directory (file-name-directory words-file) t) - (with-temp-file words-file - (insert (format "personal_ws-1.1 %s 0\n" ispell-dictionary))))) - (add-hook! 'spell-fu-mode-hook (defun +spell-init-excluded-faces-h () "Set `spell-fu-faces-exclude' according to `+spell-excluded-faces-alist'." From 5b7d6763f8f899e556c7c5d89556bf39a1c81f64 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 11 Apr 2024 21:51:14 -0400 Subject: [PATCH 5/8] revert: org emacs-straight/org-mode@e9c288dfaccc -> emacs-straight/org-mode@5bdfc02c6fa1 org-mode was bumped in 5f5a163, but this introduced substantial slowdowns in buffers where src and latex blocks were natively highlighted. This reverts to the latest known commit that doesn't present this slowness (which is still newer than the commit used in 5f5a163). Amend: 5f5a163c4920 --- modules/lang/org/packages.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/lang/org/packages.el b/modules/lang/org/packages.el index f064bbb99..b35d498ea 100644 --- a/modules/lang/org/packages.el +++ b/modules/lang/org/packages.el @@ -31,7 +31,7 @@ (format "(defun org-git-version (&rest _) \"%s-??-%s\")\n" version (cdr (doom-call-process "git" "rev-parse" "--short" "HEAD"))) "(provide 'org-version)\n"))))) - :pin "e9c288dfaccc2960e5b6889e6aabea700ad4e05a") + :pin "5bdfc02c6fa1b9ad4f075ac1ad1e4086ead310db") (package! org-contrib :recipe (:host github :repo "emacsmirror/org-contrib") From 5a92e1b94aeaba60149bb150bbadded0a0f5a1bd Mon Sep 17 00:00:00 2001 From: Levin Du Date: Tue, 16 Apr 2024 14:59:04 +0800 Subject: [PATCH 6/8] fix: doom-initialize-core-packages: extract plist from alist The doom-package-list is a list of (module :key value ...). To get the plist, apply cdr first. --- lisp/doom-packages.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/doom-packages.el b/lisp/doom-packages.el index 72d3896b6..90ffb5154 100644 --- a/lisp/doom-packages.el +++ b/lisp/doom-packages.el @@ -256,7 +256,7 @@ uses a straight or package.el command directly).") (alist-get 'straight packages) (doom--ensure-straight recipe pin)) (doom--ensure-core-packages - (seq-filter (fn! (eq (plist-get % :type) 'core)) + (seq-filter (fn! (eq (plist-get (cdr %) :type) 'core)) packages))))) (defun doom-initialize-packages (&optional force-p) From ede616fdd7c4c8d61094011fb9e1b9d7a61a4187 Mon Sep 17 00:00:00 2001 From: Levin Du Date: Tue, 16 Apr 2024 15:00:56 +0800 Subject: [PATCH 7/8] fix(cli): doom-packages-ensure: ensure local packages are built If the package is local, the local-repo has absolute local file path, and straight-modified-dir will return as it is, which always exists. Fix it by passing package only to straight-modified-dir. --- lisp/cli/packages.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/cli/packages.el b/lisp/cli/packages.el index 2f81d22b5..4d0e4b29f 100644 --- a/lisp/cli/packages.el +++ b/lisp/cli/packages.el @@ -301,7 +301,7 @@ list remains lean." (setq want-native-compile nil)) (and (or want-byte-compile want-native-compile) (or (file-newer-than-file-p repo-dir build-dir) - (file-exists-p (straight--modified-dir (or local-repo package))) + (file-exists-p (straight--modified-dir package)) (cl-loop with outdated = nil for file in (doom-files-in build-dir :match "\\.el$" :full t) if (or (if want-byte-compile (doom-packages--elc-file-outdated-p file)) From 0a635e9df9bea8a4cfa56e9cec0203aa28c61df2 Mon Sep 17 00:00:00 2001 From: StrawberryTea Date: Tue, 16 Apr 2024 03:29:36 -0500 Subject: [PATCH 8/8] fix(direnv): fix void function error in emacs30 --- modules/tools/direnv/config.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/tools/direnv/config.el b/modules/tools/direnv/config.el index a2982c2a3..b9f4f5045 100644 --- a/modules/tools/direnv/config.el +++ b/modules/tools/direnv/config.el @@ -15,7 +15,9 @@ ;; hooks, but not the body. (add-hook! 'envrc-global-mode-hook (defun +direnv-init-global-mode-earlier-h () - (let ((fn #'envrc-global-mode-enable-in-buffers)) + (let ((fn (if (fboundp #'envrc-global-mode-enable-in-buffers) + #'envrc-global-mode-enable-in-buffers ; Removed in Emacs 30. + #'envrc-global-mode-enable-in-buffer))) (if (not envrc-global-mode) (remove-hook 'change-major-mode-after-body-hook fn) (remove-hook 'after-change-major-mode-hook fn)