aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorJuri Linkov2019-06-20 00:55:07 +0300
committerJuri Linkov2019-06-20 00:55:07 +0300
commit8b379bbeca9b3765e2b1e948d9d9c90ab92ff4b6 (patch)
treeb452ae0adb93a2b31d66289d1164a6250bbfd72b /lisp
parentf6ab713bbc3dc8fccf5fe490615aa2b679071010 (diff)
downloademacs-8b379bbeca9b3765e2b1e948d9d9c90ab92ff4b6.tar.gz
emacs-8b379bbeca9b3765e2b1e948d9d9c90ab92ff4b6.zip
Add file sorting options to find-dired and grep-find (bug#36110)
* lisp/find-dired.el (find-ls-option-default-ls) (find-ls-option-default-exec, find-ls-option-default-xargs): New variables for values used for options of 'find-ls-option'. (find-ls-option): Use these variables for default values and options. (find-dired-refine-function): Refine :type. * lisp/progmodes/grep.el (grep-find-use-xargs): Use defcustom instead of defvar. Add new value 'gnu-sort'. (grep-compute-defaults): Handle new 'gnu-sort' option of 'grep-find-use-xargs'.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/find-dired.el48
-rw-r--r--lisp/progmodes/grep.el20
2 files changed, 53 insertions, 15 deletions
diff --git a/lisp/find-dired.el b/lisp/find-dired.el
index 8a283a65c98..9e9fbfcb1a7 100644
--- a/lisp/find-dired.el
+++ b/lisp/find-dired.el
@@ -51,19 +51,23 @@ than the latter."
51 :group 'find-dired 51 :group 'find-dired
52 :type 'string) 52 :type 'string)
53 53
54(defvar find-ls-option-default-ls
55 (cons "-ls" (if (eq system-type 'berkeley-unix) "-gilsb" "-dilsb")))
56
57(defvar find-ls-option-default-exec
58 (cons (format "-exec ls -ld {} %s" find-exec-terminator) "-ld"))
59
60(defvar find-ls-option-default-xargs
61 (cons "-print0 | sort -z | xargs -0 -e ls -ld" "-ld"))
62
54;; find's -ls corresponds to these switches. 63;; find's -ls corresponds to these switches.
55;; Note -b, at least GNU find quotes spaces etc. in filenames 64;; Note -b, at least GNU find quotes spaces etc. in filenames
56(defcustom find-ls-option 65(defcustom find-ls-option
57 (if (eq 0 66 (if (eq 0
58 (ignore-errors 67 (ignore-errors
59 (process-file find-program nil nil nil null-device "-ls"))) 68 (process-file find-program nil nil nil null-device "-ls")))
60 (cons "-ls" 69 find-ls-option-default-ls
61 (if (eq system-type 'berkeley-unix) 70 find-ls-option-default-exec)
62 "-gilsb"
63 "-dilsb"))
64 (cons
65 (format "-exec ls -ld {} %s" find-exec-terminator)
66 "-ld"))
67 "A pair of options to produce and parse an `ls -l'-type list from `find'. 71 "A pair of options to produce and parse an `ls -l'-type list from `find'.
68This is a cons of two strings (FIND-OPTION . LS-SWITCHES). 72This is a cons of two strings (FIND-OPTION . LS-SWITCHES).
69FIND-OPTION is the option (or options) passed to `find' to produce 73FIND-OPTION is the option (or options) passed to `find' to produce
@@ -77,10 +81,26 @@ For example, to use human-readable file sizes with GNU ls:
77To use GNU find's inbuilt \"-ls\" option to list files: 81To use GNU find's inbuilt \"-ls\" option to list files:
78 (\"-ls\" . \"-dilsb\") 82 (\"-ls\" . \"-dilsb\")
79since GNU find's output has the same format as using GNU ls with 83since GNU find's output has the same format as using GNU ls with
80the options \"-dilsb\"." 84the options \"-dilsb\".
81 :version "24.1" ; add tests for -ls and -exec + support 85
82 :type '(cons (string :tag "Find Option") 86While the option `find -ls' often produces unsorted output, the option
83 (string :tag "Ls Switches")) 87`find -exec ls -ld' maintains the sorting order only on short output,
88whereas `find -print | sort | xargs' produced sorted output even
89on the large number of files."
90 :version "27.1" ; add choice of predefined set of options
91 :type `(choice
92 (cons :tag "find -ls"
93 (string ,(car find-ls-option-default-ls))
94 (string ,(cdr find-ls-option-default-ls)))
95 (cons :tag "find -exec ls -ld"
96 (string ,(car find-ls-option-default-exec))
97 (string ,(cdr find-ls-option-default-exec)))
98 (cons :tag "find -print | sort | xargs"
99 (string ,(car find-ls-option-default-xargs))
100 (string ,(cdr find-ls-option-default-xargs)))
101 (cons :tag "Other values"
102 (string :tag "Find Option")
103 (string :tag "Ls Switches")))
84 :group 'find-dired) 104 :group 'find-dired)
85 105
86(defcustom find-ls-subdir-switches 106(defcustom find-ls-subdir-switches
@@ -123,8 +143,10 @@ This function takes no arguments. The *Find* buffer is narrowed to the
123output of `find' (one file per line) when this function is called." 143output of `find' (one file per line) when this function is called."
124 :version "27.1" 144 :version "27.1"
125 :group 'find-dired 145 :group 'find-dired
126 :type '(choice (function :tag "Function") 146 :type '(choice (const :tag "Sort file names lexicographically"
127 (const :tag "None" nil))) 147 find-dired-sort-by-filename)
148 (function :tag "Refining function")
149 (const :tag "No refining" nil)))
128 150
129(defvar find-args nil 151(defvar find-args nil
130 "Last arguments given to `find' by \\[find-dired].") 152 "Last arguments given to `find' by \\[find-dired].")
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 79178c4346e..67222f78627 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -511,14 +511,24 @@ See `grep-find-use-xargs'.
511This variable's value takes effect when `grep-compute-defaults' is called.") 511This variable's value takes effect when `grep-compute-defaults' is called.")
512 512
513;;;###autoload 513;;;###autoload
514(defvar grep-find-use-xargs nil 514(defcustom grep-find-use-xargs nil
515 "How to invoke find and grep. 515 "How to invoke find and grep.
516If `exec', use `find -exec {} ;'. 516If `exec', use `find -exec {} ;'.
517If `exec-plus' use `find -exec {} +'. 517If `exec-plus' use `find -exec {} +'.
518If `gnu', use `find -print0' and `xargs -0'. 518If `gnu', use `find -print0' and `xargs -0'.
519If `gnu-sort', use `find -print0', `sort -z' and `xargs -0'.
519Any other value means to use `find -print' and `xargs'. 520Any other value means to use `find -print' and `xargs'.
520 521
521This variable's value takes effect when `grep-compute-defaults' is called.") 522This variable's value takes effect when `grep-compute-defaults' is called."
523 :type '(choice (const :tag "find -exec {} ;" exec)
524 (const :tag "find -exec {} +" exec-plus)
525 (const :tag "find -print0 | xargs -0" gnu)
526 (const :tag "find -print0 | sort -z | xargs -0'" gnu-sort)
527 string
528 (const :tag "Not Set" nil))
529 :set 'grep-apply-setting
530 :version "27.1"
531 :group 'grep)
522 532
523;; History of grep commands. 533;; History of grep commands.
524;;;###autoload 534;;;###autoload
@@ -728,6 +738,9 @@ This function is called from `compilation-filter-hook'."
728 ;; forward slashes as directory separators. 738 ;; forward slashes as directory separators.
729 (format "%s . -type f -print0 | \"%s\" -0 %s" 739 (format "%s . -type f -print0 | \"%s\" -0 %s"
730 find-program xargs-program grep-command)) 740 find-program xargs-program grep-command))
741 ((eq grep-find-use-xargs 'gnu-sort)
742 (format "%s . -type f -print0 | sort -z | \"%s\" -0 %s"
743 find-program xargs-program grep-command))
731 ((memq grep-find-use-xargs '(exec exec-plus)) 744 ((memq grep-find-use-xargs '(exec exec-plus))
732 (let ((cmd0 (format "%s . -type f -exec %s" 745 (let ((cmd0 (format "%s . -type f -exec %s"
733 find-program grep-command)) 746 find-program grep-command))
@@ -752,6 +765,9 @@ This function is called from `compilation-filter-hook'."
752 (cond ((eq grep-find-use-xargs 'gnu) 765 (cond ((eq grep-find-use-xargs 'gnu)
753 (format "%s <D> <X> -type f <F> -print0 | \"%s\" -0 %s" 766 (format "%s <D> <X> -type f <F> -print0 | \"%s\" -0 %s"
754 find-program xargs-program gcmd)) 767 find-program xargs-program gcmd))
768 ((eq grep-find-use-xargs 'gnu-sort)
769 (format "%s <D> <X> -type f <F> -print0 | sort -z | \"%s\" -0 %s"
770 find-program xargs-program gcmd))
755 ((eq grep-find-use-xargs 'exec) 771 ((eq grep-find-use-xargs 'exec)
756 (format "%s <D> <X> -type f <F> -exec %s %s %s%s" 772 (format "%s <D> <X> -type f <F> -exec %s %s %s%s"
757 find-program gcmd quot-braces null quot-scolon)) 773 find-program gcmd quot-braces null quot-scolon))