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