unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2 0/2] Jump tagging
@ 2016-09-18 17:04 Mark Walters
  2016-09-18 17:04 ` [PATCH v2 1/2] emacs: add tag jump menu Mark Walters
  2016-09-18 17:04 ` [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations Mark Walters
  0 siblings, 2 replies; 5+ messages in thread
From: Mark Walters @ 2016-09-18 17:04 UTC (permalink / raw)
  To: notmuch

This is version 2 of the patch
id:1474146583-28476-1-git-send-email-markwalters1009@gmail.com

I have tried to respond to most of the feedback. Most of the changes
are folded in to the first patch, which does the basic jump
tagging. The second patch is an attempt at allowing non-automatically
reversed tagging operations. Note neither patch is properly documented
yet.

Changes are

1) I added some more default operations in the tagging jump map, for spam and flagged.

2) You can now specify the tag changes either as a list, or as a
variable name which is the list of tag changes. For example "a" in the
tagging jumpmap is now bound to the notmuch-archive-tags so
automatically picks up the users choice of archive tags.

3) As ctrl-u is often cumbersome, and as you may decide you want to
reverse a tag operation once you are already in the tag jump map, "r"
jumps to the reverse tag map (r again returns you to the forward map)

4) The jump tag list now appears in the order they are listed in the
variable (rather than the reverse order).

5) Omit the tick box option for the name, and just have it always used,
but if the user leaves it empty the tag changes (or the variable name)
will be used as the name.

The main change I did not make was to make any of these a toggle: I
think r as reverse is sufficient and a toggle will do weird things in
too many cases. This way it is clear that "k d" *always* add the
deleted tag, whereas "k r d" always removes it.

Finally, bremner asked about non-reversible changes. I have
implemented it as follows. When you specify the tag changes you can
use any of +tag -tag #tag and =tag. The latter two mean +tag and -tag
when done forward but are omitted when reversed.

Thus, for example, "d" for deleted is set (by default) as +deleted
=inbox which means "k d" does "+deleted -inbox" but the reverse
operation "k r d" just does "-deleted" (i.e., it does not do +inbox).

The final code is a little ugly, because it has several cases to
consider, I think for a user it is all quite straightforward. Indeed,
if a user doesn't know about #,= prefixes then they lose nothing.

(There is one potential breakage: if people have any of the automatic
tags (unread,archive etc) setup so that they include tags starting =
or # and they don't specify the + or - for them (we default to +) then
the unarchive function will break. Given the benefits, and the pretty
unusual nature of this setup, this is probably acceptable)

Best wishes

Mark


Mark Walters (2):
  emacs: add tag jump menu
  emacs: tag: allow non-automatically-reversible tag operations

 emacs/notmuch-lib.el  |  4 +++
 emacs/notmuch-show.el |  1 +
 emacs/notmuch-tag.el  | 99 ++++++++++++++++++++++++++++++++++++++++++++++-----
 emacs/notmuch-tree.el |  1 +
 emacs/notmuch.el      |  1 +
 5 files changed, 97 insertions(+), 9 deletions(-)

-- 
2.1.4

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

* [PATCH v2 1/2] emacs: add tag jump menu
  2016-09-18 17:04 [PATCH v2 0/2] Jump tagging Mark Walters
@ 2016-09-18 17:04 ` Mark Walters
  2016-09-20  1:18   ` David Bremner
  2016-09-18 17:04 ` [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations Mark Walters
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Walters @ 2016-09-18 17:04 UTC (permalink / raw)
  To: notmuch

Add a "jump" style menu for doing tagging operations.
---
 emacs/notmuch-lib.el  |  4 +++
 emacs/notmuch-show.el |  1 +
 emacs/notmuch-tag.el  | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 emacs/notmuch-tree.el |  1 +
 emacs/notmuch.el      |  1 +
 5 files changed, 75 insertions(+)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 2f015b0..b2cdace 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -57,6 +57,10 @@
 
 (custom-add-to-group 'notmuch-send 'message 'custom-group)
 
+(defgroup notmuch-tag nil
+  "Tags and tagging in Notmuch."
+  :group 'notmuch)
+
 (defgroup notmuch-crypto nil
   "Processing and display of cryptographic MIME parts."
   :group 'notmuch)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 5a585f3..756c7dd 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1428,6 +1428,7 @@ reset based on the original query."
     (define-key map "V" 'notmuch-show-view-raw-message)
     (define-key map "c" 'notmuch-show-stash-map)
     (define-key map "h" 'notmuch-show-toggle-visibility-headers)
+    (define-key map "k" 'notmuch-tag-jump)
     (define-key map "*" 'notmuch-show-tag-all)
     (define-key map "-" 'notmuch-show-remove-tag)
     (define-key map "+" 'notmuch-show-add-tag)
diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 6c8b6a7..2fdccb6 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -28,6 +28,41 @@
 (require 'crm)
 (require 'notmuch-lib)
 
+(declare-function notmuch-search-tag "notmuch" tag-changes)
+(declare-function notmuch-show-tag "notmuch-show" tag-changes)
+(declare-function notmuch-tree-tag "notmuch-tree" tag-changes)
+
+(autoload 'notmuch-jump "notmuch-jump")
+
+
+(define-widget 'notmuch-tag-key-type 'list
+  "A single key tagging binding"
+  :format "%v"
+  :args '((list :inline t
+		:format "%v"
+		(key-sequence :tag "Key")
+		(radio :tag "Tag operations" (repeat :tag "Tag list" (string :format "%v" :tag "change"))
+		       (variable :tag "Tag variable"))
+		(string :tag "Name"))))
+
+(defcustom notmuch-tagging-keys
+  `((,(kbd "a") notmuch-archive-tags "Archive")
+    (,(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"))
+  "A list of keys and corresponding tagging operations
+
+For each key (or key sequence) you can specify a sequence of
+tagging operations to apply, or a variable which contains a list
+of tagging operations such as `notmuch-archive-tags'. The final
+element is name for the this tagging operation. If it is omitted
+or empty then the list of tag changes, or the variable name is
+used as the name."
+  :tag "List of tagging bindings"
+  :type '(repeat notmuch-tag-key-type)
+  :group 'notmuch-tag)
+
 (define-widget 'notmuch-tag-format-type 'lazy
   "Customize widget for notmuch-tag-format and friends"
   :type '(alist :key-type (regexp :tag "Tag")
@@ -437,6 +472,39 @@ begin with a \"+\" or a \"-\". If REVERSE is non-nil, replace all
 		s)))
 	  tags))
 
+(defun notmuch-tag-jump (reverse)
+  (interactive "P")
+  (let (action-map)
+    (dolist (binding notmuch-tagging-keys)
+      (let* ((tag-function (case major-mode
+			     (notmuch-search-mode #'notmuch-search-tag)
+			     (notmuch-show-mode #'notmuch-show-tag)
+			     (notmuch-tree-mode #'notmuch-tree-tag)))
+	     (key (first binding))
+	     (forward-tag-change (if (symbolp (second binding))
+				     (symbol-value (second binding))
+				   (second binding)))
+	     (tag-change (if reverse
+			     (notmuch-tag-change-list forward-tag-change 't)
+			   forward-tag-change))
+	     (name (or (and (not (string= (third binding) ""))
+			    (third binding))
+		       (and (symbolp (second binding))
+			    (symbol-name (second binding)))))
+	     (name-string (if name
+			      (if reverse (concat "Reverse " name)
+				name)
+			    (mapconcat #'identity tag-change " "))))
+	(push (list key name-string
+		     `(lambda () (,tag-function ',tag-change)))
+	      action-map)))
+    (push (list "r" (if reverse
+			"Forward tag changes "
+		      "Reverse tag changes")
+		(apply-partially 'notmuch-tag-jump (not reverse)))
+	  action-map)
+    (setq action-map (nreverse action-map))
+    (notmuch-jump action-map "Tag: ")))
 
 ;;
 
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index d864e6d..5431384 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -276,6 +276,7 @@ FUNC."
     (define-key map "P" 'notmuch-tree-prev-message)
     (define-key map (kbd "M-p") 'notmuch-tree-prev-thread)
     (define-key map (kbd "M-n") 'notmuch-tree-next-thread)
+    (define-key map "k" 'notmuch-tag-jump)
     (define-key map "-" 'notmuch-tree-remove-tag)
     (define-key map "+" 'notmuch-tree-add-tag)
     (define-key map "*" 'notmuch-tree-tag-thread)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 8e14692..888672b 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -169,6 +169,7 @@ there will be called at other points of notmuch execution."
     (define-key map "t" 'notmuch-search-filter-by-tag)
     (define-key map "l" 'notmuch-search-filter)
     (define-key map [mouse-1] 'notmuch-search-show-thread)
+    (define-key map "k" 'notmuch-tag-jump)
     (define-key map "*" 'notmuch-search-tag-all)
     (define-key map "a" 'notmuch-search-archive-thread)
     (define-key map "-" 'notmuch-search-remove-tag)
-- 
2.1.4

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

* [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations
  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-18 17:04 ` Mark Walters
  2017-03-11 14:45   ` David Bremner
  1 sibling, 1 reply; 5+ messages in thread
From: Mark Walters @ 2016-09-18 17:04 UTC (permalink / raw)
  To: notmuch

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

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

* Re: [PATCH v2 1/2] emacs: add tag jump menu
  2016-09-18 17:04 ` [PATCH v2 1/2] emacs: add tag jump menu Mark Walters
@ 2016-09-20  1:18   ` David Bremner
  0 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2016-09-20  1:18 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> Add a "jump" style menu for doing tagging operations.
> ---

I wasn't too sure about the whole "k r" thing, but playing with it, I
find the UI reasonable.

I propose polishing up the documentation and including the first patch
in 0.23 (whose freeze I will get around to announcing any day
now).

The second patch does exactly impliment my feature request, so thanks
for that. I need a bit more time to play with it, both to decide if it
really helps with my workflows, also to decide if I'm the only one who
uses such workflows.

d

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

* Re: [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations
  2016-09-18 17:04 ` [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations Mark Walters
@ 2017-03-11 14:45   ` David Bremner
  0 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2017-03-11 14:45 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

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

This was originally written at my request, but I've been getting along
without it for a few months.  Does anyone feel strongly about adding the
feature, or shall we pass for now?

d

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

end of thread, other threads:[~2017-03-11 14:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 2/2] emacs: tag: allow non-automatically-reversible tag operations Mark Walters
2017-03-11 14:45   ` 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).