From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.bugs Subject: bug#70134: [PATCH] Show all date options when adding Gnus scores interactively Date: Thu, 16 May 2024 07:15:14 -0700 Message-ID: <87ikzd7si5.fsf@ericabrahamsen.net> References: <87edbovjvj.fsf@kubajecminek.cz> <87bk5eu78m.fsf@kubajecminek.cz> <87bk5esfiy.fsf@ericabrahamsen.net> <87y18hph60.fsf@ericabrahamsen.net> <87h6f08mzt.fsf@ericabrahamsen.net> <87zfssdv50.fsf@kubajecminek.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24817"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: "70134@debbugs.gnu.org" <70134@debbugs.gnu.org>, Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= , Eli Zaretskii , "larsi@gnus.org" , Richard Stallman To: Alex Bochannek Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 16 16:16:42 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1s7buS-0006EG-Rz for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 May 2024 16:16:40 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7btv-0001Dx-Cp; Thu, 16 May 2024 10:16:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s7btn-0001D9-Oi for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 10:15:59 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s7btn-0002rJ-En for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 10:15:59 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s7btp-00079h-IS for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 10:16:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eric Abrahamsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 May 2024 14:16:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70134 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 70134-submit@debbugs.gnu.org id=B70134.171586892727493 (code B ref 70134); Thu, 16 May 2024 14:16:01 +0000 Original-Received: (at 70134) by debbugs.gnu.org; 16 May 2024 14:15:27 +0000 Original-Received: from localhost ([127.0.0.1]:48977 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s7btG-00079N-Kn for submit@debbugs.gnu.org; Thu, 16 May 2024 10:15:27 -0400 Original-Received: from mail.ericabrahamsen.net ([52.70.2.18]:42324) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s7btE-00079F-Sg for 70134@debbugs.gnu.org; Thu, 16 May 2024 10:15:25 -0400 Original-Received: from localhost (71-212-21-65.tukw.qwest.net [71.212.21.65]) (Authenticated sender: eric@ericabrahamsen.net) by mail.ericabrahamsen.net (Postfix) with ESMTPSA id 86AF1FA01F; Thu, 16 May 2024 14:15:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ericabrahamsen.net; s=mail; t=1715868915; bh=HGYfsflVdsmqfCh2QEmG0hM7vSJwq2c9HpDMXH1SnEs=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Aq0rPO7ImphlDFHC1wirHUH9onPxhVJuh6+dLTNhYFFxOZxx4bJC3m3iMBSKqkC1Q 40uflVEz2tknv0bzrnvSPHDJncOFylAjFuBTuJbg6GOBzESn4ZegORH4B/L4HRB7f1 wCdcDeVqlt8Yxkm64Zpu9vsz6+zbx4wHltrPN2No= In-Reply-To: <87zfssdv50.fsf@kubajecminek.cz> ("Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\""'s message of "Tue, 14 May 2024 19:57:20 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:285155 Archived-At: Jakub Je=C4=8Dm=C3=ADnek via "Bug reports for GNU Emacs, the Swiss army kni= fe of text editors" writes: > "Alex Bochannek" writes: >> I have done some more testing with a fresh build and the most recent >> patch works as Jakub intends. I would like to suggest to add a change to >> (gnus) Summary Score Commands to include the new match types. Otherwise, >> I believe this patch is good to go. > > Thank you very much! > >> diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi >> index c5e4c885ccf..56f259db9a1 100644 >> --- a/doc/misc/gnus.texi >> +++ b/doc/misc/gnus.texi >> @@ -20093,6 +20093,9 @@ Summary Score Commands >> @item date >> @table @kbd >> >> +@item r >> +Regexp matching. >> + >> @item b >> Before date. >> >> @@ -20101,6 +20104,12 @@ Summary Score Commands >> >> @item n >> This date. >> + >> +@item < >> +Less than days. >> + >> +@item > >> +Greater than days. >> @end table >> >> @item number >> >> >> -- > > I've applied the patch and added co-authored-by message. > > From d69cf006f2e42da61714a179eb48a345a082fcf9 Mon Sep 17 00:00:00 2001 > From: =3D?UTF-8?q?Jakub=3D20Je=3DC4=3D8Dm=3DC3=3DADnek?=3D > Date: Thu, 9 May 2024 20:33:58 +0200 > Subject: [PATCH] Show all date options when adding Gnus scores interactiv= ely > > * lisp/gnus/gnus-score.el (gnus-summary-increase-score): Rename > 'char-to-type' variable to 'char-to-types' and bind all legal types > for date header. > > * 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. > > Co-authored-by: Alex Bochannek > --- > doc/misc/gnus.texi | 9 ++++++++ > lisp/gnus/gnus-score.el | 46 ++++++++++++++++++++--------------------- > lisp/gnus/gnus-util.el | 2 +- > 3 files changed, 33 insertions(+), 24 deletions(-) > > diff --git a/doc/misc/gnus.texi b/doc/misc/gnus.texi > index c5e4c885ccf..56f259db9a1 100644 > --- a/doc/misc/gnus.texi > +++ b/doc/misc/gnus.texi > @@ -20093,6 +20093,9 @@ Summary Score Commands > @item date > @table @kbd >=20=20 > +@item r > +Regexp matching. > + > @item b > Before date. >=20=20 > @@ -20101,6 +20104,12 @@ Summary Score Commands >=20=20 > @item n > This date. > + > +@item < > +Less than days. > + > +@item > > +Greater than days. > @end table >=20=20 > @item number > diff --git a/lisp/gnus/gnus-score.el b/lisp/gnus/gnus-score.el > index 479b7496cf1..4e9e0083424 100644 > --- a/lisp/gnus/gnus-score.el > +++ b/lisp/gnus/gnus-score.el > @@ -593,18 +593,18 @@ gnus-summary-increase-score > (?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) > (?=3D =3D "equal to number" number))) > (current-score-file gnus-current-score-file) > (char-to-perm > @@ -652,10 +652,9 @@ gnus-summary-increase-score > (let ((legal-types > (delq nil > (mapcar (lambda (s) > - (if (eq (nth 4 entry) > - (nth 3 s)) > + (if (member (nth 4 entry) (nthcdr 3 s)) > s nil)) > - char-to-type)))) > + char-to-types)))) > (setq header-string > (format "%s header `%s' with match type (%s?): " > (if increase "Increase" "Lower") > @@ -894,12 +893,16 @@ gnus-summary-score-entry > header > (if (< score 0) "lower" "raise")) > (cond ((numberp match) (int-to-string match)) > + ;; Provide better defaults if we're scoring on = date header > ((string=3D header "date") > - (int-to-string > - (- > - (/ (car (time-convert (current-time) 1)) 864= 00) > - (/ (car (time-convert (gnus-date-get-time ma= tch) 1)) > - 86400)))) > + (if (or (eq type '<) (eq type '>)) > + ;; Determine the time difference in days b= etween today > + ;; and the article's date > + (format-seconds "%d" > + (time-subtract > + (current-time) > + (gnus-date-get-time match= ))) > + (gnus-date-iso8601 match))) > (t match))))) >=20=20 > ;; If this is an integer comparison, we transform from string to int. > @@ -909,16 +912,13 @@ gnus-summary-score-entry > (set-text-properties 0 (length match) nil match)) >=20=20 > ;; Modify match and type for article age scoring. > - (if (string=3D "date" (nth 0 (assoc header gnus-header-index))) > - (let ((age (string-to-number match))) > - (if (or (< age 0) > - (string=3D "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=3D header "date") > + (or (eq type '<) (eq type '>))) > + (let ((age (string-to-number match))) > + (if (or (< age 0) > + (string=3D "0" match)) > + (user-error "Article age must be a positive number")) > + (setq match age))) >=20=20 > (unless (eq date 'now) > ;; Add the score entry to the score file. > @@ -1806,7 +1806,7 @@ gnus-score-date > ((eq type 'at) > (setq match-func 'string=3D > 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))) > diff --git a/lisp/gnus/gnus-util.el b/lisp/gnus/gnus-util.el > index 0b0a9bbfc1d..6097f517be0 100644 > --- a/lisp/gnus/gnus-util.el > +++ b/lisp/gnus/gnus-util.el > @@ -377,7 +377,7 @@ gnus-date-get-time > "Convert DATE string to Emacs time. > Cache the result as a text property stored in DATE." > ;; Either return the cached value... > - `(let ((d ,date)) > + `(let ((d (copy-sequence ,date))) My previous message about this macro still stands, though -- this change would break other code's use of the macro as a "cache". Is there another way to resolve the problem?