diff options
| author | Sebastian Kremer | 1992-04-30 10:29:53 +0000 |
|---|---|---|
| committer | Sebastian Kremer | 1992-04-30 10:29:53 +0000 |
| commit | 738eb4e77c70015b6ceed0552c580bebc8181319 (patch) | |
| tree | 8fbd1fa6ea6219a150040a6b01bce5c98ce9f22a | |
| parent | 4746118aca2d5cbdd054b4af4814d56550dfbc79 (diff) | |
| download | emacs-738eb4e77c70015b6ceed0552c580bebc8181319.tar.gz emacs-738eb4e77c70015b6ceed0552c580bebc8181319.zip | |
(dired-lisp-format-time): in Emacs 19 we can format times.
| -rw-r--r-- | lisp/ls-lisp.el | 152 |
1 files changed, 115 insertions, 37 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index 22bf2e02e87..8f65058c6b0 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el | |||
| @@ -1,53 +1,98 @@ | |||
| 1 | ;;;; dired-lisp.el - emulate ls completely in Emacs Lisp. $Revision: 1.4 $ | 1 | ;;;; dired-lisp.el - emulate Dired's ls completely in Emacs Lisp |
| 2 | ;;;; Copyright (C) 1991 Sebastian Kremer <sk@thp.uni-koeln.de> | ||
| 3 | 2 | ||
| 4 | ;;;; READ THE WARNING BELOW BEFORE USING THIS PROGRAM! | 3 | ;;;; READ THE WARNING BELOW BEFORE USING THIS PROGRAM! |
| 5 | 4 | ||
| 6 | ;;;; Useful if you cannot afford to fork Emacs on a real memory UNIX, | 5 | (defconst dired-lisp-version (substring "$Revision: 5.212 $" 11 -2) |
| 7 | ;;;; under VMS, or if you don't have the ls program. | 6 | "$Id: dired-lisp.el,v 4.19 1991/09/20 13:20:58 sk RelBeta $") |
| 8 | 7 | ||
| 9 | ;; This file is part of GNU Emacs. | 8 | ;; Copyright (C) 1992 by Sebastian Kremer <sk@thp.uni-koeln.de> |
| 10 | 9 | ||
| 11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | 10 | ;; This program is free software; you can redistribute it and/or modify |
| 12 | ;; it under the terms of the GNU General Public License as published by | 11 | ;; it under the terms of the GNU General Public License as published by |
| 13 | ;; the Free Software Foundation; either version 1, or (at your option) | 12 | ;; the Free Software Foundation; either version 1, or (at your option) |
| 14 | ;; any later version. | 13 | ;; any later version. |
| 15 | 14 | ;; | |
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | 15 | ;; This program is distributed in the hope that it will be useful, |
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | ;; GNU General Public License for more details. | 18 | ;; GNU General Public License for more details. |
| 20 | 19 | ;; | |
| 21 | ;; You should have received a copy of the GNU General Public License | 20 | ;; You should have received a copy of the GNU General Public License |
| 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to | 21 | ;; along with this program; if not, write to the Free Software |
| 23 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 22 | ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | |||
| 24 | ;; LISPDIR ENTRY for the Elisp Archive =============================== | ||
| 25 | ;; LCD Archive Entry: | ||
| 26 | ;; dired-lisp|Sebastian Kremer|sk@thp.uni-koeln.de | ||
| 27 | ;; |emulate Dired's ls completely in Emacs Lisp | ||
| 28 | ;; |$Date: 1991/09/20 13:20:58 $|$Revision: 4.19 $| | ||
| 29 | |||
| 30 | ;; INSTALLATION ======================================================= | ||
| 31 | ;; | ||
| 32 | ;; Put this file into your load-path. Loading it will result in | ||
| 33 | ;; redefining function dired-ls to not call ls. | ||
| 34 | |||
| 35 | ;; OVERVIEW =========================================================== | ||
| 36 | |||
| 37 | ;; This file overloads tree dired so that all fileinfo is retrieved | ||
| 38 | ;; directly from Emacs lisp, without using an ls subprocess. | ||
| 39 | |||
| 40 | ;; Useful if you cannot afford to fork Emacs on a real memory UNIX, | ||
| 41 | ;; under VMS, or if you don't have the ls program, or if you want | ||
| 42 | ;; different format from what ls offers. | ||
| 43 | |||
| 44 | ;; Beware that if you change the output format of dired-ls, you'll | ||
| 45 | ;; have to change dired-move-to-filename and | ||
| 46 | ;; dired-move-to-end-of-filename as well. | ||
| 24 | 47 | ||
| 25 | ;;;; WARNING: | 48 | ;; With this package is loaded, dired uses regexps instead of shell |
| 49 | ;; wildcards. If you enter regexps remember to double each $ sign. | ||
| 50 | ;; For example, to dired all elisp (*.el) files, enter `.*\.el$$', | ||
| 51 | ;; resulting in the regexp `.*\.el$'. | ||
| 26 | 52 | ||
| 27 | ;;;; With earlier version of this program I sometimes got an internal | 53 | ;; WARNING =========================================================== |
| 28 | ;;;; Emacs error: | ||
| 29 | 54 | ||
| 30 | ;;;; Signalling: (wrong-type-argument natnump #<EMACS BUG: ILLEGAL | 55 | ;; With earlier version of this program I sometimes got an internal |
| 31 | ;;;; DATATYPE (#o37777777727) Save your buffers immediately and please | 56 | ;; Emacs error: |
| 32 | ;;;; report this bug>) | ||
| 33 | 57 | ||
| 34 | ;;;; The datatype differs (I also got #o67 once). | 58 | ;; Signalling: (wrong-type-argument natnump #<EMACS BUG: ILLEGAL |
| 59 | ;; DATATYPE (#o37777777727) Save your buffers immediately and please | ||
| 60 | ;; report this bug>) | ||
| 35 | 61 | ||
| 36 | ;;;; Sometimes emacs just crashed with a fatal error. | 62 | ;; The datatype differs (I also got #o67 once). |
| 37 | 63 | ||
| 38 | ;;;; After I've avoided using directory-files and file-attributes | 64 | ;; Sometimes emacs just crashed with a fatal error. |
| 39 | ;;;; together inside a mapcar, the bug didn't surface any longer. | ||
| 40 | 65 | ||
| 41 | ;;; RESTRICTIONS: | 66 | ;; After I've avoided using directory-files and file-attributes |
| 42 | ;;;; ls switches are mostly ignored | 67 | ;; together inside a mapcar, the bug didn't surface any longer. |
| 43 | ;;;; Cannot display date of file, displays a fake date "Jan 00 00:00" instead | ||
| 44 | ;;;; Only numeric uid/gid | ||
| 45 | ;;;; Loading ange-ftp breaks it | ||
| 46 | 68 | ||
| 47 | ;;;; It is surprisingly fast, though! | 69 | ;; RESTRICTIONS ===================================================== |
| 48 | 70 | ||
| 49 | ;;;; TODO: | 71 | ;; * ls switches are mostly ignored, see docstring of `dired-ls'. |
| 50 | ;;;; Recognize at some more ls switches: R F | 72 | |
| 73 | ;; * In Emacs 18: cannot display date of file, displays a fake date | ||
| 74 | ;; "Jan 00 00:00" instead (dates do work in Emacs 19) | ||
| 75 | |||
| 76 | ;; * Only numeric uid/gid | ||
| 77 | |||
| 78 | ;; * if you load dired-lisp after ange-ftp, remote listings look | ||
| 79 | ;; really strange: | ||
| 80 | ;; | ||
| 81 | ;; total 1 | ||
| 82 | ;; d????????? -1 -1 -1 -1 Jan 1 1970 . | ||
| 83 | ;; d????????? -1 -1 -1 -1 Jan 1 1970 .. | ||
| 84 | ;; | ||
| 85 | ;; This is because ange-ftp's file-attributes does not return much | ||
| 86 | ;; useful information. | ||
| 87 | ;; | ||
| 88 | ;; If you load dired-lisp first, there seem to be no problems. | ||
| 89 | |||
| 90 | ;; It is surprisingly fast, though! | ||
| 91 | |||
| 92 | ;; TODO ============================================================== | ||
| 93 | |||
| 94 | ;; Recognize at some more ls switches: R F | ||
| 95 | |||
| 51 | 96 | ||
| 52 | (require 'dired) ; we will redefine dired-ls: | 97 | (require 'dired) ; we will redefine dired-ls: |
| 53 | (or (fboundp 'dired-lisp-unix-ls) | 98 | (or (fboundp 'dired-lisp-unix-ls) |
| @@ -58,11 +103,13 @@ | |||
| 58 | (defun dired-lisp-ls (file &optional switches wildcard full-directory-p) | 103 | (defun dired-lisp-ls (file &optional switches wildcard full-directory-p) |
| 59 | "dired-lisp.el's version of dired-ls. | 104 | "dired-lisp.el's version of dired-ls. |
| 60 | Known switches: A a S r i s | 105 | Known switches: A a S r i s |
| 106 | In Emacs 19, additional known switches are: c u | ||
| 61 | Others are ignored. | 107 | Others are ignored. |
| 62 | 108 | ||
| 63 | Insert ls output of FILE, optionally formatted with SWITCHES. | 109 | Insert ls output of FILE, optionally formatted with SWITCHES. |
| 64 | Optional third arg WILDCARD means treat non-directory part of FILE | 110 | Optional third arg WILDCARD means treat non-directory part of FILE as |
| 65 | as emacs regexp (_not_ a shell wildcard). | 111 | emacs regexp (_not_ a shell wildcard). If you enter regexps remember |
| 112 | to double each $ sign. | ||
| 66 | 113 | ||
| 67 | Optional fourth arg FULL-DIRECTORY-P means file is a directory and | 114 | Optional fourth arg FULL-DIRECTORY-P means file is a directory and |
| 68 | switches do not contain `d'. | 115 | switches do not contain `d'. |
| @@ -137,8 +184,8 @@ SWITCHES default to dired-listing-switches." | |||
| 137 | 184 | ||
| 138 | (defun dired-lisp-handle-switches (file-alist switches) | 185 | (defun dired-lisp-handle-switches (file-alist switches) |
| 139 | ;; FILE-ALIST's elements are (FILE . FILE-ATTRIBUTES). | 186 | ;; FILE-ALIST's elements are (FILE . FILE-ATTRIBUTES). |
| 140 | ;; Return new alist sorted according to switches. | 187 | ;; Return new alist sorted according to SWITCHES which is a list of |
| 141 | ;; Default sorting is alphabetically. | 188 | ;; characters. Default sorting is alphabetically. |
| 142 | (setq file-alist | 189 | (setq file-alist |
| 143 | (sort file-alist | 190 | (sort file-alist |
| 144 | (cond ((memq ?S switches) | 191 | (cond ((memq ?S switches) |
| @@ -147,6 +194,7 @@ SWITCHES default to dired-listing-switches." | |||
| 147 | ;; 7th file attribute is file size | 194 | ;; 7th file attribute is file size |
| 148 | ;; Make largest file come first | 195 | ;; Make largest file come first |
| 149 | (< (nth 7 (cdr y)) (nth 7 (cdr x)))))) | 196 | (< (nth 7 (cdr y)) (nth 7 (cdr x)))))) |
| 197 | ;; does Emacs 19 have a way to compare times? | ||
| 150 | (t ; sorted alphabetically | 198 | (t ; sorted alphabetically |
| 151 | (function | 199 | (function |
| 152 | (lambda (x y) | 200 | (lambda (x y) |
| @@ -173,10 +221,8 @@ SWITCHES default to dired-listing-switches." | |||
| 173 | (nth 3 file-attr) ; gid | 221 | (nth 3 file-attr) ; gid |
| 174 | (nth 7 file-attr) ; size in bytes | 222 | (nth 7 file-attr) ; size in bytes |
| 175 | ) | 223 | ) |
| 176 | ;; file-attributes's time is in a braindead format | 224 | (dired-lisp-format-time file-attr switches) |
| 177 | ;; Emacs should have a ctime function | 225 | " " |
| 178 | ;; current-time-string could take an optional arg. | ||
| 179 | "Jan 00 00:00 " ; fake time | ||
| 180 | file-name | 226 | file-name |
| 181 | (if (stringp file-type) ; is a symbolic link | 227 | (if (stringp file-type) ; is a symbolic link |
| 182 | (concat " -> " file-type) | 228 | (concat " -> " file-type) |
| @@ -184,3 +230,35 @@ SWITCHES default to dired-listing-switches." | |||
| 184 | "\n" | 230 | "\n" |
| 185 | ))) | 231 | ))) |
| 186 | 232 | ||
| 233 | (defun dired-lisp-format-time (file-attr switches) | ||
| 234 | ;; Format time string for file with attributes FILE-ATTR according | ||
| 235 | ;; to SWITCHES (a list of ls option letters of which c and u are recognized). | ||
| 236 | ;; file-attributes's time is in a braindead format | ||
| 237 | ;; Emacs 19 can format it using a new optional argument to | ||
| 238 | ;; current-time-string, for Emacs 18 we just return the faked fixed | ||
| 239 | ;; date "Jan 00 00:00 ". | ||
| 240 | (condition-case error-data | ||
| 241 | (let* ((time (current-time-string | ||
| 242 | (nth (cond | ||
| 243 | ((memq ?c switches) 6) ; last mode change | ||
| 244 | ((memq ?u switches) 4) ; last access | ||
| 245 | ;; default is last modtime | ||
| 246 | (t 5)) | ||
| 247 | file-attr))) | ||
| 248 | (date (substring time 4 11)) ; "Apr 30 " | ||
| 249 | (clock (substring time 11 16)) ; "11:27" | ||
| 250 | (year (substring time 19 24)) ; " 1992" | ||
| 251 | (same-year (equal year (substring (current-time-string) 19 24)))) | ||
| 252 | (concat date ; has trailing SPC | ||
| 253 | (if same-year | ||
| 254 | ;; this is not exactly the same test used by ls | ||
| 255 | ;; ls tests if the file is older than 6 months | ||
| 256 | ;; but we can't do time differences easily | ||
| 257 | clock | ||
| 258 | year))) | ||
| 259 | (error | ||
| 260 | "Jan 00 00:00"))) | ||
| 261 | |||
| 262 | (provide 'dired-lisp) | ||
| 263 | |||
| 264 | ; eof | ||