Mercurial > emacs
annotate lisp/ls-lisp.el @ 24719:a0382c9f41ce
(comint-password-prompt-regexp): Modified to match the output of ksu
and ssh-add.
author | Joel N. Weber II <devnull@gnu.org> |
---|---|
date | Tue, 11 May 1999 22:32:52 +0000 |
parents | 809c3c8f6b77 |
children | 2f2786f7d960 |
rev | line source |
---|---|
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
1 ;;; ls-lisp.el --- emulate insert-directory completely in Emacs Lisp |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
2 |
22154
86791cda515c
Update copyright notice.
Richard M. Stallman <rms@gnu.org>
parents:
21620
diff
changeset
|
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc. |
14169 | 4 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
5 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de> |
17977 | 6 ;; Maintainer: FSF |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
7 ;; Keywords: unix |
183 | 8 |
14169 | 9 ;; This file is part of GNU Emacs. |
183 | 10 |
14169 | 11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
183 | 12 ;; it under the terms of the GNU General Public License as published by |
12244 | 13 ;; the Free Software Foundation; either version 2, or (at your option) |
183 | 14 ;; any later version. |
14169 | 15 |
16 ;; GNU Emacs is distributed in the hope that it will be useful, | |
183 | 17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 ;; GNU General Public License for more details. | |
14169 | 20 |
183 | 21 ;; You should have received a copy of the GNU General Public License |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
24 ;; Boston, MA 02111-1307, USA. | |
25 | |
26 ;;; Commentary: | |
183 | 27 |
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 ;; INSTALLATION ======================================================= |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
29 ;; |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
30 ;; Put this file into your load-path. To use it, load it |
3916
b3f0b10b39c8
(insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3789
diff
changeset
|
31 ;; with (load "ls-lisp"). |
623 | 32 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
33 ;; OVERVIEW =========================================================== |
183 | 34 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
35 ;; 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
|
36 ;; 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
|
37 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
38 ;; 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
|
39 ;; 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
|
40 ;; different format from what ls offers. |
183 | 41 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
42 ;; 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
|
43 ;; 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
|
44 ;; 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
|
45 ;; 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
|
46 |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
47 ;; RESTRICTIONS ===================================================== |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
48 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
49 ;; * many ls switches are ignored, see docstring of `insert-directory'. |
183 | 50 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
51 ;; * Only numeric uid/gid |
183 | 52 |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
53 ;; TODO ============================================================== |
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
54 |
623 | 55 ;; 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
|
56 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
57 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
58 |
14213
aaa459c274b9
(ls-lisp-support-shell-wildcards): Add autoload cookie.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
59 ;;;###autoload |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
60 (defvar ls-lisp-support-shell-wildcards t |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
61 "*Non-nil means file patterns are treated as shell wildcards. |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
62 nil means they are treated as Emacs regexps (for backward compatibility). |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
63 This variable is checked by \\[insert-directory] only when `ls-lisp.el' |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
64 package is used.") |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
65 |
21620
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
66 (defvar ls-lisp-dired-ignore-case nil |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
67 "Non-nil causes dired buffers to sort alphabetically regardless of case.") |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
68 |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
69 (defvar ls-lisp-use-insert-directory-program nil |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
70 "Non-nil causes ls-lisp to revert back to using `insert-directory-program'. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
71 This is useful on platforms where ls-lisp is dumped into Emacs, such as |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
72 Microsoft Windows, but you would still like to use a program to list |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
73 the contents of a directory.") |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
74 |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
75 ;; Remember the original insert-directory function. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
76 (fset 'original-insert-directory (symbol-function 'insert-directory)) |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
77 |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
78 (defun insert-directory (file switches &optional wildcard full-directory-p) |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
79 "Insert directory listing for FILE, formatted according to SWITCHES. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
80 Leaves point after the inserted text. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
81 SWITCHES may be a string of options, or a list of strings. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
82 Optional third arg WILDCARD means treat FILE as shell wildcard. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
83 Optional fourth arg FULL-DIRECTORY-P means file is a directory and |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
84 switches do not contain `d', so that a full listing is expected. |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
85 |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
86 This version of the function comes from `ls-lisp.el'. Depending upon |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
87 the value of `ls-lisp-use-insert-directory-program', it will use an |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
88 external program if non-nil or the lisp function `ls-lisp-insert-directory' |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
89 otherwise." |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
90 (if ls-lisp-use-insert-directory-program |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
91 (original-insert-directory file switches wildcard full-directory-p) |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
92 (ls-lisp-insert-directory file switches wildcard full-directory-p))) |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
93 |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
94 (defun ls-lisp-insert-directory (file switches &optional wildcard full-directory-p) |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
95 "Insert directory listing for FILE, formatted according to SWITCHES. |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 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
|
100 |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
101 This version of the function comes from `ls-lisp.el'. It does not |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
102 run any external programs or shells. It supports ordinary shell |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
103 wildcards if `ls-lisp-support-shell-wildcards' variable is non-nil; |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
104 otherwise, it interprets wildcards as regular expressions to match |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
105 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
|
106 |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
107 Not all `ls' switches are supported. The switches that work |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
108 are: A a c i r S s t u" |
7030
9e51b51e8595
Pass operation to find-file-name-handler.
Karl Heuer <kwzh@gnu.org>
parents:
5457
diff
changeset
|
109 (let ((handler (find-file-name-handler file 'insert-directory))) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
110 (if handler |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
111 (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
|
112 wildcard full-directory-p) |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
113 ;; Sometimes we get ".../foo*/" as FILE. While the shell and |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
114 ;; `ls' don't mind, we certainly do, because it makes us think |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
115 ;; there is no wildcard, only a directory name. |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
116 (if (and ls-lisp-support-shell-wildcards |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
117 (string-match "[[?*]" file)) |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
118 (progn |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
119 (or (not (eq (aref file (1- (length file))) ?/)) |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
120 (setq file (substring file 0 (1- (length file))))) |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
121 (setq wildcard t))) |
3789
0af7cedb1081
* ls-lisp.el (insert-directory): If no handler, convert SWITCHES
Jim Blandy <jimb@redhat.com>
parents:
2233
diff
changeset
|
122 ;; Convert SWITCHES to a list of characters. |
0af7cedb1081
* ls-lisp.el (insert-directory): If no handler, convert SWITCHES
Jim Blandy <jimb@redhat.com>
parents:
2233
diff
changeset
|
123 (setq switches (append switches nil)) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
124 (if wildcard |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
125 (setq wildcard |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
126 (if ls-lisp-support-shell-wildcards |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
127 (wildcard-to-regexp (file-name-nondirectory file)) |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
128 (file-name-nondirectory file)) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
129 file (file-name-directory file))) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
130 (if (or wildcard |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
131 full-directory-p) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
132 (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
|
133 (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
|
134 (sum 0) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
135 elt |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
136 short |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
137 (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
|
138 file-alist |
16098
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
139 (now (current-time)) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
140 ;; do all bindings here for speed |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
141 file-size |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
142 fil attr) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
143 (cond ((memq ?A switches) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
144 (setq file-list |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
145 (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
|
146 ((not (memq ?a switches)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
147 ;; 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
|
148 (setq file-list |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
149 (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
|
150 (setq file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
151 (mapcar |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
152 (function |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
153 (lambda (x) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
154 ;; file-attributes("~bogus") bombs |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
155 (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
|
156 ;; 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
|
157 ;; 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
|
158 ;; ILLEGAL DATATYPE (#o37777777727) or #o67 |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
159 file-list)) |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
160 ;; ``Total'' line (filled in afterwards). |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
161 (insert (if (car-safe file-alist) |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
162 "total \007\n" |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
163 ;; Shell says ``No match'' if no files match |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
164 ;; the wildcard; let's say something similar. |
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
165 "(No match)\ntotal \007\n")) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
166 (setq file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
167 (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
|
168 (while file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
169 (setq elt (car file-alist) |
8409
4a27ca4bcdf4
(insert-directory): Gracefully handle the case
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
170 file-alist (cdr file-alist) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
171 short (car elt) |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
172 attr (cdr elt) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
173 file-size (nth 7 attr)) |
8409
4a27ca4bcdf4
(insert-directory): Gracefully handle the case
Richard M. Stallman <rms@gnu.org>
parents:
7300
diff
changeset
|
174 (and attr |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
175 (setq sum |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
176 ;; Even if neither SUM nor file's size |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
177 ;; overflow, their sum could. |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
178 (if (or (< sum (- 134217727 file-size)) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
179 (floatp sum) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
180 (floatp file-size)) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
181 (+ sum file-size) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
182 (+ (float sum) file-size))) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
183 (insert (ls-lisp-format short attr file-size switches now)) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
184 )) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
185 ;; 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
|
186 (save-excursion |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
187 (search-backward "total \007") |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
188 (goto-char (match-end 0)) |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
189 (delete-char -1) |
24329
40be509c47c2
(ls-lisp-insert-directory): Call fceiling to round
Eli Zaretskii <eliz@gnu.org>
parents:
23452
diff
changeset
|
190 (insert (format "%.0f" (fceiling (/ sum 1024.0)))))) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
191 ;; 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
|
192 ;; 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
|
193 ;; 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
|
194 (setq file (file-name-nondirectory file)) |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
195 (insert (ls-lisp-format file (file-attributes file) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
196 (nth 7 (file-attributes file)) switches |
16098
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
197 (current-time))))))) |
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
|
198 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
199 (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
|
200 ;; 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
|
201 ;; 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
|
202 (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
|
203 (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
|
204 (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
|
205 (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
|
206 (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
|
207 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
|
208 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
209 (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
|
210 ;; 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
|
211 ;; 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
|
212 ;; 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
|
213 (let (index) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
214 (setq file-alist |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
215 (sort file-alist |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
216 (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
|
217 (function |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
218 (lambda (x y) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
219 ;; 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
|
220 ;; Make largest file come first |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
221 (< (nth 7 (cdr y)) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
222 (nth 7 (cdr x)))))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
223 ((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
|
224 (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
|
225 (function |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
226 (lambda (x y) |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
227 (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
|
228 (nth index (cdr x)))))) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
229 (t ; sorted alphabetically |
21620
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
230 (if ls-lisp-dired-ignore-case |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
231 (function |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
232 (lambda (x y) |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
233 (string-lessp (upcase (car x)) |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
234 (upcase (car y))))) |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
235 (function |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
236 (lambda (x y) |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
237 (string-lessp (car x) |
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
238 (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
|
239 (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
|
240 (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
|
241 file-alist) |
183 | 242 |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
243 ;; 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
|
244 (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
|
245 (let ((hi0 (car time0)) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
246 (hi1 (car time1)) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
247 (lo0 (car (cdr time0))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
248 (lo1 (car (cdr time1)))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
249 (or (< hi0 hi1) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
250 (and (= hi0 hi1) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
251 (< lo0 lo1))))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
252 |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
253 |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
254 (defun ls-lisp-format (file-name file-attr file-size switches now) |
183 | 255 (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
|
256 (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
|
257 (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
|
258 ;; 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
|
259 (if (memq ?s switches) ; size in K |
24436
e5af0407bcd6
(ls-lisp-format): Under -s, print the size in blocks with %4.0f, in case
Eli Zaretskii <eliz@gnu.org>
parents:
24435
diff
changeset
|
260 (format "%4.0f " (fceiling (/ file-size 1024.0)))) |
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
|
261 (nth 8 file-attr) ; permission bits |
183 | 262 ;; 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
|
263 ;; 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
|
264 ;; 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
|
265 ;; optional arg. |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
266 (format (if (floatp file-size) |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
267 " %3d %-8s %-8s %8.0f " |
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
268 " %3d %-8s %-8s %8d ") |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
269 (nth 1 file-attr) ; no. of links |
3916
b3f0b10b39c8
(insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3789
diff
changeset
|
270 (if (= (user-uid) (nth 2 file-attr)) |
b3f0b10b39c8
(insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3789
diff
changeset
|
271 (user-login-name) |
5457
4fe8a94b0aa6
(ls-lisp-format): Bad format for uid and gid fixed.
Richard M. Stallman <rms@gnu.org>
parents:
3916
diff
changeset
|
272 (int-to-string (nth 2 file-attr))) ; uid |
3916
b3f0b10b39c8
(insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3789
diff
changeset
|
273 (if (eq system-type 'ms-dos) |
b3f0b10b39c8
(insert-directory): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
3789
diff
changeset
|
274 "root" ; everything is root on MSDOS. |
5457
4fe8a94b0aa6
(ls-lisp-format): Bad format for uid and gid fixed.
Richard M. Stallman <rms@gnu.org>
parents:
3916
diff
changeset
|
275 (int-to-string (nth 3 file-attr))) ; gid |
24435
3b5ee0390edd
(ls-lisp-insert-directory): Protect the sum total of
Eli Zaretskii <eliz@gnu.org>
parents:
24329
diff
changeset
|
276 file-size |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
277 ) |
16098
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
278 (ls-lisp-format-time file-attr switches now) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
279 " " |
183 | 280 file-name |
281 (if (stringp file-type) ; is a symbolic link | |
282 (concat " -> " file-type) | |
283 "") | |
284 "\n" | |
285 ))) | |
286 | |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
287 (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
|
288 ;; 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
|
289 (cond |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
290 ((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
|
291 ((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
|
292 ;; default is last modtime |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
293 (t 5))) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
294 |
16098
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
295 (defun ls-lisp-format-time (file-attr switches now) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
296 ;; 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
|
297 ;; to SWITCHES (a list of ls option letters of which c and u are recognized). |
16098
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
298 ;; Use the same method as `ls' to decide whether to show time-of-day or year, |
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
299 ;; depending on distance between file date and NOW. |
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
300 (let* ((time (nth (ls-lisp-time-index switches) file-attr)) |
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
301 (diff16 (- (car time) (car now))) |
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
302 (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now))))) |
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
303 (past-cutoff (- (* 6 30 24 60 60))) ; 6 30-day months |
b463288de0a8
(insert-directory): Use same value of `now' for all files.
Richard M. Stallman <rms@gnu.org>
parents:
14213
diff
changeset
|
304 (future-cutoff (* 60 60))) ; 1 hour |
24660
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
305 (condition-case nil |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
306 (format-time-string |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
307 (if (and |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
308 (<= past-cutoff diff) (<= diff future-cutoff) |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
309 ;; Sanity check in case `diff' computation overflowed. |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
310 (<= (1- (ash past-cutoff -16)) diff16) |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
311 (<= diff16 (1+ (ash future-cutoff -16)))) |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
312 "%b %e %H:%M" |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
313 "%b %e %Y") |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
314 time) |
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
315 (error "??? ?? ????")))) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
316 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
317 (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
|
318 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
319 ;;; ls-lisp.el ends here |