Mercurial > emacs
annotate lisp/ls-lisp.el @ 112382:396b01a20bde
Merge: omit auto-generated aclocal.m4 from repository
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 19 Jan 2011 21:02:52 -0800 |
parents | 61f7601898b1 |
children |
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 |
112284
61f7601898b1
Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents:
112228
diff
changeset
|
3 ;; Copyright (C) 1992, 1994, 2000, 2001, 2002, 2003, 2004, 2005, 2006, |
61f7601898b1
Refill some copyright headers.
Glenn Morris <rgm@gnu.org>
parents:
112228
diff
changeset
|
4 ;; 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
14169 | 5 |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37330
diff
changeset
|
6 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de> |
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37330
diff
changeset
|
7 ;; Modified by: Francis J. Wright <F.J.Wright@maths.qmw.ac.uk> |
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37330
diff
changeset
|
8 ;; Maintainer: FSF |
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37330
diff
changeset
|
9 ;; Keywords: unix, dired |
110015
280c8ae2476d
Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents:
108820
diff
changeset
|
10 ;; Package: emacs |
183 | 11 |
14169 | 12 ;; This file is part of GNU Emacs. |
183 | 13 |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94580
diff
changeset
|
14 ;; GNU Emacs is free software: you can redistribute it and/or modify |
183 | 15 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94580
diff
changeset
|
16 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94580
diff
changeset
|
17 ;; (at your option) any later version. |
14169 | 18 |
19 ;; GNU Emacs is distributed in the hope that it will be useful, | |
183 | 20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 ;; GNU General Public License for more details. | |
14169 | 23 |
183 | 24 ;; You should have received a copy of the GNU General Public License |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94580
diff
changeset
|
25 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
14169 | 26 |
27 ;;; Commentary: | |
183 | 28 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
29 ;; OVERVIEW ========================================================== |
623 | 30 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
31 ;; This file redefines the function `insert-directory' to implement it |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
32 ;; directly from Emacs lisp, without running ls in a subprocess. It |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
33 ;; is useful if you cannot afford to fork Emacs on a real memory UNIX, |
97142 | 34 ;; or other non-UNIX platforms if you don't have the ls |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
35 ;; program, or if you want a different format from what ls offers. |
183 | 36 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
37 ;; This function can use regexps instead of shell wildcards. If you |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
38 ;; enter regexps remember to double each $ sign. For example, to |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
39 ;; include files *.el, enter `.*\.el$$', resulting in the regexp |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
40 ;; `.*\.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
|
41 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
42 ;; RESTRICTIONS ====================================================== |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
43 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
44 ;; * A few obscure ls switches are still ignored: see the docstring of |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
45 ;; `insert-directory'. |
183 | 46 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
47 ;; TO DO ============================================================= |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
48 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
49 ;; Complete handling of F switch (if/when possible). |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
50 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
51 ;; FJW: May be able to sort much faster by consing the sort key onto |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
52 ;; the front of each list element, sorting and then stripping the key |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
53 ;; off again! |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
54 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
55 ;;; History: |
183 | 56 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
57 ;; Written originally by Sebastian Kremer <sk@thp.uni-koeln.de> |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
58 ;; Revised by Andrew Innes and Geoff Volker (and maybe others). |
183 | 59 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
60 ;; Modified by Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>, mainly |
67079
0bf8f7505426
(ls-lisp-parse-symlink): Delete.
Lars Hansen <larsh@soem.dk>
parents:
67004
diff
changeset
|
61 ;; to support many more ls options, "platform emulation" and more |
0bf8f7505426
(ls-lisp-parse-symlink): Delete.
Lars Hansen <larsh@soem.dk>
parents:
67004
diff
changeset
|
62 ;; robust sorting. |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
63 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
64 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
65 |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
66 (eval-when-compile (require 'cl)) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
67 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
68 (defgroup ls-lisp nil |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
69 "Emulate the ls program completely in Emacs Lisp." |
35011
11e866e5a825
(ls-lisp) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
34884
diff
changeset
|
70 :version "21.1" |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
71 :group 'dired) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
72 |
111496
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
73 (defun ls-lisp-set-options () |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
74 "Reset the ls-lisp options that depend on `ls-lisp-emulation'." |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
75 (mapc 'custom-reevaluate-setting |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
76 '(ls-lisp-ignore-case ls-lisp-dirs-first ls-lisp-verbosity))) |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
77 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
78 (defcustom ls-lisp-emulation |
104552
10c38084881d
Remove code for defunct system-types emx, macos, mswindows,
Glenn Morris <rgm@gnu.org>
parents:
102747
diff
changeset
|
79 (cond ;; ((eq system-type 'windows-nt) 'MS-Windows) |
111496
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
80 ((memq system-type '(hpux usg-unix-v irix berkeley-unix)) |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
81 'UNIX)) ; very similar to GNU |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
82 ;; Anything else defaults to nil, meaning GNU. |
100171 | 83 "Platform to emulate: GNU (default), MacOS, MS-Windows, UNIX. |
111496
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
84 Corresponding value is one of: nil, `MacOS', `MS-Windows', `UNIX'. |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
85 Set this to your preferred value; it need not match the actual platform |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
86 you are using. |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
87 |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
88 This variable does not affect the behavior of ls-lisp directly. |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
89 Rather, it controls the default values for some variables that do: |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
90 `ls-lisp-ignore-case', `ls-lisp-dirs-first', and `ls-lisp-verbosity'. |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
91 |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
92 If you change this variable directly (without using customize) |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
93 after loading `ls-lisp', you should use `ls-lisp-set-options' to |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
94 update the dependent variables." |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
95 :type '(choice (const :tag "GNU" nil) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
96 (const MacOS) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
97 (const MS-Windows) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
98 (const UNIX)) |
111496
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
99 :initialize 'custom-initialize-default |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
100 :set (lambda (symbol value) |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
101 (unless (equal value (eval symbol)) |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
102 (custom-set-default symbol value) |
82e69613602e
ls-lisp: get rid of the dreaded "no effect until you restart Emacs".
Glenn Morris <rgm@gnu.org>
parents:
111489
diff
changeset
|
103 (ls-lisp-set-options))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
104 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
105 |
111602 | 106 ;; Only made an obsolete alias in 23.3. Before that, the initial |
107 ;; value was set according to: | |
108 ;; (or (memq ls-lisp-emulation '(MS-Windows MacOS)) | |
109 ;; (and (boundp 'ls-lisp-dired-ignore-case) ls-lisp-dired-ignore-case)) | |
110 ;; Which isn't the right thing to do. | |
111 (define-obsolete-variable-alias 'ls-lisp-dired-ignore-case | |
112 'ls-lisp-ignore-case "21.1") | |
113 | |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
114 (defcustom ls-lisp-ignore-case |
111602 | 115 (memq ls-lisp-emulation '(MS-Windows MacOS)) |
100171 | 116 "Non-nil causes ls-lisp alphabetic sorting to ignore case." |
111489 | 117 :set-after '(ls-lisp-emulation) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
118 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
119 :group 'ls-lisp) |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
120 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
121 (defcustom ls-lisp-dirs-first (eq ls-lisp-emulation 'MS-Windows) |
100171 | 122 "Non-nil causes ls-lisp to sort directories first in any ordering. |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
123 \(Or last if it is reversed.) Follows Microsoft Windows Explorer." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
124 ;; Functionality suggested by Chris McMahan <cmcmahan@one.net> |
111489 | 125 :set-after '(ls-lisp-emulation) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
126 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
127 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
128 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
129 (defcustom ls-lisp-verbosity |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
130 (cond ((eq ls-lisp-emulation 'MacOS) nil) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
131 ((eq ls-lisp-emulation 'MS-Windows) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
132 (if (and (fboundp 'w32-using-nt) (w32-using-nt)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
133 '(links))) ; distinguish NT/2K from 9x |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
134 ((eq ls-lisp-emulation 'UNIX) '(links uid)) ; UNIX ls |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
135 (t '(links uid gid))) ; GNU ls |
100171 | 136 "A list of optional file attributes that ls-lisp should display. |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
137 It should contain none or more of the symbols: links, uid, gid. |
77711
3e2de8648d07
(ls-lisp-verbosity): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
75426
diff
changeset
|
138 A value of nil (or an empty list) means display none of them. |
21620
611b5f660ee6
(ls-lisp-dired-ignore-case): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
17977
diff
changeset
|
139 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
140 Concepts come from UNIX: `links' means count of names associated with |
111489 | 141 the file; `uid' means user (owner) identifier; `gid' means group |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
142 identifier. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
143 |
111489 | 144 If emulation is MacOS then default is nil; |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
145 if emulation is MS-Windows then default is `(links)' if platform is |
111489 | 146 Windows NT/2K, nil otherwise; |
147 if emulation is UNIX then default is `(links uid)'; | |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
148 if emulation is GNU then default is `(links uid gid)'." |
111489 | 149 :set-after '(ls-lisp-emulation) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
150 ;; Functionality suggested by Howard Melman <howard@silverstream.com> |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
151 :type '(set (const :tag "Show Link Count" links) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
152 (const :tag "Show User" uid) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
153 (const :tag "Show Group" gid)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
154 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
155 |
49328
850f7b918635
(ls-lisp-use-insert-directory-program): Make default
Markus Rost <rost@math.uni-bielefeld.de>
parents:
48917
diff
changeset
|
156 (defcustom ls-lisp-use-insert-directory-program |
104552
10c38084881d
Remove code for defunct system-types emx, macos, mswindows,
Glenn Morris <rgm@gnu.org>
parents:
102747
diff
changeset
|
157 (not (memq system-type '(ms-dos windows-nt))) |
100171 | 158 "Non-nil causes ls-lisp to revert back to using `insert-directory-program'. |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
159 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
|
160 Microsoft Windows, but you would still like to use a program to list |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
161 the contents of a directory." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
162 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
163 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
164 |
49328
850f7b918635
(ls-lisp-use-insert-directory-program): Make default
Markus Rost <rost@math.uni-bielefeld.de>
parents:
48917
diff
changeset
|
165 ;;; Autoloaded because it is let-bound in `recover-session', `mail-recover-1'. |
850f7b918635
(ls-lisp-use-insert-directory-program): Make default
Markus Rost <rost@math.uni-bielefeld.de>
parents:
48917
diff
changeset
|
166 ;;;###autoload |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
167 (defcustom ls-lisp-support-shell-wildcards t |
100171 | 168 "Non-nil means ls-lisp treats file patterns as shell wildcards. |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
169 Otherwise they are treated as Emacs regexps (for backward compatibility)." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
170 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
171 :group 'ls-lisp) |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
172 |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
173 (defcustom ls-lisp-format-time-list |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
174 '("%b %e %H:%M" |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
175 "%b %e %Y") |
100171 | 176 "List of `format-time-string' specs to display file time stamps. |
75426
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
177 These specs are used ONLY if a valid locale can not be determined. |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
178 |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
179 If `ls-lisp-use-localized-time-format' is non-nil, these specs are used |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
180 regardless of whether the locale can be determined. |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
181 |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
182 Syntax: (EARLY-TIME-FORMAT OLD-TIME-FORMAT) |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
183 |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
184 The EARLY-TIME-FORMAT is used if file has been modified within the |
111489 | 185 current year. The OLD-TIME-FORMAT is used for older files. To use ISO |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
186 8601 dates, you could set: |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
187 |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
188 \(setq ls-lisp-format-time-list |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
189 '(\"%Y-%m-%d %H:%M\" |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
190 \"%Y-%m-%d \"))" |
47510
22c6e92cccfb
(ls-lisp-format-time-list): Fix type and provide :tag's.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47329
diff
changeset
|
191 :type '(list (string :tag "Early time format") |
22c6e92cccfb
(ls-lisp-format-time-list): Fix type and provide :tag's.
Markus Rost <rost@math.uni-bielefeld.de>
parents:
47329
diff
changeset
|
192 (string :tag "Old time format")) |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
193 :group 'ls-lisp) |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
194 |
75426
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
195 (defcustom ls-lisp-use-localized-time-format nil |
111489 | 196 "Non-nil means to always use `ls-lisp-format-time-list' for time stamps. |
197 This applies even if a valid locale is specified. | |
75426
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
198 |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
199 WARNING: Using localized date/time format might cause Dired columns |
111489 | 200 to fail to line up, e.g. if month names are not all of the same length." |
75426
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
201 :type 'boolean |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
202 :group 'ls-lisp) |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
203 |
48917
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
204 (defvar original-insert-directory nil |
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
205 "This holds the original function definition of `insert-directory'.") |
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
206 |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
207 (defvar ls-lisp-uid-d-fmt "-%d" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
208 "Format to display integer UIDs.") |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
209 (defvar ls-lisp-uid-s-fmt "-%s" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
210 "Format to display user names.") |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
211 (defvar ls-lisp-gid-d-fmt "-%d" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
212 "Format to display integer GIDs.") |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
213 (defvar ls-lisp-gid-s-fmt "-%s" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
214 "Format to display user group names.") |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
215 (defvar ls-lisp-filesize-d-fmt "%d" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
216 "Format to display integer file sizes.") |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
217 (defvar ls-lisp-filesize-f-fmt "%.0f" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
218 "Format to display float file sizes.") |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
219 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
220 ;; Remember the original insert-directory function |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
221 (or (featurep 'ls-lisp) ; FJW: unless this file is being reloaded! |
48917
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
222 (setq original-insert-directory (symbol-function 'insert-directory))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
223 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
224 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
225 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
226 |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
227 (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
|
228 "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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
235 This version of the function comes from `ls-lisp.el'. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
236 If the value of `ls-lisp-use-insert-directory-program' is non-nil then |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
237 it works exactly like the version from `files.el' and runs a directory |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
238 listing program whose name is in the variable |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
239 `insert-directory-program'; if also WILDCARD is non-nil then it runs |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
240 the shell specified by `shell-file-name'. If the value of |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
241 `ls-lisp-use-insert-directory-program' is nil then it runs a Lisp |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
242 emulation. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
243 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
244 The Lisp emulation does not run any external programs or shells. It |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
245 supports ordinary shell wildcards if `ls-lisp-support-shell-wildcards' |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
246 is non-nil; otherwise, it interprets wildcards as regular expressions |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
247 to match file names. It does not support all `ls' switches -- those |
111376 | 248 that work are: A a B C c F G g h i n R r S s t U u X. The l switch |
249 is assumed to be always present and cannot be turned off." | |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
250 (if ls-lisp-use-insert-directory-program |
48917
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
251 (funcall original-insert-directory |
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
252 file switches wildcard full-directory-p) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
253 ;; We need the directory in order to find the right handler. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
254 (let ((handler (find-file-name-handler (expand-file-name file) |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
255 'insert-directory)) |
78043
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
256 (orig-file file) |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
257 wildcard-regexp) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
258 (if handler |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
259 (funcall handler 'insert-directory file switches |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
260 wildcard full-directory-p) |
50992
01a94a546935
(insert-directory): Remove --dired switch when
John Paul Wallington <jpw@pobox.com>
parents:
50767
diff
changeset
|
261 ;; Remove --dired switch |
01a94a546935
(insert-directory): Remove --dired switch when
John Paul Wallington <jpw@pobox.com>
parents:
50767
diff
changeset
|
262 (if (string-match "--dired " switches) |
01a94a546935
(insert-directory): Remove --dired switch when
John Paul Wallington <jpw@pobox.com>
parents:
50767
diff
changeset
|
263 (setq switches (replace-match "" nil nil switches))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
264 ;; Convert SWITCHES to a list of characters. |
111377
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
265 (setq switches (delete ?\ (delete ?- (append switches nil)))) |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
266 ;; Sometimes we get ".../foo*/" as FILE. While the shell and |
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
267 ;; `ls' don't mind, we certainly do, because it makes us think |
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
268 ;; there is no wildcard, only a directory name. |
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
269 (if (and ls-lisp-support-shell-wildcards |
78039
ed97a96f45fc
(insert-directory): Don't treat FILE as a wildcard if FILE exists as
Eli Zaretskii <eliz@gnu.org>
parents:
77711
diff
changeset
|
270 (string-match "[[?*]" file) |
78043
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
271 ;; Prefer an existing file to wildcards, like |
78039
ed97a96f45fc
(insert-directory): Don't treat FILE as a wildcard if FILE exists as
Eli Zaretskii <eliz@gnu.org>
parents:
77711
diff
changeset
|
272 ;; dired-noselect does. |
78043
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
273 (not (file-exists-p file))) |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
274 (progn |
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
275 (or (not (eq (aref file (1- (length file))) ?/)) |
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
276 (setq file (substring file 0 (1- (length file))))) |
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
277 (setq wildcard t))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
278 (if wildcard |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
279 (setq wildcard-regexp |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
280 (if ls-lisp-support-shell-wildcards |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
281 (wildcard-to-regexp (file-name-nondirectory file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
282 (file-name-nondirectory file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
283 file (file-name-directory file)) |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
284 (if (memq ?B switches) (setq wildcard-regexp "[^~]\\'"))) |
78043
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
285 (condition-case err |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
286 (ls-lisp-insert-directory |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
287 file switches (ls-lisp-time-index switches) |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
288 wildcard-regexp full-directory-p) |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
289 (invalid-regexp |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
290 ;; Maybe they wanted a literal file that just happens to |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
291 ;; use characters special to shell wildcards. |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
292 (if (equal (cadr err) "Unmatched [ or [^") |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
293 (progn |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
294 (setq wildcard-regexp (if (memq ?B switches) "[^~]\\'") |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
295 file (file-relative-name orig-file)) |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
296 (ls-lisp-insert-directory |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
297 file switches (ls-lisp-time-index switches) |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
298 nil full-directory-p)) |
0ef88721691e
(insert-directory): If an invalid regexp error is thrown, try using FILE
Eli Zaretskii <eliz@gnu.org>
parents:
78039
diff
changeset
|
299 (signal (car err) (cdr err))))) |
42239
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
300 ;; Try to insert the amount of free space. |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
301 (save-excursion |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
302 (goto-char (point-min)) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
303 ;; First find the line to put it on. |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
304 (when (re-search-forward "^total" nil t) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
305 (let ((available (get-free-disk-space "."))) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
306 (when available |
42427
f1a88fb2fb4e
(insert-directory): Modify the "total" line wording, in accordance with
Eli Zaretskii <eliz@gnu.org>
parents:
42239
diff
changeset
|
307 ;; Replace "total" with "total used", to avoid confusion. |
f1a88fb2fb4e
(insert-directory): Modify the "total" line wording, in accordance with
Eli Zaretskii <eliz@gnu.org>
parents:
42239
diff
changeset
|
308 (replace-match "total used in directory") |
42239
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
309 (end-of-line) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
310 (insert " available " available))))))))) |
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
|
311 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
312 (defun ls-lisp-insert-directory |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
313 (file switches time-index wildcard-regexp full-directory-p) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
314 "Insert directory listing for FILE, formatted according to SWITCHES. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
315 Leaves point after the inserted text. This is an internal function |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
316 optionally called by the `ls-lisp.el' version of `insert-directory'. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
317 It is called recursively if the -R switch is used. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
318 SWITCHES is a *list* of characters. TIME-INDEX is the time index into |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
319 file-attributes according to SWITCHES. WILDCARD-REGEXP is nil or an *Emacs |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
320 regexp*. FULL-DIRECTORY-P means file is a directory and SWITCHES does |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
321 not contain `d', so that a full listing is expected." |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
322 (if (or wildcard-regexp full-directory-p) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
323 (let* ((dir (file-name-as-directory file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
324 (default-directory dir) ; so that file-attributes works |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
325 (file-alist |
87992
1787561f6c22
(ls-lisp-insert-directory): If -n switch is used, invoke
Eli Zaretskii <eliz@gnu.org>
parents:
87649
diff
changeset
|
326 (directory-files-and-attributes dir nil wildcard-regexp t |
1787561f6c22
(ls-lisp-insert-directory): If -n switch is used, invoke
Eli Zaretskii <eliz@gnu.org>
parents:
87649
diff
changeset
|
327 (if (memq ?n switches) |
1787561f6c22
(ls-lisp-insert-directory): If -n switch is used, invoke
Eli Zaretskii <eliz@gnu.org>
parents:
87649
diff
changeset
|
328 'integer |
1787561f6c22
(ls-lisp-insert-directory): If -n switch is used, invoke
Eli Zaretskii <eliz@gnu.org>
parents:
87649
diff
changeset
|
329 'string))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
330 (sum 0) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
331 (max-uid-len 0) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
332 (max-gid-len 0) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
333 (max-file-size 0) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
334 ;; do all bindings here for speed |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
335 total-line files elt short file-size fil attr |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
336 fuid fgid uid-len gid-len) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
337 (cond ((memq ?A switches) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
338 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
339 (ls-lisp-delete-matching "^\\.\\.?$" file-alist))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
340 ((not (memq ?a switches)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
341 ;; if neither -A nor -a, flush . files |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
342 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
343 (ls-lisp-delete-matching "^\\." file-alist)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
344 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
345 (ls-lisp-handle-switches file-alist switches)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
346 (if (memq ?C switches) ; column (-C) format |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
347 (ls-lisp-column-format file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
348 (setq total-line (cons (point) (car-safe file-alist))) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
349 ;; Find the appropriate format for displaying uid, gid, and |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
350 ;; file size, by finding the longest strings among all the |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
351 ;; files we are about to display. |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
352 (dolist (elt file-alist) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
353 (setq attr (cdr elt) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
354 fuid (nth 2 attr) |
94580
9a020be031da
(ls-lisp-insert-directory): Use `string-width' instead of `length'
Eli Zaretskii <eliz@gnu.org>
parents:
94345
diff
changeset
|
355 uid-len (if (stringp fuid) (string-width fuid) |
9a020be031da
(ls-lisp-insert-directory): Use `string-width' instead of `length'
Eli Zaretskii <eliz@gnu.org>
parents:
94345
diff
changeset
|
356 (length (format "%d" fuid))) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
357 fgid (nth 3 attr) |
94580
9a020be031da
(ls-lisp-insert-directory): Use `string-width' instead of `length'
Eli Zaretskii <eliz@gnu.org>
parents:
94345
diff
changeset
|
358 gid-len (if (stringp fgid) (string-width fgid) |
9a020be031da
(ls-lisp-insert-directory): Use `string-width' instead of `length'
Eli Zaretskii <eliz@gnu.org>
parents:
94345
diff
changeset
|
359 (length (format "%d" fgid))) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
360 file-size (nth 7 attr)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
361 (if (> uid-len max-uid-len) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
362 (setq max-uid-len uid-len)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
363 (if (> gid-len max-gid-len) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
364 (setq max-gid-len gid-len)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
365 (if (> file-size max-file-size) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
366 (setq max-file-size file-size))) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
367 (setq ls-lisp-uid-d-fmt (format " %%-%dd" max-uid-len)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
368 (setq ls-lisp-uid-s-fmt (format " %%-%ds" max-uid-len)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
369 (setq ls-lisp-gid-d-fmt (format " %%-%dd" max-gid-len)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
370 (setq ls-lisp-gid-s-fmt (format " %%-%ds" max-gid-len)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
371 (setq ls-lisp-filesize-d-fmt |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
372 (format " %%%dd" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
373 (if (memq ?s switches) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
374 (length (format "%.0f" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
375 (fceiling (/ max-file-size 1024.0)))) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
376 (length (format "%.0f" max-file-size))))) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
377 (setq ls-lisp-filesize-f-fmt |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
378 (format " %%%d.0f" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
379 (if (memq ?s switches) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
380 (length (format "%.0f" |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
381 (fceiling (/ max-file-size 1024.0)))) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
382 (length (format "%.0f" max-file-size))))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
383 (setq files file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
384 (while files ; long (-l) format |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
385 (setq elt (car files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
386 files (cdr files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
387 short (car elt) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
388 attr (cdr elt) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
389 file-size (nth 7 attr)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
390 (and attr |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
391 (setq sum (+ file-size |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
392 ;; Even if neither SUM nor file's size |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
393 ;; overflow, their sum could. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
394 (if (or (< sum (- 134217727 file-size)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
395 (floatp sum) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
396 (floatp file-size)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
397 sum |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
398 (float sum)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
399 (insert (ls-lisp-format short attr file-size |
111489 | 400 switches time-index)))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
401 ;; Insert total size of all files: |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
402 (save-excursion |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
403 (goto-char (car total-line)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
404 (or (cdr total-line) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
405 ;; Shell says ``No match'' if no files match |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
406 ;; the wildcard; let's say something similar. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
407 (insert "(No match)\n")) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
408 (insert (format "total %.0f\n" (fceiling (/ sum 1024.0)))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
409 (if (memq ?R switches) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
410 ;; List the contents of all directories recursively. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
411 ;; cadr of each element of `file-alist' is t for |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
412 ;; directory, string (name linked to) for symbolic |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
413 ;; link, or nil. |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
414 (while file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
415 (setq elt (car file-alist) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
416 file-alist (cdr file-alist)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
417 (when (and (eq (cadr elt) t) ; directory |
102747
cf4d6724a83b
(ls-lisp-insert-directory): Allow for a trailing '/' when looking for "."
Eli Zaretskii <eliz@gnu.org>
parents:
101621
diff
changeset
|
418 ;; Under -F, we have already decorated all |
cf4d6724a83b
(ls-lisp-insert-directory): Allow for a trailing '/' when looking for "."
Eli Zaretskii <eliz@gnu.org>
parents:
101621
diff
changeset
|
419 ;; directories, including "." and "..", with |
cf4d6724a83b
(ls-lisp-insert-directory): Allow for a trailing '/' when looking for "."
Eli Zaretskii <eliz@gnu.org>
parents:
101621
diff
changeset
|
420 ;; a /, so allow for that as well. |
cf4d6724a83b
(ls-lisp-insert-directory): Allow for a trailing '/' when looking for "."
Eli Zaretskii <eliz@gnu.org>
parents:
101621
diff
changeset
|
421 (not (string-match "\\`\\.\\.?/?\\'" (car elt)))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
422 (setq elt (expand-file-name (car elt) dir)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
423 (insert "\n" elt ":\n") |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
424 (ls-lisp-insert-directory |
52897
6e19e784b4d1
(ls-lisp-insert-directory): Arg is now wildcard-regexp.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
425 elt switches time-index wildcard-regexp full-directory-p))))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
426 ;; If not full-directory-p, FILE *must not* end in /, as |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
427 ;; file-attributes will not recognize a symlink to a directory, |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
428 ;; so must make it a relative filename as ls does: |
107118
68c91c0692df
* ls-lisp.el (ls-lisp-insert-directory): Wen WILDCARD-REGEXP and
Michael Albinus <michael.albinus@gmx.de>
parents:
106815
diff
changeset
|
429 (if (file-name-absolute-p file) (setq file (expand-file-name file))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
430 (if (eq (aref file (1- (length file))) ?/) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
431 (setq file (substring file 0 -1))) |
53320
15f16532d823
(ls-lisp-insert-directory): Add parameter 'string in
Lars Hansen <larsh@soem.dk>
parents:
52897
diff
changeset
|
432 (let ((fattr (file-attributes file 'string))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
433 (if fattr |
111377
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
434 (insert (ls-lisp-format |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
435 (if (memq ?F switches) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
436 (ls-lisp-classify-file file fattr) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
437 file) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
438 fattr (nth 7 fattr) |
111489 | 439 switches time-index)) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
440 (message "%s: doesn't exist or is inaccessible" file) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
441 (ding) (sit-for 2))))) ; to show user the message! |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
442 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
443 (defun ls-lisp-column-format (file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
444 "Insert the file names (only) in FILE-ALIST into the current buffer. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
445 Format in columns, sorted vertically, following GNU ls -C. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
446 Responds to the window width as ls should but may not!" |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
447 (let (files fmt ncols collen (nfiles 0) (colwid 0)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
448 ;; Count number of files as `nfiles', build list of filenames as |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
449 ;; `files', and find maximum filename length as `colwid': |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
450 (let (file len) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
451 (while file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
452 (setq nfiles (1+ nfiles) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
453 file (caar file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
454 files (cons file files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
455 file-alist (cdr file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
456 len (length file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
457 (if (> len colwid) (setq colwid len)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
458 (setq files (nreverse files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
459 colwid (+ 2 colwid) ; 2 character column gap |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
460 fmt (format "%%-%ds" colwid) ; print format |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
461 ncols (/ (window-width) colwid) ; no of columns |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
462 collen (/ nfiles ncols)) ; floor of column length |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
463 (if (> nfiles (* collen ncols)) (setq collen (1+ collen))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
464 ;; Output the file names in columns, sorted vertically: |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
465 (let ((i 0) j) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
466 (while (< i collen) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
467 (setq j i) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
468 (while (< j nfiles) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
469 (insert (format fmt (nth j files))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
470 (setq j (+ j collen))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
471 ;; FJW: This is completely unnecessary, but I don't like |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
472 ;; trailing white space... |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
473 (delete-region (point) (progn (skip-chars-backward " \t") (point))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
474 (insert ?\n) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
475 (setq i (1+ i)))))) |
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
|
476 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
477 (defun ls-lisp-delete-matching (regexp list) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
478 "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
|
479 ;; 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
|
480 (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
|
481 (while list |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
482 (or (string-match regexp (caar 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
|
483 (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
|
484 (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
|
485 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
|
486 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
487 (defsubst ls-lisp-string-lessp (s1 s2) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
488 "Return t if string S1 is less than string S2 in lexicographic order. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
489 Case is significant if `ls-lisp-ignore-case' is nil. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
490 Unibyte strings are converted to multibyte for comparison." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
491 (let ((u (compare-strings s1 0 nil s2 0 nil ls-lisp-ignore-case))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
492 (and (numberp u) (< u 0)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
493 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
494 (defun ls-lisp-handle-switches (file-alist switches) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
495 "Return new FILE-ALIST sorted according to SWITCHES. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
496 SWITCHES is a list of characters. Default sorting is alphabetic." |
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
|
497 ;; FILE-ALIST's elements are (FILE . FILE-ATTRIBUTES). |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
498 (or (memq ?U switches) ; unsorted |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
499 ;; Catch and ignore unexpected sorting errors |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
500 (condition-case err |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
501 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
502 (let (index) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
503 ;; Copy file-alist in case of error |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
504 (sort (copy-sequence file-alist) ; modifies its argument! |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
505 (cond ((memq ?S switches) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
506 (lambda (x y) ; sorted on size |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
507 ;; 7th file attribute is file size |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
508 ;; Make largest file come first |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
509 (< (nth 7 (cdr y)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
510 (nth 7 (cdr x))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
511 ((setq index (ls-lisp-time-index switches)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
512 (lambda (x y) ; sorted on time |
111462
069b19afe352
Remove ls-lisp time-related functions that duplicate standard functions.
Glenn Morris <rgm@gnu.org>
parents:
111449
diff
changeset
|
513 (time-less-p (nth index (cdr y)) |
069b19afe352
Remove ls-lisp time-related functions that duplicate standard functions.
Glenn Morris <rgm@gnu.org>
parents:
111449
diff
changeset
|
514 (nth index (cdr x))))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
515 ((memq ?X switches) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
516 (lambda (x y) ; sorted on extension |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
517 (ls-lisp-string-lessp |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
518 (ls-lisp-extension (car x)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
519 (ls-lisp-extension (car y))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
520 (t |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
521 (lambda (x y) ; sorted alphabetically |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
522 (ls-lisp-string-lessp (car x) (car y)))))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
523 (error (message "Unsorted (ls-lisp sorting error) - %s" |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
524 (error-message-string err)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
525 (ding) (sit-for 2)))) ; to show user the message! |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
526 (if (memq ?F switches) ; classify switch |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
527 (setq file-alist (mapcar 'ls-lisp-classify file-alist))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
528 (if ls-lisp-dirs-first |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
529 ;; Re-sort directories first, without otherwise changing the |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
530 ;; ordering, and reverse whole list. cadr of each element of |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
531 ;; `file-alist' is t for directory, string (name linked to) for |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
532 ;; symbolic link, or nil. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
533 (let (el dirs files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
534 (while file-alist |
67079
0bf8f7505426
(ls-lisp-parse-symlink): Delete.
Lars Hansen <larsh@soem.dk>
parents:
67004
diff
changeset
|
535 (if (or (eq (cadr (setq el (car file-alist))) t) ; directory |
0bf8f7505426
(ls-lisp-parse-symlink): Delete.
Lars Hansen <larsh@soem.dk>
parents:
67004
diff
changeset
|
536 (and (stringp (cadr el)) |
0bf8f7505426
(ls-lisp-parse-symlink): Delete.
Lars Hansen <larsh@soem.dk>
parents:
67004
diff
changeset
|
537 (file-directory-p (cadr el)))) ; symlink to a directory |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
538 (setq dirs (cons el dirs)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
539 (setq files (cons el files))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
540 (setq file-alist (cdr file-alist))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
541 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
542 (if (memq ?U switches) ; unsorted order is reversed |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
543 (nconc dirs files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
544 (nconc files dirs) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
545 )))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
546 ;; Finally reverse file alist if necessary. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
547 ;; (eq below MUST compare `(not (memq ...))' to force comparison of |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
548 ;; `t' or `nil', rather than list tails!) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
549 (if (eq (eq (not (memq ?U switches)) ; unsorted order is reversed |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
550 (not (memq ?r switches))) ; reversed sort order requested |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
551 ls-lisp-dirs-first) ; already reversed |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
552 (nreverse file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
553 file-alist)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
554 |
111377
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
555 (defun ls-lisp-classify-file (filename fattr) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
556 "Append a character to FILENAME indicating the file type. |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
557 |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
558 FATTR is the file attributes returned by `file-attributes' for the file. |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
559 The file type indicators are `/' for directories, `@' for symbolic |
111377
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
560 links, `|' for FIFOs, `=' for sockets, `*' for regular files that |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
561 are executable, and nothing for other types of files." |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
562 (let* ((type (car fattr)) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
563 (modestr (nth 8 fattr)) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
564 (typestr (substring modestr 0 1))) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
565 (cond |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
566 (type |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
567 (concat filename (if (eq type t) "/" "@"))) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
568 ((string-match "x" modestr) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
569 (concat filename "*")) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
570 ((string= "p" typestr) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
571 (concat filename "|")) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
572 ((string= "s" typestr) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
573 (concat filename "=")) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
574 (t filename)))) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
575 |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
576 (defun ls-lisp-classify (filedata) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
577 "Append a character to file name in FILEDATA indicating the file type. |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
578 |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
579 FILEDATA has the form (FILENAME . ATTRIBUTES), where ATTRIBUTES is the |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
580 structure returned by `file-attributes' for that file. |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
581 |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
582 The file type indicators are `/' for directories, `@' for symbolic |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
583 links, `|' for FIFOs, `=' for sockets, `*' for regular files that |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
584 are executable, and nothing for other types of files." |
67079
0bf8f7505426
(ls-lisp-parse-symlink): Delete.
Lars Hansen <larsh@soem.dk>
parents:
67004
diff
changeset
|
585 (let ((file-name (car filedata)) |
111377
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
586 (fattr (cdr filedata))) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
587 (setq file-name (propertize file-name 'dired-filename t)) |
176c5c4dd786
Back-port from trunk the fix for bug #6294.
Eli Zaretskii <eliz@gnu.org>
parents:
111376
diff
changeset
|
588 (cons (ls-lisp-classify-file file-name fattr) fattr))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
589 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
590 (defun ls-lisp-extension (filename) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
591 "Return extension of FILENAME (ignoring any version extension) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
592 FOLLOWED by null and full filename, SOLELY for full alpha sort." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
593 ;; Force extension sort order: `no ext' then `null ext' then `ext' |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
594 ;; to agree with GNU ls. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
595 (concat |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
596 (let* ((i (length filename)) end) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
597 (if (= (aref filename (1- i)) ?.) ; null extension |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
598 "\0" |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
599 (while (and (>= (setq i (1- i)) 0) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
600 (/= (aref filename i) ?.))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
601 (if (< i 0) "\0\0" ; no extension |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
602 (if (/= (aref filename (1+ i)) ?~) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
603 (substring filename (1+ i)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
604 ;; version extension found -- ignore it |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
605 (setq end i) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
606 (while (and (>= (setq i (1- i)) 0) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
607 (/= (aref filename i) ?.))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
608 (if (< i 0) "\0\0" ; no extension |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
609 (substring filename (1+ i) end)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
610 )) "\0" filename)) |
183 | 611 |
111489 | 612 (defun ls-lisp-format (file-name file-attr file-size switches time-index) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
613 "Format one line of long ls output for file FILE-NAME. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
614 FILE-ATTR and FILE-SIZE give the file's attributes and size. |
111489 | 615 SWITCHES and TIME-INDEX give the full switch list and time data." |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
616 (let ((file-type (nth 0 file-attr)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
617 ;; t for directory, string (name linked to) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
618 ;; for symbolic link, or nil. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
619 (drwxrwxrwx (nth 8 file-attr))) ; attribute string ("drwxrwxrwx") |
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
|
620 (concat (if (memq ?i switches) ; inode number |
93697
513fb6886f41
(ls-lisp-format): Support inodes that are 2- or 3-member cons cells.
Eli Zaretskii <eliz@gnu.org>
parents:
87992
diff
changeset
|
621 (let ((inode (nth 10 file-attr))) |
513fb6886f41
(ls-lisp-format): Support inodes that are 2- or 3-member cons cells.
Eli Zaretskii <eliz@gnu.org>
parents:
87992
diff
changeset
|
622 (if (consp inode) |
513fb6886f41
(ls-lisp-format): Support inodes that are 2- or 3-member cons cells.
Eli Zaretskii <eliz@gnu.org>
parents:
87992
diff
changeset
|
623 (if (consp (cdr inode)) |
94341
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
624 ;; 2^(24+16) = 1099511627776.0, but |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
625 ;; multiplying by it and then adding the |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
626 ;; other members of the cons cell in one go |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
627 ;; loses precision, since a double does not |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
628 ;; have enough significant digits to hold a |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
629 ;; full 64-bit value. So below we split |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
630 ;; 1099511627776 into high 13 and low 5 |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
631 ;; digits and compute in two parts. |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
632 (let ((p1 (* (car inode) 10995116.0)) |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
633 (p2 (+ (* (car inode) 27776.0) |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
634 (* (cadr inode) 65536.0) |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
635 (cddr inode)))) |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
636 (format " %13.0f%05.0f " |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
637 ;; Use floor to emulate integer |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
638 ;; division. |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
639 (+ p1 (floor p2 100000.0)) |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
640 (mod p2 100000.0))) |
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
641 (format " %18.0f " |
93697
513fb6886f41
(ls-lisp-format): Support inodes that are 2- or 3-member cons cells.
Eli Zaretskii <eliz@gnu.org>
parents:
87992
diff
changeset
|
642 (+ (* (car inode) 65536.0) |
513fb6886f41
(ls-lisp-format): Support inodes that are 2- or 3-member cons cells.
Eli Zaretskii <eliz@gnu.org>
parents:
87992
diff
changeset
|
643 (cdr inode)))) |
94341
5eb3109ca278
(ls-lisp-format): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents:
93975
diff
changeset
|
644 (format " %18d " inode)))) |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
645 ;; 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
|
646 (if (memq ?s switches) ; size in K |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
647 (format ls-lisp-filesize-f-fmt |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
648 (fceiling (/ file-size 1024.0)))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
649 drwxrwxrwx ; attribute string |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
650 (if (memq 'links ls-lisp-verbosity) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
651 (format "%3d" (nth 1 file-attr))) ; link count |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
652 ;; 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
|
653 ;; Emacs should be able to make strings of them. |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
654 ;; They tend to be bogus on non-UNIX platforms anyway so |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
655 ;; optionally hide them. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
656 (if (memq 'uid ls-lisp-verbosity) |
110987
cda2045a5ee8
Fix typos in docstrings, comments and ChangeLogs.
Juanma Barranquero <lekktu@gmail.com>
parents:
107118
diff
changeset
|
657 ;; uid can be a string or an integer |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
658 (let ((uid (nth 2 file-attr))) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
659 (format (if (stringp uid) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
660 ls-lisp-uid-s-fmt |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
661 ls-lisp-uid-d-fmt) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
662 uid))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
663 (if (not (memq ?G switches)) ; GNU ls -- shows group by default |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
664 (if (or (memq ?g switches) ; UNIX ls -- no group by default |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
665 (memq 'gid ls-lisp-verbosity)) |
53320
15f16532d823
(ls-lisp-insert-directory): Add parameter 'string in
Lars Hansen <larsh@soem.dk>
parents:
52897
diff
changeset
|
666 (let ((gid (nth 3 file-attr))) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
667 (format (if (stringp gid) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
668 ls-lisp-gid-s-fmt |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
669 ls-lisp-gid-d-fmt) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
670 gid)))) |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
671 (ls-lisp-format-file-size file-size (memq ?h switches)) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
672 " " |
111489 | 673 (ls-lisp-format-time file-attr time-index) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
674 " " |
101621
5011679286cf
(ls-lisp-classify): Propertize file name before concatenating the type
Eli Zaretskii <eliz@gnu.org>
parents:
100908
diff
changeset
|
675 (if (not (memq ?F switches)) ; ls-lisp-classify already did that |
5011679286cf
(ls-lisp-classify): Propertize file name before concatenating the type
Eli Zaretskii <eliz@gnu.org>
parents:
100908
diff
changeset
|
676 (propertize file-name 'dired-filename t) |
5011679286cf
(ls-lisp-classify): Propertize file name before concatenating the type
Eli Zaretskii <eliz@gnu.org>
parents:
100908
diff
changeset
|
677 file-name) |
183 | 678 (if (stringp file-type) ; is a symbolic link |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
679 (concat " -> " file-type)) |
183 | 680 "\n" |
681 ))) | |
682 | |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
683 (defun ls-lisp-time-index (switches) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
684 "Return time index into file-attributes according to ls SWITCHES list. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
685 Return nil if no time switch found." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
686 ;; FJW: Default of nil is IMPORTANT and used in `ls-lisp-handle-switches'! |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
687 (cond ((memq ?c switches) 6) ; last mode change |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
688 ((memq ?t switches) 5) ; last modtime |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
689 ((memq ?u switches) 4))) ; last access |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
690 |
111489 | 691 (defun ls-lisp-format-time (file-attr time-index) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
692 "Format time for file with attributes FILE-ATTR according to TIME-INDEX. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
693 Use the same method as ls to decide whether to show time-of-day or year, |
111489 | 694 depending on distance between file date and the current time. |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
695 All ls time options, namely c, t and u, are handled." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
696 (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime |
111489 | 697 (diff (- (float-time time) (float-time))) |
40755
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
698 ;; Consider a time to be recent if it is within the past six |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
699 ;; months. A Gregorian year has 365.2425 * 24 * 60 * 60 == |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
700 ;; 31556952 seconds on the average, and half of that is 15778476. |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
701 ;; Write the constant explicitly to avoid roundoff error. |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
702 (past-cutoff -15778476)) ; half a Gregorian year |
24660
809c3c8f6b77
(ls-lisp-format-time): Trap errors from
Andrew Innes <andrewi@gnu.org>
parents:
24436
diff
changeset
|
703 (condition-case nil |
40755
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
704 ;; Use traditional time format in the C or POSIX locale, |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
705 ;; ISO-style time format otherwise, so columns line up. |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
706 (let ((locale system-time-locale)) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
707 (if (not locale) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
708 (let ((vars '("LC_ALL" "LC_TIME" "LANG"))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
709 (while (and vars (not (setq locale (getenv (car vars))))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
710 (setq vars (cdr vars))))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
711 (if (member locale '("C" "POSIX")) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
712 (setq locale nil)) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
713 (format-time-string |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
714 (if (and (<= past-cutoff diff) (<= diff 0)) |
75426
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
715 (if (and locale (not ls-lisp-use-localized-time-format)) |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
716 "%m-%d %H:%M" |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
717 (nth 0 ls-lisp-format-time-list)) |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
718 (if (and locale (not ls-lisp-use-localized-time-format)) |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
719 "%Y-%m-%d " |
7b38b48667a7
(ls-lisp-use-localized-time-format): New defcustom.
Eli Zaretskii <eliz@gnu.org>
parents:
75347
diff
changeset
|
720 (nth 1 ls-lisp-format-time-list))) |
40755
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
721 time)) |
24854
2f2786f7d960
(ls-lisp-format-time): If timestamp is invalid,
Andrew Innes <andrewi@gnu.org>
parents:
24660
diff
changeset
|
722 (error "Unk 0 0000")))) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
723 |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
724 (defun ls-lisp-format-file-size (file-size human-readable) |
94345
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
725 (if (not human-readable) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
726 (format (if (floatp file-size) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
727 ls-lisp-filesize-f-fmt |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
728 ls-lisp-filesize-d-fmt) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
729 file-size) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
730 (if (< file-size 1024) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
731 (format " %4d" file-size) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
732 (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0)) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
733 ;; kilo, mega, giga, tera, peta, exa |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
734 (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes))) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
735 ((< file-size 1024) |
4ebe66bf947b
(ls-lisp-uid-d-fmt, ls-lisp-uid-s-fmt, ls-lisp-gid-d-fmt)
Eli Zaretskii <eliz@gnu.org>
parents:
94341
diff
changeset
|
736 (format " %3.0f%s" file-size (car post-fixes))))))) |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
737 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
738 (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
|
739 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
740 ;;; ls-lisp.el ends here |