annotate lisp/ls-lisp.el @ 1225:e16f52a7c9f9

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