Skip to content

Commit

Permalink
Support gnus-dired attach file feature
Browse files Browse the repository at this point in the history
This patch adds the support of the `gnus-dired-attach' feature when
org-msg-mode is enabled.

This patch is an alternative to the implementation submitted in #118.

Suggested-by: Philip Heringlake
Signed-off-by: Jeremy Compostella <[email protected]>
  • Loading branch information
jeremy-compostella committed Jul 16, 2021
1 parent b0449e3 commit 797785f
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion org-msg.el
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
(require 'cl-seq)
(require 'gnus-art)
(require 'gnus-cite)
(require 'gnus-dired)
(require 'gnus-msg)
(require 'htmlize)
(require 'message)
Expand Down Expand Up @@ -1265,7 +1266,7 @@ function is called. `org-cycle' is called otherwise."
(org-cycle)
(message-tab)))

(defun org-msg-attach-attach (file)
(defun org-msg-attach-attach (file &rest _args)
"Link FILE into the list of attachment."
(interactive (list (read-file-name "File to attach: ")))
(let ((files (org-msg-get-prop "attachment")))
Expand Down Expand Up @@ -1298,6 +1299,21 @@ d Delete one attachment, you will be prompted for a file name."))
(cond ((memq c '(?a ?\C-a)) (call-interactively 'org-msg-attach-attach))
((memq c '(?d ?\C-d)) (call-interactively 'org-msg-attach-delete)))))

(defun org-msg-dired-attach (orig-fun files-to-attach)
"Attach dired's marked files to a OrgMsg message composition.
This function is used as an advice function of
`gnus-dired-attach'."
(cl-flet* ((mail-buffer-p (b)
(with-current-buffer b
(and (derived-mode-p 'org-msg-edit-mode)
(null message-sent-message-via))))
(mail-buffers ()
(when-let (bufs (cl-remove-if-not #'mail-buffer-p (buffer-list)))
(mapcar 'buffer-name bufs))))
(cl-letf (((symbol-function #'mml-attach-file) #'org-msg-attach-attach)
((symbol-function #'gnus-dired-mail-buffers) #'mail-buffers))
(funcall orig-fun files-to-attach))))

(defun org-msg-start ()
"Return the point of the beginning of the message body."
(save-excursion
Expand Down Expand Up @@ -1403,6 +1419,7 @@ HTML emails."
(unless (org-msg-mml-recursive-support)
(advice-add 'mml-expand-html-into-multipart-related
:around #'org-msg-mml-into-multipart-related))
(advice-add 'gnus-dired-attach :around #'org-msg-dired-attach)
(advice-add 'org-html--todo :around #'org-msg-html--todo)
(when (boundp 'bbdb-mua-mode-alist)
(add-to-list 'bbdb-mua-mode-alist '(message org-msg-edit-mode))))
Expand All @@ -1414,6 +1431,7 @@ HTML emails."
(unless (org-msg-mml-recursive-support)
(advice-remove 'mml-expand-html-into-multipart-related
#'org-msg-mml-into-multipart-related))
(advice-remove 'gnus-dired-attach #'org-msg-dired-attach)
(advice-remove 'org-html--todo #'org-msg-html--todo)
(when (boundp 'bbdb-mua-mode-alist)
(setq bbdb-mua-mode-alist (delete '(message org-msg-edit-mode)
Expand Down

0 comments on commit 797785f

Please sign in to comment.