refactor(mu4e): mu4e config

In preparation for all the work I have in store for this module.
This commit is contained in:
Henrik Lissner 2024-09-05 04:04:01 -04:00
parent 60e94479a7
commit 5c0211d635
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -20,10 +20,10 @@
(version< mu4e-mu-version "1.4")) (version< mu4e-mu-version "1.4"))
(setq mu4e-maildir "~/.mail" (setq mu4e-maildir "~/.mail"
mu4e-user-mail-address-list nil)) mu4e-user-mail-address-list nil))
(setq mu4e-attachment-dir
(lambda (&rest _)
(expand-file-name ".attachments" (mu4e-root-maildir))))
:config :config
;; mu4e now uses `display-buffer-alist' so we need to add some rules of our own
(set-popup-rule! "^\\*mu4e-\\(main\\|headers\\)\\*" :ignore t)
;; 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
;; must install via your OS package manager). ;; must install via your OS package manager).
@ -233,50 +233,46 @@ is non-nil."
;; Wrap text in messages ;; Wrap text in messages
(setq-hook! 'mu4e-view-mode-hook truncate-lines nil) (setq-hook! 'mu4e-view-mode-hook truncate-lines nil)
;; mu4e now uses `display-buffer-alist' so we need to add some rules of our own
(set-popup-rule! "^\\*mu4e-\\(main\\|headers\\)\\*" :ignore t)
;; Html mails might be better rendered in a browser ;; Html mails might be better rendered in a browser
(add-to-list 'mu4e-view-actions '("View in browser" . mu4e-action-view-in-browser)) (add-to-list 'mu4e-view-actions '("View in browser" . mu4e-action-view-in-browser))
(when (fboundp 'make-xwidget) (when (fboundp 'make-xwidget)
(add-to-list 'mu4e-view-actions '("xwidgets view" . mu4e-action-view-in-xwidget))) (add-to-list 'mu4e-view-actions '("xwidgets view" . mu4e-action-view-in-xwidget)))
;; Detect empty subjects, and give users an opotunity to fill something in ;; Detect empty subjects, and give users an opotunity to fill something in
(defun +mu4e-check-for-subject () (add-hook! 'message-send-hook
"Check that a subject is present, and prompt for a subject if not." (defun +mu4e-check-for-subject ()
(save-excursion "Check that a subject is present, and prompt for a subject if not."
(goto-char (point-min)) (save-excursion
(search-forward "--text follows this line--") (goto-char (point-min))
(re-search-backward "^Subject:") ; this should be present no matter what (search-forward "--text follows this line--")
(let ((subject (string-trim (substring (thing-at-point 'line) 8)))) (re-search-backward "^Subject:") ; this should be present no matter what
(when (string-empty-p subject) (let ((subject (string-trim (substring (thing-at-point 'line) 8))))
(end-of-line) (when (string-empty-p subject)
(insert (read-string "Subject (optional): ")) (end-of-line)
(message "Sending..."))))) (insert (read-string "Subject (optional): "))
(message "Sending..."))))))
(add-hook 'message-send-hook #'+mu4e-check-for-subject) ;; The header view needs a certain amount of horizontal space to actually show
;; you all the information you want to see so if the header view is entered
;; The header view needs a certain amount of horizontal space to ;; from a narrow frame, it's probably worth trying to expand it
;; actually show you all the information you want to see (defvar +mu4e-min-header-frame-width 120
;; so if the header view is entered from a narrow frame, "Minimum reasonable with for the header view.")
;; it's probably worth trying to expand it (add-hook! 'mu4e-headers-mode-hook
(defun +mu4e-widen-frame-maybe () (defun +mu4e-widen-frame-maybe ()
"Expand the mu4e-headers containing frame's width to `+mu4e-min-header-frame-width'." "Expand the mu4e-headers containing frame's width to `+mu4e-min-header-frame-width'."
(dolist (frame (frame-list)) (dolist (frame (frame-list))
(when (and (string= (buffer-name (window-buffer (frame-selected-window frame))) (when (and (string= (buffer-name (window-buffer (frame-selected-window frame)))
mu4e-headers-buffer-name) mu4e-headers-buffer-name)
(< (frame-width) +mu4e-min-header-frame-width)) (< (frame-width) +mu4e-min-header-frame-width))
(set-frame-width frame +mu4e-min-header-frame-width)))) (set-frame-width frame +mu4e-min-header-frame-width)))))
(add-hook 'mu4e-headers-mode-hook #'+mu4e-widen-frame-maybe)
(when (fboundp 'imagemagick-register-types) (when (fboundp 'imagemagick-register-types)
(imagemagick-register-types)) (imagemagick-register-types))
(when (modulep! :ui workspaces) (map! (:when (modulep! :ui workspaces)
(map! :map mu4e-main-mode-map :map mu4e-main-mode-map
:ne "h" #'+workspace/other)) :ne "h" #'+workspace/other)
:map mu4e-headers-mode-map
(map! :map mu4e-headers-mode-map
:vne "l" #'+mu4e/capture-msg-to-agenda) :vne "l" #'+mu4e/capture-msg-to-agenda)
;; Functionality otherwise obscured in mu4e 1.6 ;; Functionality otherwise obscured in mu4e 1.6
@ -354,18 +350,19 @@ Acts like a singular `mu4e-view-save-attachments', without the saving."
:desc "save draft" "S" #'message-dont-send :desc "save draft" "S" #'message-dont-send
:desc "attach" "a" #'+mu4e/attach-files) :desc "attach" "a" #'+mu4e/attach-files)
;; Due to evil, none of the marking commands work when making a visual selection in ;; Due to evil, none of the marking commands work when making a visual
;; the headers view of mu4e. Without overriding any evil commands we may actually ;; selection in the headers view of mu4e. Without overriding any evil commands
;; want to use in and evil selection, this can be easily fixed. ;; we may actually want to use in and evil selection, this can be easily
(when (modulep! :editor evil) ;; fixed.
(map! :map mu4e-headers-mode-map (map! :map mu4e-headers-mode-map
:v "*" #'mu4e-headers-mark-for-something :v "*" #'mu4e-headers-mark-for-something
:v "!" #'mu4e-headers-mark-for-read :v "!" #'mu4e-headers-mark-for-read
:v "?" #'mu4e-headers-mark-for-unread :v "?" #'mu4e-headers-mark-for-unread
:v "u" #'mu4e-headers-mark-for-unmark)) :v "u" #'mu4e-headers-mark-for-unmark)
(add-hook 'mu4e-compose-pre-hook '+mu4e-set-from-address-h) (add-hook 'mu4e-compose-pre-hook #'+mu4e-set-from-address-h)
;; HACK
(defadvice! +mu4e-ensure-compose-writeable-a (&rest _) (defadvice! +mu4e-ensure-compose-writeable-a (&rest _)
"Ensure that compose buffers are writable. "Ensure that compose buffers are writable.
This should already be the case yet it does not always seem to be." This should already be the case yet it does not always seem to be."
@ -375,15 +372,14 @@ This should already be the case yet it does not always seem to be."
:before #'mu4e-compose-resend :before #'mu4e-compose-resend
(read-only-mode -1)) (read-only-mode -1))
;; process lock control ;; HACK: process lock control
(when (featurep :system 'windows) (when (featurep :system 'windows)
(setq (setq +mu4e-lock-file (expand-file-name "~/AppData/Local/Temp/mu4e_lock")
+mu4e-lock-file (expand-file-name "~/AppData/Local/Temp/mu4e_lock") +mu4e-lock-request-file (expand-file-name "~/AppData/Local/Temp/mu4e_lock_request")))
+mu4e-lock-request-file (expand-file-name "~/AppData/Local/Temp/mu4e_lock_request")))
(add-hook 'kill-emacs-hook #'+mu4e-lock-file-delete-maybe) (add-hook 'kill-emacs-hook #'+mu4e-lock-file-delete-maybe)
(advice-add 'mu4e--start :around #'+mu4e-lock-start) (advice-add #'mu4e--start :around #'+mu4e-lock-start)
(advice-add 'mu4e-quit :after #'+mu4e-lock-file-delete-maybe)) (advice-add #'mu4e-quit :after #'+mu4e-lock-file-delete-maybe))
(use-package! org-msg (use-package! org-msg