summaryrefslogtreecommitdiff
path: root/lisp/find-dired.el
diff options
context:
space:
mode:
authorAllen Li <darkfeline@felesatra.moe>2022-06-27 09:46:27 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2022-06-27 09:46:27 +0200
commitbc3b20b44164aad1b196518516ecf3645219ac72 (patch)
tree28e8cb72ca64c3e0207be3bcf068d6c77279e114 /lisp/find-dired.el
parent995fb1677d640784f1ca58ef99a71314a3ac9d30 (diff)
downloademacs-bc3b20b44164aad1b196518516ecf3645219ac72.tar.gz
find-dired: Add find-dired-with-command
Add a command that runs and sets up the find-dired buffer with an arbitrary find command. Also rewrite the existing find-dired commands using it. The set of commands possible with find-dired is limited; the new command allows users to run the full set of commands, but also leaves the responsibility to the user to construct the command manually. * lisp/find-dired.el (find-command-history): New var. (find-dired-with-command): New command. (find-dired): Rewritten with new command.
Diffstat (limited to 'lisp/find-dired.el')
-rw-r--r--lisp/find-dired.el53
1 files changed, 39 insertions, 14 deletions
diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index 998ddbc721f..2f3f6b689aa 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -154,6 +154,9 @@ output of `find' (one file per line) when this function is called."
;; History of find-args values entered in the minibuffer.
(defvar find-args-history nil)
+(defvar find-command-history nil
+ "History of commands passed interactively to `find-dired-with-command'.")
+
(defvar dired-sort-inhibit)
;;;###autoload
@@ -171,6 +174,38 @@ 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))))
+ (setq find-args args ; save for next interactive call
+ args (concat find-program " . "
+ (if (string= args "")
+ ""
+ (concat
+ (shell-quote-argument "(")
+ " " args " "
+ (shell-quote-argument ")")
+ " "))
+ (find-dired--escaped-ls-option)))
+ (find-dired-with-command dir args))
+
+;;;###autoload
+(defun find-dired-with-command (dir command)
+ "Run `find' and go into Dired mode on a buffer of the output.
+The user-supplied COMMAND is run after changing into DIR and should look like
+
+ find . GLOBALARGS \\( ARGS \\) -ls
+
+The car of the variable `find-ls-option' specifies what to
+use in place of \"-ls\" as the starting input.
+
+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 command: "
+ (cons (concat find-program
+ " . \\( \\) "
+ (find-dired--escaped-ls-option))
+ (+ 1 (length find-program) (length " . \\( ")))
+ find-command-history)))
(let ((dired-buffers dired-buffers))
;; Expand DIR ("" means default-directory), and make sure it has a
;; trailing slash.
@@ -199,19 +234,9 @@ it finishes, type \\[kill-find]."
(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 ")")
- " "))
- (find-dired--escaped-ls-option)))
+ (setq default-directory dir)
;; Start the find process.
- (shell-command (concat args "&") (current-buffer))
+ (shell-command (concat command "&") (current-buffer))
(dired-mode dir (cdr find-ls-option))
(let ((map (make-sparse-keymap)))
(set-keymap-parent map (current-local-map))
@@ -220,7 +245,7 @@ it finishes, type \\[kill-find]."
(setq-local dired-sort-inhibit t)
(setq-local revert-buffer-function
(lambda (_ignore-auto _noconfirm)
- (find-dired dir find-args)))
+ (find-dired-with-command dir command)))
;; Set subdir-alist so that Tree Dired will work:
(if (fboundp 'dired-simple-subdir-alist)
;; will work even with nested dired format (dired-nstd.el,v 1.15
@@ -240,7 +265,7 @@ it finishes, type \\[kill-find]."
;; Make second line a ``find'' line in analogy to the ``total'' or
;; ``wildcard'' line.
(let ((point (point)))
- (insert " " args "\n")
+ (insert " " command "\n")
(dired-insert-set-properties point (point)))
(setq buffer-read-only t)
(let ((proc (get-buffer-process (current-buffer))))