all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: 33122@debbugs.gnu.org
Subject: bug#33122: Acknowledgement (27.0.50; Allow use of Gnus search groups as notmuch :path search terms)
Date: Wed, 24 Oct 2018 08:46:29 +0800	[thread overview]
Message-ID: <875zxscgt6.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <handler.33122.B.154026344121931.ack@debbugs.gnu.org> (GNU bug Tracking System's message of "Tue, 23 Oct 2018 02:58:02 +0000")

[-- Attachment #1: Type: text/plain, Size: 94 bytes --]

Here's an updated version of the patch, thanks to Andreas Goesele for
reporting and testing.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-use-of-Gnus-search-groups-as-notmuch-path-sear.patch --]
[-- Type: text/x-patch, Size: 4154 bytes --]

From 517ca66601e97babeda7a20150bee24df9c9975b Mon Sep 17 00:00:00 2001
From: Eric Abrahamsen <eric@ericabrahamsen.net>
Date: Tue, 23 Oct 2018 10:51:37 +0800
Subject: [PATCH] Allow use of Gnus search groups as notmuch path: search term

* lisp/gnus/nnir.el (nnir-notmuch-filter-group-names-function): New
  option governing whether and how to use Gnus' search groups as path:
  search terms to notmuch.
  (nnir-run-notmuch): Check and possibly use above variable.
---
 lisp/gnus/nnir.el | 58 +++++++++++++++++++++++++++++++++++------------
 1 file changed, 43 insertions(+), 15 deletions(-)

diff --git a/lisp/gnus/nnir.el b/lisp/gnus/nnir.el
index 7e5f56e4dd..ea7257d0c9 100644
--- a/lisp/gnus/nnir.el
+++ b/lisp/gnus/nnir.el
@@ -518,6 +518,26 @@ nnir-notmuch-remove-prefix
   :type '(regexp)
   :group 'nnir)
 
+(defcustom nnir-notmuch-filter-group-names-function
+  #'gnus-group-short-name
+  "Whether and how to use Gnus group names as \"path:\" search terms.
+When nil, the groups being searched in are not used as notmuch
+:path search terms.  It's still possible to use \"path:\" terms
+manually within the search query, however.
+
+When a function, map this function over all the group names.  By
+default this runs them through `gnus-group-short-name', and it is
+recommended to use this transform, at least.  Further
+transforms (for instance, converting \".\" to \"/\") can be
+added like so:
+
+\(add-function :filter-return
+   nnir-notmuch-filter-group-names-function
+   (lambda (g) (replace-regexp-in-string \"\\\\.\" \"/\" g)))"
+  :version "27.1"
+  :type '(choice function
+		 nil))
+
 ;;; Developer Extension Variable:
 
 (defvar nnir-engines
@@ -1505,23 +1525,30 @@ nnir-run-namazu
                                (> (nnir-artitem-rsv x)
                                   (nnir-artitem-rsv y)))))))))
 
-(defun nnir-run-notmuch (query server &optional _group)
+(defun nnir-run-notmuch (query server &optional groups)
   "Run QUERY against notmuch.
 Returns a vector of (group name, file name) pairs (also vectors,
-actually)."
-
-  ;; (when group
-  ;;   (error "The notmuch backend cannot search specific groups"))
+actually).  If GROUPS is a list of group names, use them to
+construct path: search terms (see the variable
+`nnir-notmuch-filter-group-names-function')."
 
   (save-excursion
-    (let ( (qstring (cdr (assq 'query query)))
-	   (groupspec (cdr (assq 'notmuch-group query)))
+    (let* ((qstring (cdr (assq 'query query)))
 	   (prefix (nnir-read-server-parm 'nnir-notmuch-remove-prefix server))
            artlist
 	   (article-pattern (if (string-match "\\`nnmaildir:"
 					      (gnus-group-server server))
-			       ":[0-9]+"
-			     "^[0-9]+$"))
+				":[0-9]+"
+			      "^[0-9]+$"))
+	   (groups (when nnir-notmuch-filter-group-names-function
+		     (mapcar nnir-notmuch-filter-group-names-function
+			     groups)))
+	   (pathquery (when groups
+			(concat "("
+			 (mapconcat (lambda (g)
+				      (format " path:%s" g))
+				    groups " or")
+			 ")")))
            artno dirnam filenam)
 
       (when (equal "" qstring)
@@ -1530,10 +1557,14 @@ nnir-run-notmuch
       (set-buffer (get-buffer-create nnir-tmp-buffer))
       (erase-buffer)
 
-      (if groupspec
-          (message "Doing notmuch query %s on %s..." qstring groupspec)
+      (if groups
+          (message "Doing notmuch query %s on %s..."
+		   qstring (mapconcat #'identity groups " "))
         (message "Doing notmuch query %s..." qstring))
 
+      (when groups
+	(setq qstring (concat qstring pathquery)))
+
       (let* ((cp-list `( ,nnir-notmuch-program
                          nil            ; input from /dev/null
                          t              ; output
@@ -1571,10 +1602,7 @@ nnir-run-notmuch
         (when (string-match article-pattern artno)
           (when (not (null dirnam))
 
-	    ;; maybe limit results to matching groups.
-	    (when (or (not groupspec)
-		      (string-match groupspec dirnam))
-	      (nnir-add-result dirnam artno "" prefix server artlist)))))
+	    (nnir-add-result dirnam artno "" prefix server artlist))))
 
       (message "Massaging notmuch output...done")
 
-- 
2.19.1


  parent reply	other threads:[~2018-10-24  0:46 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23  2:56 bug#33122: 27.0.50; Allow use of Gnus search groups as notmuch :path search terms Eric Abrahamsen
     [not found] ` <handler.33122.B.154026344121931.ack@debbugs.gnu.org>
2018-10-24  0:46   ` Eric Abrahamsen [this message]
2018-11-03  8:43     ` bug#33122: Acknowledgement (27.0.50; Allow use of Gnus search groups as notmuch :path search terms) Eli Zaretskii
2018-11-19 18:17       ` Eric Abrahamsen

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=875zxscgt6.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=33122@debbugs.gnu.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.