diff options
author | Ken Raeburn <raeburn@raeburn.org> | 2015-11-01 01:42:21 -0400 |
---|---|---|
committer | Ken Raeburn <raeburn@raeburn.org> | 2015-11-01 01:42:21 -0400 |
commit | 39372e1a1032521be74575bb06f95a3898fbae30 (patch) | |
tree | 754bd242a23d2358ea116126fcb0a629947bd9ec /lisp/find-cmd.el | |
parent | 6a3121904d76e3b2f63007341d48c5c1af55de80 (diff) | |
parent | e11aaee266da52937a3a031cb108fe13f68958c3 (diff) | |
download | emacs-39372e1a1032521be74575bb06f95a3898fbae30.tar.gz |
merge from trunk
Diffstat (limited to 'lisp/find-cmd.el')
-rw-r--r-- | lisp/find-cmd.el | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/lisp/find-cmd.el b/lisp/find-cmd.el index a41a32762dc..71c7a9b9c77 100644 --- a/lisp/find-cmd.el +++ b/lisp/find-cmd.el @@ -1,6 +1,6 @@ ;;; find-cmd.el --- Build a valid find(1) command with sexps -;; Copyright (C) 2008-2013 Free Software Foundation, Inc. +;; Copyright (C) 2008-2015 Free Software Foundation, Inc. ;; Author: Philip Jackson <phil@shellarchive.co.uk> ;; Version: 0.6 @@ -39,6 +39,8 @@ ;;; Code: +(require 'grep) + (defconst find-constituents '((and . find-and) (not . find-not) @@ -138,63 +140,65 @@ the string will be quoted).") "Initiate the building of a find command. For example: -\(find-cmd '\(prune \(name \".svn\" \".git\" \".CVS\"\)\) - '\(and \(or \(name \"*.pl\" \"*.pm\" \"*.t\"\) - \(mtime \"+1\"\)\) - \(fstype \"nfs\" \"ufs\"\)\)\)\) +\(find-cmd \\='(prune (name \".svn\" \".git\" \".CVS\")) + \\='(and (or (name \"*.pl\" \"*.pm\" \"*.t\") + (mtime \"+1\")) + (fstype \"nfs\" \"ufs\")))) `default-directory' is used as the initial search path. The result is a string that should be ready for the command line." - (concat - "find " (shell-quote-argument (expand-file-name default-directory)) " " - (cond - ((cdr subfinds) - (mapconcat 'find-to-string subfinds "")) - (t - (find-to-string (car subfinds)))))) + ;; FIXME: Provide a version that returns a list of strings (ready to pass to + ;; call-process). + (concat find-program " " + (shell-quote-argument (expand-file-name default-directory)) " " + (cond + ((cdr subfinds) + (mapconcat #'find-to-string subfinds "")) + (t + (find-to-string (car subfinds)))))) (defun find-and (form) "And FORMs together, so: - \(and \(mtime \"+1\"\) \(name \"something\"\)\) + (and (mtime \"+1\") (name \"something\")) will produce: - find . \\\( -mtime '+1' -and -name 'something' \\\)" + find . \\( -mtime +1 -and -name something \\)" (if (< (length form) 2) (find-to-string (car form)) (concat "\\( " - (mapconcat 'find-to-string form "-and ") + (mapconcat #'find-to-string form "-and ") "\\) "))) (defun find-or (form) "Or FORMs together, so: - \(or \(mtime \"+1\"\) \(name \"something\"\)\) + (or (mtime \"+1\") (name \"something\")) will produce: - find . \\\( -mtime '+1' -or -name 'something' \\\)" + find . \\( -mtime +1 -or -name something \\)" (if (< (length form) 2) (find-to-string (car form)) (concat "\\( " - (mapconcat 'find-to-string form "-or ") + (mapconcat #'find-to-string form "-or ") "\\) "))) (defun find-not (form) "Or FORMs together and prefix with a -not, so: - \(not \(mtime \"+1\"\) \(name \"something\"\)\) + (not (mtime \"+1\") (name \"something\")) will produce: - -not \\\( -mtime '+1' -or -name 'something' \\\) + -not \\( -mtime +1 -or -name something \\) If you wanted the FORMs -and(ed) together instead then this would suffice: - \(not \(and \(mtime \"+1\"\) \(name \"something\"\)\)\)" - (concat "-not " (find-or (mapcar 'find-to-string form)))) + (not (and (mtime \"+1\") (name \"something\")))" + (concat "-not " (find-or (mapcar #'find-to-string form)))) (defun find-prune (form) - "-or together FORMs postfix '-prune' and then -or that with a + "-or together FORMs postfix `-prune' and then -or that with a -true, so: - \(prune \(name \".svn\" \".git\"\)\) \(name \"*.pm\"\) + ((prune (name \".svn\" \".git\")) (name \"*.pm\")) will produce (unwrapped): - \\\( \\\( \\\( -name '.svn' -or -name '.git' \\\) / - -prune -or -true \\\) -and -name '*.pm' \\\)" + \\( \\( \\( -name .svn -or -name .git \\) / + -prune -or -true \\) -and -name *.pm \\)" (find-or (list - (concat (find-or (mapcar 'find-to-string form)) (find-generic "prune")) + (concat (find-or (mapcar #'find-to-string form)) (find-generic "prune")) (find-generic "true")))) (defun find-generic (option &optional oper argcount args dont-quote) @@ -205,7 +209,7 @@ args that OPTION can receive and ARGS are the arguments for OPTION. If DONT-QUOTE is non-nil, arguments are quoted for passing them to the shell." (when (and (numberp argcount) (< (length args) argcount)) - (error "'%s' needs at least %d arguments" option argcount)) + (error "`%s' needs at least %d arguments" option argcount)) (let ((oper (or oper 'find-or))) (if (and args (length args)) (funcall oper (mapcar (lambda (x) @@ -243,7 +247,7 @@ them into valid switches. The result is -and(ed) together." (find-to-string (find-generic option oper argcnt (cdr form) dont-quote)))) (t - (error "Sorry I don't know how to handle '%s'" (car form)))))))) + (error "Sorry I don't know how to handle `%s'" (car form)))))))) (provide 'find-cmd) |