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, 09 May 2024 19:15:41 +0000 Message-ID: <87bk5eu78m.fsf@kubajecminek.cz> References: <87edbovjvj.fsf@kubajecminek.cz> <86bk6dr8wi.fsf@gnu.org> <87jzkqjclv.fsf@ericabrahamsen.net> <87le4tz61f.fsf@kubajecminek.cz> 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="6587"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eric Abrahamsen , 70134@debbugs.gnu.org, eliz@gnu.org, 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 09 21: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 1s59Fx-0001RB-Ri for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 09 May 2024 21:16:42 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s59Fm-0001Wg-02; Thu, 09 May 2024 15:16:30 -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 1s59FM-0001OT-Bp for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 15:16:10 -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 1s59FM-0004SU-3X for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 15:16:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s59FJ-0000W1-Tq for bug-gnu-emacs@gnu.org; Thu, 09 May 2024 15:16:01 -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, 09 May 2024 19: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.17152821541975 (code B ref 70134); Thu, 09 May 2024 19:16:01 +0000 Original-Received: (at 70134) by debbugs.gnu.org; 9 May 2024 19:15:54 +0000 Original-Received: from localhost ([127.0.0.1]:40794 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s59FB-0000Vn-7r for submit@debbugs.gnu.org; Thu, 09 May 2024 15:15:53 -0400 Original-Received: from mail-4317.proton.ch ([185.70.43.17]:62245) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s59F9-0000Vh-0n for 70134@debbugs.gnu.org; Thu, 09 May 2024 15:15:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kubajecminek.cz; s=protonmail; t=1715282146; x=1715541346; bh=AHWaDzYpveyJ+K+yDeZW4PMowfOTGA150wt7rgl9gcg=; 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=V/ue1oGlUVEFdAt4njkpneodpcfhwYLBRYCBvK5E4UncIcUZ54wXrHmq7xy4d7wha v0yB0DIp8NWWmSmTLyuAtEMPSPcRph2P3D5qRf9H26blsWejKO/hW6hkdbhmsTAZ9Y 2qfK1vX/yDGtM3tqrN5u3U/UB5pMM8t3wGwtfQx0pAl8OV7mZnTA+5+89BACCQOgDI UbWVEFIwmtgx8QOvSl7EEmbQ80e2bhuyXeC/Hf/eP0mtJLh+3He7MS2Zm1JdkSxrPW y7/uZO1EKCon4uSDGoF3YSFy/QVBRs+wo7fSVnBAZmP4YWjaIfQ7Er+X4qvhXI8E4G Y3d5QksFhApmg== In-Reply-To: Feedback-ID: 98803324:user:proton X-Pm-Message-ID: e22e678d79b47ebb12249123ed9c1ba7afeba335 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:284774 Archived-At: "Alex Bochannek" writes: > I finally had some time to look at these changes, apologies for the > delay. Thank you very much for your time and all your comments. > I like the approach and tested them out. The legal-types change in > gnus-summary-increase-score is straightforward and makes sense to me. I > have one stylistic comment: (nthcdr 3 s) seems to be easier to read to > me than (cdddr s), but I have no strong opinions on that. Thank you, I used (nthcdr 3 s) instead. > My suspicion is that this started out as a copy of the integer > comparison right above that code and I never cleaned it up. Yes, feel > free to simplify, I don't remember any good reason why it needs to pick > apart a list. It also seems perfectly fine to remove the (eq type > 'after) etc. stuff, it's not necessary anymore. I've adjusted only the age scoring part (not the integer comparison) because I did not studied that part of the code and there's still possibility that it is needed somehow. > The rest of the changes in gnus-summary-score-entry look good. I think > some more help text or additional documentation about the defaults would > be useful. It gets a bit confusing what you are prompted for. Having > said that, I like the idea of pulling a default date from the current > message, it just surprised me. I've added a comment explaining the changes I made to the date prompt. If you feel like the code needs more comments, please pinpoint where and I will add them. > I also think I might have found a bug in how the dates are written out > to the SCORE file. I interactively increased the score in the order of > <, r, n, b, and n as you can see below. Only the b, a, and n entries get > converted to the list format with the un-evaluated gnus-time after > another entry is written. Meaning the second and third entry below, the > "before" and "at," looked just like the topmost "at" entry before the > following entry was written. I've found the reason why it happens and found a solution. The problem is in the `gnus-date-get-time' macro. This macro accepts a single argument - date - and returns a different one - time - with text property added. However, this macro is written in such way that it modifies the input argument as well. We can fix it by adding `copy-sequence= ' function to the let form. > Hope this is useful! Very helpful yes. I've also noticed that the change I proposed - moving the part of the code which modifies match variable to the beginning of the `gnus-summary-score-entry' function is a bad idea because we're modifying input argument to the function. It would mean that if the user called the function non interactively (without prompt): (gnus-summary-score-entry "date" "55" '< 1000 nil) then it would change "55" to different number based on article age. I've moved that code back where it was. I attach the patch below. Thank you, Best >From 22c8bcc0b52b70baf9931d168a07fd69dbbd1e8c 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 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. --- lisp/gnus/gnus-score.el | 46 ++++++++++++++++++++--------------------- lisp/gnus/gnus-util.el | 2 +- 2 files changed, 24 insertions(+), 24 deletions(-) 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))) 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))) (if (equal "" d) =09 0 (or (get-text-property 0 'gnus-time d) --=20 2.34.1 --=20 Kuba Je=C4=8Dm=C3=ADnek (http://kubajecminek.cz)