Mercurial > emacs
annotate lisp/ls-lisp.el @ 52604:cf28ad83bf76
(c-electric-brace): Fixed a bug in the expand-abbrev' workaround
which caused braces to disbehave inside macros.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Wed, 24 Sep 2003 13:55:07 +0000 |
parents | 695cf19ef79e |
children | 6e19e784b4d1 375f2633d815 |
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 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
3 ;; Copyright (C) 1992, 1994, 2000 Free Software Foundation, Inc. |
14169 | 4 |
38412
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37330
diff
changeset
|
5 ;; 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
|
6 ;; 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
|
7 ;; Maintainer: FSF |
253f761ad37b
Some fixes to follow coding conventions in files maintained by FSF.
Pavel Janík <Pavel@Janik.cz>
parents:
37330
diff
changeset
|
8 ;; Keywords: unix, dired |
183 | 9 |
14169 | 10 ;; This file is part of GNU Emacs. |
183 | 11 |
14169 | 12 ;; GNU Emacs is free software; you can redistribute it and/or modify |
183 | 13 ;; it under the terms of the GNU General Public License as published by |
12244 | 14 ;; the Free Software Foundation; either version 2, or (at your option) |
183 | 15 ;; any later version. |
14169 | 16 |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
183 | 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
14169 | 21 |
183 | 22 ;; You should have received a copy of the GNU General Public License |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
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, |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
34 ;; under VMS or other non-UNIX platforms if you don't have the ls |
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 ;; * Generally only numeric uid/gid. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
48 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
49 ;; 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
|
50 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
51 ;; 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
|
52 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
53 ;; 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
|
54 ;; 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
|
55 ;; 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
|
56 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
57 ;;; History: |
183 | 58 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
59 ;; 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
|
60 ;; Revised by Andrew Innes and Geoff Volker (and maybe others). |
183 | 61 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
62 ;; Modified by Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>, mainly |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
63 ;; to support many more ls options, "platform emulation", hooks for |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
64 ;; external symbolic link support and more 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
|
65 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
66 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
67 |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
68 (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
|
69 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
70 (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
|
71 "Emulate the ls program completely in Emacs Lisp." |
35011
11e866e5a825
(ls-lisp) <defgroup>: Add :version.
Dave Love <fx@gnu.org>
parents:
34884
diff
changeset
|
72 :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
|
73 :group 'dired) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
74 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
75 (defcustom ls-lisp-emulation |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
76 (cond ((eq system-type 'macos) 'MacOS) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
77 ;; ((eq system-type 'windows-nt) 'MS-Windows) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
78 ((memq system-type |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
79 '(hpux dgux usg-unix-v unisoft-unix rtu irix berkeley-unix)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
80 'UNIX)) ; very similar to GNU |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
81 ;; Anything else defaults to nil, meaning GNU. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
82 "*Platform to emulate: GNU (default), MacOS, MS-Windows, UNIX. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
83 Corresponding value is one of the atoms: nil, MacOS, MS-Windows, UNIX. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
84 Sets default values for: `ls-lisp-ignore-case', `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
|
85 `ls-lisp-verbosity'. Need not match actual platform. Changing this |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
86 option will have no effect until you restart Emacs." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
87 :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
|
88 (const MacOS) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
89 (const MS-Windows) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
90 (const UNIX)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
91 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
92 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
93 (defcustom 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
|
94 ;; Name change for consistency with other option names. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
95 (or (memq ls-lisp-emulation '(MS-Windows MacOS)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
96 (and (boundp 'ls-lisp-dired-ignore-case) ls-lisp-dired-ignore-case)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
97 "*Non-nil causes ls-lisp alphabetic sorting to ignore case." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
98 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
99 :group 'ls-lisp) |
13883
a4eef7470b6b
(ls-lisp-support-shell-wildcards): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
12244
diff
changeset
|
100 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
101 (defcustom ls-lisp-dirs-first (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
|
102 "*Non-nil causes ls-lisp to sort directories first in any ordering. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
103 \(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
|
104 ;; Functionality suggested by Chris McMahan <cmcmahan@one.net> |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
105 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
106 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
107 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
108 (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
|
109 (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
|
110 ((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
|
111 (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
|
112 '(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
|
113 ((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
|
114 (t '(links uid gid))) ; GNU ls |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
115 "*A list of optional file attributes that ls-lisp should display. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
116 It should contain none or more of the symbols: links, uid, gid. |
42206 | 117 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
|
118 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
119 Concepts come from UNIX: `links' means count of names associated with |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
120 the file\; `uid' means user (owner) identifier\; `gid' means group |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
121 identifier. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
122 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
123 If emulation is MacOS then default is nil\; |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
124 if emulation is MS-Windows then default is `(links)' if platform is |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
125 Windows NT/2K, nil otherwise\; |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
126 if emulation is UNIX then default is `(links uid)'\; |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
127 if emulation is GNU then default is `(links uid gid)'." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
128 ;; 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
|
129 :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
|
130 (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
|
131 (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
|
132 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
133 |
49328
850f7b918635
(ls-lisp-use-insert-directory-program): Make default
Markus Rost <rost@math.uni-bielefeld.de>
parents:
48917
diff
changeset
|
134 (defcustom ls-lisp-use-insert-directory-program |
850f7b918635
(ls-lisp-use-insert-directory-program): Make default
Markus Rost <rost@math.uni-bielefeld.de>
parents:
48917
diff
changeset
|
135 (not (memq system-type '(macos ms-dos windows-nt))) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
136 "*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
|
137 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
|
138 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
|
139 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
|
140 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
141 :group 'ls-lisp) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
142 |
49328
850f7b918635
(ls-lisp-use-insert-directory-program): Make default
Markus Rost <rost@math.uni-bielefeld.de>
parents:
48917
diff
changeset
|
143 ;;; 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
|
144 ;;;###autoload |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
145 (defcustom ls-lisp-support-shell-wildcards t |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
146 "*Non-nil means ls-lisp treats file patterns as shell wildcards. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
147 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
|
148 :type 'boolean |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
149 :group 'ls-lisp) |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
150 |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
151 (defcustom ls-lisp-format-time-list |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
152 '("%b %e %H:%M" |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
153 "%b %e %Y") |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
154 "*List of `format-time-string' specs to display file time stamps. |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
155 They are used whenever a locale is not specified to use instead. |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
156 |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
157 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
|
158 |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
159 The EARLY-TIME-FORMAT is used if file has been modified within the |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
160 current year. The OLD-TIME-FORMAT is used for older files. To use ISO |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
161 8601 dates, you could set: |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
162 |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
163 \(setq ls-lisp-format-time-list |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
164 '(\"%Y-%m-%d %H:%M\" |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
165 \"%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
|
166 :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
|
167 (string :tag "Old time format")) |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
168 :group 'ls-lisp) |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
169 |
48917
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
170 (defvar original-insert-directory nil |
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
171 "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
|
172 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
173 ;; 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
|
174 (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
|
175 (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
|
176 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
177 ;; This stub is to allow ls-lisp to parse symbolic links via another |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
178 ;; library such as w32-symlinks.el from |
48800 | 179 ;; http://centaur.maths.qmw.ac.uk/Emacs/: |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
180 (defun ls-lisp-parse-symlink (file-name) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
181 "This stub may be redefined to parse FILE-NAME as a symlink. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
182 It should return nil or the link target as a string." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
183 nil) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
184 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
185 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
187 |
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
188 (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
|
189 "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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 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
|
200 `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
|
201 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
|
202 `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
|
203 emulation. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
204 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 to match file names. It does not support all `ls' switches -- those |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
209 that work are: A a c i r S s t u U X g G B C R and F partly." |
23452
f0077d5425f2
(ls-lisp-use-insert-directory-program): New variable.
Geoff Voelker <voelker@cs.washington.edu>
parents:
22154
diff
changeset
|
210 (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
|
211 (funcall original-insert-directory |
9b8d6678be5c
(original-insert-directory): Make this a variable,
Richard M. Stallman <rms@gnu.org>
parents:
48800
diff
changeset
|
212 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
|
213 ;; 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
|
214 (let ((handler (find-file-name-handler (expand-file-name file) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
215 'insert-directory))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
216 (if handler |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
217 (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
|
218 wildcard full-directory-p) |
50992
01a94a546935
(insert-directory): Remove --dired switch when
John Paul Wallington <jpw@pobox.com>
parents:
50767
diff
changeset
|
219 ;; Remove --dired switch |
01a94a546935
(insert-directory): Remove --dired switch when
John Paul Wallington <jpw@pobox.com>
parents:
50767
diff
changeset
|
220 (if (string-match "--dired " switches) |
01a94a546935
(insert-directory): Remove --dired switch when
John Paul Wallington <jpw@pobox.com>
parents:
50767
diff
changeset
|
221 (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
|
222 ;; Convert SWITCHES to a list of characters. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
223 (setq switches (delete ?- (append switches nil))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
224 (if wildcard |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
225 (setq wildcard |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
226 (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
|
227 (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
|
228 (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
|
229 file (file-name-directory file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
230 (if (memq ?B switches) (setq wildcard "[^~]\\'"))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
231 (ls-lisp-insert-directory |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
232 file switches (ls-lisp-time-index switches) |
42239
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
233 wildcard full-directory-p) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
234 ;; 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
|
235 (save-excursion |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
236 (goto-char (point-min)) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
237 ;; 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
|
238 (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
|
239 (let ((available (get-free-disk-space "."))) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
240 (when available |
42427
f1a88fb2fb4e
(insert-directory): Modify the "total" line wording, in accordance with
Eli Zaretskii <eliz@gnu.org>
parents:
42239
diff
changeset
|
241 ;; 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
|
242 (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
|
243 (end-of-line) |
1e736b882b4f
(insert-directory): Insert the amount of free disk
Eli Zaretskii <eliz@gnu.org>
parents:
42206
diff
changeset
|
244 (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
|
245 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
246 (defun ls-lisp-insert-directory |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
247 (file switches time-index wildcard full-directory-p) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
248 "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
|
249 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
|
250 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
|
251 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
|
252 SWITCHES is a *list* of characters. TIME-INDEX is the time index into |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
253 file-attributes according to SWITCHES. WILDCARD is nil or an *Emacs |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
254 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
|
255 not contain `d', so that a full listing is expected." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
256 ;; Sometimes we get ".../foo*/" as FILE. While the shell and |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
257 ;; `ls' don't mind, we certainly do, because it makes us think |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
258 ;; there is no wildcard, only a directory name. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
259 (if (and 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
|
260 (string-match "[[?*]" file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
261 (progn |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
262 (or (not (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
|
263 (setq file (substring file 0 (1- (length file))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
264 (setq wildcard t))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
265 (if (or wildcard full-directory-p) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
266 (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
|
267 (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
|
268 (file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
269 (directory-files-and-attributes dir nil wildcard t)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
270 (now (current-time)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
271 (sum 0) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
272 ;; do all bindings here for speed |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
273 total-line files elt short file-size fil attr) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
274 (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
|
275 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
276 (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
|
277 ((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
|
278 ;; 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
|
279 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
280 (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
|
281 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
282 (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
|
283 (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
|
284 (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
|
285 (setq total-line (cons (point) (car-safe file-alist))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
286 (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
|
287 (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
|
288 (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
|
289 files (cdr files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
290 short (car elt) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
291 attr (cdr elt) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
292 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
|
293 (and attr |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
294 (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
|
295 ;; 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
|
296 ;; 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
|
297 (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
|
298 (floatp sum) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
299 (floatp file-size)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
300 sum |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
301 (float sum)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
302 (insert (ls-lisp-format short attr file-size |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
303 switches time-index now)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
304 ;; 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
|
305 (save-excursion |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
306 (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
|
307 (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
|
308 ;; 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
|
309 ;; 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
|
310 (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
|
311 (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
|
312 (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
|
313 ;; 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
|
314 ;; 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
|
315 ;; 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
|
316 ;; link, or nil. |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
317 (while file-alist |
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
318 (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
|
319 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
|
320 (when (and (eq (cadr elt) t) ; directory |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
321 (not (string-match "\\`\\.\\.?\\'" (car elt)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
322 (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
|
323 (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
|
324 (ls-lisp-insert-directory |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
325 elt switches time-index wildcard full-directory-p))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
326 ;; 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
|
327 ;; 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
|
328 ;; so must make it a relative filename as ls does: |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
329 (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
|
330 (setq file (substring file 0 -1))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
331 (let ((fattr (file-attributes file))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
332 (if fattr |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
333 (insert (ls-lisp-format file fattr (nth 7 fattr) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
334 switches time-index (current-time))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
335 (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
|
336 (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
|
337 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
338 (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
|
339 "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
|
340 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
|
341 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
|
342 (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
|
343 ;; 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
|
344 ;; `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
|
345 (let (file len) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
346 (while file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
347 (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
|
348 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
|
349 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
|
350 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
|
351 len (length file)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
352 (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
|
353 (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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 (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
|
359 ;; 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
|
360 (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
|
361 (while (< i collen) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
362 (setq j i) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
363 (while (< j nfiles) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
364 (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
|
365 (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
|
366 ;; 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
|
367 ;; trailing white space... |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
368 (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
|
369 (insert ?\n) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
370 (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
|
371 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
372 (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
|
373 "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
|
374 ;; 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
|
375 (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
|
376 (while list |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
377 (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
|
378 (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
|
379 (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
|
380 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
|
381 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
382 (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
|
383 "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
|
384 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
|
385 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
|
386 (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
|
387 (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
|
388 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
389 (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
|
390 "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
|
391 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
|
392 ;; 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
|
393 (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
|
394 ;; 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
|
395 (condition-case err |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
396 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
397 (let (index) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
398 ;; 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
|
399 (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
|
400 (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
|
401 (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
|
402 ;; 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
|
403 ;; 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
|
404 (< (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
|
405 (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
|
406 ((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
|
407 (lambda (x y) ; sorted on time |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
408 (ls-lisp-time-lessp (nth index (cdr y)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
409 (nth index (cdr x))))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
410 ((memq ?X switches) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
411 (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
|
412 (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
|
413 (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
|
414 (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
|
415 (t |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
416 (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
|
417 (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
|
418 (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
|
419 (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
|
420 (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
|
421 (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
|
422 (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
|
423 (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
|
424 ;; 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
|
425 ;; 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
|
426 ;; `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
|
427 ;; 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
|
428 (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
|
429 (while file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
430 (if (eq (cadr (setq el (car file-alist))) t) ; directory |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
431 (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
|
432 (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
|
433 (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
|
434 (setq file-alist |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
435 (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
|
436 (nconc dirs files) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
437 (nconc files dirs) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
438 )))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
439 ;; 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
|
440 ;; (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
|
441 ;; `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
|
442 (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
|
443 (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
|
444 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
|
445 (nreverse file-alist) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
446 file-alist)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
447 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
448 (defun ls-lisp-classify (filedata) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
449 "Append a character to each file name indicating the file type. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
450 Also, for regular files that are executable, append `*'. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
451 The file type indicators are `/' for directories, `@' for symbolic |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
452 links, `|' for FIFOs, `=' for sockets, and nothing for regular files. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
453 \[But FIFOs and sockets are not recognised.] |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
454 FILEDATA has the form (filename . `file-attributes'). Its `cadr' is t |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
455 for directory, string (name linked to) 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
|
456 (let ((dir (cadr filedata)) (file-name (car filedata))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
457 (cond ((or dir |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
458 ;; Parsing .lnk files here is perhaps overkill! |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
459 (setq dir (ls-lisp-parse-symlink file-name))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
460 (cons |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
461 (concat file-name (if (eq dir t) "/" "@")) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
462 (cdr filedata))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
463 ((string-match "x" (nth 9 filedata)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
464 (cons |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
465 (concat file-name "*") |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
466 (cdr filedata))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
467 (t filedata)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
468 |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
469 (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
|
470 "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
|
471 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
|
472 ;; 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
|
473 ;; 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
|
474 (concat |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
475 (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
|
476 (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
|
477 "\0" |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
478 (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
|
479 (/= (aref filename i) ?.))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
480 (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
|
481 (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
|
482 (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
|
483 ;; 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
|
484 (setq end i) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
485 (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
|
486 (/= (aref filename i) ?.))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
487 (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
|
488 (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
|
489 )) "\0" filename)) |
183 | 490 |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
491 ;; From Roland McGrath. Can use this to sort on time. |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
492 (defun ls-lisp-time-lessp (time0 time1) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
493 "Return t if time TIME0 is earlier than time TIME1." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
494 (let ((hi0 (car time0)) (hi1 (car time1))) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
495 (or (< hi0 hi1) |
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
496 (and (= hi0 hi1) |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
497 (< (cadr time0) (cadr time1)))))) |
626
ff8773516db2
(dired-lisp-handle-switches): understands `-t' now.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
623
diff
changeset
|
498 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
499 (defun ls-lisp-format (file-name file-attr file-size switches time-index now) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
500 "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
|
501 FILE-ATTR and FILE-SIZE give the file's attributes and size. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
502 SWITCHES, TIME-INDEX and NOW give the full switch list and time data." |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
503 (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
|
504 ;; 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
|
505 ;; 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
|
506 (drwxrwxrwx (nth 8 file-attr))) ; attribute string ("drwxrwxrwx") |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
507 (and (null file-type) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
508 ;; Maybe no kernel support for symlinks, so... |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
509 (setq file-type (ls-lisp-parse-symlink file-name)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
510 (aset drwxrwxrwx 0 ?l)) ; symbolic link - update attribute string |
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
|
511 (concat (if (memq ?i switches) ; inode number |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
512 (format " %6d" (nth 10 file-attr))) |
417
51793184f9a9
(dired-lisp-format): format can pad after all.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
416
diff
changeset
|
513 ;; 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
|
514 (if (memq ?s switches) ; size in K |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
515 (format " %4.0f" (fceiling (/ file-size 1024.0)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
516 drwxrwxrwx ; attribute string |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
517 (if (memq 'links ls-lisp-verbosity) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
518 (format " %3d" (nth 1 file-attr))) ; link count |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
519 ;; 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
|
520 ;; 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
|
521 ;; 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
|
522 ;; optionally hide them. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
523 (if (memq 'uid ls-lisp-verbosity) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
524 ;; (user-login-name uid) works on Windows NT but not |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
525 ;; on 9x and maybe not on some other platforms, so... |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
526 (let ((uid (nth 2 file-attr))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
527 (if (= uid (user-uid)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
528 (format " %-8s" (user-login-name)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
529 (format " %-8d" uid)))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
530 (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
|
531 (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
|
532 (memq 'gid ls-lisp-verbosity)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
533 (if (memq system-type '(macos windows-nt ms-dos)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
534 ;; No useful concept of group... |
37330
5e7b789ce251
(ls-lisp-format): Leave a blank before "root".
Eli Zaretskii <eliz@gnu.org>
parents:
35011
diff
changeset
|
535 " root" |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
536 (let* ((gid (nth 3 file-attr)) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
537 (group (user-login-name gid))) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
538 (if group |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
539 (format " %-8s" group) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
540 (format " %-8d" gid)))))) |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
541 (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
|
542 " " |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
543 (ls-lisp-format-time file-attr time-index now) |
622
1d4abb4dfecb
(dired-lisp-format-time): in Emacs 19 we can format times.
Sebastian Kremer <sk@thp.uni-koeln.de>
parents:
417
diff
changeset
|
544 " " |
183 | 545 file-name |
546 (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
|
547 (concat " -> " file-type)) |
183 | 548 "\n" |
549 ))) | |
550 | |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
551 (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
|
552 "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
|
553 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
|
554 ;; 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
|
555 (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
|
556 ((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
|
557 ((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
|
558 |
40755
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
559 (defun ls-lisp-time-to-seconds (time) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
560 "Convert TIME to a floating point number." |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
561 (+ (* (car time) 65536.0) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
562 (cadr time) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
563 (/ (or (nth 2 time) 0) 1000000.0))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
564 |
34884
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
565 (defun ls-lisp-format-time (file-attr time-index now) |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
566 "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
|
567 Use the same method as ls to decide whether to show time-of-day or year, |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
568 depending on distance between file date and NOW. |
469d99929953
From Francis J. Wright <F.J.Wright@maths.qmw.ac.uk>:
Eli Zaretskii <eliz@gnu.org>
parents:
26914
diff
changeset
|
569 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
|
570 (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime |
40755
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
571 (diff (- (ls-lisp-time-to-seconds time) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
572 (ls-lisp-time-to-seconds now))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
573 ;; 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
|
574 ;; 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
|
575 ;; 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
|
576 ;; 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
|
577 (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
|
578 (condition-case nil |
40755
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
579 ;; 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
|
580 ;; 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
|
581 (let ((locale system-time-locale)) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
582 (if (not locale) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
583 (let ((vars '("LC_ALL" "LC_TIME" "LANG"))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
584 (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
|
585 (setq vars (cdr vars))))) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
586 (if (member locale '("C" "POSIX")) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
587 (setq locale nil)) |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
588 (format-time-string |
08abdcc6bcf5
(ls-lisp-time-to-seconds): New function.
Paul Eggert <eggert@twinsun.com>
parents:
38412
diff
changeset
|
589 (if (and (<= past-cutoff diff) (<= diff 0)) |
47329
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
590 (if locale "%m-%d %H:%M" (nth 0 ls-lisp-format-time-list)) |
4bc33b241589
(ls-lisp-format-time-list): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
42427
diff
changeset
|
591 (if locale "%Y-%m-%d " (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
|
592 time)) |
24854
2f2786f7d960
(ls-lisp-format-time): If timestamp is invalid,
Andrew Innes <andrewi@gnu.org>
parents:
24660
diff
changeset
|
593 (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
|
594 |
50767
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
595 (defun ls-lisp-format-file-size (file-size human-readable) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
596 (if (or (not human-readable) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
597 (< file-size 1024)) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
598 (format (if (floatp file-size) " %8.0f" " %8d") file-size) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
599 (do ((file-size (/ file-size 1024.0) (/ file-size 1024.0)) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
600 ;; kilo, mega, giga, tera, peta, exa |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
601 (post-fixes (list "k" "M" "G" "T" "P" "E") (cdr post-fixes))) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
602 ((< file-size 1024) (format " %7.0f%s" file-size (car post-fixes)))))) |
5e248d2a95e7
(ls-lisp-format-file-size): New function to implement "-h" switch.
Juanma Barranquero <lekktu@gmail.com>
parents:
49328
diff
changeset
|
603 |
1334
92791ed2d1eb
Most functions renamed to start with ls-lisp.
Richard M. Stallman <rms@gnu.org>
parents:
1333
diff
changeset
|
604 (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
|
605 |
52401 | 606 ;;; arch-tag: e55f399b-05ec-425c-a6d5-f5e349c35ab4 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
1672
diff
changeset
|
607 ;;; ls-lisp.el ends here |