annotate lisp/eshell/em-ls.el @ 58327:a360835c5032

*** empty log message ***
author Richard M. Stallman <rms@gnu.org>
date Fri, 19 Nov 2004 19:40:32 +0000
parents 76ece241e712
children b7ea6515f1ba
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 37661
diff changeset
1 ;;; em-ls.el --- implementation of ls in Lisp
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
32526
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 32446
diff changeset
5 ;; Author: John Wiegley <johnw@gnu.org>
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 32446
diff changeset
6
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; any later version.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 (provide 'em-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 (eval-when-compile (require 'esh-maint))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 (defgroup eshell-ls nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 "This module implements the \"ls\" utility fully in Lisp. If it is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 passed any unrecognized command switches, it will revert to the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 operating system's version. This version of \"ls\" uses text
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 properties to colorize its output based on the setting of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 `eshell-ls-use-colors'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 :tag "Implementation of `ls' in Lisp"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 :group 'eshell-module)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;;; Commentary:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; Most of the command switches recognized by GNU's ls utility are
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; supported ([(fileutils)ls invocation]).
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 (require 'esh-util)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 (require 'esh-opt)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;;; User Variables:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (defvar eshell-ls-orig-insert-directory
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 (symbol-function 'insert-directory)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 "Preserve the original definition of `insert-directory'.")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (defcustom eshell-ls-unload-hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 (lambda ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 (fset 'insert-directory eshell-ls-orig-insert-directory))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 "*When unloading `eshell-ls', restore the definition of `insert-directory'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
60 (defcustom eshell-ls-initial-args nil
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
61 "*If non-nil, this list of args is included before any call to `ls'.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
62 This is useful for enabling human-readable format (-h), for example."
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
63 :type '(repeat :tag "Arguments" string)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
64 :group 'eshell-ls)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
65
39984
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
66 (defcustom eshell-ls-dired-initial-args nil
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
67 "*If non-nil, args is included before any call to `ls' in dired.
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
68 This is useful for enabling human-readable format (-h), for example."
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
69 :type '(repeat :tag "Arguments" string)
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
70 :group 'eshell-ls)
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
71
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (defcustom eshell-ls-use-in-dired nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 "*If non-nil, use `eshell-ls' to read directories in dired."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 :set (lambda (symbol value)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (if value
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (unless (and (boundp 'eshell-ls-use-in-dired)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 eshell-ls-use-in-dired)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (fset 'insert-directory 'eshell-ls-insert-directory))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (when (and (boundp 'eshell-ls-insert-directory)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 eshell-ls-use-in-dired)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 (fset 'insert-directory eshell-ls-orig-insert-directory)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (setq eshell-ls-use-in-dired value))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 :require 'em-ls
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (defcustom eshell-ls-default-blocksize 1024
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 "*The default blocksize to use when display file sizes with -s."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 :type 'integer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
92 (defcustom eshell-ls-exclude-regexp nil
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 "*Unless -a is specified, files matching this regexp will not be shown."
35718
96d933eb13f4 (eshell-ls-exclude-regexp): Fix :type.
Dave Love <fx@gnu.org>
parents: 33020
diff changeset
94 :type '(choice regexp (const nil))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
97 (defcustom eshell-ls-exclude-hidden t
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
98 "*Unless -a is specified, files beginning with . will not be shown.
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
99 Using this boolean, instead of `eshell-ls-exclude-regexp', is both
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
100 faster and conserves more memory."
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
101 :type 'boolean
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
102 :group 'eshell-ls)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
103
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (defcustom eshell-ls-use-colors t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 "*If non-nil, use colors in file listings."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 :type 'boolean
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (defface eshell-ls-directory-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
110 '((((class color) (background light)) (:foreground "Blue" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
111 (((class color) (background dark)) (:foreground "SkyBlue" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
112 (t (:weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 "*The face used for highlight directories."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 (defface eshell-ls-symlink-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
117 '((((class color) (background light)) (:foreground "Dark Cyan" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
118 (((class color) (background dark)) (:foreground "Cyan" :weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 "*The face used for highlight symbolic links."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (defface eshell-ls-executable-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
123 '((((class color) (background light)) (:foreground "ForestGreen" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
124 (((class color) (background dark)) (:foreground "Green" :weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 "*The face used for highlighting executables (not directories, though)."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (defface eshell-ls-readonly-face
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 '((((class color) (background light)) (:foreground "Brown"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (((class color) (background dark)) (:foreground "Pink")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 "*The face used for highlighting read-only files."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (defface eshell-ls-unreadable-face
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 '((((class color) (background light)) (:foreground "Grey30"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (((class color) (background dark)) (:foreground "DarkGrey")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 "*The face used for highlighting unreadable files."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (defface eshell-ls-special-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
141 '((((class color) (background light)) (:foreground "Magenta" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
142 (((class color) (background dark)) (:foreground "Magenta" :weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 "*The face used for highlighting non-regular files."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (defface eshell-ls-missing-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
147 '((((class color) (background light)) (:foreground "Red" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
148 (((class color) (background dark)) (:foreground "Red" :weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 "*The face used for highlighting non-existant file names."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (defcustom eshell-ls-archive-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (concat "\\.\\(t\\(a[rz]\\|gz\\)\\|arj\\|lzh\\|"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 "zip\\|[zZ]\\|gz\\|bz2\\|deb\\|rpm\\)\\'")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 "*A regular expression that matches names of file archives.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 This typically includes both traditional archives and compressed
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 files."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 :type 'regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161 (defface eshell-ls-archive-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
162 '((((class color) (background light)) (:foreground "Orchid" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
163 (((class color) (background dark)) (:foreground "Orchid" :weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 "*The face used for highlighting archived and compressed file names."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 (defcustom eshell-ls-backup-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 "\\(\\`\\.?#\\|\\(\\.bak\\|~\\)\\'\\)"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 "*A regular expression that matches names of backup files."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 :type 'regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (defface eshell-ls-backup-face
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 '((((class color) (background light)) (:foreground "OrangeRed"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (((class color) (background dark)) (:foreground "LightSalmon")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 "*The face used for highlighting backup file names."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (defcustom eshell-ls-product-regexp
48704
18ebc473a07d (eshell-ls-product-regexp): Fix typo.
Andreas Schwab <schwab@suse.de>
parents: 46853
diff changeset
180 "\\.\\(elc\\|o\\(bj\\)?\\|a\\|lib\\|res\\)\\'"
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 "*A regular expression that matches names of product files.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 Products are files that get generated from a source file, and hence
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 ought to be recreatable if they are deleted."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 :type 'regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 (defface eshell-ls-product-face
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 '((((class color) (background light)) (:foreground "OrangeRed"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 (((class color) (background dark)) (:foreground "LightSalmon")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 "*The face used for highlighting files that are build products."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 (defcustom eshell-ls-clutter-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 "\\(^texput\\.log\\|^core\\)\\'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 "*A regular expression that matches names of junk files.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 These are mainly files that get created for various reasons, but don't
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 really need to stick around for very long."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 :type 'regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 (defface eshell-ls-clutter-face
42456
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
202 '((((class color) (background light)) (:foreground "OrangeRed" :weight bold))
8a4077ab418c (various face definitions): Use :weight, not :bold.
Richard M. Stallman <rms@gnu.org>
parents: 39984
diff changeset
203 (((class color) (background dark)) (:foreground "OrangeRed" :weight bold)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 "*The face used for highlighting junk file names."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (defsubst eshell-ls-filetype-p (attrs type)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 "Test whether ATTRS specifies a directory."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (if (nth 8 attrs)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (eq (aref (nth 8 attrs) 0) type)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (defmacro eshell-ls-applicable (attrs index func file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 "Test whether, for ATTRS, the user UID can do what corresponds to INDEX.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 This is really just for efficiency, to avoid having to stat the file
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 yet again."
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
216 `(if (numberp (nth 2 ,attrs))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
217 (if (= (user-uid) (nth 2 ,attrs))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
218 (not (eq (aref (nth 8 ,attrs) ,index) ?-))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
219 (,(eval func) ,file))
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
220 (not (eq (aref (nth 8 ,attrs)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
221 (+ ,index (if (member (nth 2 ,attrs)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
222 (eshell-current-ange-uids))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
223 0 6)))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
224 ?-))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (defcustom eshell-ls-highlight-alist nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 "*This alist correlates test functions to color.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 The format of the members of this alist is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (TEST-SEXP . FACE)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 If TEST-SEXP evals to non-nil, that face will be used to highlight the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 name of the file. The first match wins. `file' and `attrs' are in
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 scope during the evaluation of TEST-SEXP."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 :type '(repeat (cons function face))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 :group 'eshell-ls)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 ;;; Functions:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 (defun eshell-ls-insert-directory
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (file switches &optional wildcard full-directory-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 "Insert directory listing for FILE, formatted according to SWITCHES.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 Leaves point after the inserted text.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 SWITCHES may be a string of options, or a list of strings.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 Optional third arg WILDCARD means treat FILE as shell wildcard.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 switches do not contain `d', so that a full listing is expected.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 This version of the function uses `eshell/ls'. If any of the switches
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 passed are not recognized, the operating system's version will be used
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 instead."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (let ((handler (find-file-name-handler file 'insert-directory)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (if handler
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (funcall handler 'insert-directory file switches
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 wildcard full-directory-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (if (stringp switches)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (setq switches (split-string switches)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (let (eshell-current-handles
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 eshell-current-subjob-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 ;; use the fancy highlighting in `eshell-ls' rather than font-lock
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (when (and eshell-ls-use-colors
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (featurep 'font-lock))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (font-lock-mode -1)
37326
19d97e9f6689 (eshell-ls-insert-directory): Set font-lock-defaults to nil, to
John Wiegley <johnw@newartisans.com>
parents: 35718
diff changeset
264 (setq font-lock-defaults nil)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 (if (boundp 'font-lock-buffers)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (set 'font-lock-buffers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (delq (current-buffer)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (symbol-value 'font-lock-buffers)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 (let ((insert-func 'insert)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (error-func 'insert)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
271 (flush-func 'ignore)
39984
5e4848f89017 (eshell-ls-dired-initial-args): Added an extra customization variable,
John Wiegley <johnw@newartisans.com>
parents: 38414
diff changeset
272 eshell-ls-dired-initial-args)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (eshell-do-ls (append switches (list file))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (defsubst eshell/ls (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 "An alias version of `eshell-do-ls'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (let ((insert-func 'eshell-buffered-print)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 (error-func 'eshell-error)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 (flush-func 'eshell-flush))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (eshell-do-ls args)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281
37661
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37326
diff changeset
282 (put 'eshell/ls 'eshell-no-numeric-conversions t)
6d7c89c79996 Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents: 37326
diff changeset
283
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (eval-when-compile
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (defvar block-size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (defvar dereference-links)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (defvar dir-literal)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (defvar error-func)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (defvar flush-func)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (defvar human-readable)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (defvar ignore-pattern)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (defvar insert-func)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (defvar listing-style)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (defvar numeric-uid-gid)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (defvar reverse-list)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 (defvar show-all)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (defvar show-recursive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (defvar show-size)
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
299 (defvar sort-method)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
300 (defvar ange-cache))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (defun eshell-do-ls (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 "Implementation of \"ls\" in Lisp, passing ARGS."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (funcall flush-func -1)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;; process the command arguments, and begin listing files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 (eshell-eval-using-options
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
307 "ls" (if eshell-ls-initial-args
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
308 (list eshell-ls-initial-args args)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
309 args)
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
310 `((?a "all" nil show-all
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
311 "show all files in directory")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (?c nil by-ctime sort-method
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 "sort by modification time")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 (?d "directory" nil dir-literal
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 "list directory entries instead of contents")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (?k "kilobytes" 1024 block-size
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
317 "using 1024 as the block size")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (?h "human-readable" 1024 human-readable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 "print sizes in human readable format")
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
320 (?H "si" 1000 human-readable
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
321 "likewise, but use powers of 1000 not 1024")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (?I "ignore" t ignore-pattern
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 "do not list implied entries matching pattern")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 (?l nil long-listing listing-style
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 "use a long listing format")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (?n "numeric-uid-gid" nil numeric-uid-gid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 "list numeric UIDs and GIDs instead of names")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (?r "reverse" nil reverse-list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 "reverse order while sorting")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (?s "size" nil show-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 "print size of each file, in blocks")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (?t nil by-mtime sort-method
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 "sort by modification time")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (?u nil by-atime sort-method
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 "sort by last access time")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (?x nil by-lines listing-style
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 "list entries by lines instead of by columns")
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
338 (?C nil by-columns listing-style
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
339 "list entries by columns")
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
340 (?L "deference" nil dereference-links
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
341 "list entries pointed to by symbolic links")
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
342 (?R "recursive" nil show-recursive
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
343 "list subdirectories recursively")
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
344 (?S nil by-size sort-method
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
345 "sort by file size")
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
346 (?U nil unsorted sort-method
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
347 "do not sort; list entries in directory order")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (?X nil by-extension sort-method
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 "sort alphabetically by entry extension")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (?1 nil single-column listing-style
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 "list one file per line")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (nil "help" nil nil
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
353 "show this usage display")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 :external "ls"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 :usage "[OPTION]... [FILE]...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 List information about the FILEs (the current directory by default).
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
357 Sort entries alphabetically across.")
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 ;; setup some defaults, based on what the user selected
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (unless block-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (setq block-size eshell-ls-default-blocksize))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (unless listing-style
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (setq listing-style 'by-columns))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (unless args
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (setq args (list ".")))
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
365 (let ((eshell-ls-exclude-regexp eshell-ls-exclude-regexp) ange-cache)
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
366 (when ignore-pattern
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (unless (eshell-using-module 'eshell-glob)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (error (concat "-I option requires that `eshell-glob'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 " be a member of `eshell-modules-list'")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 (set-text-properties 0 (length ignore-pattern) nil ignore-pattern)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
371 (setq eshell-ls-exclude-regexp
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
372 (if eshell-ls-exclude-regexp
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (concat "\\(" eshell-ls-exclude-regexp "\\|"
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
374 (eshell-glob-regexp ignore-pattern) "\\)")
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
375 (eshell-glob-regexp ignore-pattern))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 ;; list the files!
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (eshell-ls-entries
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (mapcar (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (lambda (arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (cons (if (and (eshell-under-windows-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (file-name-absolute-p arg))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 (expand-file-name arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 arg)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
384 (eshell-file-attributes arg))))
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
385 args)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 t (expand-file-name default-directory)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (funcall flush-func)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (defsubst eshell-ls-printable-size (filesize &optional by-blocksize)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 "Return a printable FILESIZE."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (eshell-printable-size filesize human-readable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (and by-blocksize block-size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 eshell-ls-use-colors))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (defsubst eshell-ls-size-string (attrs size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 "Return the size string for ATTRS length, using SIZE-WIDTH."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 (let* ((str (eshell-ls-printable-size (nth 7 attrs) t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (len (length str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (if (< len size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (concat (make-string (- size-width len) ? ) str)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 (defun eshell-ls-annotate (fileinfo)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 "Given a FILEINFO object, return a resolved, decorated FILEINFO.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 This means resolving any symbolic links, determining what face the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 name should be displayed as, etc. Think of it as cooking a FILEINFO."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (if (not (and (stringp (cadr fileinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408 (or dereference-links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (eq listing-style 'long-listing))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 (setcar fileinfo (eshell-ls-decorated-name fileinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (let (dir attr)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 (unless (file-name-absolute-p (cadr fileinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (setq dir (file-truename
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (file-name-directory
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (expand-file-name (car fileinfo))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 (setq attr
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
417 (eshell-file-attributes
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 (let ((target (if dir
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (expand-file-name (cadr fileinfo) dir)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 (cadr fileinfo))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (if dereference-links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 (file-truename target)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 target))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 (if (or dereference-links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (string-match "^\\.\\.?$" (car fileinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 (setcdr fileinfo attr)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (setcar fileinfo (eshell-ls-decorated-name fileinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (assert (eq listing-style 'long-listing))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (setcar fileinfo
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (concat (eshell-ls-decorated-name fileinfo) " -> "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (eshell-ls-decorated-name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (cons (cadr fileinfo) attr)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 fileinfo)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (defun eshell-ls-file (fileinfo &optional size-width copy-fileinfo)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 "Output FILE in long format.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 FILE may be a string, or a cons cell whose car is the filename and
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 whose cdr is the list of file attributes."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (if (not (cdr fileinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (funcall error-func (format "%s: No such file or directory\n"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (car fileinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (setq fileinfo
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (eshell-ls-annotate (if copy-fileinfo
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (cons (car fileinfo)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (cdr fileinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 fileinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (let ((file (car fileinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (attrs (cdr fileinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (if (not (eq listing-style 'long-listing))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 (if show-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (funcall insert-func (eshell-ls-size-string attrs size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 " " file "\n")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (funcall insert-func file "\n"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 (let ((line
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (concat
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 (if show-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 (concat (eshell-ls-size-string attrs size-width) " "))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (format
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
460 "%s%4d %-8s %-8s "
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 (or (nth 8 attrs) "??????????")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 (or (nth 1 attrs) 0)
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
463 (or (let ((user (nth 2 attrs)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
464 (and (not numeric-uid-gid)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
465 user
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
466 (eshell-substring
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
467 (if (numberp user)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
468 (user-login-name user)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
469 user) 8)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 (nth 2 attrs)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
471 "")
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
472 (or (let ((group (nth 3 attrs)))
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
473 (and (not numeric-uid-gid)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
474 group
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
475 (eshell-substring
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
476 (if (numberp group)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
477 (eshell-group-name group)
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 31241
diff changeset
478 group) 8)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 (nth 3 attrs)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 ""))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (let* ((str (eshell-ls-printable-size (nth 7 attrs)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (len (length str)))
53080
76ece241e712 (eshell-ls-file): There are times with size-width is nil and
John Wiegley <johnw@newartisans.com>
parents: 53066
diff changeset
483 (if (< len (or size-width 4))
76ece241e712 (eshell-ls-file): There are times with size-width is nil and
John Wiegley <johnw@newartisans.com>
parents: 53066
diff changeset
484 (concat (make-string (- (or size-width 4) len) ? ) str)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 str))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 " " (format-time-string
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
487 (concat
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
488 "%b %e "
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
489 (if (= (nth 5 (decode-time (current-time)))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
490 (nth 5 (decode-time
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
491 (nth (cond
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
492 ((eq sort-method 'by-atime) 4)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
493 ((eq sort-method 'by-ctime) 6)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
494 (t 5)) attrs))))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
495 "%H:%M"
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
496 " %Y")) (nth (cond
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
497 ((eq sort-method 'by-atime) 4)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
498 ((eq sort-method 'by-ctime) 6)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
499 (t 5)) attrs)) " ")))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (funcall insert-func line file "\n"))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 (defun eshell-ls-dir (dirinfo &optional insert-name root-dir size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503 "Output the entries in DIRINFO.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 If INSERT-NAME is non-nil, the name of DIRINFO will be output. If
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 ROOT-DIR is also non-nil, and a directory name, DIRINFO will be output
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 relative to that directory."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (let ((dir (car dirinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 (if (not (cdr dirinfo))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 (funcall error-func (format "%s: No such file or directory\n" dir))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 (if dir-literal
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 (eshell-ls-file dirinfo size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 (if insert-name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (funcall insert-func
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 (eshell-ls-decorated-name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 (cons (concat
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (if root-dir
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 (file-relative-name dir root-dir)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (expand-file-name dir)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (cdr dirinfo))) ":\n"))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
520 (let ((entries (eshell-directory-files-and-attributes
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
521 dir nil (and (not show-all)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
522 eshell-ls-exclude-hidden
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
523 "\\`[^.]") t)))
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
524 (when (and (not show-all) eshell-ls-exclude-regexp)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
525 (while (and entries (string-match eshell-ls-exclude-regexp
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
526 (caar entries)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (setq entries (cdr entries)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 (let ((e entries))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (while (cdr e)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 (if (string-match eshell-ls-exclude-regexp (car (cadr e)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 (setcdr e (cddr e))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532 (setq e (cdr e))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (when (or (eq listing-style 'long-listing) show-size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 (let ((total 0.0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (setq size-width 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 (eshell-for e entries
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (if (nth 7 (cdr e))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 (setq total (+ total (nth 7 (cdr e)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 size-width
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (max size-width
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 (length (eshell-ls-printable-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 (nth 7 (cdr e)) t))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543 (funcall insert-func "total "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 (eshell-ls-printable-size total t) "\n")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 (let ((default-directory (expand-file-name dir)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (if show-recursive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (eshell-ls-entries
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (let ((e entries) (good-entries (list t)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (while e
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 (unless (let ((len (length (caar e))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (and (eq (aref (caar e) 0) ?.)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 (or (= len 1)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 (and (= len 2)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 (eq (aref (caar e) 1) ?.)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (nconc good-entries (list (car e))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 (setq e (cdr e)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (cdr good-entries))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 nil root-dir)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 (eshell-ls-files (eshell-ls-sort-entries entries)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560 size-width))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 (defsubst eshell-ls-compare-entries (l r inx func)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 "Compare the time of two files, L and R, the attribute indexed by INX."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 (let ((lt (nth inx (cdr l)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (rt (nth inx (cdr r))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (if (equal lt rt)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 (string-lessp (directory-file-name (car l))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (directory-file-name (car r)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 (funcall func rt lt))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 (defun eshell-ls-sort-entries (entries)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 "Sort the given ENTRIES, which may be files, directories or both.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 In Eshell's implementation of ls, ENTRIES is always reversed."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 (if (eq sort-method 'unsorted)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575 (nreverse entries)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 (sort entries
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (lambda (l r)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 (let ((result
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 ((eq sort-method 'by-atime)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
582 (eshell-ls-compare-entries l r 4 'eshell-time-less-p))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 ((eq sort-method 'by-mtime)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
584 (eshell-ls-compare-entries l r 5 'eshell-time-less-p))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 ((eq sort-method 'by-ctime)
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
586 (eshell-ls-compare-entries l r 6 'eshell-time-less-p))
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
587 ((eq sort-method 'by-size)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
588 (eshell-ls-compare-entries l r 7 '<))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 ((eq sort-method 'by-extension)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 (let ((lx (file-name-extension
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (directory-file-name (car l))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 (rx (file-name-extension
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 (directory-file-name (car r)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 ((or (and (not lx) (not rx))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 (equal lx rx))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (string-lessp (directory-file-name (car l))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 (directory-file-name (car r))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 ((not lx) t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 ((not rx) nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (string-lessp lx rx)))))
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
603 (t
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 (string-lessp (directory-file-name (car l))
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
605 (directory-file-name (car r)))))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
606 (if reverse-list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
607 (not result)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
608 result)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
609
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
610 (defun eshell-ls-files (files &optional size-width copy-fileinfo)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
611 "Output a list of FILES.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
612 Each member of FILES is either a string or a cons cell of the form
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
613 \(FILE . ATTRS)."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
614 (if (memq listing-style '(long-listing single-column))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
615 (eshell-for file files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
616 (if file
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
617 (eshell-ls-file file size-width copy-fileinfo)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
618 (let ((f files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
619 last-f
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
620 display-files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
621 ignore)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
622 (while f
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
623 (if (cdar f)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
624 (setq last-f f
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
625 f (cdr f))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
626 (unless ignore
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
627 (funcall error-func
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
628 (format "%s: No such file or directory\n" (caar f))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
629 (if (eq f files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
630 (setq files (cdr files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
631 f files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
632 (if (not (cdr f))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
633 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
634 (setcdr last-f nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
635 (setq f nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
636 (setcar f (cadr f))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
637 (setcdr f (cddr f))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
638 (if (not show-size)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
639 (setq display-files (mapcar 'eshell-ls-annotate files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
640 (eshell-for file files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
641 (let* ((str (eshell-ls-printable-size (nth 7 (cdr file)) t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
642 (len (length str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
643 (if (< len size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
644 (setq str (concat (make-string (- size-width len) ? ) str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
645 (setq file (eshell-ls-annotate file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
646 display-files (cons (cons (concat str " " (car file))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
647 (cdr file))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
648 display-files))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
649 (setq display-files (nreverse display-files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
650 (let* ((col-vals
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
651 (if (eq listing-style 'by-columns)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
652 (eshell-ls-find-column-lengths display-files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
653 (assert (eq listing-style 'by-lines))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
654 (eshell-ls-find-column-widths display-files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
655 (col-widths (car col-vals))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
656 (display-files (cdr col-vals))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
657 (columns (length col-widths))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
658 (col-index 1)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
659 need-return)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
660 (eshell-for file display-files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
661 (let ((name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
662 (if (car file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
663 (if show-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
664 (concat (substring (car file) 0 size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
665 (eshell-ls-decorated-name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
666 (cons (substring (car file) size-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
667 (cdr file))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
668 (eshell-ls-decorated-name file))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
669 "")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
670 (if (< col-index columns)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
671 (setq need-return
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
672 (concat need-return name
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
673 (make-string
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
674 (max 0 (- (aref col-widths
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
675 (1- col-index))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
676 (length name))) ? ))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
677 col-index (1+ col-index))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
678 (funcall insert-func need-return name "\n")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
679 (setq col-index 1 need-return nil))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
680 (if need-return
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
681 (funcall insert-func need-return "\n"))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
682
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
683 (defun eshell-ls-entries (entries &optional separate root-dir)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
684 "Output PATH's directory ENTRIES, formatted according to OPTIONS.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
685 Each member of ENTRIES may either be a string or a cons cell, the car
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
686 of which is the file name, and the cdr of which is the list of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
687 attributes.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
688 If SEPARATE is non-nil, directories name will be entirely separated
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
689 from the filenames. This is the normal behavior, except when doing a
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
690 recursive listing.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
691 ROOT-DIR, if non-nil, specifies the root directory of the listing, to
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
692 which non-absolute directory names will be made relative if ever they
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
693 need to be printed."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
694 (let (dirs files show-names need-return (size-width 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
695 (eshell-for entry entries
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
696 (if (and (not dir-literal)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
697 (or (eshell-ls-filetype-p (cdr entry) ?d)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
698 (and (eshell-ls-filetype-p (cdr entry) ?l)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
699 (file-directory-p (car entry)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
700 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
701 (unless separate
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
702 (setq files (cons entry files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
703 size-width
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
704 (if show-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
705 (max size-width
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
706 (length (eshell-ls-printable-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
707 (nth 7 (cdr entry)) t))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
708 (setq dirs (cons entry dirs)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
709 (setq files (cons entry files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
710 size-width
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
711 (if show-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
712 (max size-width
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
713 (length (eshell-ls-printable-size
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
714 (nth 7 (cdr entry)) t)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
715 (when files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
716 (eshell-ls-files (eshell-ls-sort-entries files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
717 size-width show-recursive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
718 (setq need-return t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
719 (setq show-names (or show-recursive
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
720 (> (+ (length files) (length dirs)) 1)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
721 (eshell-for dir (eshell-ls-sort-entries dirs)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
722 (if (and need-return (not dir-literal))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
723 (funcall insert-func "\n"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
724 (eshell-ls-dir dir show-names
33020
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
725 (unless (file-name-absolute-p (car dir)) root-dir)
e21feeab77fb See ChangeLog
John Wiegley <johnw@newartisans.com>
parents: 32526
diff changeset
726 size-width)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
727 (setq need-return t))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
728
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
729 (defun eshell-ls-find-column-widths (files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
730 "Find the best fitting column widths for FILES.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
731 It will be returned as a vector, whose length is the number of columns
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
732 to use, and each member of which is the width of that column
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
733 \(including spacing)."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
734 (let* ((numcols 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
735 (width 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
736 (widths
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
737 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
738 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
739 (lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
740 (+ 2 (length (car file)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
741 files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
742 ;; must account for the added space...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
743 (max-width (+ (window-width) 2))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
744 (best-width 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
745 col-widths)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
746
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
747 ;; determine the largest number of columns in the first row
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
748 (let ((w widths))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
749 (while (and w (< width max-width))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
750 (setq width (+ width (car w))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
751 numcols (1+ numcols)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
752 w (cdr w))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
753
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
754 ;; refine it based on the following rows
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
755 (while (> numcols 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
756 (let ((i 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
757 (colw (make-vector numcols 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
758 (w widths))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
759 (while w
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
760 (if (= i numcols)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
761 (setq i 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
762 (aset colw i (max (aref colw i) (car w)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
763 (setq w (cdr w) i (1+ i)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
764 (setq i 0 width 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
765 (while (< i numcols)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
766 (setq width (+ width (aref colw i))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
767 i (1+ i)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
768 (if (and (< width max-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
769 (> width best-width))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
770 (setq col-widths colw
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
771 best-width width)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
772 (setq numcols (1- numcols)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
773
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
774 (cons (or col-widths (vector max-width)) files)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
775
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
776 (defun eshell-ls-find-column-lengths (files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
777 "Find the best fitting column lengths for FILES.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
778 It will be returned as a vector, whose length is the number of columns
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
779 to use, and each member of which is the width of that column
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
780 \(including spacing)."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
781 (let* ((numcols 1)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
782 (width 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
783 (widths
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
784 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
785 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
786 (lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
787 (+ 2 (length (car file)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
788 files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
789 (max-width (+ (window-width) 2))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
790 col-widths
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
791 colw)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
792
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
793 ;; refine it based on the following rows
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
794 (while numcols
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
795 (let* ((rows (ceiling (/ (length widths)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
796 (float numcols))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
797 (w widths)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
798 (len (* rows numcols))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
799 (index 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
800 (i 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
801 (setq width 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
802 (unless (or (= rows 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
803 (<= (/ (length widths) (float rows))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
804 (float (1- numcols))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
805 (setq colw (make-vector numcols 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
806 (while (> len 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
807 (if (= i numcols)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
808 (setq i 0 index (1+ index)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
809 (aset colw i
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
810 (max (aref colw i)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
811 (or (nth (+ (* i rows) index) w) 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
812 (setq len (1- len) i (1+ i)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
813 (setq i 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
814 (while (< i numcols)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
815 (setq width (+ width (aref colw i))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
816 i (1+ i))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
817 (if (>= width max-width)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
818 (setq numcols nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
819 (if colw
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
820 (setq col-widths colw))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
821 (if (>= numcols (length widths))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
822 (setq numcols nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
823 (setq numcols (1+ numcols))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
824
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
825 (if (not col-widths)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
826 (cons (vector max-width) files)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
827 (setq numcols (length col-widths))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
828 (let* ((rows (ceiling (/ (length widths)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
829 (float numcols))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
830 (len (* rows numcols))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
831 (newfiles (make-list len nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
832 (index 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
833 (i 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
834 (j 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
835 (while (< j len)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
836 (if (= i numcols)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
837 (setq i 0 index (1+ index)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
838 (setcar (nthcdr j newfiles)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
839 (nth (+ (* i rows) index) files))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
840 (setq j (1+ j) i (1+ i)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
841 (cons col-widths newfiles)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
842
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
843 (defun eshell-ls-decorated-name (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
844 "Return FILE, possibly decorated.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
845 Use TRUENAME for predicate tests, if passed."
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
846 (if eshell-ls-use-colors
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
847 (let ((face
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
848 (cond
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
849 ((not (cdr file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
850 'eshell-ls-missing-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
851
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
852 ((stringp (cadr file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
853 'eshell-ls-symlink-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
854
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
855 ((eq (cadr file) t)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
856 'eshell-ls-directory-face)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
857
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
858 ((not (eshell-ls-filetype-p (cdr file) ?-))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
859 'eshell-ls-special-face)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
860
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
861 ((and (/= (user-uid) 0) ; root can execute anything
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
862 (eshell-ls-applicable (cdr file) 3
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
863 'file-executable-p (car file)))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
864 'eshell-ls-executable-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
865
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
866 ((not (eshell-ls-applicable (cdr file) 1
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
867 'file-readable-p (car file)))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
868 'eshell-ls-unreadable-face)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
869
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
870 ((string-match eshell-ls-archive-regexp (car file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
871 'eshell-ls-archive-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
872
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
873 ((string-match eshell-ls-backup-regexp (car file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
874 'eshell-ls-backup-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
875
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
876 ((string-match eshell-ls-product-regexp (car file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
877 'eshell-ls-product-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
878
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
879 ((string-match eshell-ls-clutter-regexp (car file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
880 'eshell-ls-clutter-face)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
881
46853
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
882 ((not (eshell-ls-applicable (cdr file) 2
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
883 'file-writable-p (car file)))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
884 'eshell-ls-readonly-face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
885 (eshell-ls-highlight-alist
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
886 (let ((tests eshell-ls-highlight-alist)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
887 value)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
888 (while tests
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
889 (if (funcall (caar tests) (car file) (cdr file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
890 (setq value (cdar tests) tests nil)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
891 (setq tests (cdr tests))))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
892 value)))))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
893 (if face
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
894 (add-text-properties 0 (length (car file))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
895 (list 'face face)
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
896 (car file)))))
cb339473da3b I did not mean to check in these changes yet, they are still
John Wiegley <johnw@newartisans.com>
parents: 46852
diff changeset
897 (car file))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
898
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
899 ;;; Code:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
900
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 48704
diff changeset
901 ;;; arch-tag: 9295181c-0cb2-499c-999b-89f5359842cb
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
902 ;;; em-ls.el ends here