unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively.
@ 2016-10-16 16:12 Mark Walters
  2016-10-16 16:26 ` [PATCH] emacs: tag-jump: tag the region when active in search mode Mark Walters
  2016-10-31 11:19 ` [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively David Bremner
  0 siblings, 2 replies; 4+ messages in thread
From: Mark Walters @ 2016-10-16 16:12 UTC (permalink / raw)
  To: notmuch

The normal tag commands in search mode tag the all threads meeting the
region when called interactively. This makes them do the same when
called non-interactively. This is a change in the api.
---

Previously calling notmuch-search-tag non-interactively meant it just
acted on the current thread, unless BEG and END were both
specified. This was true even when the region was active. This changes
it so that the non-interactive use matches the interactive use, and
uses the region when active. The caller can obtain the old behaviour
by passing (point) for both BEG and END.

This change has the side effect of fixing a bug aidecoe pointed out on
irc -- that tag-jump only tags single messages, not the whole
region. I think this is a genuine bug as it makes tag-jump
inconsistent with "+" and "a" for example.

The reason for this bug is that it calls notmuch-search-tag
non-interactively but doesn't specify BEG and END.

(Note that notmuch-search-archive-thread explicitly passes BEG and END
of the region to notmuch-search-tag -- this would not be necessary
with this patch).

Since this is a genuine bug in tag-jump it should be fixed -- if we
prefer not to break/change the api then the alternative is to pass the
region start and end explicitly. I will post a reply to this email
which does that for comparison.

Best wishes

Mark






emacs/notmuch.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6c36ad8..8bb6706 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -562,12 +562,15 @@ Returns (TAG-CHANGES REGION-BEGIN REGION-END)."
 See `notmuch-tag' for information on the format of TAG-CHANGES.
 When called interactively, this uses the region if the region is
 active.  When called directly, BEG and END provide the region.
-If these are nil or not provided, this applies to the thread at
-point.
+If these are nil or not provided, then, if the region is active
+this applied to all threads meeting the region, and if the region
+is inactive this applies to the thread at point.
 
 If ONLY-MATCHED is non-nil, only tag matched messages."
   (interactive (notmuch-search-interactive-tag-changes))
-  (unless (and beg end) (setq beg (point) end (point)))
+  (unless (and beg end)
+    (setq beg (car (notmuch-search-interactive-region))
+	  end (cadr (notmuch-search-interactive-region))))
   (let ((search-string (notmuch-search-find-stable-query-region
 			beg end only-matched)))
     (notmuch-tag search-string tag-changes)
-- 
2.1.4

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

* [PATCH] emacs: tag-jump: tag the region when active in search mode
  2016-10-16 16:12 [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively Mark Walters
@ 2016-10-16 16:26 ` Mark Walters
  2016-10-23  2:07   ` David Bremner
  2016-10-31 11:19 ` [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively David Bremner
  1 sibling, 1 reply; 4+ messages in thread
From: Mark Walters @ 2016-10-16 16:26 UTC (permalink / raw)
  To: notmuch

The normal tag commands make in search mode tag the all threads
meeting the region. This makes the tag jump commands do the same.

Since the notmuch-search-tag commands only look at the region when
called interactively we pass the region bounds as explicit arguments.

Also note that tree mode does not have the tag region functionality --
that is an omission but is independent of tag-jump.
---

This is an alternative to the patch in the parent email. The advantage
is that it doesn't break the api.

Note it would make sense to add tag-region functionality to tree-mode
but that would be a moderately large patch, and is essentially
independent of this change.

Best wishes

Mark


emacs/notmuch-tag.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
index 1b2ce5c..ef99803 100644
--- a/emacs/notmuch-tag.el
+++ b/emacs/notmuch-tag.el
@@ -28,6 +28,7 @@
 (require 'crm)
 (require 'notmuch-lib)
 
+(declare-function notmuch-search-interactive-region "notmuch" ())
 (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)
@@ -511,6 +512,8 @@ and vice versa."
 			     (notmuch-search-mode #'notmuch-search-tag)
 			     (notmuch-show-mode #'notmuch-show-tag)
 			     (notmuch-tree-mode #'notmuch-tree-tag)))
+	     (extra-args (when (eq major-mode 'notmuch-search-mode)
+			   (notmuch-search-interactive-region)))
 	     (key (first binding))
 	     (forward-tag-change (if (symbolp (second binding))
 				     (symbol-value (second binding))
@@ -527,7 +530,7 @@ and vice versa."
 				name)
 			    (mapconcat #'identity tag-change " "))))
 	(push (list key name-string
-		     `(lambda () (,tag-function ',tag-change)))
+		     `(lambda () (,tag-function ',tag-change ,@extra-args)))
 	      action-map)))
     (push (list notmuch-tag-jump-reverse-key
 		(if reverse
-- 
2.1.4

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

* Re: [PATCH] emacs: tag-jump: tag the region when active in search mode
  2016-10-16 16:26 ` [PATCH] emacs: tag-jump: tag the region when active in search mode Mark Walters
@ 2016-10-23  2:07   ` David Bremner
  0 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2016-10-23  2:07 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:
> +	     (extra-args (when (eq major-mode 'notmuch-search-mode)
> +			   (notmuch-search-interactive-region)))

I think I prefer the previous patch for simplicity. If people think it's
better not to break the API, then I'd rather not use the when here in a
value returning position.

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

* Re: [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively.
  2016-10-16 16:12 [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively Mark Walters
  2016-10-16 16:26 ` [PATCH] emacs: tag-jump: tag the region when active in search mode Mark Walters
@ 2016-10-31 11:19 ` David Bremner
  1 sibling, 0 replies; 4+ messages in thread
From: David Bremner @ 2016-10-31 11:19 UTC (permalink / raw)
  To: Mark Walters, notmuch

Mark Walters <markwalters1009@gmail.com> writes:

> The normal tag commands in search mode tag the all threads meeting the
> region when called interactively. This makes them do the same when
> called non-interactively. This is a change in the api.

pushed to master

d

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

end of thread, other threads:[~2016-10-31 11:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-16 16:12 [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively Mark Walters
2016-10-16 16:26 ` [PATCH] emacs: tag-jump: tag the region when active in search mode Mark Walters
2016-10-23  2:07   ` David Bremner
2016-10-31 11:19 ` [PATCH] emacs: make notmuch-search-tag tag the region when called non-interactively 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).