From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#70134: [PATCH] Show all date options when adding Gnus scores interactively Date: Thu, 16 May 2024 19:40:03 +0000 Message-ID: <874jaxzgtr.fsf@kubajecminek.cz> References: <87edbovjvj.fsf@kubajecminek.cz> <87bk5esfiy.fsf@ericabrahamsen.net> <87y18hph60.fsf@ericabrahamsen.net> <87h6f08mzt.fsf@ericabrahamsen.net> <87zfssdv50.fsf@kubajecminek.cz> <87ikzd7si5.fsf@ericabrahamsen.net> Reply-To: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= 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="31636"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "70134@debbugs.gnu.org" <70134@debbugs.gnu.org>, Eli Zaretskii , "larsi@gnus.org" , Alex Bochannek , Richard Stallman To: Eric Abrahamsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu May 16 21:41:12 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 1s7gyV-00080Y-Tn for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 May 2024 21:41:12 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s7gyM-0005Tr-BN; Thu, 16 May 2024 15:41:02 -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 1s7gyK-0005TM-ES for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 15:41:00 -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 1s7gyK-0000S1-5w for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 15:41:00 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s7gyM-0002xk-8E for bug-gnu-emacs@gnu.org; Thu, 16 May 2024 15:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jakub =?UTF-8?Q?Je=C4=8Dm=C3=ADnek?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 May 2024 19:41:02 +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.171588842211358 (code B ref 70134); Thu, 16 May 2024 19:41:02 +0000 Original-Received: (at 70134) by debbugs.gnu.org; 16 May 2024 19:40:22 +0000 Original-Received: from localhost ([127.0.0.1]:50588 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s7gxi-0002x8-2z for submit@debbugs.gnu.org; Thu, 16 May 2024 15:40:22 -0400 Original-Received: from mail-40136.proton.ch ([185.70.40.136]:36135) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s7gxc-0002x1-5g for 70134@debbugs.gnu.org; Thu, 16 May 2024 15:40:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kubajecminek.cz; s=protonmail; t=1715888407; x=1716147607; bh=YmWDdEdXhxKxwJknYwvIYE5qckUPVlE6//jDYiZ9Lwo=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=jilybH0kWMN/HPnykWINkr6zmmCbdDjBpEQLybniAeOGQGx3iRvNoDayLzmlhl5qT O8MgJs67qQA4pFkHAnSiDdMv+ZkVI1hZ3TD+MAytJFesvDnc46rNVIEnnRwzqHqIWs 4vn3uvgQ3IoFoTzGlHU9k5aPl/unm6Vaqw5Eqp59M9W9AerAoEgyAeRNxeR0+u9LKS datY5LbvBDm2b1HFThunxNUfjRlGLRP1WpbxRYoLbcfkcScDVQLCe3lqWr0YsN0cBg DrPJS9D2GkBAiTaH+jXHIsg2dMbBtsqpt2GrTHTJ0JpTMpqwGw6kxhRZTF1plxVimc ZkTNFZqEmlg1g== In-Reply-To: <87ikzd7si5.fsf@ericabrahamsen.net> Feedback-ID: 98803324:user:proton X-Pm-Message-ID: d5249c09dc5c721762efa3f589b9495b5fe67bbe 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:285196 Archived-At: "Eric Abrahamsen" writes: > 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? Oh, shoot, I realized the mistake only when I wrote the ert tests as a response to this message. I stand corrected, I'm sorry. I have to think abo= ut other ways how to resolve the bug, though... I'm sending the patch without the macro change: >From e281f37263ca6b307df9ca124d7d3121d86a2b11 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Jakub=3D20Je=3DC4=3D8Dm=3DC3=3DADnek?=3D Date: Thu, 16 May 2024 21:38:01 +0200 Subject: [PATCH] Show all date options when adding Gnus scores interactivel= y * 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 ++++++++++++++++++++--------------------- 2 files changed, 32 insertions(+), 23 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 +@item r +Regexp matching. + @item b Before date. =20 @@ -20101,6 +20104,12 @@ Summary Score Commands =20 @item n This date. + +@item < +Less than days. + +@item > +Greater than days. @end table =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 =09 (?d "date" nil nil date) =09 (?f "followup" nil nil string) =09 (?t "thread" "message-id" nil string))) -=09 (char-to-type +=09 (char-to-types =09 '((?s s "substring" string) =09 (?e e "exact string" string) =09 (?f f "fuzzy string" string) -=09 (?r r "regexp string" string) +=09 (?r r "regexp string" string date) =09 (?z s "substring" body-string) =09 (?p r "regexp string" body-string) =09 (?b before "before date" date) =09 (?a after "after date" date) =09 (?n at "this date" date) -=09 (?< < "less than number" number) -=09 (?> > "greater than number" number) +=09 (?< < "less than number" number date) +=09 (?> > "greater than number" number date) =09 (?=3D =3D "equal to number" number))) =09 (current-score-file gnus-current-score-file) =09 (char-to-perm @@ -652,10 +652,9 @@ gnus-summary-increase-score =09 (let ((legal-types =09=09 (delq nil =09=09 (mapcar (lambda (s) -=09=09=09=09 (if (eq (nth 4 entry) -=09=09=09=09=09 (nth 3 s)) +=09=09=09=09 (if (member (nth 4 entry) (nthcdr 3 s)) =09=09=09=09 s nil)) -=09=09=09 char-to-type)))) +=09=09=09 char-to-types)))) (setq header-string (format "%s header `%s' with match type (%s?): " =09=09=09 (if increase "Increase" "Lower") @@ -894,12 +893,16 @@ gnus-summary-score-entry =09=09=09 header =09=09=09 (if (< score 0) "lower" "raise")) (cond ((numberp match) (int-to-string match)) + ;; Provide better defaults if we're scoring on da= te header ((string=3D header "date") - (int-to-string - (- - (/ (car (time-convert (current-time) 1)) 86400= ) - (/ (car (time-convert (gnus-date-get-time matc= h) 1)) - 86400)))) + (if (or (eq type '<) (eq type '>)) + ;; Determine the time difference in days bet= ween 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 ;; 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 ;; Modify match and type for article age scoring. - (if (string=3D "date" (nth 0 (assoc header gnus-header-index))) -=09(let ((age (string-to-number match))) -=09 (if (or (< age 0) -=09=09 (string=3D "0" match)) -=09 (user-error "Article age must be a positive number")) -=09 (setq match age -=09=09type (cond ((eq type 'after) -=09=09=09 '<) -=09=09=09 ((eq type 'before) -=09=09=09 '>))))) + (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 (unless (eq date 'now) ;; Add the score entry to the score file. @@ -1806,7 +1806,7 @@ gnus-score-date =09 ((eq type 'at) =09 (setq match-func 'string=3D =09=09 match (gnus-date-iso8601 (nth 0 kill)))) -=09 ((eq type 'regexp) +=09 ((or (eq type 'regexp) (eq type 'r)) =09 (setq match-func 'string-match =09=09 match (nth 0 kill))) =09 (t (error "Invalid match type: %s" type))) --=20 2.34.1 --=20 Kuba Je=C4=8Dm=C3=ADnek (http://kubajecminek.cz)