Subject: bug#70134: closed (Re: bug#70134: [PATCH] Show all date options when adding Gnus scores interactively)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 07 Aug 2024 20:23:01 +0000

Your bug report

#70134: [PATCH] Show all date options when adding Gnus scores interactively

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
70134: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=70134
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#70134: [PATCH] Show all date options when adding Gnus scores interactively
From: Jakub Ječmínek <[email-masked]>
To: [email-masked]
Date: Wed, 07 Aug 2024 20:22:03 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Commited as 39b704e36e308783dcec791d333fca317c6a5202 so I'm closing this.

Subject: [PATCH] Show all date options when adding Gnus scores interactively
From: Jakub Ječmínek <[email-masked]>
To: [email-masked]
Cc: Eric Abrahamsen <[email-masked]>, [email-masked], Alex Bochannek <[email-masked]>
Date: Mon, 01 Apr 2024 21:44:04 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

Hello, I'm attaching a patch that enhances user experience when adding
Gnus scores interactively based on date header. This patch does multiple
things:

1. `char-to-type' variable is renamed to `char-to-types' and we allow it
to be mapped to multiple types. This is useful because date header
supports all these types for scoring - '<, '>, 'r, 'after, 'before, 'at
but only the last three were previously offered to the user when using
interactive scoring.

2. `gnus-summary-score-entry' now provides sensible defaults for each
date scoring type - if we're scoring based on integer value ('<, '>) we
offer number of days between now and entry at point (revised version of
what was introduced in bug#61002) and if we're scoring based on string
value ('after, 'before, 'at, 'r) we provide valid date string.

3. If the user scores articles based on date strings ('before, 'after,
'at, 'r), `gnus-summary-score-entry' will no longer cast the type to the
integer type.

4. `gnus-score-date' catches 'r type as well.

I'm also Cc'ing Alex who was the original author of '< '> date scoring
types. Please let me know what you think.

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.33, cairo version 1.16.0) of 2024-03-23 built on
 kuba-ThinkPad-T14-Gen-3
Repository revision: 7e32e8392ab77f9df08a1f11831cbba2242d721f
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12201001
System Description: Ubuntu 22.04.4 LTS

From 64659d65c3b43960bc0347d5be035ec64779b0ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Je=C4=8Dm=C3=ADnek?= <[email-masked]>
Date: Sat, 30 Mar 2024 00:34:07 +0100
Subject: [PATCH] Show all date options when adding Gnus scores interactively

* lisp/gnus/gnus-score.el (gnus-summary-increase-score): Rename
'char-to-type' variable to 'char-to-types' and allow multiple types
for each char.

* lisp/gnus/gnus-score.el (gnus-summary-score-entry): Provide better
default values for each scoring type and cast 'match' to number only
if necessary.
---
 lisp/gnus/gnus-score.el | 55 ++++++++++++++++++++---------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index 479b7496cf1..d7346581f2f 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -593,18 +593,18 @@ current score file."
 	    (?d "date" nil nil date)
 	    (?f "followup" nil nil string)
 	    (?t "thread" "message-id" nil string)))
-	 (char-to-type
+	 (char-to-types
 	  '((?s s "substring" string)
 	    (?e e "exact string" string)
 	    (?f f "fuzzy string" string)
-	    (?r r "regexp string" string)
+	    (?r r "regexp string" string date)
 	    (?z s "substring" body-string)
 	    (?p r "regexp string" body-string)
 	    (?b before "before date" date)
 	    (?a after "after date" date)
 	    (?n at "this date" date)
-	    (?< < "less than number" number)
-	    (?> > "greater than number" number)
+	    (?< < "less than number" number date)
+	    (?> > "greater than number" number date)
 	    (?= = "equal to number" number)))
 	 (current-score-file gnus-current-score-file)
 	 (char-to-perm
@@ -652,10 +652,9 @@ current score file."
 	  (let ((legal-types
 		 (delq nil
 		       (mapcar (lambda (s)
-				 (if (eq (nth 4 entry)
-					 (nth 3 s))
+				 (if (member (nth 4 entry) (cdddr s))
 				     s nil))
-			       char-to-type))))
+			       char-to-types))))
             (setq header-string
                   (format "%s header `%s' with match type (%s?): "
 			  (if increase "Increase" "Lower")
@@ -875,10 +874,18 @@ If optional argument `EXTRA' is non-nil, it's a non-standard overview header."
   (when (eq type t)
     (setq type 'r))
   ;; Simplify matches...
-  (cond ((or (eq type 'r) (eq type 's) (eq type nil))
+  (cond ((or (and (eq type 'r) (not (string= header "date"))) (eq type 's) (eq type nil))
 	 (setq match (if match (gnus-simplify-subject-re match) "")))
 	((eq type 'f)
-	 (setq match (gnus-simplify-subject-fuzzy match))))
+	 (setq match (gnus-simplify-subject-fuzzy match)))
+        ;; Provide better default values if we're scoring on date header
+        ((string= header "date")
+         (setq match (if (or (eq type '<) (eq type '>))
+                         (format-seconds "%d"
+                                         (time-subtract
+                                          (current-time)
+                                          (gnus-date-get-time match)))
+                       (substring-no-properties (gnus-date-iso8601 match))))))
   (let ((score (gnus-score-delta-default score))
 	(header (downcase header))
 	new)
@@ -893,14 +900,9 @@ If optional argument `EXTRA' is non-nil, it's a non-standard overview header."
 				 (t "permanent"))
 			   header
 			   (if (< score 0) "lower" "raise"))
-                   (cond ((numberp match) (int-to-string match))
-                         ((string= header "date")
-                          (int-to-string
-                           (-
-                            (/ (car (time-convert (current-time) 1)) 86400)
-                            (/ (car (time-convert (gnus-date-get-time match) 1))
-                               86400))))
-                         (t match)))))
+		   (if (numberp match)
+		       (int-to-string match)
+		     match))))
 
     ;; If this is an integer comparison, we transform from string to int.
     (if (eq (nth 2 (assoc header gnus-header-index)) 'gnus-score-integer)
@@ -909,16 +911,13 @@ If optional argument `EXTRA' is non-nil, it's a non-standard overview header."
       (set-text-properties 0 (length match) nil match))
 
     ;; Modify match and type for article age scoring.
-    (if (string= "date" (nth 0 (assoc header gnus-header-index)))
-	(let ((age (string-to-number match)))
-	  (if (or (< age 0)
-		  (string= "0" match))
-	      (user-error "Article age must be a positive number"))
-	  (setq match age
-		type (cond ((eq type 'after)
-			    '<)
-			   ((eq type 'before)
-			    '>)))))
+    (when (and (string= "date" (nth 0 (assoc header gnus-header-index)))
+               (or (eq type '<) (eq type '>)))
+      (let ((age (string-to-number match)))
+        (if (or (< age 0)
+                (string= "0" match))
+            (user-error "Article age must be a positive number"))
+        (setq match age)))
 
     (unless (eq date 'now)
       ;; Add the score entry to the score file.
@@ -1806,7 +1805,7 @@ score in `gnus-newsgroup-scored' by SCORE."
 	   ((eq type 'at)
 	    (setq match-func 'string=
 		  match (gnus-date-iso8601 (nth 0 kill))))
-	   ((eq type 'regexp)
+	   ((or (eq type 'regexp) (eq type 'r))
 	    (setq match-func 'string-match
 		  match (nth 0 kill)))
 	   (t (error "Invalid match type: %s" type)))
-- 
2.39.3 (Apple Git-145)