From 7c2335ff5140a13578b03d3b147381c111bdd528 Mon Sep 17 00:00:00 2001 From: Allen Li Date: Tue, 2 Mar 2021 14:24:16 -0800 Subject: [PATCH] find-dired: Split out find-dired-unescaped The original find-dired does not allow for constructing queries like find . -maxdepth 3 \( OTHER-ARGS \) -ls It also makes the find-dired logic essential impossible to reuse. The new find-dired-unescaped can by used to construct more interesting queries. * lisp/find-dired.el (find-dired-unescaped): Added new function. (find-dired): Rewritten to use find-dired-unescaped. --- etc/NEWS | 4 ++++ lisp/find-dired.el | 30 +++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 73f136cfa7..3a3a086373 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -653,6 +653,10 @@ keys, add the following to your init file: (global-set-key "\C-x\C-j" nil) (global-set-key "\C-x4\C-j" nil) +--- +*** New function 'find-dired-unescaped' enables user code to run more +complicated find commands. + ** Change Logs and VC *** More VC commands can be used from non-file buffers. diff --git a/lisp/find-dired.el b/lisp/find-dired.el index adc5672eca..f0aa764471 100644 --- a/lisp/find-dired.el +++ b/lisp/find-dired.el @@ -171,6 +171,25 @@ find-dired (interactive (list (read-directory-name "Run find in directory: " nil "" t) (read-string "Run find (with args): " find-args '(find-args-history . 1)))) + (find-dired-with-args dir (if (string= args "") + "" + (concat + (shell-quote-argument "(") + " " args " " + (shell-quote-argument ")") + " ")))) + +;;;###autoload +(defun find-dired-unescaped (dir args) + "Run `find' and go into Dired mode on a buffer of the output. +The command run (after changing into DIR) is essentially + + find . ARGS -ls + +except that the car of the variable `find-ls-option' specifies what to +use in place of \"-ls\" as the final argument. + +This function can be used to build more specialized commands using `find-dired'." (let ((dired-buffers dired-buffers)) ;; Expand DIR ("" means default-directory), and make sure it has a ;; trailing slash. @@ -200,15 +219,8 @@ find-dired (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 ")") - " ")) + args (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|\\+\\)\\'" (car find-ls-option)) (format "%s %s %s" @@ -393,7 +405,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.1