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
This commit is contained in:
2026-02-24 12:30:00 +01:00
parent 1346551e93
commit 02997923e4

View File

@@ -657,11 +657,27 @@ and optional priority indicator [#A]."
(setq message-cite-function #'message-cite-original-without-signature) (setq message-cite-function #'message-cite-original-without-signature)
;; Move cursor past headers to message body when opening a message ;; 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 () (defun my/mu4e-view-goto-body ()
"Position cursor at the start of the message body, skipping headers." "Position cursor at the start of the message body, skipping headers."
(run-with-idle-timer
0.05 nil
(lambda ()
(when-let ((buf (get-buffer "*mu4e-article*")))
(with-current-buffer buf
(goto-char (point-min)) (goto-char (point-min))
(when (re-search-forward "^$" nil t) ;; Skip header block: lines matching "Key: value" or continuation whitespace
(forward-line 1))) (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) (add-hook 'mu4e-view-mode-hook #'my/mu4e-view-goto-body)
;; Maildir shortcuts ;; Maildir shortcuts
(setq mu4e-maildir-shortcuts (setq mu4e-maildir-shortcuts