unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Allen Li <darkfeline@felesatra.moe>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 46884@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#46884: [PATCH] 27.1; Cannot run find-dired with -maxdepth
Date: Sat, 13 Mar 2021 21:38:11 +0000	[thread overview]
Message-ID: <CADbSrJz5xp63shi7kDFc8K+PcF5f=4zrzsc_M2MsiCpbGpG9jQ@mail.gmail.com> (raw)
In-Reply-To: <831rcjjsht.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1052 bytes --]

Sorry, I attached the wrong patch, here's the one for the rgrep approach.

On Sat, Mar 13, 2021 at 9:46 AM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Allen Li <darkfeline@felesatra.moe>
> > Date: Fri, 12 Mar 2021 08:08:55 +0000
> > Cc: Juri Linkov <juri@linkov.net>, 46884@debbugs.gnu.org
> >
> > Attached patch, does this approach look good?
>
> I guess my suggestion to additionally allow specification of
> GLOBAL-ARGS interactively (via prefix arg) got voted down?
>
> > +---
> > +*** Optional 'global-args' parameter added to 'find-dired'.
> > +This allows passing find global options like -maxdepth.
>
> "find" should be in quotes: 'find'
>
> > @@ -202,6 +203,7 @@ find-dired
> >      (setq default-directory dir
> >         find-args args              ; save for next interactive call
> >         args (concat find-program " . "
> > +                       (if global-args global-args "")
>
> 'concat' knows how to handle nil arguments, so you don't need the
> empty string alternative here.  Just (if global-args global-args)
> should do.

[-- Attachment #2: 0001-find-dired-Add-command-editing-like-rgrep.patch --]
[-- Type: text/x-patch, Size: 4937 bytes --]

From a8dce73ca0ae1482dbfb8c10a82f51529fbe1226 Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
Date: Fri, 12 Mar 2021 00:07:22 -0800
Subject: [PATCH] find-dired: Add command editing like rgrep

The original find-dired does not allow for constructing queries like

 find . -maxdepth 3 \( OTHER-ARGS \) -ls

* lisp/find-dired.el (find-dired): Added command editing and
confirmation.
---
 lisp/find-dired.el | 79 +++++++++++++++++++++++++++++++---------------
 1 file changed, 54 insertions(+), 25 deletions(-)

diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index adc5672eca..d263bef706 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -151,13 +151,16 @@ find-dired-refine-function
 (defvar find-args nil
   "Last arguments given to `find' by \\[find-dired].")
 
-;; History of find-args values entered in the minibuffer.
-(defvar find-args-history nil)
+(defvar find-args-history nil
+  "History list for args provided to `find-dired'.")
+
+(defvar find-dired-history nil
+  "History list for `find-dired'.")
 
 (defvar dired-sort-inhibit)
 
 ;;;###autoload
-(defun find-dired (dir args)
+(defun find-dired (dir &optional args confirm)
   "Run `find' and go into Dired mode on a buffer of the output.
 The command run (after changing into DIR) is essentially
 
@@ -166,11 +169,29 @@ find-dired
 except that the car of the variable `find-ls-option' specifies what to
 use in place of \"-ls\" as the final argument.
 
+With \\[universal-argument] prefix, you can edit the constructed shell command line
+before it is executed.
+With two \\[universal-argument] prefixes, directly edit and run `grep-find-command'.
+
 Collect output in the \"*Find*\" buffer.  To kill the job before
-it finishes, type \\[kill-find]."
-  (interactive (list (read-directory-name "Run find in directory: " nil "" t)
-		     (read-string "Run find (with args): " find-args
-				  '(find-args-history . 1))))
+it finishes, type \\[kill-find].
+
+When called programmatically and ARGS is nil, DIR is expected to
+specify a command to run.
+
+If CONFIRM is non-nil, the user will be given an opportunity to edit the
+command before it's run."
+  (interactive
+   (cond
+    ((and grep-find-command (equal current-prefix-arg '(16)))
+     (list (read-from-minibuffer "Run: " (cons (format "%s . -ls" find-program)
+                                               (+ (length find-program) 3))
+				 nil nil 'find-dired-history)))
+    (t (let* ((dir (read-directory-name "Run find in directory: " nil "" t))
+              (args (read-string "Run find (with args): " find-args
+                                 '(find-args-history . 1)))
+	      (confirm (equal current-prefix-arg '(4))))
+	 (list dir args confirm)))))
   (let ((dired-buffers dired-buffers))
     ;; Expand DIR ("" means default-directory), and make sure it has a
     ;; trailing slash.
@@ -199,23 +220,31 @@ find-dired
     (kill-all-local-variables)
     (setq buffer-read-only nil)
     (erase-buffer)
-    (setq default-directory dir
-	  find-args args	      ; save for next interactive call
-	  args (concat find-program " . "
-		       (if (string= args "")
-			   ""
-			 (concat
-			  (shell-quote-argument "(")
-			  " " args " "
-			  (shell-quote-argument ")")
-			  " "))
-		       (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|\\+\\)\\'"
-					 (car find-ls-option))
-			   (format "%s %s %s"
-				   (match-string 1 (car find-ls-option))
-				   (shell-quote-argument "{}")
-				   find-exec-terminator)
-			 (car find-ls-option))))
+    (setq default-directory dir)
+    (if (null args)
+        (setq args dir)
+      (setq find-args args	      ; save for next interactive call
+            args (concat find-program " . "
+		         (if (string= args "")
+		             ""
+		           (concat
+		            (shell-quote-argument "(")
+		            " " args " "
+		            (shell-quote-argument ")")
+		            " "))
+		         (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|\\+\\)\\'"
+				           (car find-ls-option))
+		             (format "%s %s %s"
+			             (match-string 1 (car find-ls-option))
+			             (shell-quote-argument "{}")
+			             find-exec-terminator)
+		           (car find-ls-option)))))
+    (if confirm
+        (setq args
+              (read-from-minibuffer "Confirm: "
+			            args nil nil 'find-dired-history))
+      (add-to-history 'find-dired-history args))
+
     ;; Start the find process.
     (shell-command (concat args "&") (current-buffer))
     (dired-mode dir (cdr find-ls-option))
@@ -393,7 +422,7 @@ find-dired-sentinel
 	      ;; will stay around until M-x `list-processes'.
 	      (delete-process proc)
 	      (force-mode-line-update))))
-	  (message "find-dired %s finished." buf))))
+      (message "find-dired %s finished." buf))))
 
 (defun find-dired-sort-by-filename ()
   "Sort entries in *Find* buffer by file name lexicographically."
-- 
2.30.2


  parent reply	other threads:[~2021-03-13 21:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03  1:12 bug#46884: 27.1; Cannot run find-dired with -maxdepth Allen Li
2021-03-03  1:20 ` bug#46884: [PATCH] " Allen Li
2021-03-03  3:38   ` Allen Li
2021-03-03  6:28     ` Eli Zaretskii
2021-03-03  8:22       ` Allen Li
2021-03-03  8:55         ` Eli Zaretskii
2021-03-04  4:50           ` Allen Li
2021-03-04  9:35             ` Juri Linkov
2021-03-05  3:21               ` Allen Li
2021-03-05  7:27                 ` Eli Zaretskii
2021-03-12  8:08                   ` Allen Li
2021-03-12 15:49                     ` bug#46884: [External] : " Drew Adams
2021-03-13  0:42                       ` Allen Li
2021-03-13  1:09                         ` Drew Adams
2021-03-13  9:46                     ` Eli Zaretskii
2021-03-13  9:58                       ` Andreas Schwab
2021-03-13 21:38                       ` Allen Li [this message]
2021-03-13 21:53                         ` Juri Linkov
2021-03-14  0:40                           ` Allen Li
2021-03-18 18:52                             ` Juri Linkov
2022-06-19 23:55                               ` bug#46884: " Lars Ingebrigtsen
2022-06-26  3:54                                 ` Allen Li
2022-06-27  7:46                                   ` Lars Ingebrigtsen
2021-03-04 13:53             ` bug#46884: [PATCH] " Eli Zaretskii
2021-03-03  9:03         ` Juri Linkov
2021-03-03 15:42         ` bug#46884: [External] : " Drew Adams
2021-03-03 16:20           ` Eli Zaretskii
2021-03-03  6:15   ` Eli Zaretskii
2021-03-03  1:34 ` bug#46884: [External] : bug#46884: " Drew Adams

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CADbSrJz5xp63shi7kDFc8K+PcF5f=4zrzsc_M2MsiCpbGpG9jQ@mail.gmail.com' \
    --to=darkfeline@felesatra.moe \
    --cc=46884@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=juri@linkov.net \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).