Mercurial > emacs
annotate lisp/ls-lisp.el @ 2130:e5971e883f67
Bug fix.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Thu, 11 Mar 1993 07:45:02 +0000 |
parents | ecf43116a845 |
children | fb0ed5a1d0f3 |
rev | line source |
---|---|
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
1 ;;;; directory.el - emulate insert-directory completely in Emacs Lisp |
183 | 2 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
3 ;; Copyright (C) 1992 by Sebastian Kremer <sk@thp.uni-koeln.de> |
183 | 4 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
5 ;; This program is free software; you can redistribute it and/or modify |
183 | 6 ;; it under the terms of the GNU General Public License as published by |
7 ;; the Free Software Foundation; either version 1, or (at your option) | |
8 ;; any later version. | |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
9 ;; |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
10 ;; This program is distributed in the hope that it will be useful, |
183 | 11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 ;; GNU General Public License for more details. | |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
14 ;; |
183 | 15 ;; You should have received a copy of the GNU General Public License |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
16 ;; along with this program; if not, write to the Free Software |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
17 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
183 | 18 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
19 ;; INSTALLATION ======================================================= |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
20 ;; |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
21 ;; Put this file into your load-path. To use it, load it |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
22 ;; with (load "directory"). |
623 | 23 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
24 ;; OVERVIEW =========================================================== |
183 | 25 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
26 ;; This file overloads the function insert-directory to implement it |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
27 ;; directly from Emacs lisp, without running `ls' in a subprocess. |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
28 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
29 ;; It is useful if you cannot afford to fork Emacs on a real memory UNIX, |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
30 ;; under VMS, or if you don't have the ls program, or if you want |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
31 ;; different format from what ls offers. |
183 | 32 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
33 ;; This function uses regexps instead of shell |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
34 ;; wildcards. If you enter regexps remember to double each $ sign. |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
35 ;; For example, to include files *.el, enter `.*\.el$$', |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
36 ;; resulting in the regexp `.*\.el$'. |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
37 |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
38 ;; RESTRICTIONS ===================================================== |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
39 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
40 ;; * many ls switches are ignored, see docstring of `insert-directory'. |
183 | 41 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
42 ;; * Only numeric uid/gid |
183 | 43 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
44 ;; TODO ============================================================== |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
45 |
623 | 46 ;; Recognize some more ls switches: R F |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
47 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
48 (defun insert-directory (file &optional switches wildcard full-directory-p) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
49 "Insert directory listing for of FILE, formatted according to SWITCHES. |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
50 Leaves point after the inserted text. |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
51 Optional third arg WILDCARD means treat FILE as shell wildcard. |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
52 Optional fourth arg FULL-DIRECTORY-P means file is a directory and |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
53 switches do not contain `d', so that a full listing is expected. |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
54 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
55 This version of the function comes from `directory.el'. |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
56 It does not support ordinary shell wildcards; instead, it allows |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
57 regular expressions to match file names. |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
58 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
59 The switches that work are: A a c i r S s t u" |
1672
ecf43116a845
The find-file-name-handler function in ../src/fileio.c is now
Jim Blandy <jimb@redhat.com>
parents:
1334
diff
changeset
|
60 (let (handler ((find-file-name-handler file))) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
61 (if handler |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
62 (funcall handler 'insert-directory file switches |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
63 wildcard full-directory-p) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
64 (if wildcard |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
65 (setq wildcard (file-name-nondirectory file) ; actually emacs regexp |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
66 ;; perhaps convert it from shell to emacs syntax? |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
67 file (file-name-directory file))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
68 (if (or wildcard |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
69 full-directory-p) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
70 (let* ((dir (file-name-as-directory file)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
71 (default-directory dir);; so that file-attributes works |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
72 (sum 0) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
73 elt |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
74 short |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
75 (file-list (directory-files dir nil wildcard)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
76 file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
77 ;; do all bindings here for speed |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
78 fil attr) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
79 (cond ((memq ?A switches) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
80 (setq file-list |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
81 (ls-lisp-delete-matching "^\\.\\.?$" file-list))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
82 ((not (memq ?a switches)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
83 ;; if neither -A nor -a, flush . files |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
84 (setq file-list |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
85 (ls-lisp-delete-matching "^\\." file-list)))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
86 (setq file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
87 (mapcar |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
88 (function |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
89 (lambda (x) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
90 ;; file-attributes("~bogus") bombs |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
91 (cons x (file-attributes (expand-file-name x))))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
92 ;; inserting the call to directory-files right here |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
93 ;; seems to stimulate an Emacs bug |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
94 ;; ILLEGAL DATATYPE (#o37777777727) or #o67 |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
95 file-list)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
96 (insert "total \007\n") ; filled in afterwards |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
97 (setq file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
98 (ls-lisp-handle-switches file-alist switches)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
99 (while file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
100 (setq elt (car file-alist) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
101 short (car elt) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
102 attr (cdr elt) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
103 file-alist (cdr file-alist) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
104 fil (concat dir short) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
105 sum (+ sum (nth 7 attr))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
106 (insert (ls-lisp-format short attr switches))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
107 ;; Fill in total size of all files: |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
108 (save-excursion |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
109 (search-backward "total \007") |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
110 (goto-char (match-end 0)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
111 (delete-char -1) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
112 (insert (format "%d" (1+ (/ sum 1024)))))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
113 ;; if not full-directory-p, FILE *must not* end in /, as |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
114 ;; file-attributes will not recognize a symlink to a directory |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
115 ;; must make it a relative filename as ls does: |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
116 (setq file (file-name-nondirectory file)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
117 (insert (ls-lisp-format file (file-attributes file) switches)))))) |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
118 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
119 (defun ls-lisp-delete-matching (regexp list) |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
120 ;; Delete all elements matching REGEXP from LIST, return new list. |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
121 ;; Should perhaps use setcdr for efficiency. |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
122 (let (result) |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
123 (while list |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
124 (or (string-match regexp (car list)) |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
125 (setq result (cons (car list) result))) |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
126 (setq list (cdr list))) |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
127 result)) |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
128 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
129 (defun ls-lisp-handle-switches (file-alist switches) |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
130 ;; FILE-ALIST's elements are (FILE . FILE-ATTRIBUTES). |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
131 ;; Return new alist sorted according to SWITCHES which is a list of |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
132 ;; characters. Default sorting is alphabetically. |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
133 (let (index) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
134 (setq file-alist |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
135 (sort file-alist |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
136 (cond ((memq ?S switches) ; sorted on size |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
137 (function |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
138 (lambda (x y) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
139 ;; 7th file attribute is file size |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
140 ;; Make largest file come first |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
141 (< (nth 7 (cdr y)) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
142 (nth 7 (cdr x)))))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
143 ((memq ?t switches) ; sorted on time |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
144 (setq index (ls-lisp-time-index switches)) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
145 (function |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
146 (lambda (x y) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
147 (ls-lisp-time-lessp (nth index (cdr y)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
148 (nth index (cdr x)))))) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
149 (t ; sorted alphabetically |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
150 (function |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
151 (lambda (x y) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
152 (string-lessp (car x) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
153 (car y))))))))) |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
154 (if (memq ?r switches) ; reverse sort order |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
155 (setq file-alist (nreverse file-alist))) |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
156 file-alist) |
183 | 157 |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
158 ;; From Roland McGrath. Can use this to sort on time. |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
159 (defun ls-lisp-time-lessp (time0 time1) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
160 (let ((hi0 (car time0)) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
161 (hi1 (car time1)) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
162 (lo0 (car (cdr time0))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
163 (lo1 (car (cdr time1)))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
164 (or (< hi0 hi1) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
165 (and (= hi0 hi1) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
166 (< lo0 lo1))))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
167 |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
168 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
169 (defun ls-lisp-format (file-name file-attr &optional switches) |
183 | 170 (let ((file-type (nth 0 file-attr))) |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
171 (concat (if (memq ?i switches) ; inode number |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
172 (format "%6d " (nth 10 file-attr))) |
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
173 ;; nil is treated like "" in concat |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
174 (if (memq ?s switches) ; size in K |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
175 (format "%4d " (1+ (/ (nth 7 file-attr) 1024)))) |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
176 (nth 8 file-attr) ; permission bits |
183 | 177 ;; numeric uid/gid are more confusing than helpful |
416
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
178 ;; Emacs should be able to make strings of them. |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
179 ;; user-login-name and user-full-name could take an |
954d6271f0e9
(dired-lisp-ls): handles A a S r i s switches now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
185
diff
changeset
|
180 ;; optional arg. |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
181 (format " %3d %-8d %-8d %8d " |
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
182 (nth 1 file-attr) ; no. of links |
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
183 (nth 2 file-attr) ; uid |
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
184 (nth 3 file-attr) ; gid |
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
185 (nth 7 file-attr) ; size in bytes |
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
186 ) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
187 (ls-lisp-format-time file-attr switches) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
188 " " |
183 | 189 file-name |
190 (if (stringp file-type) ; is a symbolic link | |
191 (concat " -> " file-type) | |
192 "") | |
193 "\n" | |
194 ))) | |
195 | |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
196 (defun ls-lisp-time-index (switches) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
197 ;; Return index into file-attributes according to ls SWITCHES. |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
198 (cond |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
199 ((memq ?c switches) 6) ; last mode change |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
200 ((memq ?u switches) 4) ; last access |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
201 ;; default is last modtime |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
202 (t 5))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
203 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
204 (defun ls-lisp-format-time (file-attr switches) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
205 ;; Format time string for file with attributes FILE-ATTR according |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
206 ;; to SWITCHES (a list of ls option letters of which c and u are recognized). |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
207 ;; file-attributes's time is in a braindead format |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
208 ;; Emacs 19 can format it using a new optional argument to |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
209 ;; current-time-string, for Emacs 18 we just return the faked fixed |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
210 ;; date "Jan 00 00:00 ". |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
211 (condition-case error-data |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
212 (let* ((time (current-time-string |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
213 (nth (ls-lisp-time-index switches) file-attr))) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
214 (date (substring time 4 11)) ; "Apr 30 " |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
215 (clock (substring time 11 16)) ; "11:27" |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
216 (year (substring time 19 24)) ; " 1992" |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
217 (same-year (equal year (substring (current-time-string) 19 24)))) |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
218 (concat date ; has trailing SPC |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
219 (if same-year |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
220 ;; this is not exactly the same test used by ls |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
221 ;; ls tests if the file is older than 6 months |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
222 ;; but we can't do time differences easily |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
223 clock |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
224 year))) |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
225 (error |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
226 "Jan 00 00:00"))) |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
227 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
228 (provide 'ls-lisp) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
229 |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
230 ; eof |