From: Allen Li <darkfeline@felesatra.moe>
To: 46884@debbugs.gnu.org
Subject: bug#46884: [PATCH] 27.1; Cannot run find-dired with -maxdepth
Date: Wed, 3 Mar 2021 01:20:45 +0000 [thread overview]
Message-ID: <CADbSrJyvaNFHtsWhWnqo0xVYApvN2KHjuRLGg1yqWZvAwJxmVg@mail.gmail.com> (raw)
In-Reply-To: <80k0qpdoqd.fsf@felesatra.moe>
[-- Attachment #1.1: Type: text/plain, Size: 348 bytes --]
Some additional context: I'm not asking for find-dired to support -maxdepth
necessarily, but the way find-dired is structured makes it impossible to
reuse any of the code to write a command that could support -maxdepth.
I attached a patch pulling most of the find-dired logic into a
find-dired-unescaped function so that it can be readily reused.
[-- Attachment #1.2: Type: text/html, Size: 398 bytes --]
[-- Attachment #2: 0001-find-dired-Split-out-find-dired-unescaped.patch --]
[-- Type: text/x-patch, Size: 3184 bytes --]
From 7c2335ff5140a13578b03d3b147381c111bdd528 Mon Sep 17 00:00:00 2001
From: Allen Li <darkfeline@felesatra.moe>
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
next prev parent reply other threads:[~2021-03-03 1:20 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 ` Allen Li [this message]
2021-03-03 3:38 ` bug#46884: [PATCH] " 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
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=CADbSrJyvaNFHtsWhWnqo0xVYApvN2KHjuRLGg1yqWZvAwJxmVg@mail.gmail.com \
--to=darkfeline@felesatra.moe \
--cc=46884@debbugs.gnu.org \
/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).