-;;; find-lisp.el --- Emulation of find in Emacs Lisp
+;;; find-lisp.el --- emulation of find in Emacs Lisp
-;; Author: Peter Breton
+;; Author: Peter Breton
;; Created: Fri Mar 26 1999
;; Keywords: unix
-;; Time-stamp: <2000-10-04 00:17:29 pbreton>
+;; Time-stamp: <2006-02-06 13:40:10 ttn>
-;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
+;; 2005, 2006 Free Software Foundation, Inc.
;; This file is part of GNU Emacs.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;;; Code:
+(require 'dired)
+
+(defvar dired-buffers)
+(defvar dired-subdir-alist)
+
;; Internal variables
(defvar find-lisp-regexp nil
"Find files in DIRECTORY which match REGEXP."
(let ((file-predicate 'find-lisp-default-file-predicate)
(directory-predicate 'find-lisp-default-directory-predicate)
- (find-lisp-regexp regexp)
- )
+ (find-lisp-regexp regexp))
(find-lisp-find-files-internal
directory
file-predicate
DIRECTORY-PREDICATE is used to decide whether to descend into directories.
It is a function which takes two arguments, the directory and its parent."
- (or (string-match "/$" directory)
- (setq directory (concat directory "/")))
+ (setq directory (file-name-as-directory directory))
(let (results sub-results)
- (mapcar
- (function
- (lambda(file)
- (let ((fullname (expand-file-name file directory)))
- (and (file-readable-p (expand-file-name file directory))
+ (dolist (file (directory-files directory nil nil t))
+ (let ((fullname (expand-file-name file directory)))
+ (when (file-readable-p (expand-file-name file directory))
+ ;; If a directory, check it we should descend into it
+ (and (file-directory-p fullname)
+ (funcall directory-predicate file directory)
(progn
- ;; If a directory, check it we should descend into it
- (and (file-directory-p fullname)
- (funcall directory-predicate file directory)
- (progn
- (setq sub-results
- (find-lisp-find-files-internal
- fullname
- file-predicate
- directory-predicate))
- (if results
- (nconc results sub-results)
- (setq results sub-results))))
- ;; For all files and directories, call the file predicate
- (and (funcall file-predicate file directory)
- (if results
- (nconc results (list fullname))
- (setq results (list fullname))))
- )))))
- (directory-files directory nil nil t))
+ (setq sub-results
+ (find-lisp-find-files-internal
+ fullname
+ file-predicate
+ directory-predicate))
+ (if results
+ (nconc results sub-results)
+ (setq results sub-results))))
+ ;; For all files and directories, call the file predicate
+ (and (funcall file-predicate file directory)
+ (if results
+ (nconc results (list fullname))
+ (setq results (list fullname)))))))
results))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Find-dired all in Lisp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;###autoload
(defun find-lisp-find-dired (dir regexp)
"Find files in DIR, matching REGEXP."
(interactive "DFind files in directory: \nsMatching regexp: ")
"*Find Lisp Dired*")))
;; Just the subdirectories
+;;;###autoload
(defun find-lisp-find-dired-subdirectories (dir)
"Find all subdirectories of DIR."
(interactive "DFind subdirectories of directory: ")
(regexp find-lisp-regexp))
;; Expand DIR ("" means default-directory), and make sure it has a
;; trailing slash.
- (setq dir (abbreviate-file-name
- (file-name-as-directory (expand-file-name dir))))
+ (setq dir (file-name-as-directory (expand-file-name dir)))
;; Check that it's really a directory.
(or (file-directory-p dir)
(error "find-dired needs a directory: %s" dir))
(goto-char (point-min))
(dired-goto-next-file)))
+;;;###autoload
(defun find-lisp-find-dired-filter (regexp)
"Change the filter on a find-lisp-find-dired buffer to REGEXP."
(interactive "sSet filter to regexp: ")
(defun find-lisp-find-dired-insert-file (file buffer)
(set-buffer buffer)
(insert find-lisp-line-indent
- (find-lisp-format file (file-attributes file) (list "")
+ (find-lisp-format file (file-attributes file 'string) (list "")
(current-time))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (memq ?s switches) ; size in K
(format "%4d " (1+ (/ (nth 7 file-attr) 1024))))
(nth 8 file-attr) ; permission bits
- ;; numeric uid/gid are more confusing than helpful
- ;; Emacs should be able to make strings of them.
- ;; user-login-name and user-full-name could take an
- ;; optional arg.
(format " %3d %-8s %-8s %8d "
(nth 1 file-attr) ; no. of links
- (if (= (user-uid) (nth 2 file-attr))
- (user-login-name)
- (int-to-string (nth 2 file-attr))) ; uid
+ (if (numberp (nth 2 file-attr))
+ (int-to-string (nth 2 file-attr))
+ (nth 2 file-attr)) ; uid
(if (eq system-type 'ms-dos)
"root" ; everything is root on MSDOS.
- (int-to-string (nth 3 file-attr))) ; gid
+ (if (numberp (nth 3 file-attr))
+ (int-to-string (nth 3 file-attr))
+ (nth 3 file-attr))) ; gid
(nth 7 file-attr) ; size in bytes
)
(find-lisp-format-time file-attr switches now)
(provide 'find-lisp)
+;;; arch-tag: a711374c-f12a-46f6-aa18-ba7d77b9602a
;;; find-lisp.el ends here
-
-;; Local Variables:
-;; autocompile: t
-;; End: