Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: "Andreas Goesele" <goesele@hfph.mwn.de>
To: info-gnus-english@gnu.org
Subject: Re: nnir notmuch search on specific groups?
Date: Sun, 21 Oct 2018 21:41:35 +0200	[thread overview]
Message-ID: <878t2rjde8.fsf@hfph.mwn.de> (raw)
In-Reply-To: <mailman.2552.1540148988.1284.info-gnus-english@gnu.org>

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> Adam Sjøgren <asjo@koldfront.dk> writes:
>
> Would you try this and see if it does what you'd expect?

That's great: It works like charme with folders directly in the Mail
directory. For subfolders it only would be necessary to replace the "."
by a slash "/". So instead of searching "mail.subfolder" (as subfolders
are shown in the group buffer) it should search "mail/subfolder".

> (defun nnir-run-notmuch (query server &optional groups)
>   "Run QUERY against notmuch.
> Returns a vector of (group name, file name) pairs (also vectors,
> actually).  If GROUPS is a list of group names, use them to
> construct path: search terms."
>
>   (save-excursion
>     (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]+$"))
> 	   (groups (mapcar #'gnus-group-short-name groups))
> 	   (pathquery (when groups
> 			(mapconcat (lambda (g)
> 				     (format " path:%s" g))
> 				   groups " or")))
>            artno dirnam filenam)
>
>       (when (equal "" qstring)
>         (error "notmuch: You didn't enter anything"))
>
>       (set-buffer (get-buffer-create nnir-tmp-buffer))
>       (erase-buffer)
>
>       (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
>                          nil            ; don't redisplay
>                          "search"
>                          "--format=text"
>                          "--output=files"
>                          ,@(nnir-read-server-parm 'nnir-notmuch-additional-switches server)
>                          ,qstring       ; the query, in notmuch format
>                          ))
>              (exitstatus
>               (progn
>                 (message "%s args: %s" nnir-notmuch-program
>                          (mapconcat #'identity (nthcdr 4 cp-list) " ")) ;; ???
>                 (apply #'call-process cp-list))))
>         (unless (or (null exitstatus)
>                     (zerop exitstatus))
>           (nnheader-report 'nnir "Couldn't run notmuch: %s" exitstatus)
>           ;; notmuch failure reason is in this buffer, show it if
>           ;; the user wants it.
>           (when (> gnus-verbose 6)
>             (display-buffer nnir-tmp-buffer))))
>
>       ;; The results are output in the format of:
>       ;; absolute-path-name
>       (goto-char (point-min))
>       (while (not (eobp))
>         (setq filenam (buffer-substring-no-properties (line-beginning-position)
>                                                       (line-end-position))
>               artno (file-name-nondirectory filenam)
>               dirnam (file-name-directory filenam))
>         (forward-line 1)
>
>         ;; don't match directories
>         (when (string-match article-pattern artno)
>           (when (not (null dirnam))
>
> 	    (nnir-add-result dirnam artno "" prefix server artlist))))
>
>       (message "Massaging notmuch output...done")
>
>       artlist)))
>
>

-- 
Omnis enim res, quae dando non deficit, dum habetur et non datur,
nondum habetur, quomodo habenda est.
                                      Augustinus, De doctrina christiana
_______________________________________________
info-gnus-english mailing list
info-gnus-english@gnu.org
https://lists.gnu.org/mailman/listinfo/info-gnus-english

  parent reply	other threads:[~2018-10-21 19:41 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-20 21:56 Andreas Goesele
2018-10-21  3:48 ` Eric Abrahamsen
2018-10-21 10:35   ` Adam Sjøgren
2018-10-21 16:49     ` Eric Abrahamsen
2018-10-21 17:50       ` Adam Sjøgren
2018-10-21 18:58         ` Eric Abrahamsen
     [not found]         ` <mailman.2552.1540148988.1284.info-gnus-english@gnu.org>
2018-10-21 19:41           ` Andreas Goesele [this message]
2018-10-21 20:08             ` Eric Abrahamsen
2018-10-21 20:24               ` Eric Abrahamsen
     [not found]             ` <mailman.2556.1540152550.1284.info-gnus-english@gnu.org>
2018-10-21 21:17               ` Andreas Goesele
2018-10-23  3:01                 ` Eric Abrahamsen
     [not found]                 ` <mailman.2606.1540263818.1284.info-gnus-english@gnu.org>
2018-10-23 20:37                   ` Andreas Goesele
2018-10-24  0:47                     ` Eric Abrahamsen
     [not found]                     ` <mailman.2644.1540342724.1284.info-gnus-english@gnu.org>
2018-10-24 16:46                       ` Andreas Goesele
     [not found]     ` <mailman.2547.1540140585.1284.info-gnus-english@gnu.org>
2018-10-21 18:49       ` Andreas Goesele
     [not found]   ` <mailman.2538.1540118168.1284.info-gnus-english@gnu.org>
2018-10-21 16:41     ` Andreas Goesele

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=878t2rjde8.fsf@hfph.mwn.de \
    --to=goesele@hfph.mwn.de \
    --cc=info-gnus-english@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.
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 NNTP newsgroup(s).