Edit some email stuff

This commit is contained in:
2026-02-20 07:47:47 -08:00
parent eca7942215
commit b26ff9e735
2 changed files with 74 additions and 56 deletions

View File

@ -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