diff options
| author | Glenn Morris | 2011-04-02 13:36:47 -0700 |
|---|---|---|
| committer | Glenn Morris | 2011-04-02 13:36:47 -0700 |
| commit | 1d2e369d6cc534d812f5fc025fd9f1f52e7df710 (patch) | |
| tree | 70911e027a06dfae446a6cc9b3ecd7ef090c9e38 | |
| parent | e7a395b5128e98dd9b65f71ccb6c4655253116d6 (diff) | |
| download | emacs-1d2e369d6cc534d812f5fc025fd9f1f52e7df710.tar.gz emacs-1d2e369d6cc534d812f5fc025fd9f1f52e7df710.zip | |
find-dired improvements for bug#4403.
* lisp/find-dired.el (find-exec-terminator): New option.
(find-ls-option): Test for -ls support.
(find-ls-subdir-switches): Test for -b in find-ls-option.
(find-dired, find-grep-dired): Doc fixes.
(find-dired): Use find-exec-terminator.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/find-dired.el | 64 |
2 files changed, 56 insertions, 14 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 77497f5c01a..9a5b1fd6cc4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,11 @@ | |||
| 1 | 2011-04-02 Glenn Morris <rgm@gnu.org> | 1 | 2011-04-02 Glenn Morris <rgm@gnu.org> |
| 2 | 2 | ||
| 3 | * find-dired.el (find-exec-terminator): New option. | ||
| 4 | (find-ls-option): Test for -ls support. | ||
| 5 | (find-ls-subdir-switches): Test for -b in find-ls-option. | ||
| 6 | (find-dired, find-grep-dired): Doc fixes. | ||
| 7 | (find-dired): Use find-exec-terminator. | ||
| 8 | |||
| 3 | * find-dired.el (find-ls-option, find-ls-subdir-switches) | 9 | * find-dired.el (find-ls-option, find-ls-subdir-switches) |
| 4 | (find-grep-options): Do not autoload these defcustoms, remove purecopy. | 10 | (find-grep-options): Do not autoload these defcustoms, remove purecopy. |
| 5 | (find-name-arg): Remove purecopy. | 11 | (find-name-arg): Remove purecopy. |
diff --git a/lisp/find-dired.el b/lisp/find-dired.el index d24a51edd35..a2b196dc029 100644 --- a/lisp/find-dired.el +++ b/lisp/find-dired.el | |||
| @@ -33,27 +33,56 @@ | |||
| 33 | :group 'dired | 33 | :group 'dired |
| 34 | :prefix "find-") | 34 | :prefix "find-") |
| 35 | 35 | ||
| 36 | ;; FIXME this option does not really belong in this file, it's more general. | ||
| 37 | ;; Eg cf some tests in grep.el. | ||
| 38 | (defcustom find-exec-terminator | ||
| 39 | (if (eq 0 | ||
| 40 | (ignore-errors | ||
| 41 | (process-file find-program nil nil nil | ||
| 42 | null-device "-exec" "echo" "{}" "+"))) | ||
| 43 | "+" | ||
| 44 | (shell-quote-argument ";")) | ||
| 45 | "String that terminates \"find -exec COMMAND {} \". | ||
| 46 | The value should include any needed quoting for the shell. | ||
| 47 | Common values are \"+\" and \"\\\\;\", with the former more efficient | ||
| 48 | than the latter." | ||
| 49 | :version "24.1" | ||
| 50 | :group 'find-dired | ||
| 51 | :type 'string) | ||
| 52 | |||
| 36 | ;; find's -ls corresponds to these switches. | 53 | ;; find's -ls corresponds to these switches. |
| 37 | ;; Note -b, at least GNU find quotes spaces etc. in filenames | 54 | ;; Note -b, at least GNU find quotes spaces etc. in filenames |
| 38 | (defcustom find-ls-option | 55 | (defcustom find-ls-option |
| 39 | (if (eq system-type 'berkeley-unix) '("-ls" . "-gilsb") | 56 | (if (eq 0 |
| 40 | '("-exec ls -ld {} \\;" . "-ld")) | 57 | (ignore-errors |
| 58 | (process-file find-program nil nil nil null-device "-ls"))) | ||
| 59 | (cons "-ls" | ||
| 60 | (if (eq system-type 'berkeley-unix) | ||
| 61 | "-gilsb" | ||
| 62 | "-dilsb")) | ||
| 63 | (cons | ||
| 64 | (format "-exec ls -ld {} %s" find-exec-terminator) | ||
| 65 | "-ld")) | ||
| 41 | "Description of the option to `find' to produce an `ls -l'-type listing. | 66 | "Description of the option to `find' to produce an `ls -l'-type listing. |
| 42 | This is a cons of two strings (FIND-OPTION . LS-SWITCHES). FIND-OPTION | 67 | This is a cons of two strings (FIND-OPTION . LS-SWITCHES). FIND-OPTION |
| 43 | gives the option (or options) to `find' that produce the desired output. | 68 | gives the option (or options) to `find' that produce the desired output. |
| 44 | LS-SWITCHES is a list of `ls' switches to tell dired how to parse the output." | 69 | LS-SWITCHES is a list of `ls' switches to tell dired how to parse the output." |
| 70 | :version "24.1" ; add tests for -ls and -exec + support | ||
| 45 | :type '(cons (string :tag "Find Option") | 71 | :type '(cons (string :tag "Find Option") |
| 46 | (string :tag "Ls Switches")) | 72 | (string :tag "Ls Switches")) |
| 47 | :group 'find-dired) | 73 | :group 'find-dired) |
| 48 | 74 | ||
| 49 | (defcustom find-ls-subdir-switches "-al" | 75 | (defcustom find-ls-subdir-switches |
| 76 | (if (string-match "-[a-z]*b" (cdr find-ls-option)) | ||
| 77 | "-alb" | ||
| 78 | "-al") | ||
| 50 | "`ls' switches for inserting subdirectories in `*Find*' buffers. | 79 | "`ls' switches for inserting subdirectories in `*Find*' buffers. |
| 51 | This should contain the \"-l\" switch. | 80 | This should contain the \"-l\" switch. |
| 52 | Use the \"-F\" or \"-b\" switches if and only if you also use | 81 | Use the \"-F\" or \"-b\" switches if and only if you also use |
| 53 | them for `find-ls-option'." | 82 | them for `find-ls-option'." |
| 83 | :version "24.1" ; add -b test | ||
| 54 | :type 'string | 84 | :type 'string |
| 55 | :group 'find-dired | 85 | :group 'find-dired) |
| 56 | :version "22.1") | ||
| 57 | 86 | ||
| 58 | (defcustom find-grep-options | 87 | (defcustom find-grep-options |
| 59 | (if (or (eq system-type 'berkeley-unix) | 88 | (if (or (eq system-type 'berkeley-unix) |
| @@ -89,12 +118,12 @@ find also ignores case. Otherwise, -name is used." | |||
| 89 | ;;;###autoload | 118 | ;;;###autoload |
| 90 | (defun find-dired (dir args) | 119 | (defun find-dired (dir args) |
| 91 | "Run `find' and go into Dired mode on a buffer of the output. | 120 | "Run `find' and go into Dired mode on a buffer of the output. |
| 92 | The command run (after changing into DIR) is | 121 | The command run (after changing into DIR) is essentially |
| 93 | 122 | ||
| 94 | find . \\( ARGS \\) -ls | 123 | find . \\( ARGS \\) -ls |
| 95 | 124 | ||
| 96 | except that the variable `find-ls-option' specifies what to use | 125 | except that the car of the variable `find-ls-option' specifies what to |
| 97 | as the final argument." | 126 | use in place of \"-ls\" as the final argument." |
| 98 | (interactive (list (read-directory-name "Run find in directory: " nil "" t) | 127 | (interactive (list (read-directory-name "Run find in directory: " nil "" t) |
| 99 | (read-string "Run find (with args): " find-args | 128 | (read-string "Run find (with args): " find-args |
| 100 | '(find-args-history . 1)))) | 129 | '(find-args-history . 1)))) |
| @@ -135,11 +164,12 @@ as the final argument." | |||
| 135 | " " args " " | 164 | " " args " " |
| 136 | (shell-quote-argument ")") | 165 | (shell-quote-argument ")") |
| 137 | " ")) | 166 | " ")) |
| 138 | (if (equal (car find-ls-option) "-exec ls -ld {} \\;") | 167 | (if (string-match "\\`\\(.*\\) {} \\(\\\\;\\|+\\)\\'" |
| 139 | (concat "-exec ls -ld " | 168 | (car find-ls-option)) |
| 169 | (format "%s %s %s" | ||
| 170 | (match-string 1 (car find-ls-option)) | ||
| 140 | (shell-quote-argument "{}") | 171 | (shell-quote-argument "{}") |
| 141 | " " | 172 | find-exec-terminator) |
| 142 | (shell-quote-argument ";")) | ||
| 143 | (car find-ls-option)))) | 173 | (car find-ls-option)))) |
| 144 | ;; Start the find process. | 174 | ;; Start the find process. |
| 145 | (shell-command (concat args "&") (current-buffer)) | 175 | (shell-command (concat args "&") (current-buffer)) |
| @@ -213,9 +243,14 @@ The command run (after changing into DIR) is | |||
| 213 | "Find files in DIR containing a regexp REGEXP and start Dired on output. | 243 | "Find files in DIR containing a regexp REGEXP and start Dired on output. |
| 214 | The command run (after changing into DIR) is | 244 | The command run (after changing into DIR) is |
| 215 | 245 | ||
| 216 | find . -exec grep -s -e REGEXP {} \\\; -ls | 246 | find . \\( -type f -exec `grep-program' `find-grep-options' \\ |
| 247 | -e REGEXP {} \\; \\) -ls | ||
| 217 | 248 | ||
| 218 | Thus ARG can also contain additional grep options." | 249 | where the car of the variable `find-ls-option' specifies what to |
| 250 | use in place of \"-ls\" as the final argument." | ||
| 251 | ;; Doc used to say "Thus ARG can also contain additional grep options." | ||
| 252 | ;; i) Presumably ARG == REGEXP? | ||
| 253 | ;; ii) No it can't have options, since it gets shell-quoted. | ||
| 219 | (interactive "DFind-grep (directory): \nsFind-grep (grep regexp): ") | 254 | (interactive "DFind-grep (directory): \nsFind-grep (grep regexp): ") |
| 220 | ;; find -exec doesn't allow shell i/o redirections in the command, | 255 | ;; find -exec doesn't allow shell i/o redirections in the command, |
| 221 | ;; or we could use `grep -l >/dev/null' | 256 | ;; or we could use `grep -l >/dev/null' |
| @@ -228,6 +263,7 @@ Thus ARG can also contain additional grep options." | |||
| 228 | " " | 263 | " " |
| 229 | (shell-quote-argument "{}") | 264 | (shell-quote-argument "{}") |
| 230 | " " | 265 | " " |
| 266 | ;; Doesn't work with "+". | ||
| 231 | (shell-quote-argument ";")))) | 267 | (shell-quote-argument ";")))) |
| 232 | 268 | ||
| 233 | (defun find-dired-filter (proc string) | 269 | (defun find-dired-filter (proc string) |