Ephemeral notmuch search group

Jakub Ječmínek <[email protected]> Sun, 13 Jul 2025 00:14:17 +0200
Newsgroups gmane.emacs.gnus.general
Message-ID <[email protected]>
Hi, here's a little function which creates ephemeral group based on a
Notmuch search result.  I ocasionally use Notmuch to perform fast search
but I don't want to use nnmaildir or leave Gnus. Maybe it will be useful
to someone :).


(defun gnus-read-ephemeral-notmuch-search-group (query limit &optional window-conf)
  "Create an ephemeral group based on a Notmuch search.

Performs a Notmuch search using QUERY and displays them in an ephemeral
group.

If called without a prefix argument, prompts for a LIMIT value."
  (interactive (list
		(read-string "Query: ")
		(or current-prefix-arg (read-number "Limit: " 200))))
  (unless (executable-find gnus-search-notmuch-program)
    (user-error "Notmuch executable not found in PATH"))
  (unless (file-exists-p gnus-search-notmuch-config-file)
    (user-error "Notmuch config file does not exist: %s"
	   gnus-search-notmuch-config-file))
  (let* ((tmpfile (make-temp-file "notmuch-search#"))
	 (file-name (file-name-nondirectory tmpfile)))
    (with-temp-file tmpfile
      (mm-disable-multibyte)
      (call-process
       gnus-search-notmuch-program nil t nil
       (format "--config=%s" gnus-search-notmuch-config-file)
       "show" "--format=mbox" "--sort=newest-first" (format "--limit=%s" limit)
       "--" query))
      (gnus-group-read-ephemeral-group
       (concat "nndoc+ephemeral:" file-name)
       `(nndoc ,tmpfile
               (nndoc-article-type mbox))
       nil window-conf)
    (delete-file tmpfile)))