[PATCH v2 1/6] emacs: add helper for tag change list manipulation

Jani Nikula jani at nikula.org
Thu Sep 6 08:32:37 PDT 2012


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



More information about the notmuch mailing list