* [PATCH] emacs: Add notmuch-before/after-tag-hook
@ 2011-05-16 20:48 Daniel Schoepe
2011-05-24 20:29 ` Carl Worth
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Schoepe @ 2011-05-16 20:48 UTC (permalink / raw)
To: notmuch
[-- Attachment #1.1: Type: text/plain, Size: 690 bytes --]
From the commit message:
emacs: add notmuch-before- and notmuch-after-tag-hook
This patch adds hooks that are run before/after messages are tagged
from the emacs interface. In order to implement this and to avoid
having hooks parse all the arguments to the notmuch binary again, I
created a `notmuch-tag' function that other modules should use instead
of running (notmuch-call-notmuch-process "tag" ...) directly.
I wasn't sure about adding the notmuch-tag function, but I think it is a
bit cleaner than calling notmuch-call-notmuch-process directly in so
many places anyway.
Of course, any comments or criticism is appreciated.
-- Daniel
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-emacs-add-notmuch-before-and-notmuch-after-tag-hook.patch --]
[-- Type: text/x-diff, Size: 5934 bytes --]
From 1acc99736a84e5294ba44368690dd79001e2e347 Mon Sep 17 00:00:00 2001
From: Daniel Schoepe <daniel.schoepe@googlemail.com>
Date: Sun, 15 May 2011 17:48:58 +0200
Subject: [PATCH] emacs: add notmuch-before- and notmuch-after-tag-hook
This patch adds hooks that are run before/after messages are tagged
From the emacs interface. In order to implement this and to avoid
having hooks parse all the arguments to the notmuch binary again, I
created a `notmuch-tag' function that other modules should use instead
of running (notmuch-call-notmuch-process "tag" ...) directly.
---
emacs/notmuch-message.el | 3 +--
emacs/notmuch-show.el | 12 ++++--------
emacs/notmuch.el | 45 +++++++++++++++++++++++++++++++++++++++++----
3 files changed, 46 insertions(+), 14 deletions(-)
diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index d5c96c2..aefd3fb 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -44,8 +44,7 @@ the \"inbox\" and \"todo\", you would set
(concat "+" str)
str))
notmuch-message-replied-tags)))
- (apply 'notmuch-call-notmuch-process "tag"
- (append tags (list (concat "id:" (car (car rep)))) nil))))))
+ (apply 'notmuch-tag (concat "id:" (car (car rep))) tags)))))
(add-hook 'message-send-hook 'notmuch-message-mark-replied)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 825988c..2b905c8 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1273,10 +1273,8 @@ the result."
(new-tags (notmuch-show-add-tags-worker current-tags toadd)))
(unless (equal current-tags new-tags)
- (apply 'notmuch-call-notmuch-process
- (append (cons "tag"
- (mapcar (lambda (s) (concat "+" s)) toadd))
- (cons (notmuch-show-get-message-id) nil)))
+ (apply 'notmuch-tag (notmuch-show-get-message-id)
+ (mapcar (lambda (s) (concat "+" s)) toadd))
(notmuch-show-set-tags new-tags))))
(defun notmuch-show-remove-tag (&rest toremove)
@@ -1289,10 +1287,8 @@ the result."
(new-tags (notmuch-show-del-tags-worker current-tags toremove)))
(unless (equal current-tags new-tags)
- (apply 'notmuch-call-notmuch-process
- (append (cons "tag"
- (mapcar (lambda (s) (concat "-" s)) toremove))
- (cons (notmuch-show-get-message-id) nil)))
+ (apply 'notmuch-tag (notmuch-show-get-message-id)
+ (mapcar (lambda (s) (concat "-" s)) toremove))
(notmuch-show-set-tags new-tags))))
(defun notmuch-show-toggle-headers ()
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 1d683f8..837136d 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -465,6 +465,44 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
(error (buffer-substring beg end))
))))))
+(defun notmuch-tag (query &rest tags)
+ "Add/remove tags in TAGS to messages matching QUERY.
+
+TAGS should be a list of strings of the form \"+TAG\" or \"-TAG\" and
+QUERY should be a string containing the search-query.
+
+Note: Other code should always use this function alter tags of
+messages instead of running (notmuch-call-notmuch-process \"tag\" ..)
+directly, so that hooks specified in notmuch-before-tag-hook and
+notmuch-after-tag-hook will be run."
+ (run-hooks 'notmuch-before-tag-hook)
+ (apply 'notmuch-call-notmuch-process
+ (append (list "tag") tags (list "--" query)))
+ (run-hooks 'notmuch-after-tag-hook))
+
+(defcustom notmuch-before-tag-hook nil
+ "Hooks that are run before tags of a message are modified.
+
+'tags' will contain the tags that are about to be added or removed as
+a list of strings of the form \"+TAG\" or \"-TAG\".
+'query' will be a string containing the search query that determines
+the messages that are about to be tagged"
+
+ :type 'hook
+ :options '(hl-line-mode)
+ :group 'notmuch)
+
+(defcustom notmuch-after-tag-hook nil
+ "Hooks that are run before tags of a message are modified.
+
+'tags' will contain the tags that were added or removed as
+a list of strings of the form \"+TAG\" or \"-TAG\".
+'query' will be a string containing the search query that determines
+the messages that were tagged"
+ :type 'hook
+ :options '(hl-line-mode)
+ :group 'notmuch)
+
(defun notmuch-search-set-tags (tags)
(save-excursion
(end-of-line)
@@ -504,7 +542,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
(defun notmuch-search-add-tag-region (tag beg end)
(let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
- (notmuch-call-notmuch-process "tag" (concat "+" tag) search-id-string)
+ (notmuch-tag search-id-string (concat "+" tag))
(save-excursion
(let ((last-line (line-number-at-pos end))
(max-line (- (line-number-at-pos (point-max)) 2)))
@@ -518,7 +556,7 @@ and will also appear in a buffer named \"*Notmuch errors*\"."
(defun notmuch-search-remove-tag-region (tag beg end)
(let ((search-id-string (mapconcat 'identity (notmuch-search-find-thread-id-region beg end) " or ")))
- (notmuch-call-notmuch-process "tag" (concat "-" tag) search-id-string)
+ (notmuch-tag search-id-string (concat "-" tag))
(save-excursion
(let ((last-line (line-number-at-pos end))
(max-line (- (line-number-at-pos (point-max)) 2)))
@@ -815,8 +853,7 @@ characters as well as `_.+-'.
(unless (string-match-p "^[-+][-+_.[:word:]]+$" (car words))
(error "Action must be of the form `+thistag -that_tag'"))
(setq words (cdr words))))
- (apply 'notmuch-call-notmuch-process "tag"
- (append action-split (list notmuch-search-query-string) nil))))
+ (apply 'notmuch-tag notmuch-search-query-string action-split)))
(defun notmuch-search-buffer-title (query)
"Returns the title for a buffer with notmuch search results."
--
1.7.5.1
[-- Attachment #2: Type: application/pgp-signature, Size: 835 bytes --]
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-05-24 20:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-16 20:48 [PATCH] emacs: Add notmuch-before/after-tag-hook Daniel Schoepe
2011-05-24 20:29 ` Carl Worth
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).