annotate lisp/find-lisp.el @ 31547:55b581b3fc5b

*** empty log message ***
author Kenichi Handa <handa@m17n.org>
date Mon, 11 Sep 2000 23:42:27 +0000
parents a5051216d618
children 3f09592bbc80
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29696
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; find-lisp.el --- Emulation of find in Emacs Lisp
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 ;; Author: Peter Breton
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 ;; Created: Fri Mar 26 1999
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; Keywords: unix
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 ;; Time-stamp: <1999-04-19 16:37:01 pbreton>
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; Copyright (C) 1999, 2000 Free Software Foundation, Inc.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; any later version.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 ;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 ;; This is a very generalized form of find; it basically implements a
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 ;; recursive directory descent. The conditions which bound the search
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 ;; are expressed as predicates, and I have not addressed the question
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ;; of how to wrap up the common chores that find does in a simpler
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;; format than writing code for all the various predicates.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 ;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; Some random thoughts are to express simple queries directly with
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; user-level functions, and perhaps use some kind of forms interface
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; for medium-level queries. Really complicated queries can be
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; expressed in Lisp.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;; Todo
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; It would be nice if we could sort the results without running the find
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; again. Maybe that could work by storing the original file attributes?
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;;; Code:
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; Internal variables
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 (defvar find-lisp-regexp nil
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 "Internal variable.")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (defconst find-lisp-line-indent " "
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 "Indentation for dired file lines.")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (defvar find-lisp-file-predicate nil
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 "Predicate for choosing to include files.")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (defvar find-lisp-directory-predicate nil
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 "Predicate for choosing to descend into directories.")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;; Debugging Code
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 (defvar find-lisp-debug-buffer "*Find Lisp Debug*"
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 "Buffer for debugging information.")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 (defvar find-lisp-debug nil
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 "Whether debugging is enabled.")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (defun find-lisp-debug-message (message)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 "Print a debug message MESSAGE in `find-lisp-debug-buffer'."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 (set-buffer (get-buffer-create find-lisp-debug-buffer))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (goto-char (point-max))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (insert message "\n"))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 ;; Directory and File predicates
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (defun find-lisp-default-directory-predicate (dir parent)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 "True if DIR is not a dot file, and not a symlink.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 PARENT is the parent directory of DIR."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (and find-lisp-debug
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (find-lisp-debug-message
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (format "Processing directory %s in %s" dir parent)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 ;; Skip current and parent directories
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (not (or (string= dir ".")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (string= dir "..")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 ;; Skip directories which are symlinks
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; Easy way to circumvent recursive loops
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 (file-symlink-p dir))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (defun find-lisp-default-file-predicate (file dir)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 "True if FILE matches `find-lisp-regexp'.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 DIR is the directory containing FILE."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (and find-lisp-debug
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 (find-lisp-debug-message
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (format "Processing file %s in %s" file dir)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (and (not (file-directory-p (expand-file-name file dir)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (string-match find-lisp-regexp file)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (defun find-lisp-file-predicate-is-directory (file dir)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 "True if FILE is a directory.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 Argument DIR is the directory containing FILE."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 (and find-lisp-debug
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 (find-lisp-debug-message
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (format "Processing file %s in %s" file dir)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 (and (file-directory-p (expand-file-name file dir))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 (not (or (string= file ".")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 (string= file "..")))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ;; Find functions
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 (defun find-lisp-find-files (directory regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 "Find files in DIRECTORY which match REGEXP."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (let ((file-predicate 'find-lisp-default-file-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (directory-predicate 'find-lisp-default-directory-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (find-lisp-regexp regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 )
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (find-lisp-find-files-internal
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 directory
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 directory-predicate)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 ;; Workhorse function
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (defun find-lisp-find-files-internal (directory file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 directory-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 "Find files under DIRECTORY which satisfy FILE-PREDICATE.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 FILE-PREDICATE is a function which takes two arguments: the file and its
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 directory.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 DIRECTORY-PREDICATE is used to decide whether to descend into directories.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 It is a function which takes two arguments, the directory and its parent."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (let (results sub-results)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (mapcar
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (function
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (lambda(file)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (let ((fullname (expand-file-name file directory)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (and (file-readable-p (expand-file-name file directory))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (progn
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 ;; If a directory, check it we should descend into it
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (and (file-directory-p fullname)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (funcall directory-predicate file directory)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (progn
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (setq sub-results
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (find-lisp-find-files-internal
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 fullname
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 directory-predicate))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (if results
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (nconc results sub-results)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 (setq results sub-results))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 ;; For all files and directories, call the file predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (and (funcall file-predicate file directory)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (if results
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (nconc results (list fullname))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (setq results (list fullname))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 )))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 (directory-files directory nil nil t))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 results))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 ;; Find-dired all in Lisp
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (defun find-lisp-find-dired (dir regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 "Find files in DIR, matching REGEXP."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (interactive "DFind files in directory: \nsMatching regexp: ")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (let ((find-lisp-regexp regexp))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (find-lisp-find-dired-internal
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 dir
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 'find-lisp-default-file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 'find-lisp-default-directory-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 "*Find Lisp Dired*")))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 ;; Just the subdirectories
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (defun find-lisp-find-dired-subdirectories (dir)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 "Find all subdirectories of DIR."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (interactive "DFind subdirectories of directory: ")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (find-lisp-find-dired-internal
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 dir
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 'find-lisp-file-predicate-is-directory
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 'find-lisp-default-directory-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 "*Find Lisp Dired Subdirectories*"))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 ;; Most of this is lifted from find-dired.el
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 ;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (defun find-lisp-find-dired-internal (dir file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 directory-predicate buffer-name)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 "Run find (Lisp version) and go into Dired mode on a buffer of the output."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 (let ((dired-buffers dired-buffers)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 buf
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (regexp find-lisp-regexp))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 ;; Expand DIR ("" means default-directory), and make sure it has a
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 ;; trailing slash.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 (setq dir (abbreviate-file-name
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (file-name-as-directory (expand-file-name dir))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 ;; Check that it's really a directory.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (or (file-directory-p dir)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 (error "find-dired needs a directory: %s" dir))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 (or
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (and (buffer-name)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (string= buffer-name (buffer-name)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (switch-to-buffer (setq buf (get-buffer-create buffer-name))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (widen)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (kill-all-local-variables)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (setq buffer-read-only nil)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (erase-buffer)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 (setq default-directory dir)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 (dired-mode dir)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 (use-local-map (append (make-sparse-keymap) (current-local-map)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 (make-local-variable 'find-lisp-file-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (setq find-lisp-file-predicate file-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (make-local-variable 'find-lisp-directory-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (setq find-lisp-directory-predicate directory-predicate)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (make-local-variable 'find-lisp-regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (setq find-lisp-regexp regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (make-local-variable 'revert-buffer-function)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (setq revert-buffer-function
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (function
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (lambda(ignore1 ignore2)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (find-lisp-insert-directory
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 default-directory
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 find-lisp-file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 find-lisp-directory-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 'ignore)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 )
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 ))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 ;; Set subdir-alist so that Tree Dired will work:
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 (if (fboundp 'dired-simple-subdir-alist)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 ;; will work even with nested dired format (dired-nstd.el,v 1.15
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 ;; and later)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (dired-simple-subdir-alist)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 ;; else we have an ancient tree dired (or classic dired, where
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 ;; this does no harm)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (set (make-local-variable 'dired-subdir-alist)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (list (cons default-directory (point-min-marker)))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (find-lisp-insert-directory
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 dir file-predicate directory-predicate 'ignore)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (goto-char (point-min))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (dired-goto-next-file)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (defun find-lisp-insert-directory (dir
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 directory-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 sort-function)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 "Insert the results of `find-lisp-find-files' in the current buffer."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (let ((buffer-read-only nil)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (files (find-lisp-find-files-internal
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 dir
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 file-predicate
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 directory-predicate))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (len (length dir)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (erase-buffer)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 ;; Subdir headlerline must come first because the first marker in
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 ;; subdir-alist points there.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (insert find-lisp-line-indent dir ":\n")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 ;; Make second line a ``find'' line in analogy to the ``total'' or
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 ;; ``wildcard'' line.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 ;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 ;; No analog for find-lisp?
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (insert find-lisp-line-indent "\n")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 ;; Run the find function
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (mapcar
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (function
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (lambda(file)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (find-lisp-find-dired-insert-file
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (substring file len)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (current-buffer))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (sort files 'string-lessp))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 ;; FIXME: Sort function is ignored for now
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 ;; (funcall sort-function files))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (goto-char (point-min))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (dired-goto-next-file)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (defun find-lisp-find-dired-filter (regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 "Change the filter on a find-lisp-find-dired buffer to REGEXP."
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (interactive "sSet filter to regexp: ")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (setq find-lisp-regexp regexp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (revert-buffer))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (defun find-lisp-find-dired-insert-file (file buffer)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (set-buffer buffer)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (insert find-lisp-line-indent
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (find-lisp-format file (file-attributes file) (list "")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (current-time))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 ;; Lifted from ls-lisp. We don't want to require it, because that
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 ;; would alter the insert-directory function.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (defun find-lisp-format (file-name file-attr switches now)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (let ((file-type (nth 0 file-attr)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 (concat (if (memq ?i switches) ; inode number
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (format "%6d " (nth 10 file-attr)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;; nil is treated like "" in concat
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (if (memq ?s switches) ; size in K
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (format "%4d " (1+ (/ (nth 7 file-attr) 1024))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 (nth 8 file-attr) ; permission bits
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 ;; numeric uid/gid are more confusing than helpful
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 ;; Emacs should be able to make strings of them.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 ;; user-login-name and user-full-name could take an
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 ;; optional arg.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (format " %3d %-8s %-8s %8d "
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (nth 1 file-attr) ; no. of links
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 (if (= (user-uid) (nth 2 file-attr))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (user-login-name)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 (int-to-string (nth 2 file-attr))) ; uid
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (if (eq system-type 'ms-dos)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 "root" ; everything is root on MSDOS.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (int-to-string (nth 3 file-attr))) ; gid
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (nth 7 file-attr) ; size in bytes
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 )
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (find-lisp-format-time file-attr switches now)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 " "
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 file-name
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (if (stringp file-type) ; is a symbolic link
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (concat " -> " file-type)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 "")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 "\n")))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (defun find-lisp-time-index (switches)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 ;; Return index into file-attributes according to ls SWITCHES.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (cond
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 ((memq ?c switches) 6) ; last mode change
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 ((memq ?u switches) 4) ; last access
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 ;; default is last modtime
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (t 5)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (defun find-lisp-format-time (file-attr switches now)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 ;; Format time string for file with attributes FILE-ATTR according
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 ;; to SWITCHES (a list of ls option letters of which c and u are recognized).
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 ;; Use the same method as `ls' to decide whether to show time-of-day or year,
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 ;; depending on distance between file date and NOW.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 (let* ((time (nth (find-lisp-time-index switches) file-attr))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (diff16 (- (car time) (car now)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now)))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 (past-cutoff (- (* 6 30 24 60 60))) ; 6 30-day months
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (future-cutoff (* 60 60))) ; 1 hour
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 (format-time-string
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (if (and
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (<= past-cutoff diff) (<= diff future-cutoff)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 ;; Sanity check in case `diff' computation overflowed.
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (<= (1- (ash past-cutoff -16)) diff16)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (<= diff16 (1+ (ash future-cutoff -16))))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 "%b %e %H:%M"
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 "%b %e %Y")
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 time)))
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (provide 'find-lisp)
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 ;;; find-lisp.el ends here
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 ;; Local Variables:
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 ;; autocompile: t
a5051216d618 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 ;; End: