[gnus git] branch master updated: =2= Change the Date defaults to showing a combined, continuosly updated "lapsed" format. ; (article-lapsed-string): Refactor out and allow specifying how many segments you want.

Lars Magne Ingebrigtsen <[email protected]>
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  85148cc66e2b9ea96ed9373e892aacd718c53d69 (commit)
       via  9e2d2f3c5084e290935304a372a38a3ded2e95b0 (commit)
      from  659352f2cfd41471c57ed9d3cdd810fcda50edc0 (commit)


- Log -----------------------------------------------------------------
commit 85148cc66e2b9ea96ed9373e892aacd718c53d69
Author: Lars Magne Ingebrigtsen <[email protected]>
Date:   Wed Jan 26 15:50:11 2011 -0800

    Change the Date defaults to showing a combined, continuosly updated "lapsed" format.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ba42762..900b5a5 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -5,6 +5,8 @@
 	next article at once.
 	(article-lapsed-string): Refactor out and allow specifying how many
 	segments you want.
+	(gnus-article-setup-buffer): Start updating the lapsed header directly.
+	(gnus-article-update-lapsed-header): New variable.
 
 	* 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 96f3136..327250e 100644
--- a/lisp/gnus-art.el
+++ b/lisp/gnus-art.el
@@ -1023,6 +1023,15 @@ be added below it (otherwise)."
   :group 'gnus-article-headers
   :type 'boolean)
 
+(defcustom gnus-article-update-lapsed-header 1
+  "How often to update the lapsed date header.
+If nil, don't update it at all."
+  :version "24.1"
+  :group 'gnus-article-headers
+  :type '(choice
+	  (item :tag "Don't update" :value nil)
+	  integer))
+
 (defcustom gnus-article-mime-match-handle-function 'undisplayed-alternative
   "Function called with a MIME handle as the argument.
 This is meant for people who want to view first matched part.
@@ -1290,6 +1299,14 @@ predicate.  See Info node `(gnus)Customizing Articles'."
   :link '(custom-manual "(gnus)Customizing Articles")
   :type gnus-article-treat-head-custom)
 
+(defcustom gnus-treat-date-combined-lapsed 'head
+  "Display the Date header in a way that says how much time has elapsed.
+Valid values are nil, t, `head', `first', `last', an integer or a
+predicate.  See Info node `(gnus)Customizing Articles'."
+  :group 'gnus-article-treat
+  :link '(custom-manual "(gnus)Customizing Articles")
+  :type gnus-article-treat-head-custom)
+
 (defcustom gnus-treat-date-original nil
   "Display the date in the original timezone.
 Valid values are nil, t, `head', `first', `last', an integer or a
@@ -1680,6 +1697,7 @@ regexp."
     (gnus-treat-date-user-defined gnus-article-date-user)
     (gnus-treat-date-iso8601 gnus-article-date-iso8601)
     (gnus-treat-date-lapsed gnus-article-date-lapsed)
+    (gnus-treat-date-combined-lapsed gnus-article-date-combined-lapsed)
     (gnus-treat-display-x-face gnus-article-display-x-face)
     (gnus-treat-display-face gnus-article-display-face)
     (gnus-treat-hide-headers gnus-article-maybe-hide-headers)
@@ -3500,7 +3518,8 @@ 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 date-lapsed))
+  (unless (memq type '(local ut original user iso8601 lapsed english
+			     combined-lapsed))
     (error "Unknown conversion type: %s" type))
   (condition-case ()
       (let ((time (date-to-time date)))
@@ -3550,8 +3569,9 @@ should replace the \"Date:\" one, or should be added below it."
 	 ((eq type 'lapsed)
 	  (concat "X-Sent: " (article-lapsed-string time)))
 	 ;; A combined date/lapsed format.
-	 ((eq type 'date-lapsed)
-	  (concat "Date: " (article-lapsed-string time 3)))
+	 ((eq type 'combined-lapsed)
+	  (concat (article-make-date-line date 'original)
+		  " (" (article-lapsed-string time 3) ")"))
 	 ;; Display the date in proper English
 	 ((eq type 'english)
 	  (let ((dtime (decode-time time)))
@@ -3591,12 +3611,11 @@ should replace the \"Date:\" one, or should be added below it."
       (setq max-segments (length article-time-units)))
     (cond
      ((null real-time)
-      "X-Sent: Unknown")
+      "Unknown")
      ((zerop sec)
-      "X-Sent: Now")
+      "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
@@ -3646,6 +3665,11 @@ function and want to see what the date was before converting."
   (interactive (list t))
   (article-date-ut 'lapsed highlight))
 
+(defun article-date-combined-lapsed (&optional highlight)
+  "Convert the current article date to time lapsed since it was sent."
+  (interactive (list t))
+  (article-date-ut 'combined-lapsed highlight))
+
 (defun article-update-date-lapsed ()
   "Function to be run from a timer to update the lapsed time line."
   (save-match-data
@@ -3658,8 +3682,10 @@ function and want to see what the date was before converting."
 	    (when (eq major-mode 'gnus-article-mode)
 	      (let ((mark (point-marker)))
 		(goto-char (point-min))
-		(when (re-search-forward "^X-Sent:" nil t)
-		  (article-date-lapsed t))
+		(when (re-search-forward "^X-Sent:\\|^Date:" nil t)
+		  (if gnus-treat-date-combined-lapsed
+		      (article-date-combined-lapsed t)
+		    (article-date-lapsed t)))
 		(goto-char (marker-position mark))
 		(move-marker mark nil))))
 	  nil 'visible))))))
@@ -4307,6 +4333,7 @@ If variable `gnus-use-long-file-name' is non-nil, it is
      article-decode-encoded-words
      article-date-user
      article-date-lapsed
+     article-date-combined-lapsed
      article-emphasize
      article-treat-dumbquotes
      article-treat-non-ascii
@@ -4503,6 +4530,9 @@ commands:
 	(setq gnus-summary-buffer
 	      (gnus-summary-buffer-name gnus-newsgroup-name))
 	(gnus-summary-set-local-parameters gnus-newsgroup-name)
+	(when (and gnus-article-update-lapsed-header
+		   (not article-lapsed-timer))
+	  (gnus-start-date-timer gnus-article-update-lapsed-header))
 	(current-buffer)))))
 
 ;; Set article window start at LINE, where LINE is the number of lines

commit 9e2d2f3c5084e290935304a372a38a3ded2e95b0
Author: Lars Magne Ingebrigtsen <[email protected]>
Date:   Wed Jan 26 15:31:06 2011 -0800

    (article-lapsed-string): Refactor out and allow specifying how many segments you want.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 4c93ce0..ba42762 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 110e5c8..96f3136 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,6 +3548,35 @@ should replace the \"Date:\" one, or should be added below it."
 		     (/ (% (abs tz) 3600) 60)))))
 	 ;; Do an X-Sent lapsed format.
 	 ((eq type 'lapsed)
+	  (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)))
+	    (concat
+	     "Date: the "
+	     (number-to-string (nth 3 dtime))
+	     (let ((digit (% (nth 3 dtime) 10)))
+	       (cond
+		((memq (nth 3 dtime) '(11 12 13)) "th")
+		((= digit 1) "st")
+		((= digit 2) "nd")
+		((= digit 3) "rd")
+		(t "th")))
+	     " of "
+	     (nth (1- (nth 4 dtime)) gnus-english-month-names)
+	     " "
+	     (number-to-string (nth 5 dtime))
+	     " at "
+	     (format "%02d" (nth 2 dtime))
+	     ":"
+	     (format "%02d" (nth 1 dtime)))))))
+    (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))
@@ -3556,7 +3585,10 @@ should replace the \"Date:\" one, or should be added below it."
 				(+ (* (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")
@@ -3571,7 +3603,8 @@ should replace the \"Date:\" one, or should be added below it."
 	       ;; in positive answers.
 	       (mapconcat
 		(lambda (unit)
-		  (if (zerop (setq num (ffloor (/ sec (cdr 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.
 		      ""
@@ -3582,36 +3615,14 @@ should replace the \"Date:\" one, or should be added below it."
 						   (floor num))
 				" " (symbol-name (car unit))
 				(if (> num 1) "s" ""))
-		      (setq prev t))))
+	      (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"))))))
-	 ;; Display the date in proper English
-	 ((eq type 'english)
-	  (let ((dtime (decode-time time)))
-	    (concat
-	     "Date: the "
-	     (number-to-string (nth 3 dtime))
-	     (let ((digit (% (nth 3 dtime) 10)))
-	       (cond
-		((memq (nth 3 dtime) '(11 12 13)) "th")
-		((= digit 1) "st")
-		((= digit 2) "nd")
-		((= digit 3) "rd")
-		(t "th")))
-	     " of "
-	     (nth (1- (nth 4 dtime)) gnus-english-month-names)
-	     " "
-	     (number-to-string (nth 5 dtime))
-	     " at "
-	     (format "%02d" (nth 2 dtime))
-	     ":"
-	     (format "%02d" (nth 1 dtime)))))))
-    (error
-     (format "Date: %s (from Gnus)" date))))
 
 (defun article-date-local (&optional highlight)
   "Convert the current article date to the local timezone."

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog   |    4 ++
 lisp/gnus-art.el |  131 +++++++++++++++++++++++++++++++++++------------------
 2 files changed, 90 insertions(+), 45 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.