unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Mark Walters <markwalters1009@gmail.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations
Date: Sun, 18 Sep 2016 18:04:31 +0100	[thread overview]
Message-ID: <1474218271-8312-3-git-send-email-markwalters1009@gmail.com> (raw)
In-Reply-To: <1474218271-8312-1-git-send-email-markwalters1009@gmail.com>

This lets the user specify some tag changes as #tag or =tag which mean
the same as +tag and -tag except the reverse changes are not applied
when reversing the operation.
---
 emacs/notmuch-tag.el | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 2fdccb6..b18dbf0 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -50,7 +50,7 @@
     (,(kbd "u") notmuch-show-mark-read-tags "Mark read")
     (,(kbd "f") ("+flagged") "Flag")
     (,(kbd "s") ("+spam" "-inbox") "Mark as spam")
-    (,(kbd "d") ("+deleted" "-inbox") "Delete"))
+    (,(kbd "d") ("+deleted" "=inbox") "Delete"))
   "A list of keys and corresponding tagging operations
 
 For each key (or key sequence) you can specify a sequence of
@@ -463,14 +463,27 @@ notmuch-after-tag-hook will be run."
 
 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))
+\"+\" prefixes with \"-\" and vice versa in the result.
+
+Tags may also start with \"#\" or \"=\" which mean the same as +
+or - (respectively) when the forward operation is done, but are
+dropped when REVERSE is non-nil."
+  (remove-if 'null
+	     (mapcar (lambda (str)
+		       (let* ((s (if (string-match "^[+#=-]" str)
+				     str
+				   (concat "+" str)))
+			      (change (string-to-char s))
+			      (tag (substring s 1)))
+			 ;; we have a no-op if reverse and # or =
+			 (unless (and reverse (or (= change ?#) (= change ?=)))
+			   (let ((real-change (if reverse
+						  (if (= change ?-) "+" "-")
+						(case change
+						  ((?+ ?#) "+")
+						  ((?- ?=) "-")))))
+			     (concat real-change tag)))))
+		     tags)))
 
 (defun notmuch-tag-jump (reverse)
   (interactive "P")
@@ -486,7 +499,7 @@ begin with a \"+\" or a \"-\". If REVERSE is non-nil, replace all
 				   (second binding)))
 	     (tag-change (if reverse
 			     (notmuch-tag-change-list forward-tag-change 't)
-			   forward-tag-change))
+			   (notmuch-tag-change-list forward-tag-change)))
 	     (name (or (and (not (string= (third binding) ""))
 			    (third binding))
 		       (and (symbolp (second binding))
-- 
2.1.4

  parent reply	other threads:[~2016-09-18 17:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-18 17:04 [PATCH v2 0/2] Jump tagging Mark Walters
2016-09-18 17:04 ` [PATCH v2 1/2] emacs: add tag jump menu Mark Walters
2016-09-20  1:18   ` David Bremner
2016-09-18 17:04 ` Mark Walters [this message]
2017-03-11 14:45   ` [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations 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=1474218271-8312-3-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).