Subject: bug#27456: 25.2; Not possible to use -prune with find-dired

From: Drew Adams <[email-masked]>
Date: Sun, 9 Sep 2018 07:04:26 -0700 (PDT)

> For now I have raised this as bug#32668: 26.1; Give find-dired prefix
> argument behaviour equivalent to that of rgrep

FWIW, in my library `find-dired+.el', which adds to `find-dired.el',
`find-dired' acts as follows (`C-h f find-dired'):

------8<---------------
find-dired is an interactive Lisp function in ‘find-dired+.el’. 

(find-dired DIR ARGS &optional DEPTH-LIMITS EXCLUDED-PATHS)

Run ‘find’ and put its output in a buffer in Dired Mode.
Then run ‘find-dired-hook’ and ‘dired-after-readin-hook’.
The ‘find’ command run (after changing into DIR) is essentially this,
where LS-SWITCHES is ‘(car find-ls-option)’:

  find . \( ARGS \) LS-SWITCHES

Optional args:

* DEPTH-LIMITS:   Minimum and maximum depths: (MIN-DEPTH MAX-DEPTH).
* EXCLUDED-PATHS: Strings matching paths to be excluded.
                  Uses ‘find’ switch ‘-path’.

When both optional args are non-nil, the ‘find’ command run is this:

  find . -mindepth MIN-DEPTH -maxdepth MAX-DEPTH
         \( -path EXCLUDE1 -o -path EXCLUDE2 ... \)
         -prune -o \( ARGS \) LS-SWITCHES

where EXCLUDE1, EXCLUDE2... are the EXCLUDED-PATHS, but shell-quoted.
------8<---------------

The same is true for `find-name-dired' and `find-grep-dired' - they make the same use of `-prune', as does the new command `find-time-dired' (`C-h f'):

------8<---------------
find-time-dired is an interactive Lisp function in ‘find-dired+.el’.
 
(find-time-dired DIR MIN-TIME MAX-TIME &optional DEPTH-LIMITS
EXCLUDED-PATHS)

Find files in directory DIR newer or older than a timestamp.
The output is shown in a Dired buffer.

MIN-TIME is a format-time string parsable by ‘parse-time-string’, such
 as "2014-12-25 23:59:00".  Only files newer than this are shown.
 If MIN-TIME is nil or a string matching regexp "^\s-*$", there is
 no lower time limit.

MAX-TIME is also a format-time string parsable by ‘parse-time-string’.
 Only files older than this time are shown.
 If MAX-TIME is nil or a string matching regexp "^\s-*$", the upper
 time limit is the current system time.

Optional arg DEPTH-LIMITS is a list (MIN-DEPTH MAX-DEPTH) of the
 minimum and maximum depths.  If nil, search directory tree under DIR.

Optional arg EXCLUDED-PATHS is a list of strings that match paths to
 exclude from the search.  If nil, search all directories.

If args DEPTH-LIMITS and EXCLUDED-PATHS are both non-nil then the
command run is essentially the following:

    find . -mindepth MIN-DEPTH -maxdepth MAX-DEPTH
           \( -path EXCLUDE1 -o -path EXCLUDE2 ... \)
           -prune -o \( -TIME-SWITCH -SINCE-MIN -TIME-SWITCH +SINCE-MAX \)
           LS-SWITCHES

where:

* EXCLUDE1, EXCLUDE2... are the EXCLUDED-PATHS, but shell-quoted.
* TIME-SWITCH is ‘find-diredp-time-prefix’ concatenated with "min".
* SINCE-MIN is the elapsed time since MIN-TIME in minutes.
* SINCE-MAX is the elapsed time since MAX-TIME in minutes.
* LS-SWITCHES is ‘(car find-ls-option)’.
------8<---------------

This code was improved by Tino Calancha. Without having studied
the bug threads of #27456 or #32668, this sounds relevant. If it
helps I can offer this code, as a patch or as is. The code is here:

https://www.emacswiki.org/emacs/download/find-dired%2b.el