From b26ff9e73507550c55b86c9c1509c91c3b22db49 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Fri, 20 Feb 2026 07:47:47 -0800 Subject: [PATCH] Edit some email stuff --- elisp/org-mu4e-compose.el | 60 ++++++++++++++++----------------- init.el | 70 +++++++++++++++++++++++++-------------- 2 files changed, 74 insertions(+), 56 deletions(-) diff --git a/elisp/org-mu4e-compose.el b/elisp/org-mu4e-compose.el index b020ed5..336d3a2 100644 --- a/elisp/org-mu4e-compose.el +++ b/elisp/org-mu4e-compose.el @@ -16,27 +16,10 @@ (defvar-local org-mu4e--html-message-p t "Weather or not the current message should be htmlized.") -(defvar-local org-mu4e--override-org-mode-check nil - "Internal variable. -See `org-mu4e--override-org-mode-check-advice' for information about what this -does.") - (defvar org-mu4e--internal-message-mode-function (symbol-function 'mu4e-compose-mode) "The `message-mode' (or derived mode) used by `org-mu4e-compose-mode'.") -(defun org-mu4e--override-org-mode-check-advice (oldfun &rest r) - "Around advice for various org mode functions. -This function will call OLDFUN with arguments R with `major-mode' let-bound to -\\='org-mode when `org-mu4e--override-org-mode-check' is t." - (let ((major-mode (if org-mu4e--override-org-mode-check - 'org-mode - major-mode))) - (apply oldfun r))) - -(advice-add 'org-element-at-point :around - 'org-mu4e--override-org-mode-check-advice) - (defun org-mu4e-toggle-htmlize-mssage (&optional arg no-message) "Toggle weather the current message should be htmlized. If ARG is a positive number or zero, enable htmlization, if it is negative, @@ -206,17 +189,22 @@ ARG is passed directly to `message-send'." t ;; this tells org that we have handled the C-c C-c ) +(defmacro org-mu4e--with-replaced-compse-func (&rest body) + "Evaluate BODY with `mu4e-compose-mode' rebound to `org-mu4e-compose-mode'. +This makes use of `cl-letf' internally." + `(let ((org-mu4e--internal-message-mode-function + (symbol-function 'mu4e-compose-mode))) + (cl-letf (((symbol-function 'mu4e-compose-mode) 'org-mu4e-compose-mode)) + ,@body))) + ;;;###autoload (defun org-mu4e-compose-new (&rest r) "This is like `mu4e-compose-new', but it utilizes `org-mu4e-compose-mode'. Each of the arguments in R are the same as `mu4e-compose-new', and are directly passed to it." (interactive) - ;; Save local variables set by `mu4e-compose-new' - (let ((org-mu4e--internal-message-mode-function - (symbol-function 'mu4e-compose-mode))) - (cl-letf (((symbol-function 'mu4e-compose-mode) 'org-mu4e-compose-mode)) - (apply 'mu4e-compose-new r)))) + (org-mu4e--with-replaced-compse-func + (apply 'mu4e-compose-new r))) ;;;###autoload (defun org-mu4e-compose-reply-to (&optional to wide) @@ -227,15 +215,13 @@ TO and WIDE are the same as `mu4e-compose-reply-to'." (let ((html-part-p (seq-find (lambda (handle) (equal (mm-handle-media-type (cdr handle)) "text/html")) - gnus-article-mime-handle-alist)) - (org-mu4e--internal-message-mode-function - (symbol-function 'mu4e-compose-mode))) - (cl-letf (((symbol-function 'mu4e-compose-mode) 'org-mu4e-compose-mode)) - (let ((buf (mu4e-compose-reply-to to wide))) - (with-current-buffer buf - (setq org-mu4e--html-message-p - ;; make the variable look nicer by not having random data in it - (not (not html-part-p)))))))) + gnus-article-mime-handle-alist))) + (org-mu4e--with-replaced-compse-func + (let ((buf (mu4e-compose-reply-to to wide))) + (with-current-buffer buf + (setq org-mu4e--html-message-p + ;; make the variable look nicer by not having random data in it + (not (not html-part-p)))))))) ;;;###autoload (defun org-mu4e-compose-reply (&optional wide) @@ -244,6 +230,13 @@ WIDE is the same as `mu4e-compose-reply'." (interactive "P") (org-mu4e-compose-reply-to nil wide)) +;;;###autoload +(defun org-mu4e-compose-edit () + "This is like `mu4e-compose-edit', but utilizes `org-mu4e-compose-mode'." + (interactive) + (org-mu4e--with-replaced-compse-func + (mu4e-compose-edit))) + ;;;###autoload (defvar-keymap org-mu4e-compose-mode-map :parent org-mode-map @@ -340,13 +333,16 @@ This is derived from `org-mode', but it also essentially runs ;; Add `message-mode' keyword and quote highlighting on top of the org syntax ;; highlighting (font-lock-add-keywords nil message-font-lock-keywords) - (setq-local org-mu4e--override-org-mode-check t) + (setq-local org-mu4e--override-org-mode-check t + org-export-with-toc nil) (add-to-list (make-local-variable 'org-ctrl-c-ctrl-c-final-hook) 'org-mu4e-send-and-exit) (add-to-list (make-local-variable 'mode-line-misc-info) '(:eval (if org-mu4e--html-message-p "Text/HTML " "Text Only ")))) +;;;###autoload(derived-mode-add-parents 'org-mu4e-compose-mode '(mu4e-compose-mode)) +(derived-mode-add-parents 'org-mu4e-compose-mode '(mu4e-compose-mode)) ;;;###autoload (define-mail-user-agent 'org-mu4e-user-agent diff --git a/init.el b/init.el index bc52a71..36479fc 100644 --- a/init.el +++ b/init.el @@ -2352,6 +2352,14 @@ Note that this erases the buffer before doing anything." (advice-add 'jupyter-org--set-src-block-cache :around #'my/-fix-jupyter-org--set-src-block-cache) + ;; prevent warning in `execute-extended-command' + (defun my/-fix-jupyter-org--define-key-filter (oldfun &rest args) + "Prevent calling `jupyter-org--define-key-filter' outside of `org-mode'." + (when (derived-mode-p 'org-mode) + (apply oldfun args))) + (advice-add 'jupyter-org--define-key-filter :around + #'my/-fix-jupyter-org--define-key-filter) + (face-spec-set 'jupyter-repl-traceback '((default . (:background unspecified))) 'face-override-spec) @@ -3317,30 +3325,44 @@ This will also update waybar." ;; mu4e compose HTML messages (use-package org-mime) (require 'org-mu4e-compose) -(setq ;; mail-user-agent 'org-mu4e-user-agent - org-mime-org-html-with-latex-default 'dvisvgm - org-mime-export-options '(:with-latex dvisvgm :with-footnotes t)) -;; (evil-define-key '(normal visual) org-mu4e-compose-mode-map -;; "G" #'mu4e-compose-goto-bottom -;; "gg" #'mu4e-compose-goto-top) -;; (evil-define-key 'normal org-mu4e-compose-mode-map -;; "ZZ" #'message-send-and-exit -;; "ZD" #'message-dont-send -;; "ZQ" #'message-kill-buffer -;; "ZF" #'mml-attach-file) -;; (evil-define-key 'normal mu4e-view-mode-map -;; "R" 'org-mu4e-compose-reply -;; "cr" 'org-mu4e-compose-reply) -;; (evil-define-key 'normal mu4e-headers-mode-map -;; "R" 'org-mu4e-compose-reply -;; "cr" 'org-mu4e-compose-reply) -;; (defun my/-setup-org-mu4e-compose-mode () -;; "Setup up stuff in `org-mu4e-compose' buffers." -;; (setq-local ltex-eglot-variable-save-method 'file) -;; ;; this should come last so it can pick up the above -;; ;; (my/eglot-if-trusted) -;; ) -;; (add-hook 'org-mu4e-compose-mode-hook #'my/-setup-org-mu4e-compose-mode) +(setq mail-user-agent 'org-mu4e-user-agent + org-mime-org-html-with-latex-default 'dvisvgm + org-mime-export-options '(:with-latex dvisvgm :with-footnotes t)) +(evil-define-key '(normal visual) org-mu4e-compose-mode-map + "G" #'mu4e-compose-goto-bottom + "gg" #'mu4e-compose-goto-top) +(evil-define-key 'normal org-mu4e-compose-mode-map + "ZZ" #'message-send-and-exit + "ZD" #'message-dont-send + "ZQ" #'message-kill-buffer + "ZF" #'mml-attach-file) +(evil-define-key 'normal mu4e-view-mode-map + "R" #'org-mu4e-compose-reply + "cr" #'org-mu4e-compose-reply + "ce" #'org-mu4e-compose-edit) +(evil-define-key 'normal mu4e-headers-mode-map + "R" #'org-mu4e-compose-reply + "cr" #'org-mu4e-compose-reply + "E" #'org-mu4e-compose-edit + "ce" #'org-mu4e-compose-edit) +(evil-define-key 'normal mu4e-main-mode-map + "C" #'compose-mail + "cc" #'compose-mail) +(defun my/-setup-org-mu4e-compose-mode () + "Setup up stuff in `org-mu4e-compose' buffers." + (setq-local ltex-eglot-variable-save-method 'file) + ;; this should come last so it can pick up the above + ;; (my/eglot-if-trusted) + ) +(add-hook 'org-mu4e-compose-mode-hook #'my/-setup-org-mu4e-compose-mode) +(setopt mu4e-compose-switch 'display-buffer) +(defun my/-match-mu4e-message-buffer (buffer _action) + "Matcher for mu4e message buffers for `display-buffer-alist'. +BUFFER is the buffer-or-string to match against." + (provided-mode-derived-p (buffer-local-value 'major-mode (get-buffer buffer)) + 'mu4e-compose-mode)) +(add-to-list 'display-buffer-alist + '(my/-match-mu4e-message-buffer . (display-buffer-same-window))) ;; elfeed (use-package elfeed