GNU bug report logs - #73581
29.4; Gnus: Error doing a search on nnmaildir with gnus-search-find-grep

Previous Next

Packages: gnus, emacs;

Reported by: Daniel Cerqueira <dan.list <at> lispclub.com>

Date: Tue, 1 Oct 2024 15:55:02 UTC

Severity: normal

Found in version 29.4

Full log


View this message in rfc822 format

From: Visuwesh <visuweshm <at> gmail.com>
To: Daniel Cerqueira <dan.list <at> lispclub.com>
Cc: 73581 <at> debbugs.gnu.org
Subject: bug#73581: 29.4; Gnus: Error doing a search on nnmaildir with gnus-search-find-grep
Date: Sat, 12 Apr 2025 10:11:04 +0530
[வெள்ளி ஏப்ரல் 11, 2025] Daniel Cerqueira wrote:

> A bit related:
>
> Can you give an overview how to make search queries with find-grep?
>
> For example, I am trying to make a query with "grep:"happy birthday"
> subject:friend" and it is not working.  Should I prepend a "grep:" after
> each space (on the search keywords)?

AFAIU the code, you can't have space in the grep part.  See how
gnus-search parses these "meta keywords" in gnus-search-prepare-query.
Having two grep: selects the last one.  Give the patch below a try, I
don't think it is a good idea to reuse gnus-search-query-next-expr since
it does more than just go over "":

diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el
index 41915a0e3c0..7ca67e2134b 100644
--- a/lisp/gnus/gnus-search.el
+++ b/lisp/gnus/gnus-search.el
@@ -2110,20 +2140,28 @@ gnus-search-prepare-query
 	val)
     (when (stringp query)
       ;; Look for these meta keys:
-      (while (string-match
-	      "\\(thread\\|grep\\|limit\\|raw\\):\\([^ ]+\\)"
-	      query)
-	(setq val (match-string 2 query))
-	(setf (alist-get (intern (match-string 1 query)) query-spec)
-	      ;; This is stupid.
-	      (cond
-	       ((equal val "t"))
-	       ((null (zerop (string-to-number val)))
-		(string-to-number val))
-	       (t val)))
-	(setq query
-	      (string-trim (replace-match "" t t query 0)))
-	(setf (alist-get 'query query-spec) query)))
+      (with-temp-buffer
+        (insert query)
+        (goto-char (point-min))
+        (while (re-search-forward "\\(thread\\|grep\\|limit\\|raw\\):" nil t)
+          (setq val (cons
+                     (match-string 1)
+                     (buffer-substring (point)
+                                       (if (eq (char-after) ?\")
+                                           (progn (forward-sexp) (point))
+                                         (progn (forward-whitespace) (1- (point)))))))
+          (setf (alist-get (intern (car val)) query-spec)
+                ;; This is stupid.
+                (cond
+	         ((equal (cdr val) "t"))
+	         ((null (zerop (string-to-number (cdr val))))
+		  (string-to-number (cdr val)))
+	         (t (string-trim (cdr val) "\"" "\""))))
+          (setq query (string-trim (string-replace
+                                    (concat (car val) ":" (cdr val))
+                                    ""
+                                    query)))
+          (setf (alist-get 'query query-spec) query))))
     (when (and gnus-search-use-parsed-queries
 	       (null (alist-get 'raw query-spec)))
       (setf (alist-get 'parsed-query query-spec)

> How to search in the subject or by date?

You can't, the find-grep search backend simply runs grep.  If you don't
want to use mu or notmuch, you could try writing a backend for mblaze.




This bug report was last modified 66 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.