unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
@ 2020-09-08  1:28 Alex Bochannek
  2020-09-08  9:51 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bochannek @ 2020-09-08  1:28 UTC (permalink / raw)
  To: 43270

[-- Attachment #1: Type: text/plain, Size: 403 bytes --]

The below patch to Gnus allows for scoring based on article age.

For example:

(("date"
  (7 10 nil <)
  (7 -10 nil >)
  (14 -10 nil >)))

results in articles less than a week old to get a 10 point increase,
older than a week a 10 point decrease, and older than two weeks a
cumulative 20 point decrease.

I am also including a documentation change. I have not made any changes
to interactive scoring.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Enhance gnus-score-date to support scoring by article age (code) --]
[-- Type: text/x-patch, Size: 1637 bytes --]

*** /Users/awb/Desktop/gnus-score.el.~1~	2020-07-27 14:21:49.000000000 -0700
--- /Users/awb/Desktop/gnus-score.el	2020-09-07 12:21:36.000000000 -0700
***************
*** 1370,1378 ****
  	       (setq
  		err
  		(cond
! 		 ((if (member (downcase type) '("lines" "chars"))
! 		      (not (numberp (car s)))
! 		    (not (stringp (car s))))
  		  (format "Invalid match %s in %s" (car s) file))
  		 ((and (cadr s) (not (integerp (cadr s))))
  		  (format "Non-integer score %s in %s" (cadr s) file))
--- 1370,1381 ----
  	       (setq
  		err
  		(cond
! 		 ((cond ((member (downcase type) '("lines" "chars"))
! 			 (not (numberp (car s))))
! 			((string= (downcase type) "date")
! 			 (not (or (numberp (car s))
! 				  (stringp (car s)))))
! 			(t (not (stringp (car s)))))
  		  (format "Invalid match %s in %s" (car s) file))
  		 ((and (cadr s) (not (integerp (cadr s))))
  		  (format "Non-integer score %s in %s" (cadr s) file))
***************
*** 1690,1698 ****
--- 1693,1711 ----
  	   ((eq type 'after)
  	    (setq match-func 'string<
  		  match (gnus-date-iso8601 (nth 0 kill))))
+ 	   ((eq type '<)
+ 	    (setq type 'after
+ 		  match-func 'gnus-string>
+ 		  match (gnus-time-iso8601
+ 			 (time-add (current-time) (* 86400 (nth 0 kill))))))
  	   ((eq type 'before)
  	    (setq match-func 'gnus-string>
  		  match (gnus-date-iso8601 (nth 0 kill))))
+ 	   ((eq type '>)
+ 	    (setq type 'before
+ 		  match-func 'gnus-string>
+ 		  match (gnus-time-iso8601
+ 			 (time-add (current-time) (* -86400 (nth 0 kill))))))
  	   ((eq type 'at)
  	    (setq match-func 'string=
  		  match (gnus-date-iso8601 (nth 0 kill))))

[-- Attachment #3: Enhance gnus-score-date to support scoring by article age (info) --]
[-- Type: text/x-patch, Size: 791 bytes --]

*** /Users/awb/Desktop/gnus.info.~1~	2020-08-11 22:15:17.000000000 -0700
--- /Users/awb/Desktop/gnus.info	2020-09-07 18:14:22.000000000 -0700
***************
*** 16155,16160 ****
--- 16155,16168 ----
                 from.  Time zones are such wholesome fun for the whole
                 family, eh?)
  
+                The two additional match types ‘<’ and ‘>’ take an integer
+                number of days as a match, similar to ‘lines’:
+ 
+                       (7 -10 nil >)
+ 
+               The above reduces the score for articles older than 7 days
+               at scoring time by 10.
+ 
            “Head, Body, All”
                 These three match keys use the same match types as the
                 ‘From’ (etc.) header uses.

[-- Attachment #4: Type: text/plain, Size: 11 bytes --]


-- 
Alex.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-08  1:28 bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age Alex Bochannek
@ 2020-09-08  9:51 ` Lars Ingebrigtsen
  2020-09-09 23:59   ` Alex Bochannek
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-08  9:51 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 43270

Alex Bochannek <alex@bochannek.com> writes:

> The below patch to Gnus allows for scoring based on article age.
>
> For example:
>
> (("date"
>   (7 10 nil <)
>   (7 -10 nil >)
>   (14 -10 nil >)))
>
> results in articles less than a week old to get a 10 point increase,
> older than a week a 10 point decrease, and older than two weeks a
> cumulative 20 point decrease.

Thanks; applied with one change:

> *** /Users/awb/Desktop/gnus.info.~1~	2020-08-11 22:15:17.000000000 -0700
> --- /Users/awb/Desktop/gnus.info	2020-09-07 18:14:22.000000000 -0700

[...]

> +                The two additional match types ‘<’ and ‘>’ take an integer
> +                number of days as a match, similar to ‘lines’:

The .info files are generated files -- the documentation goes into
doc/misc/gnus.texi (and I expanded upon the feature somewhat based on
your email).

The patch is just small enough to go through without a copyright
assignment (and I forgot to mark the commit as such; sigh), but for any
future patches you might send, we'd need to have the copyright assigned
to the FSF.  Would you be willing to do that?  If so, we could start the
ball rolling now on the paperwork, so that any subsequent patches can be
applied faster.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-08  9:51 ` Lars Ingebrigtsen
@ 2020-09-09 23:59   ` Alex Bochannek
  2020-09-10 13:16     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bochannek @ 2020-09-09 23:59 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 43270

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> The .info files are generated files -- the documentation goes into
> doc/misc/gnus.texi (and I expanded upon the feature somewhat based on
> your email).

Thanks for the reminder, forgot about that.

Looks like I inverted the logic for '<'. New patch attached.

> The patch is just small enough to go through without a copyright
> assignment (and I forgot to mark the commit as such; sigh), but for any
> future patches you might send, we'd need to have the copyright assigned
> to the FSF.  Would you be willing to do that?  If so, we could start the
> ball rolling now on the paperwork, so that any subsequent patches can be
> applied faster.

I believe my employer is already on file, so if there are any more
substantial contributions, I can use that.

Thanks!

-- 
Alex.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Fix inverted logic in gnus-score-date when scoring by less-than date --]
[-- Type: text/x-patch, Size: 938 bytes --]

diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index c5156a195a..12f733ac13 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -1695,9 +1695,9 @@ gnus-score-date
 		  match (gnus-date-iso8601 (nth 0 kill))))
 	   ((eq type '<)
 	    (setq type 'after
-		  match-func 'gnus-string>
+		  match-func 'string<
 		  match (gnus-time-iso8601
-			 (time-add (current-time) (* 86400 (nth 0 kill))))))
+			 (time-subtract (current-time) (* 86400 (nth 0 kill))))))
 	   ((eq type 'before)
 	    (setq match-func 'gnus-string>
 		  match (gnus-date-iso8601 (nth 0 kill))))
@@ -1705,7 +1705,7 @@ gnus-score-date
 	    (setq type 'before
 		  match-func 'gnus-string>
 		  match (gnus-time-iso8601
-			 (time-add (current-time) (* -86400 (nth 0 kill))))))
+			 (time-subtract (current-time) (* 86400 (nth 0 kill))))))
 	   ((eq type 'at)
 	    (setq match-func 'string=
 		  match (gnus-date-iso8601 (nth 0 kill))))

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-09 23:59   ` Alex Bochannek
@ 2020-09-10 13:16     ` Lars Ingebrigtsen
  2020-09-11  0:58       ` Alex Bochannek
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-10 13:16 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 43270

Alex Bochannek <alex@bochannek.com> writes:

> Looks like I inverted the logic for '<'. New patch attached.

Thanks; applied.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-10 13:16     ` Lars Ingebrigtsen
@ 2020-09-11  0:58       ` Alex Bochannek
  2020-09-11 12:17         ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bochannek @ 2020-09-11  0:58 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 43270

[-- Attachment #1: Type: text/plain, Size: 383 bytes --]

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Alex Bochannek <alex@bochannek.com> writes:
>
>> Looks like I inverted the logic for '<'. New patch attached.
>
> Thanks; applied.

Thanks, Lars! Below is another small patch to also support article age
in interactive scoring. I wasn't sure about the error handling, so feel
free to change that if there is a preferred style.

-- 
Alex.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Modify gnus-summary-score-entry to support interactive article scoring by age --]
[-- Type: text/x-patch, Size: 830 bytes --]

diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el
index 6a0e8ceb99..fce7b68db1 100644
--- a/lisp/gnus/gnus-score.el
+++ b/lisp/gnus/gnus-score.el
@@ -862,6 +862,18 @@ gnus-summary-score-entry
 	    (setq match (string-to-number match)))
       (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)
+			    '>)))))
+
     (unless (eq date 'now)
       ;; Add the score entry to the score file.
       (when (= score gnus-score-interactive-default-score)

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-11  0:58       ` Alex Bochannek
@ 2020-09-11 12:17         ` Lars Ingebrigtsen
  2020-09-12  6:14           ` Alex Bochannek
  0 siblings, 1 reply; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-11 12:17 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 43270

Alex Bochannek <alex@bochannek.com> writes:

> Thanks, Lars! Below is another small patch to also support article age
> in interactive scoring. I wasn't sure about the error handling, so feel
> free to change that if there is a preferred style.

Looks good -- you said your employer was on file (for the copyright
assignment), but you didn't say who your employer was.  :-)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-11 12:17         ` Lars Ingebrigtsen
@ 2020-09-12  6:14           ` Alex Bochannek
  2020-09-12 12:04             ` Lars Ingebrigtsen
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bochannek @ 2020-09-12  6:14 UTC (permalink / raw)
  To: Lars Ingebrigtsen; +Cc: 43270

Lars Ingebrigtsen <larsi@gnus.org> writes:

> Alex Bochannek <alex@bochannek.com> writes:
>
>> Thanks, Lars! Below is another small patch to also support article age
>> in interactive scoring. I wasn't sure about the error handling, so feel
>> free to change that if there is a preferred style.
>
> Looks good -- you said your employer was on file (for the copyright
> assignment), but you didn't say who your employer was.  :-)

Yes, I heard back from the folks in Legal and they confirmed a CLA is in
place. I am at Google <abochannek@google.com>

Thanks!

-- 
Alex.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age
  2020-09-12  6:14           ` Alex Bochannek
@ 2020-09-12 12:04             ` Lars Ingebrigtsen
  0 siblings, 0 replies; 8+ messages in thread
From: Lars Ingebrigtsen @ 2020-09-12 12:04 UTC (permalink / raw)
  To: Alex Bochannek; +Cc: 43270

Alex Bochannek <alex@bochannek.com> writes:

> Lars Ingebrigtsen <larsi@gnus.org> writes:
>
>> Alex Bochannek <alex@bochannek.com> writes:
>>
>>> Thanks, Lars! Below is another small patch to also support article age
>>> in interactive scoring. I wasn't sure about the error handling, so feel
>>> free to change that if there is a preferred style.
>>
>> Looks good -- you said your employer was on file (for the copyright
>> assignment), but you didn't say who your employer was.  :-)
>
> Yes, I heard back from the folks in Legal and they confirmed a CLA is in
> place. I am at Google <abochannek@google.com>

Thanks for checking; I've now applied your patch to the trunk.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-09-12 12:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-08  1:28 bug#43270: 27.1; [PATCH] Enhance gnus-score-date to support scoring by article age Alex Bochannek
2020-09-08  9:51 ` Lars Ingebrigtsen
2020-09-09 23:59   ` Alex Bochannek
2020-09-10 13:16     ` Lars Ingebrigtsen
2020-09-11  0:58       ` Alex Bochannek
2020-09-11 12:17         ` Lars Ingebrigtsen
2020-09-12  6:14           ` Alex Bochannek
2020-09-12 12:04             ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).