From 02997923e45ec02cf915785143f98640622c7664 Mon Sep 17 00:00:00 2001 From: Daneel Date: Tue, 24 Feb 2026 12:30:00 +0100 Subject: [PATCH] fix(mu4e): cursor to body after headers on message open Modern mu4e (1.8+) uses gnus-article-mode, not mu4e-view-mode, so mu4e-view-mode-hook never fired. Fix: - Use gnus-article-prepare-hook (primary) + mu4e-view-mode-hook (fallback) - Target *mu4e-article* buffer explicitly via when-let - Skip header lines by pattern (Key: value / continuation) instead of blank line - Add idle timer (0.05s) to ensure buffer is fully populated --- config.el | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/config.el b/config.el index ea7a92e..b4f6f49 100644 --- a/config.el +++ b/config.el @@ -657,11 +657,27 @@ and optional priority indicator [#A]." (setq message-cite-function #'message-cite-original-without-signature) ;; Move cursor past headers to message body when opening a message + ;; Modern mu4e (1.8+) uses gnus-article-mode, not mu4e-view-mode. + ;; We use mu4e-view-rendered-hook which fires after the message is displayed, + ;; with a small idle timer to ensure the buffer is fully populated. (defun my/mu4e-view-goto-body () "Position cursor at the start of the message body, skipping headers." - (goto-char (point-min)) - (when (re-search-forward "^$" nil t) - (forward-line 1))) + (run-with-idle-timer + 0.05 nil + (lambda () + (when-let ((buf (get-buffer "*mu4e-article*"))) + (with-current-buffer buf + (goto-char (point-min)) + ;; Skip header block: lines matching "Key: value" or continuation whitespace + (while (and (not (eobp)) + (looking-at "^\\([A-Za-z-]+:\\|[ \t]\\)")) + (forward-line 1)) + ;; Skip blank separator line(s) + (while (and (not (eobp)) (looking-at "^\\s-*$")) + (forward-line 1))))))) + ;; Hook into gnus-article-prepare-hook (fires in gnus-based mu4e view) + (add-hook 'gnus-article-prepare-hook #'my/mu4e-view-goto-body) + ;; Also keep mu4e-view-mode-hook as fallback for older mu4e / non-gnus view (add-hook 'mu4e-view-mode-hook #'my/mu4e-view-goto-body) ;; Maildir shortcuts (setq mu4e-maildir-shortcuts