unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: Alex Bochannek <alex@bochannek.com>
Cc: "70134@debbugs.gnu.org" <70134@debbugs.gnu.org>,
	"Jakub Ječmínek" <kuba@kubajecminek.cz>,
	"Eli Zaretskii" <eliz@gnu.org>, "larsi@gnus.org" <larsi@gnus.org>,
	"Richard Stallman" <rms@gnu.org>
Subject: bug#70134: [PATCH] Show all date options when adding Gnus scores interactively
Date: Thu, 16 May 2024 07:15:14 -0700	[thread overview]
Message-ID: <87ikzd7si5.fsf@ericabrahamsen.net> (raw)
In-Reply-To: <87zfssdv50.fsf@kubajecminek.cz> ("Jakub Ječmínek via \"Bug reports for GNU Emacs, the Swiss army knife of text editors\""'s message of "Tue, 14 May 2024 19:57:20 +0000")

Jakub Ječmínek via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> "Alex Bochannek" <alex@bochannek.com> 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: =?UTF-8?q?Jakub=20Je=C4=8Dm=C3=ADnek?= <kuba@kubajecminek.cz>
> Date: Thu, 9 May 2024 20:33:58 +0200
> 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 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 <alex@bochannek.com>
> ---
>  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
>  
> +@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
> 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)
>  	    (?= = "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= header "date")
> -                          (int-to-string
> -                           (-
> -                            (/ (car (time-convert (current-time) 1)) 86400)
> -                            (/ (car (time-convert (gnus-date-get-time match) 1))
> -                               86400))))
> +                          (if (or (eq type '<) (eq type '>))
> +                              ;; Determine the time difference in days between today
> +                              ;; and the article's date
> +                              (format-seconds "%d"
> +                                              (time-subtract
> +                                               (current-time)
> +                                               (gnus-date-get-time match)))
> +                            (gnus-date-iso8601 match)))
>                           (t match)))))
>  
>      ;; 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))
>  
>      ;; 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= header "date")
> +               (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 +1806,7 @@ gnus-score-date
>  	   ((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)))
> 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?





  reply	other threads:[~2024-05-16 14:15 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01 21:44 bug#70134: [PATCH] Show all date options when adding Gnus scores interactively Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-04-13  7:58 ` Eli Zaretskii
2024-04-22  3:33   ` Eric Abrahamsen
2024-04-24 22:52     ` Richard Stallman
2024-04-24 23:08       ` Alex Bochannek
2024-05-01 19:27         ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-07  2:53           ` Alex Bochannek
2024-05-09 19:15             ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-09 23:59               ` Eric Abrahamsen
2024-05-10 20:04                 ` Eric Abrahamsen
2024-05-10 20:38                   ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-10 21:27                     ` Eric Abrahamsen
2024-05-14  2:00                     ` Alex Bochannek
2024-05-14 14:52                       ` Eric Abrahamsen
2024-05-14 18:43                         ` Alex Bochannek
2024-05-14 19:57                           ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-16 14:15                             ` Eric Abrahamsen [this message]
2024-05-16 19:40                               ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-22 21:34 ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-22 23:30   ` Alex Bochannek
2024-05-23  2:50     ` Eric Abrahamsen
2024-05-26 14:22       ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-26 22:09 ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-29 21:23 ` Jakub Ječmínek via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-05-30  0:16   ` Alex Bochannek
2024-05-30  9:01     ` Andrea Corallo
2024-05-30 16:30       ` Alex Bochannek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ikzd7si5.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=70134@debbugs.gnu.org \
    --cc=alex@bochannek.com \
    --cc=eliz@gnu.org \
    --cc=kuba@kubajecminek.cz \
    --cc=larsi@gnus.org \
    --cc=rms@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).