From 9e2d2f3c5084e290935304a372a38a3ded2e95b0 Mon Sep 17 00:00:00 2001 From: Lars Magne Ingebrigtsen Date: Wed, 26 Jan 2011 15:31:06 -0800 Subject: [PATCH] (article-lapsed-string): Refactor out and allow specifying how many segments you want. --- lisp/ChangeLog | 2 + lisp/gnus-art.el | 97 +++++++++++++++++++++++++++--------------------- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 4c93ce092..ba4276241 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -3,6 +3,8 @@ * gnus-art.el (gnus-article-next-page): When the last line of the article is displayed, scroll down once more instead of going to the next article at once. + (article-lapsed-string): Refactor out and allow specifying how many + segments you want. * shr.el: Revert change that made headings use different-sized faces. The Emacs display engine isn't advanced enough that, for instance, diff --git a/lisp/gnus-art.el b/lisp/gnus-art.el index 110e5c867..96f3136c2 100644 --- a/lisp/gnus-art.el +++ b/lisp/gnus-art.el @@ -3500,7 +3500,7 @@ should replace the \"Date:\" one, or should be added below it." (defun article-make-date-line (date type) "Return a DATE line of TYPE." - (unless (memq type '(local ut original user iso8601 lapsed english)) + (unless (memq type '(local ut original user iso8601 lapsed english date-lapsed)) (error "Unknown conversion type: %s" type)) (condition-case () (let ((time (date-to-time date))) @@ -3548,47 +3548,10 @@ should replace the \"Date:\" one, or should be added below it." (/ (% (abs tz) 3600) 60))))) ;; Do an X-Sent lapsed format. ((eq type 'lapsed) - ;; If the date is seriously mangled, the timezone functions are - ;; liable to bug out, so we ignore all errors. - (let* ((now (current-time)) - (real-time (subtract-time now time)) - (real-sec (and real-time - (+ (* (float (car real-time)) 65536) - (cadr real-time)))) - (sec (and real-time (abs real-sec))) - num prev) - (cond - ((null real-time) - "X-Sent: Unknown") - ((zerop sec) - "X-Sent: Now") - (t - (concat - "X-Sent: " - ;; This is a bit convoluted, but basically we go - ;; through the time units for years, weeks, etc, - ;; and divide things to see whether that results - ;; in positive answers. - (mapconcat - (lambda (unit) - (if (zerop (setq num (ffloor (/ sec (cdr unit))))) - ;; The (remaining) seconds are too few to - ;; be divided into this time unit. - "" - ;; It's big enough, so we output it. - (setq sec (- sec (* num (cdr unit)))) - (prog1 - (concat (if prev ", " "") (int-to-string - (floor num)) - " " (symbol-name (car unit)) - (if (> num 1) "s" "")) - (setq prev t)))) - article-time-units "") - ;; If dates are odd, then it might appear like the - ;; article was sent in the future. - (if (> real-sec 0) - " ago" - " in the future")))))) + (concat "X-Sent: " (article-lapsed-string time))) + ;; A combined date/lapsed format. + ((eq type 'date-lapsed) + (concat "Date: " (article-lapsed-string time 3))) ;; Display the date in proper English ((eq type 'english) (let ((dtime (decode-time time))) @@ -3610,9 +3573,57 @@ should replace the \"Date:\" one, or should be added below it." (format "%02d" (nth 2 dtime)) ":" (format "%02d" (nth 1 dtime))))))) - (error + (foo (format "Date: %s (from Gnus)" date)))) +(defun article-lapsed-string (time &optional max-segments) + ;; If the date is seriously mangled, the timezone functions are + ;; liable to bug out, so we ignore all errors. + (let* ((now (current-time)) + (real-time (subtract-time now time)) + (real-sec (and real-time + (+ (* (float (car real-time)) 65536) + (cadr real-time)))) + (sec (and real-time (abs real-sec))) + (segments 0) + num prev) + (unless max-segments + (setq max-segments (length article-time-units))) + (cond + ((null real-time) + "X-Sent: Unknown") + ((zerop sec) + "X-Sent: Now") + (t + (concat + "X-Sent: " + ;; This is a bit convoluted, but basically we go + ;; through the time units for years, weeks, etc, + ;; and divide things to see whether that results + ;; in positive answers. + (mapconcat + (lambda (unit) + (if (or (zerop (setq num (ffloor (/ sec (cdr unit))))) + (>= segments max-segments)) + ;; The (remaining) seconds are too few to + ;; be divided into this time unit. + "" + ;; It's big enough, so we output it. + (setq sec (- sec (* num (cdr unit)))) + (prog1 + (concat (if prev ", " "") (int-to-string + (floor num)) + " " (symbol-name (car unit)) + (if (> num 1) "s" "")) + (setq prev t + segments (1+ segments))))) + article-time-units "") + ;; If dates are odd, then it might appear like the + ;; article was sent in the future. + (if (> real-sec 0) + " ago" + " in the future")))))) + (defun article-date-local (&optional highlight) "Convert the current article date to the local timezone." (interactive (list t)) -- 2.25.1