annotate lisp/dired/dired-lisp.el @ 9:6f2bbbbbe05a

Added tag r19-15b5 for changeset 4b173ad71786
author cvs
date Mon, 13 Aug 2007 08:47:36 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;;; dired-lisp.el - emulate Tree Dired's ls completely in Emacs Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;;; READ THE WARNING BELOW BEFORE USING THIS PROGRAM!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 (defconst dired-lisp-version (substring "!Revision: 1.8 !" 11 -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 "!Id: dired-lisp.el,v 1.8 1992/05/01 17:50:56 sk Exp !")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Copyright (C) 1992 by Sebastian Kremer <sk@thp.uni-koeln.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 1, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; LISPDIR ENTRY for the Elisp Archive ===============================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; dired-lisp|Sebastian Kremer|sk@thp.uni-koeln.de
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; |emulate Tree Dired's ls completely in Emacs Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; |Date: 1992/05/01 17:50:56 |Revision: 1.8 |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; INSTALLATION =======================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; Put this file into your load-path. Loading it will result in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; redefining function dired-ls to not call ls.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; You need tree dired from ftp.cs.buffalo.edu:pub/Emacs/diredall.tar.Z,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; classic (e.g. 18.57) dired.el will not work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; OVERVIEW ===========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; This file overloads tree dired so that all fileinfo is retrieved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; directly from Emacs lisp, without using an ls subprocess.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; Useful if you cannot afford to fork Emacs on a real memory UNIX,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; under VMS, or if you don't have the ls program, or if you want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; different format from what ls offers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; Beware that if you change the output format of dired-ls, you'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; have to change dired-move-to-filename and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; dired-move-to-end-of-filename as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; With this package is loaded, dired uses regexps instead of shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; wildcards. If you enter regexps remember to double each $ sign.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; For example, to dired all elisp (*.el) files, enter `.*\.el$$',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; resulting in the regexp `.*\.el$'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; WARNING ===========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; With earlier version of this program I sometimes got an internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; Emacs error:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; Signalling: (wrong-type-argument natnump #<EMACS BUG: ILLEGAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; DATATYPE (#o37777777727) Save your buffers immediately and please
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; report this bug>)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; The datatype differs (I also got #o67 once).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; Sometimes emacs just crashed with a fatal error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; After I've avoided using directory-files and file-attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; together inside a mapcar, the bug didn't surface any longer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; RESTRICTIONS =====================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; * many ls switches are ignored, see docstring of `dired-ls'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; * In Emacs 18: cannot display date of file, displays a fake date
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; "Jan 00 00:00" instead (dates do work in Emacs 19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; * Only numeric uid/gid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; * if you load dired-lisp after ange-ftp, remote listings look
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; really strange:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; total 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; d????????? -1 -1 -1 -1 Jan 1 1970 .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; d????????? -1 -1 -1 -1 Jan 1 1970 ..
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; This is because ange-ftp's file-attributes does not return much
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; useful information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; If you load dired-lisp first, there seem to be no problems.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; TODO ==============================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Recognize some more ls switches: R F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (require 'dired) ; we will redefine dired-ls:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (or (fboundp 'dired-lisp-unix-ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (fset 'dired-lisp-unix-ls (symbol-function 'dired-ls)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (fset 'dired-ls 'dired-lisp-ls)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (defun dired-lisp-ls (file &optional switches wildcard full-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 "dired-lisp.el's version of dired-ls.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 Known switches: A a S r i s t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 In Emacs 19, additional known switches are: c u
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 Others are ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 Insert ls output of FILE, optionally formatted with SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Optional third arg WILDCARD means treat non-directory part of FILE as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 emacs regexp (_not_ a shell wildcard). If you enter regexps remember
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 to double each $ sign.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 switches do not contain `d'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 SWITCHES default to dired-listing-switches."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (or switches (setq switches dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (or (consp switches) ; convert to list of chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (setq switches (mapcar 'identity switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (if wildcard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq wildcard (file-name-nondirectory file) ; actually emacs regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; perhaps convert it from shell to emacs syntax?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 file (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (or wildcard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 full-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (let* ((dir (file-name-as-directory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (default-directory dir);; so that file-attributes works
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (sum 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (file-list (directory-files dir nil wildcard))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 file-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; do all bindings here for speed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 fil attr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (cond ((memq ?A switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (setq file-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (dired-lisp-delete-matching "^\\.\\.?$" file-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ((not (memq ?a switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; if neither -A nor -a, flush . files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (setq file-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (dired-lisp-delete-matching "^\\." file-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq file-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; file-attributes("~bogus") bombs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (cons x (file-attributes (expand-file-name x)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; inserting the call to directory-files right here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;; seems to stimulate an Emacs bug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 ;; ILLEGAL DATATYPE (#o37777777727) or #o67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (insert "total \007\n") ; filled in afterwards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (setq file-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (dired-lisp-handle-switches file-alist switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (while file-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (setq elt (car file-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 short (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 attr (cdr elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 file-alist (cdr file-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 fil (concat dir short)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 sum (+ sum (nth 7 attr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (insert (dired-lisp-format short attr switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; Fill in total size of all files:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (search-backward "total \007")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (insert (format "%d" (1+ (/ sum 1024))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; if not full-directory-p, FILE *must not* end in /, as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; file-attributes will not recognize a symlink to a directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; must make it a relative filename as ls does:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (setq file (file-name-nondirectory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (insert (dired-lisp-format file (file-attributes file) switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defun dired-lisp-delete-matching (regexp list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; Delete all elements matching REGEXP from LIST, return new list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 ;; Should perhaps use setcdr for efficiency.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (let (result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (while list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (or (string-match regexp (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq result (cons (car list) result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (defun dired-lisp-handle-switches (file-alist switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;; FILE-ALIST's elements are (FILE . FILE-ATTRIBUTES).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; Return new alist sorted according to SWITCHES which is a list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; characters. Default sorting is alphabetically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (let (index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (setq file-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (sort file-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (cond ((memq ?S switches) ; sorted on size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 ;; 7th file attribute is file size
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; Make largest file come first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (< (nth 7 (cdr y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (nth 7 (cdr x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ((memq ?t switches) ; sorted on time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (setq index (dired-lisp-time-index switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (time-lessp (nth index (cdr y))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (nth index (cdr x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (t ; sorted alphabetically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (lambda (x y)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (string-lessp (car x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (car y)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if (memq ?r switches) ; reverse sort order
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (setq file-alist (nreverse file-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 file-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;; From Roland McGrath. Can use this to sort on time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (defun time-lessp (time0 time1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (let ((hi0 (car time0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (hi1 (car time1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (lo0 (car (cdr time0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (lo1 (car (cdr time1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (or (< hi0 hi1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (and (= hi0 hi1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (< lo0 lo1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (defun dired-lisp-format (file-name file-attr &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (let ((file-type (nth 0 file-attr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (concat (if (memq ?i switches) ; inode number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (format "%6d " (nth 10 file-attr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; nil is treated like "" in concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (if (memq ?s switches) ; size in K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (format "%4d " (1+ (/ (nth 7 file-attr) 1024))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (nth 8 file-attr) ; permission bits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; numeric uid/gid are more confusing than helpful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; Emacs should be able to make strings of them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; user-login-name and user-full-name could take an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 ;; optional arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (format " %3d %-8d %-8d %8d "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (nth 1 file-attr) ; no. of links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (nth 2 file-attr) ; uid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (nth 3 file-attr) ; gid
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (nth 7 file-attr) ; size in bytes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (dired-lisp-format-time file-attr switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (if (stringp file-type) ; is a symbolic link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (concat " -> " file-type)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun dired-lisp-time-index (switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 ;; Return index into file-attributes according to ls SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ((memq ?c switches) 6) ; last mode change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ((memq ?u switches) 4) ; last access
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ;; default is last modtime
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (t 5)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (defun dired-lisp-format-time (file-attr switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;; Format time string for file with attributes FILE-ATTR according
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; to SWITCHES (a list of ls option letters of which c and u are recognized).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; file-attributes's time is in a braindead format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; Emacs 19 can format it using a new optional argument to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; current-time-string, for Emacs 18 we just return the faked fixed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; date "Jan 00 00:00 ".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (condition-case error-data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (let* ((time (current-time-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (nth (dired-lisp-time-index switches) file-attr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (date (substring time 4 11)) ; "Apr 30 "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (clock (substring time 11 16)) ; "11:27"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (year (substring time 19 24)) ; " 1992"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (same-year (equal year (substring (current-time-string) 19 24))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (concat date ; has trailing SPC
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (if same-year
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;; this is not exactly the same test used by ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;; ls tests if the file is older than 6 months
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;; but we can't do time differences easily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 clock
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 year)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 "Jan 00 00:00")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (provide 'dired-lisp)