diff options
| author | Richard M. Stallman | 1996-09-03 23:25:46 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-03 23:25:46 +0000 |
| commit | 1fff30af6cd2df77f795f026e90ab85d18c7afbf (patch) | |
| tree | e138e1c04552ccee42c113fbf474a3357d095d08 | |
| parent | aa8fe325129b4425fe6b2682e5376bf5ab9e2b43 (diff) | |
| download | emacs-1fff30af6cd2df77f795f026e90ab85d18c7afbf.tar.gz emacs-1fff30af6cd2df77f795f026e90ab85d18c7afbf.zip | |
(insert-directory): Use same value of `now' for all files.
(ls-lisp-format): New argument NOW. Arguments are no longer optional.
(ls-lisp-format-time): New argument NOW. Use same method as `ls'
to decide whether to show time-of-day or year.
| -rw-r--r-- | lisp/ls-lisp.el | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index 4678ac3e506..158414664f3 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el | |||
| @@ -107,6 +107,7 @@ are: A a c i r S s t u" | |||
| 107 | short | 107 | short |
| 108 | (file-list (directory-files dir nil wildcard)) | 108 | (file-list (directory-files dir nil wildcard)) |
| 109 | file-alist | 109 | file-alist |
| 110 | (now (current-time)) | ||
| 110 | ;; do all bindings here for speed | 111 | ;; do all bindings here for speed |
| 111 | fil attr) | 112 | fil attr) |
| 112 | (cond ((memq ?A switches) | 113 | (cond ((memq ?A switches) |
| @@ -141,7 +142,7 @@ are: A a c i r S s t u" | |||
| 141 | attr (cdr elt)) | 142 | attr (cdr elt)) |
| 142 | (and attr | 143 | (and attr |
| 143 | (setq sum (+ sum (nth 7 attr))) | 144 | (setq sum (+ sum (nth 7 attr))) |
| 144 | (insert (ls-lisp-format short attr switches)))) | 145 | (insert (ls-lisp-format short attr switches now)))) |
| 145 | ;; Fill in total size of all files: | 146 | ;; Fill in total size of all files: |
| 146 | (save-excursion | 147 | (save-excursion |
| 147 | (search-backward "total \007") | 148 | (search-backward "total \007") |
| @@ -152,7 +153,8 @@ are: A a c i r S s t u" | |||
| 152 | ;; file-attributes will not recognize a symlink to a directory | 153 | ;; file-attributes will not recognize a symlink to a directory |
| 153 | ;; must make it a relative filename as ls does: | 154 | ;; must make it a relative filename as ls does: |
| 154 | (setq file (file-name-nondirectory file)) | 155 | (setq file (file-name-nondirectory file)) |
| 155 | (insert (ls-lisp-format file (file-attributes file) switches)))))) | 156 | (insert (ls-lisp-format file (file-attributes file) switches |
| 157 | (current-time))))))) | ||
| 156 | 158 | ||
| 157 | (defun ls-lisp-delete-matching (regexp list) | 159 | (defun ls-lisp-delete-matching (regexp list) |
| 158 | ;; Delete all elements matching REGEXP from LIST, return new list. | 160 | ;; Delete all elements matching REGEXP from LIST, return new list. |
| @@ -204,7 +206,7 @@ are: A a c i r S s t u" | |||
| 204 | (< lo0 lo1))))) | 206 | (< lo0 lo1))))) |
| 205 | 207 | ||
| 206 | 208 | ||
| 207 | (defun ls-lisp-format (file-name file-attr &optional switches) | 209 | (defun ls-lisp-format (file-name file-attr switches now) |
| 208 | (let ((file-type (nth 0 file-attr))) | 210 | (let ((file-type (nth 0 file-attr))) |
| 209 | (concat (if (memq ?i switches) ; inode number | 211 | (concat (if (memq ?i switches) ; inode number |
| 210 | (format "%6d " (nth 10 file-attr))) | 212 | (format "%6d " (nth 10 file-attr))) |
| @@ -226,7 +228,7 @@ are: A a c i r S s t u" | |||
| 226 | (int-to-string (nth 3 file-attr))) ; gid | 228 | (int-to-string (nth 3 file-attr))) ; gid |
| 227 | (nth 7 file-attr) ; size in bytes | 229 | (nth 7 file-attr) ; size in bytes |
| 228 | ) | 230 | ) |
| 229 | (ls-lisp-format-time file-attr switches) | 231 | (ls-lisp-format-time file-attr switches now) |
| 230 | " " | 232 | " " |
| 231 | file-name | 233 | file-name |
| 232 | (if (stringp file-type) ; is a symbolic link | 234 | (if (stringp file-type) ; is a symbolic link |
| @@ -243,29 +245,25 @@ are: A a c i r S s t u" | |||
| 243 | ;; default is last modtime | 245 | ;; default is last modtime |
| 244 | (t 5))) | 246 | (t 5))) |
| 245 | 247 | ||
| 246 | (defun ls-lisp-format-time (file-attr switches) | 248 | (defun ls-lisp-format-time (file-attr switches now) |
| 247 | ;; Format time string for file with attributes FILE-ATTR according | 249 | ;; Format time string for file with attributes FILE-ATTR according |
| 248 | ;; to SWITCHES (a list of ls option letters of which c and u are recognized). | 250 | ;; to SWITCHES (a list of ls option letters of which c and u are recognized). |
| 249 | ;; file-attributes's time is in a braindead format | 251 | ;; Use the same method as `ls' to decide whether to show time-of-day or year, |
| 250 | ;; Emacs 19 can format it using a new optional argument to | 252 | ;; depending on distance between file date and NOW. |
| 251 | ;; current-time-string, for Emacs 18 we just return the faked fixed | 253 | (let* ((time (nth (ls-lisp-time-index switches) file-attr)) |
| 252 | ;; date "Jan 00 00:00 ". | 254 | (diff16 (- (car time) (car now))) |
| 253 | (condition-case error-data | 255 | (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now))))) |
| 254 | (let* ((time (current-time-string | 256 | (past-cutoff (- (* 6 30 24 60 60))) ; 6 30-day months |
| 255 | (nth (ls-lisp-time-index switches) file-attr))) | 257 | (future-cutoff (* 60 60))) ; 1 hour |
| 256 | (date (substring time 4 11)) ; "Apr 30 " | 258 | (format-time-string |
| 257 | (clock (substring time 11 16)) ; "11:27" | 259 | (if (and |
| 258 | (year (substring time 19 24)) ; " 1992" | 260 | (<= past-cutoff diff) (<= diff future-cutoff) |
| 259 | (same-year (equal year (substring (current-time-string) 19 24)))) | 261 | ;; Sanity check in case `diff' computation overflowed. |
| 260 | (concat date ; has trailing SPC | 262 | (<= (1- (ash past-cutoff -16)) diff16) |
| 261 | (if same-year | 263 | (<= diff16 (1+ (ash future-cutoff -16)))) |
| 262 | ;; this is not exactly the same test used by ls | 264 | "%b %e %H:%M" |
| 263 | ;; ls tests if the file is older than 6 months | 265 | "%b %e %Y") |
| 264 | ;; but we can't do time differences easily | 266 | time))) |
| 265 | clock | ||
| 266 | year))) | ||
| 267 | (error | ||
| 268 | "Jan 00 00:00"))) | ||
| 269 | 267 | ||
| 270 | (provide 'ls-lisp) | 268 | (provide 'ls-lisp) |
| 271 | 269 | ||