Subject: bug#60024: 28.2; rgrep as part of function don't work

From: Stefan Kangas <[email-masked]>
Date: Mon, 12 Dec 2022 16:32:30 -0800

tags 60024 + patch confirmed
found 60024 29.0.60
thanks

Einar Largenius <[email-masked]> writes:

> I have the following function:
>
> (defun search-journal (regexp)
>   "Searches journal for `regexp'."
>   (interactive "sSök i journalen: ")
>   (rgrep regexp "* .*" org-directory))
>
> When I run it after startup. It gives me an error:
>
> rgrep-default-command: Wrong type argument: stringp, nil
>
> After I run M-x rgrep<RET>C-g. The above command works just fine. I
> tested with emacs -Q and the same thing happens.

Could you please test the attached patch and see if it fixes your
problem?

Thanks.
From db1194069df971736812c5b1f4f891306b804d6b Mon Sep 17 00:00:00 2001
From: Stefan Kangas <[email-masked]>
Date: Tue, 13 Dec 2022 01:27:58 +0100
Subject: [PATCH] Fix bug when calling `rgrep` non-interactively

* lisp/progmodes/grep.el (rgrep): Fix bug where running
non-interactively requires running it interactively
first.  (Bug#60024)
---
 lisp/progmodes/grep.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 2446e86abb..35cac43bee 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -1254,6 +1254,10 @@ rgrep
 					  nil default-directory t))
 		(confirm (equal current-prefix-arg '(4))))
 	   (list regexp files dir confirm))))))
+  ;; If called non-interactively, also compute the defaults if we
+  ;; haven't already.
+  (unless grep-find-template
+    (grep-compute-defaults))
   (when (and (stringp regexp) (> (length regexp) 0))
     (unless (and dir (file-accessible-directory-p dir))
       (setq dir default-directory))
-- 
2.35.1