From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs 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 Message-ID: <875zxscgt6.fsf@ericabrahamsen.net> References: <871s8hfk0g.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1540342625 20980 195.159.176.226 (24 Oct 2018 00:57:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 24 Oct 2018 00:57:05 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: 33122@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Oct 24 02:57:01 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gF7Tn-0005Jf-Pr for geb-bug-gnu-emacs@m.gmane.org; Wed, 24 Oct 2018 02:57:00 +0200 Original-Received: from localhost ([::1]:45017 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF7Vq-0006wy-Uo for geb-bug-gnu-emacs@m.gmane.org; Tue, 23 Oct 2018 20:59:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gF7Vb-0006s4-W4 for bug-gnu-emacs@gnu.org; Tue, 23 Oct 2018 20:58:56 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gF7KA-0006Wq-KQ for bug-gnu-emacs@gnu.org; Tue, 23 Oct 2018 20:47:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:34699) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gF7KA-0006Sm-AZ for bug-gnu-emacs@gnu.org; Tue, 23 Oct 2018 20:47:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gF7KA-0005sA-1l for bug-gnu-emacs@gnu.org; Tue, 23 Oct 2018 20:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 24 Oct 2018 00:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 33122 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 33122-submit@debbugs.gnu.org id=B33122.154034200822554 (code B ref 33122); Wed, 24 Oct 2018 00:47:01 +0000 Original-Received: (at 33122) by debbugs.gnu.org; 24 Oct 2018 00:46:48 +0000 Original-Received: from localhost ([127.0.0.1]:38957 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gF7Jv-0005ri-Kc for submit@debbugs.gnu.org; Tue, 23 Oct 2018 20:46:47 -0400 Original-Received: from mail.ericabrahamsen.net ([50.56.99.223]:54031) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gF7Jt-0005rZ-Be for 33122@debbugs.gnu.org; Tue, 23 Oct 2018 20:46:45 -0400 Original-Received: from localhost (unknown [123.116.140.152]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 791813F8B1 for <33122@debbugs.gnu.org>; Wed, 24 Oct 2018 00:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mail.ericabrahamsen.net; s=mail; t=1540342004; bh=K7wip/JHnDkO+Su4G/AGiyMcUcyrLwPZ4ylwzjR/G+g=; h=From:To:Subject:In-Reply-To:References:Date:From; b=PKLImOj/yzfOPuBGeguC5AI8XgXwAuISkfV24nAGrIJ7ZCrjk4DGGJKWJNcqSXLhu Cntb3Pk/6i6nLNlZcnVJdrCp8e0NCItR6ixXwFm0mlqW8BiZESws4P2zwUNUtAjs+U spVA5fL4J6KO8i5ShaCk8SnvymdapAmb6HLZgZ6Q= In-Reply-To: (GNU bug Tracking System's message of "Tue, 23 Oct 2018 02:58:02 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:151537 Archived-At: --=-=-= Content-Type: text/plain Here's an updated version of the patch, thanks to Andreas Goesele for reporting and testing. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Allow-use-of-Gnus-search-groups-as-notmuch-path-sear.patch >From 517ca66601e97babeda7a20150bee24df9c9975b Mon Sep 17 00:00:00 2001 From: Eric Abrahamsen 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 --=-=-=--