mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-10 00:00:39 -08:00
(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.
This commit is contained in:
parent
aa8fe32512
commit
1fff30af6c
1 changed files with 23 additions and 25 deletions
|
|
@ -107,6 +107,7 @@ are: A a c i r S s t u"
|
||||||
short
|
short
|
||||||
(file-list (directory-files dir nil wildcard))
|
(file-list (directory-files dir nil wildcard))
|
||||||
file-alist
|
file-alist
|
||||||
|
(now (current-time))
|
||||||
;; do all bindings here for speed
|
;; do all bindings here for speed
|
||||||
fil attr)
|
fil attr)
|
||||||
(cond ((memq ?A switches)
|
(cond ((memq ?A switches)
|
||||||
|
|
@ -141,7 +142,7 @@ are: A a c i r S s t u"
|
||||||
attr (cdr elt))
|
attr (cdr elt))
|
||||||
(and attr
|
(and attr
|
||||||
(setq sum (+ sum (nth 7 attr)))
|
(setq sum (+ sum (nth 7 attr)))
|
||||||
(insert (ls-lisp-format short attr switches))))
|
(insert (ls-lisp-format short attr switches now))))
|
||||||
;; Fill in total size of all files:
|
;; Fill in total size of all files:
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(search-backward "total \007")
|
(search-backward "total \007")
|
||||||
|
|
@ -152,7 +153,8 @@ are: A a c i r S s t u"
|
||||||
;; file-attributes will not recognize a symlink to a directory
|
;; file-attributes will not recognize a symlink to a directory
|
||||||
;; must make it a relative filename as ls does:
|
;; must make it a relative filename as ls does:
|
||||||
(setq file (file-name-nondirectory file))
|
(setq file (file-name-nondirectory file))
|
||||||
(insert (ls-lisp-format file (file-attributes file) switches))))))
|
(insert (ls-lisp-format file (file-attributes file) switches
|
||||||
|
(current-time)))))))
|
||||||
|
|
||||||
(defun ls-lisp-delete-matching (regexp list)
|
(defun ls-lisp-delete-matching (regexp list)
|
||||||
;; Delete all elements matching REGEXP from LIST, return new list.
|
;; Delete all elements matching REGEXP from LIST, return new list.
|
||||||
|
|
@ -204,7 +206,7 @@ are: A a c i r S s t u"
|
||||||
(< lo0 lo1)))))
|
(< lo0 lo1)))))
|
||||||
|
|
||||||
|
|
||||||
(defun ls-lisp-format (file-name file-attr &optional switches)
|
(defun ls-lisp-format (file-name file-attr switches now)
|
||||||
(let ((file-type (nth 0 file-attr)))
|
(let ((file-type (nth 0 file-attr)))
|
||||||
(concat (if (memq ?i switches) ; inode number
|
(concat (if (memq ?i switches) ; inode number
|
||||||
(format "%6d " (nth 10 file-attr)))
|
(format "%6d " (nth 10 file-attr)))
|
||||||
|
|
@ -226,7 +228,7 @@ are: A a c i r S s t u"
|
||||||
(int-to-string (nth 3 file-attr))) ; gid
|
(int-to-string (nth 3 file-attr))) ; gid
|
||||||
(nth 7 file-attr) ; size in bytes
|
(nth 7 file-attr) ; size in bytes
|
||||||
)
|
)
|
||||||
(ls-lisp-format-time file-attr switches)
|
(ls-lisp-format-time file-attr switches now)
|
||||||
" "
|
" "
|
||||||
file-name
|
file-name
|
||||||
(if (stringp file-type) ; is a symbolic link
|
(if (stringp file-type) ; is a symbolic link
|
||||||
|
|
@ -243,29 +245,25 @@ are: A a c i r S s t u"
|
||||||
;; default is last modtime
|
;; default is last modtime
|
||||||
(t 5)))
|
(t 5)))
|
||||||
|
|
||||||
(defun ls-lisp-format-time (file-attr switches)
|
(defun ls-lisp-format-time (file-attr switches now)
|
||||||
;; Format time string for file with attributes FILE-ATTR according
|
;; Format time string for file with attributes FILE-ATTR according
|
||||||
;; to SWITCHES (a list of ls option letters of which c and u are recognized).
|
;; to SWITCHES (a list of ls option letters of which c and u are recognized).
|
||||||
;; file-attributes's time is in a braindead format
|
;; Use the same method as `ls' to decide whether to show time-of-day or year,
|
||||||
;; Emacs 19 can format it using a new optional argument to
|
;; depending on distance between file date and NOW.
|
||||||
;; current-time-string, for Emacs 18 we just return the faked fixed
|
(let* ((time (nth (ls-lisp-time-index switches) file-attr))
|
||||||
;; date "Jan 00 00:00 ".
|
(diff16 (- (car time) (car now)))
|
||||||
(condition-case error-data
|
(diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now)))))
|
||||||
(let* ((time (current-time-string
|
(past-cutoff (- (* 6 30 24 60 60))) ; 6 30-day months
|
||||||
(nth (ls-lisp-time-index switches) file-attr)))
|
(future-cutoff (* 60 60))) ; 1 hour
|
||||||
(date (substring time 4 11)) ; "Apr 30 "
|
(format-time-string
|
||||||
(clock (substring time 11 16)) ; "11:27"
|
(if (and
|
||||||
(year (substring time 19 24)) ; " 1992"
|
(<= past-cutoff diff) (<= diff future-cutoff)
|
||||||
(same-year (equal year (substring (current-time-string) 19 24))))
|
;; Sanity check in case `diff' computation overflowed.
|
||||||
(concat date ; has trailing SPC
|
(<= (1- (ash past-cutoff -16)) diff16)
|
||||||
(if same-year
|
(<= diff16 (1+ (ash future-cutoff -16))))
|
||||||
;; this is not exactly the same test used by ls
|
"%b %e %H:%M"
|
||||||
;; ls tests if the file is older than 6 months
|
"%b %e %Y")
|
||||||
;; but we can't do time differences easily
|
time)))
|
||||||
clock
|
|
||||||
year)))
|
|
||||||
(error
|
|
||||||
"Jan 00 00:00")))
|
|
||||||
|
|
||||||
(provide 'ls-lisp)
|
(provide 'ls-lisp)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue