unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2 0/6] emacs: customization for tag changes on archive
@ 2012-09-06 15:32 Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 1/6] emacs: add helper for tag change list manipulation Jani Nikula
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

Hi all, this is v2 of [1], the only change being Michal's suggestion [2] for
patch 1/6.

[1] id:"cover.1346614915.git.jani@nikula.org"
[2] id:"xa1tipbvwdb0.fsf@mina86.com"

BR,
Jani.


Jani Nikula (6):
  emacs: add helper for tag change list manipulation
  emacs: fix notmuch-message-replied-tags defcustom type
  emacs: use new tag change helper to mark messages as replied
  emacs: add support for custom tag changes on message/thread archive
  emacs: add support for reversing notmuch-search-archive-thread tag
    changes
  emacs: add support for reversing notmuch-show-mark-read tag changes

 emacs/notmuch-lib.el     |   14 ++++++++++++
 emacs/notmuch-message.el |   26 ++++++++++------------
 emacs/notmuch-show.el    |   54 +++++++++++++++++++++++++++++++---------------
 emacs/notmuch-tag.el     |   15 +++++++++++++
 emacs/notmuch.el         |   16 ++++++++++----
 5 files changed, 89 insertions(+), 36 deletions(-)

-- 
1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/6] emacs: add helper for tag change list manipulation
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
@ 2012-09-06 15:32 ` Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 2/6] emacs: fix notmuch-message-replied-tags defcustom type Jani Nikula
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

Add a helper to create (and optionally reverse) a list of tag changes.
---
 emacs/notmuch-tag.el |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 0c0fc87..4fce3a9 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -140,6 +140,21 @@ notmuch-after-tag-hook will be run."
   ;; in all cases we return tag-changes as a list
   tag-changes)
 
+(defun notmuch-tag-change-list (tags &optional reverse)
+  "Convert TAGS into a list of tag changes.
+
+Add a \"+\" prefix to any tag in TAGS list that doesn't already
+begin with a \"+\" or a \"-\". If REVERSE is non-nil, replace all
+\"+\" prefixes with \"-\" and vice versa in the result."
+  (mapcar (lambda (str)
+	    (let ((s (if (string-match "^[+-]" str) str (concat "+" str))))
+	      (if reverse
+		  (concat (if (= (string-to-char s) ?-) "+" "-")
+			  (substring s 1))
+		s)))
+	  tags))
+
+
 ;;
 
 (provide 'notmuch-tag)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/6] emacs: fix notmuch-message-replied-tags defcustom type
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 1/6] emacs: add helper for tag change list manipulation Jani Nikula
@ 2012-09-06 15:32 ` Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 3/6] emacs: use new tag change helper to mark messages as replied Jani Nikula
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

---
 emacs/notmuch-message.el |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index d3738bf..3798046 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -31,7 +31,7 @@ if it is prefaced with a \"-\", removed.
 For example, if you wanted to add a \"replied\" tag and remove
 the \"inbox\" and \"todo\", you would set
     (\"replied\" \"-inbox\" \"-todo\"\)"
-  :type 'list
+  :type '(repeat string)
   :group 'notmuch-send)
 
 (defun notmuch-message-mark-replied ()
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 3/6] emacs: use new tag change helper to mark messages as replied
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 1/6] emacs: add helper for tag change list manipulation Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 2/6] emacs: fix notmuch-message-replied-tags defcustom type Jani Nikula
@ 2012-09-06 15:32 ` Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 4/6] emacs: add support for custom tag changes on message/thread archive Jani Nikula
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

Clarify documentation while at it.
---
 emacs/notmuch-message.el |   24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 3798046..4dc4883 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -23,14 +23,16 @@
 (require 'notmuch-tag)
 (require 'notmuch-mua)
 
-(defcustom notmuch-message-replied-tags '("replied")
-  "Tags to be automatically added to or removed from a message when it is replied to.
-Any tag in the list will be added to a replied message or,
-if it is prefaced with a \"-\", removed.
+(defcustom notmuch-message-replied-tags '("+replied")
+  "List of tag changes to apply to a message when it has been replied to.
+
+Tags starting with \"+\" (or not starting with either \"+\" or
+\"-\") in the list will be added, and tags starting with \"-\"
+will be removed from the message being replied to.
 
 For example, if you wanted to add a \"replied\" tag and remove
-the \"inbox\" and \"todo\", you would set
-    (\"replied\" \"-inbox\" \"-todo\"\)"
+the \"inbox\" and \"todo\" tags, you would set:
+    (\"+replied\" \"-inbox\" \"-todo\"\)"
   :type '(repeat string)
   :group 'notmuch-send)
 
@@ -38,14 +40,8 @@ the \"inbox\" and \"todo\", you would set
   ;; 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)
-      ;; add a "+" to any tag that is doesn't already begin with a "+"
-      ;; or "-"
-      (let ((tags (mapcar (lambda (str)
-			    (if (not (string-match "^[+-]" str))
-				(concat "+" str)
-			      str))
-			  notmuch-message-replied-tags)))
-	(funcall 'notmuch-tag (notmuch-id-to-query (car (car rep))) tags)))))
+      (funcall '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)
 
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 4/6] emacs: add support for custom tag changes on message/thread archive
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
                   ` (2 preceding siblings ...)
  2012-09-06 15:32 ` [PATCH v2 3/6] emacs: use new tag change helper to mark messages as replied Jani Nikula
@ 2012-09-06 15:32 ` Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 5/6] emacs: add support for reversing notmuch-search-archive-thread tag changes Jani Nikula
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

Add support for customization of the tag changes that are applied when
a message or a thread is archived. Instead of hard-coded removal of
the "inbox" tag, the user can now specify a list of tag changes to
perform.
---
 emacs/notmuch-lib.el  |   14 ++++++++++++++
 emacs/notmuch-show.el |   29 +++++++++++++++++------------
 emacs/notmuch.el      |   12 ++++++++++--
 3 files changed, 41 insertions(+), 14 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 900235b..20d990d 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -82,6 +82,20 @@
   :type '(alist :key-type string :value-type string)
   :group 'notmuch-hello)
 
+(defcustom notmuch-archive-tags '("-inbox")
+  "List of tag changes to apply to a message or a thread when it is archived.
+
+Tags starting with \"+\" (or not starting with either \"+\" or
+\"-\") in the list will be added, and tags starting with \"-\"
+will be removed from the message or thread being archived.
+
+For example, if you wanted to remove an \"inbox\" tag and add an
+\"archived\" tag, you would set:
+    (\"-inbox\" \"+archived\")"
+  :type '(repeat string)
+  :group 'notmuch-search
+  :group 'notmuch-show)
+
 (defvar notmuch-folders nil
   "Deprecated name for what is now known as `notmuch-saved-searches'.")
 
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index ce5ea6f..e701aec 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1748,18 +1748,20 @@ argument, hide all of the messages."
 (defun notmuch-show-archive-thread (&optional unarchive)
   "Archive each message in thread.
 
-Archive each message currently shown by removing the \"inbox\"
-tag from each.  If a prefix argument is given, the messages will
-be \"unarchived\" (ie. the \"inbox\" tag will be added instead of
-removed).
+Archive each message currently shown by applying the tag changes
+in `notmuch-archive-tags' to each (remove the \"inbox\" tag by
+default). If a prefix argument is given, the messages will be
+\"unarchived\", i.e. the tag changes in `notmuch-archive-tags'
+will be reversed.
 
 Note: This command is safe from any race condition of new messages
 being delivered to the same thread. It does not archive the
 entire thread, but only the messages shown in the current
 buffer."
   (interactive "P")
-  (let ((op (if unarchive "+" "-")))
-    (notmuch-show-tag-all (concat op "inbox"))))
+  (when notmuch-archive-tags
+    (notmuch-show-tag-all
+     (notmuch-tag-change-list notmuch-archive-tags unarchive))))
 
 (defun notmuch-show-archive-thread-then-next ()
   "Archive all messages in the current buffer, then show next thread from search."
@@ -1774,14 +1776,17 @@ buffer."
   (notmuch-show-next-thread))
 
 (defun notmuch-show-archive-message (&optional unarchive)
-  "Archive the current message (remove \"inbox\" tag).
+  "Archive the current message.
 
-If a prefix argument is given, the message will be
-\"unarchived\" (ie. the \"inbox\" tag will be added instead of
-removed)."
+Archive the current message by applying the tag changes in
+`notmuch-archive-tags' to it (remove the \"inbox\" tag by
+default). If a prefix argument is given, the message will be
+\"unarchived\", i.e. the tag changes in `notmuch-archive-tags'
+will be reversed."
   (interactive "P")
-  (let ((op (if unarchive "+" "-")))
-    (notmuch-show-tag-message (concat op "inbox"))))
+  (when notmuch-archive-tags
+    (apply 'notmuch-show-tag-message
+	   (notmuch-tag-change-list notmuch-archive-tags unarchive))))
 
 (defun notmuch-show-archive-message-then-next-or-exit ()
   "Archive the current message, then show the next open message in the current thread.
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 1c43d3e..64caa3e 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -594,11 +594,19 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
   (notmuch-search-tag "-"))
 
 (defun notmuch-search-archive-thread ()
-  "Archive the currently selected thread (remove its \"inbox\" tag).
+  "Archive the currently selected thread.
+
+Archive each message in the currently selected thread by applying
+the tag changes in `notmuch-archive-tags' to each (remove the
+\"inbox\" tag by default). If a prefix argument is given, the
+messages will be \"unarchived\" (i.e. the tag changes in
+`notmuch-archive-tags' will be reversed).
 
 This function advances the next thread when finished."
   (interactive)
-  (notmuch-search-tag '("-inbox"))
+  (when notmuch-archive-tags
+    (notmuch-search-tag
+     (notmuch-tag-change-list notmuch-archive-tags)))
   (notmuch-search-next-thread))
 
 (defun notmuch-search-update-result (result &optional pos)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 5/6] emacs: add support for reversing notmuch-search-archive-thread tag changes
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
                   ` (3 preceding siblings ...)
  2012-09-06 15:32 ` [PATCH v2 4/6] emacs: add support for custom tag changes on message/thread archive Jani Nikula
@ 2012-09-06 15:32 ` Jani Nikula
  2012-09-06 15:32 ` [PATCH v2 6/6] emacs: add support for reversing notmuch-show-mark-read " Jani Nikula
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

Since archiving a thread can now be a user customized set of tag
changes, make reversing this easier. Allow a prefix argument to
notmuch-search-archive-thread to reverse the archiving, similar to the
unarchiving in notmuch-show-archive-message.
---
 emacs/notmuch.el |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 64caa3e..a8a85ce 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -593,7 +593,7 @@ See `notmuch-tag' for information on the format of TAG-CHANGES."
   (interactive)
   (notmuch-search-tag "-"))
 
-(defun notmuch-search-archive-thread ()
+(defun notmuch-search-archive-thread (&optional unarchive)
   "Archive the currently selected thread.
 
 Archive each message in the currently selected thread by applying
@@ -603,10 +603,10 @@ messages will be \"unarchived\" (i.e. the tag changes in
 `notmuch-archive-tags' will be reversed).
 
 This function advances the next thread when finished."
-  (interactive)
+  (interactive "P")
   (when notmuch-archive-tags
     (notmuch-search-tag
-     (notmuch-tag-change-list notmuch-archive-tags)))
+     (notmuch-tag-change-list notmuch-archive-tags unarchive)))
   (notmuch-search-next-thread))
 
 (defun notmuch-search-update-result (result &optional pos)
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 6/6] emacs: add support for reversing notmuch-show-mark-read tag changes
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
                   ` (4 preceding siblings ...)
  2012-09-06 15:32 ` [PATCH v2 5/6] emacs: add support for reversing notmuch-search-archive-thread tag changes Jani Nikula
@ 2012-09-06 15:32 ` Jani Nikula
  2012-09-07  7:27 ` [PATCH v2 0/6] emacs: customization for tag changes on archive Tomi Ollila
  2012-09-19 11:14 ` David Bremner
  7 siblings, 0 replies; 9+ messages in thread
From: Jani Nikula @ 2012-09-06 15:32 UTC (permalink / raw)
  To: notmuch; +Cc: Tomi Ollila

Since marking a message as read can now be a user customized set of
tag changes, make reversing this easier. Allow a prefix argument to
notmuch-show-mark-read to reverse the marking as read, similar to the
unarchiving in notmuch-show-archive-message.

While at it, update the relevant documentation to match that of other
automatic tagging (i.e. archive and reply).
---
 emacs/notmuch-show.el |   25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index e701aec..1c1cf9c 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -184,8 +184,15 @@ provided with an MLA argument nor `completing-read' input."
   :group 'notmuch-show)
 
 (defcustom notmuch-show-mark-read-tags '("-unread")
-  "List of tags to apply when message is read, ie. shown in notmuch-show
-buffer."
+  "List of tag changes to apply to a message when it is marked as read.
+
+Tags starting with \"+\" (or not starting with either \"+\" or
+\"-\") in the list will be added, and tags starting with \"-\"
+will be removed from the message being marked as read.
+
+For example, if you wanted to remove an \"unread\" tag and add a
+\"read\" tag (which would make little sense), you would set:
+    (\"-unread\" \"+read\")"
   :type '(repeat string)
   :group 'notmuch-show)
 
@@ -1390,10 +1397,18 @@ current thread."
   "Are the headers of the current message visible?"
   (notmuch-show-get-prop :headers-visible))
 
-(defun notmuch-show-mark-read ()
-  "Apply `notmuch-show-mark-read-tags' to the message."
+(defun notmuch-show-mark-read (&optional unread)
+  "Mark the current message as read.
+
+Mark the current message as read by applying the tag changes in
+`notmuch-show-mark-read-tags' to it (remove the \"unread\" tag by
+default). If a prefix argument is given, the message will be
+marked as unread, i.e. the tag changes in
+`notmuch-show-mark-read-tags' will be reversed."
+  (interactive "P")
   (when notmuch-show-mark-read-tags
-    (apply 'notmuch-show-tag-message notmuch-show-mark-read-tags)))
+    (apply 'notmuch-show-tag-message
+	   (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
 
 ;; Functions for getting attributes of several messages in the current
 ;; thread.
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/6] emacs: customization for tag changes on archive
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
                   ` (5 preceding siblings ...)
  2012-09-06 15:32 ` [PATCH v2 6/6] emacs: add support for reversing notmuch-show-mark-read " Jani Nikula
@ 2012-09-07  7:27 ` Tomi Ollila
  2012-09-19 11:14 ` David Bremner
  7 siblings, 0 replies; 9+ messages in thread
From: Tomi Ollila @ 2012-09-07  7:27 UTC (permalink / raw)
  To: Jani Nikula, notmuch

On Thu, Sep 06 2012, Jani Nikula <jani@nikula.org> wrote:

> Hi all, this is v2 of [1], the only change being Michal's suggestion [2] for
> patch 1/6.
>
> [1] id:"cover.1346614915.git.jani@nikula.org"
> [2] id:"xa1tipbvwdb0.fsf@mina86.com"
>
> BR,
> Jani.

LGTM

Tomi

>
>
> Jani Nikula (6):
>   emacs: add helper for tag change list manipulation
>   emacs: fix notmuch-message-replied-tags defcustom type
>   emacs: use new tag change helper to mark messages as replied
>   emacs: add support for custom tag changes on message/thread archive
>   emacs: add support for reversing notmuch-search-archive-thread tag
>     changes
>   emacs: add support for reversing notmuch-show-mark-read tag changes
>
>  emacs/notmuch-lib.el     |   14 ++++++++++++
>  emacs/notmuch-message.el |   26 ++++++++++------------
>  emacs/notmuch-show.el    |   54 +++++++++++++++++++++++++++++++---------------
>  emacs/notmuch-tag.el     |   15 +++++++++++++
>  emacs/notmuch.el         |   16 ++++++++++----
>  5 files changed, 89 insertions(+), 36 deletions(-)
>
> -- 
> 1.7.9.5

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/6] emacs: customization for tag changes on archive
  2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
                   ` (6 preceding siblings ...)
  2012-09-07  7:27 ` [PATCH v2 0/6] emacs: customization for tag changes on archive Tomi Ollila
@ 2012-09-19 11:14 ` David Bremner
  7 siblings, 0 replies; 9+ messages in thread
From: David Bremner @ 2012-09-19 11:14 UTC (permalink / raw)
  To: Jani Nikula, notmuch

Jani Nikula <jani@nikula.org> writes:

> Hi all, this is v2 of [1], the only change being Michal's suggestion [2] for
> patch 1/6.
>
> [1] id:"cover.1346614915.git.jani@nikula.org"
> [2] id:"xa1tipbvwdb0.fsf@mina86.com"
>

Pushed,

d

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2012-09-19 11:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-06 15:32 [PATCH v2 0/6] emacs: customization for tag changes on archive Jani Nikula
2012-09-06 15:32 ` [PATCH v2 1/6] emacs: add helper for tag change list manipulation Jani Nikula
2012-09-06 15:32 ` [PATCH v2 2/6] emacs: fix notmuch-message-replied-tags defcustom type Jani Nikula
2012-09-06 15:32 ` [PATCH v2 3/6] emacs: use new tag change helper to mark messages as replied Jani Nikula
2012-09-06 15:32 ` [PATCH v2 4/6] emacs: add support for custom tag changes on message/thread archive Jani Nikula
2012-09-06 15:32 ` [PATCH v2 5/6] emacs: add support for reversing notmuch-search-archive-thread tag changes Jani Nikula
2012-09-06 15:32 ` [PATCH v2 6/6] emacs: add support for reversing notmuch-show-mark-read " Jani Nikula
2012-09-07  7:27 ` [PATCH v2 0/6] emacs: customization for tag changes on archive Tomi Ollila
2012-09-19 11:14 ` David Bremner

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).