From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: remove use of message-send-hook
Date: Thu, 17 Nov 2016 20:54:39 +0000 [thread overview]
Message-ID: <1479416079-6319-1-git-send-email-markwalters1009@gmail.com> (raw)
We use message-send-hook for two things -- tagging drafts deleted, and
tagging replied the parent message of a reply. We should not use
message-send-hook as that will affect gnus etc too. Moreover,
message-send-hook is run before the message is sent, even before the
user confirms they want to send it (if message-confirm-send is
set). This means the user can do C-c C-c to send, then cancel, and the
parent is still tagged replied.
Now we have our own send function it is natural to put these functions
there rather than in the hook. We also fix the bug mentioned
above. This is slightly tricky as message-send-and-exit kills the
compose buffer, so we need to store the tagging commands ready to be
run after the send is successful.
---
As mentioned in the commit message, we need to remove our use of
message-send-hook and fix the bug of erroneously tagging messages
"replied" or "deleted". This approach might be a little overkill (a
dolist for a list of two elements), but it avoids breaking the api
(for notmuch-message-mark-replied) and is easily extendable if we need
to add more post send tagging operations later.
Also, it seemed easiest to tweak the require orders, but maybe we
should just move the two things in notmuch-message into notmuch-mua.
Best wishes
Mark
emacs/notmuch-draft.el | 12 ++++++------
emacs/notmuch-message.el | 12 +++++++-----
emacs/notmuch-mua.el | 19 +++++++++++++++----
3 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index fb7f4f5..738628b 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -91,12 +91,15 @@ postponing and resuming a message."
"Message-id of the most recent saved draft of this message")
(make-variable-buffer-local 'notmuch-draft-id)
-(defun notmuch-draft--mark-deleted ()
+(defun notmuch-draft--mark-deleted (&optional dry-run)
"Tag the last saved draft deleted.
-Used when a new version is saved, or the message is sent."
+Used when a new version is saved, or the message is sent. If
+DRY-RUN is set, then just return a list of the arguments for
+`notmuch-tag' rather than doing the tagging."
(when notmuch-draft-id
- (notmuch-tag notmuch-draft-id '("+deleted"))))
+ (funcall (if dry-run #'list #'notmuch-tag)
+ notmuch-draft-id '("+deleted"))))
(defun notmuch-draft-quote-some-mml ()
"Quote the mml tags in `notmuch-draft-quoted-tags`."
@@ -259,9 +262,6 @@ applied to newly inserted messages)."
(setq notmuch-draft-id (when draft id)))))
-(add-hook 'message-send-hook 'notmuch-draft--mark-deleted)
-
-
(provide 'notmuch-draft)
;;; notmuch-draft.el ends here
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfe..373d38c 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -23,7 +23,6 @@
(require 'message)
(require 'notmuch-tag)
-(require 'notmuch-mua)
(defcustom notmuch-message-replied-tags '("+replied")
"List of tag changes to apply to a message when it has been replied to.
@@ -38,15 +37,18 @@ the \"inbox\" and \"todo\" tags, you would set:
:type '(repeat string)
:group 'notmuch-send)
-(defun notmuch-message-mark-replied ()
+(defun notmuch-message-mark-replied (&optional dry-run)
+ "Tag the parent message replied.
+
+If DRY-RUN is set, then just return a list of the arguments for
+`notmuch-tag' rather than doing the tagging."
;; get the in-reply-to header and parse it for the message id.
(let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
(when (and notmuch-message-replied-tags rep)
- (notmuch-tag (notmuch-id-to-query (car (car rep)))
+ (funcall (if dry-run #'list #'notmuch-tag)
+ (notmuch-id-to-query (car (car rep)))
(notmuch-tag-change-list notmuch-message-replied-tags)))))
-(add-hook 'message-send-hook 'notmuch-message-mark-replied)
-
(provide 'notmuch-message)
;;; notmuch-message.el ends here
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 93747b1..07be69a 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -28,6 +28,7 @@
(require 'notmuch-lib)
(require 'notmuch-address)
(require 'notmuch-draft)
+(require 'notmuch-message)
(eval-when-compile (require 'cl))
@@ -545,10 +546,20 @@ unencrypted. Really send? "))))
(interactive "P")
(when (and (notmuch-mua-check-no-misplaced-secure-tag)
(notmuch-mua-check-secure-tag-has-newline))
- (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
- (if exit
- (message-send-and-exit arg)
- (message-send arg)))))
+ (let (tag-change
+ post-send-tag-changes)
+ ;; post-send-tag-changes are tag-changes to apply after sending,
+ ;; but we need to store them now as the compose buffer is
+ ;; typically killed before message-send-and-exit returns.
+ (push (notmuch-message-mark-replied t) post-send-tag-changes)
+ (push (notmuch-draft--mark-deleted t) post-send-tag-changes)
+ (letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
+ (if exit
+ (message-send-and-exit arg)
+ (message-send arg)))
+ (dolist (tag-change post-send-tag-changes)
+ (when tag-change
+ (apply #'notmuch-tag tag-change))))))
(defun notmuch-mua-send-and-exit (&optional arg)
(interactive "P")
--
2.1.4
next reply other threads:[~2016-11-17 20:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-17 20:54 Mark Walters [this message]
2017-03-10 23:50 ` [PATCH] emacs: remove use of message-send-hook David Bremner
2017-03-11 1:10 ` Mark Walters
2017-03-11 13:37 ` David Bremner
2017-03-11 14:08 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1479416079-6319-1-git-send-email-markwalters1009@gmail.com \
--to=markwalters1009@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).