emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dired-move-to-filename-regexp and Chinese (was: dired-do-toggle)


From: Paul Eggert
Subject: Re: dired-move-to-filename-regexp and Chinese (was: dired-do-toggle)
Date: 05 Nov 2001 18:16:51 -0800
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/21.1

Re <http://mail.gnu.org/pipermail/bug-gnu-emacs/2001-November/008054.html>,
Yong Lu wrote me that there wasn't a bug in dired-filename-to-regexp
after all.  His complaint was merely one about the appearance, not
about functionality.  That is, the Lisp emulation output something
like this:

  -rw-rw-rw-   1 Administrator root        0 十二月 25  1990 file1
  -rw-rw-rw-   1 Administrator root        0 三月 24  2001 file2

and the "file1" and "file2" columns didn't line up.

This problem has been encountered with GNU ls, and a fix has been
introduced in fileutils 4.1.1: namely, use ISO timestamps in locales
like that.  There was also another discrepancy between ls-lisp and GNU
ls that was introduced in recent fileutils releases, which is that the
'6 months' window is now half a Gregorian year in GNU ls, with no slop.

Since the intent is that ls-lisp mirrors GNU ls, I checked in the
following patch to the main branch to remove these discrepancies.
This should fix Yong Lu's problem.  (Is this the proper protocol for
checking in patches these days?  If not, please let me know and I'll
correct it.)

2001-11-05  Paul Eggert  <address@hidden>

        * ls-lisp.el (ls-lisp-time-to-seconds): New function.
        (ls-lisp-format-time): Emulate GNU fileutils 4.1.1 ls, whose time
        stamps always line up by default.  Also, it uses a slightly
        different window to determine whether files are "recent".

Index: ls-lisp.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ls-lisp.el,v
retrieving revision 1.38
retrieving revision 1.39
diff -p -c -r1.38 -r1.39
*** ls-lisp.el  2001/07/15 16:15:34     1.38
--- ls-lisp.el  2001/11/06 01:56:02     1.39
*************** Return nil if no time switch found."
*** 515,540 ****
        ((memq ?t switches) 5)          ; last modtime
        ((memq ?u switches) 4)))        ; last access
  
  (defun ls-lisp-format-time (file-attr time-index now)
    "Format time for file with attributes FILE-ATTR according to TIME-INDEX.
  Use the same method as ls to decide whether to show time-of-day or year,
  depending on distance between file date and NOW.
  All ls time options, namely c, t and u, are handled."
    (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime
!        (diff16 (- (car time) (car now)))
!        (diff (+ (ash diff16 16) (- (car (cdr time)) (car (cdr now)))))
!        (past-cutoff (- (* 6 30 24 60 60)))    ; 6 30-day months
!        (future-cutoff (* 60 60)))             ; 1 hour
      (condition-case nil
!       (format-time-string
!        (if (and
!             (<= past-cutoff diff) (<= diff future-cutoff)
!             ;; Sanity check in case `diff' computation overflowed.
!             (<= (1- (ash past-cutoff -16)) diff16)
!             (<= diff16 (1+ (ash future-cutoff -16))))
!            "%b %e %H:%M"
!          "%b %e  %Y")
!        time)
        (error "Unk  0  0000"))))
  
  (provide 'ls-lisp)
--- 515,554 ----
        ((memq ?t switches) 5)          ; last modtime
        ((memq ?u switches) 4)))        ; last access
  
+ (defun ls-lisp-time-to-seconds (time)
+   "Convert TIME to a floating point number."
+   (+ (* (car time) 65536.0)
+      (cadr time)
+      (/ (or (nth 2 time) 0) 1000000.0)))
+ 
  (defun ls-lisp-format-time (file-attr time-index now)
    "Format time for file with attributes FILE-ATTR according to TIME-INDEX.
  Use the same method as ls to decide whether to show time-of-day or year,
  depending on distance between file date and NOW.
  All ls time options, namely c, t and u, are handled."
    (let* ((time (nth (or time-index 5) file-attr)) ; default is last modtime
!        (diff (- (ls-lisp-time-to-seconds time)
!                 (ls-lisp-time-to-seconds now)))
!        ;; Consider a time to be recent if it is within the past six
!        ;; months.  A Gregorian year has 365.2425 * 24 * 60 * 60 ==
!        ;; 31556952 seconds on the average, and half of that is 15778476.
!        ;; Write the constant explicitly to avoid roundoff error.
!        (past-cutoff -15778476)) ; half a Gregorian year
      (condition-case nil
!       ;; Use traditional time format in the C or POSIX locale,
!       ;; ISO-style time format otherwise, so columns line up.
!       (let ((locale system-time-locale))
!         (if (not locale)
!             (let ((vars '("LC_ALL" "LC_TIME" "LANG")))
!               (while (and vars (not (setq locale (getenv (car vars)))))
!                 (setq vars (cdr vars)))))
!         (if (member locale '("C" "POSIX"))
!             (setq locale nil))
!         (format-time-string
!          (if (and (<= past-cutoff diff) (<= diff 0))
!              (if locale "%m-%d %H:%M" "%b %e %H:%M")
!            (if locale "%Y-%m-%d " "%b %e  %Y"))
!          time))
        (error "Unk  0  0000"))))
  
  (provide 'ls-lisp)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]