From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Andrea Monaco Newsgroups: gmane.emacs.devel Subject: Re: [PATCH v3] Allow applying filters to summary consecutively Date: Fri, 28 Oct 2022 15:26:39 +0200 Message-ID: <871qqshyeo.fsf@autistici.org> References: <83y1t1l4tz.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16488"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, rpluim@gmail.com, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Oct 28 15:27:51 2022 Return-path: Envelope-to: ged-emacs-devel@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 1ooPOp-00045h-AS for ged-emacs-devel@m.gmane-mx.org; Fri, 28 Oct 2022 15:27:51 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ooPNx-0006jK-C8; Fri, 28 Oct 2022 09:26:57 -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 1ooPNt-0006Nv-5x for emacs-devel@gnu.org; Fri, 28 Oct 2022 09:26:53 -0400 Original-Received: from latitanza.investici.org ([82.94.249.234]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ooPNq-0005od-8G; Fri, 28 Oct 2022 09:26:52 -0400 Original-Received: from mx3.investici.org (unknown [127.0.0.1]) by latitanza.investici.org (Postfix) with ESMTP id 4MzNcL2Z8DzGp38; Fri, 28 Oct 2022 13:26:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1666963602; bh=SPWKf6GnCzuWZRog0w7rO7GI1lGya9kqCEnAtEwOYQw=; h=From:To:Cc:Subject:In-Reply-To:Date:From; b=hpn8PYOtPaEh+gui30BQILWR5xFy+xphIfjoi23zKDe+jXRJSGmJrG49aoFKXJkDj +aVyCY86vEtMKUZc2q1LdhWkOt9U+Ll0GAryC4PVLuPsUrPx49Er0eHasTdp6AwD/m ZMha13e9G8jzDyKs5IqIsnBW1U9RGg/aemhKjwkE= Original-Received: from [82.94.249.234] (mx3.investici.org [82.94.249.234]) (Authenticated sender: andrea.monaco@autistici.org) by localhost (Postfix) with ESMTPSA id 4MzNcL0YvSzGp2g; Fri, 28 Oct 2022 13:26:42 +0000 (UTC) In-Reply-To: <83y1t1l4tz.fsf@gnu.org> (message from Eli Zaretskii on Thu, 27 Oct 2022 17:27:20 +0300) Received-SPF: pass client-ip=82.94.249.234; envelope-from=andrea.monaco@autistici.org; helo=latitanza.investici.org X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: "Emacs-devel" Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:298673 Archived-At: This version should be final. I change the name of the new configuration item. It will also work as expected when generating a filtered summary with no existing summary. Moreover, pressing q (rmail-summary-quit) will kill the summary so the next filter starts from scratch. I add a function called rmail-summary--exists-1. The existing rmail-summary-exists is not enough and I didn't know if changing it could break something. Andrea Monaco Fix application of consecutive filters in rmail. * lisp/mail/rmailsum.el (rmail-summary-intersect-consecutive-filters): Change name. (rmail-summary-currently-displayed-msgs): Change to a bool-vector that is more natural. (rmail-summary-populate-displayed-messages): Change name. (rmail-summary--exists-1): New function. (rmail-summary-by-labels, rmail-summary-by-recipients) (rmail-summary-by-regexp, rmail-summary-by-topic) (rmail-summary-by-senders): Fix so they work correctly when they are invoked and no summary exists. diff --git a/lisp/mail/rmailsum.el b/lisp/mail/rmailsum.el index 0144a34e5e..b522449157 100644 --- a/lisp/mail/rmailsum.el +++ b/lisp/mail/rmailsum.el @@ -50,21 +50,18 @@ rmail-summary-line-count-flag :type 'boolean :group 'rmail-summary) -(defcustom rmail-summary-apply-filters-consecutively nil - "If non-nil, Rmail summary commands apply filtering on top existing filtering. -When this variable is non-nil, `rmail-summary-by-*' commands work on the -current summary, and so their filtering can be stacked one on top of another. -This allows gradual narrowing of the selection of the messages." +(defcustom rmail-summary-intersect-consecutive-filters nil + "Non-nil means that commands rmail-summary-by-* works on the +current summary and so can be intersected one after the other." :type 'boolean :version "29.1" :group 'rmail-summary) (defvar rmail-summary-currently-displayed-msgs nil - "String made of `y' and `n'. -The character at position i tells wether message i is shown in the -summary or not. First character is ignored. -Used when applying `rmail-summary-by-*' commands consecutively. Filled -by `rmail-summary-fill-displayed-messages'.") + "Boolean vector that for index i tells whether message i is +shown on the summary or not. First element is ignored. Used +when applying rmail-summary-by-* commands consecutively. Filled +by rmail-summary-populate-displayed-messages.") (put 'rmail-summary-currently-displayed-msgs 'permanent-local t) (defvar rmail-summary-font-lock-keywords @@ -284,33 +281,39 @@ rmail-summary-mode-map (defun rmail-update-summary (&rest _) (apply (car rmail-summary-redo) (cdr rmail-summary-redo))) -(defun rmail-summary-fill-displayed-messages () - "Fill the rmail-summary-currently-displayed-msgs string." +(defun rmail-summary-populate-displayed-messages () + "Populate the rmail-summary-currently-displayed-msgs vector." (with-current-buffer rmail-buffer - (with-current-buffer rmail-summary-buffer - (setq rmail-summary-currently-displayed-msgs - (make-string (1+ rmail-total-messages) ?n)) - (goto-char (point-min)) - (while (not (eobp)) - (aset rmail-summary-currently-displayed-msgs - (string-to-number (thing-at-point 'line)) - ?y) - (forward-line 1))))) + (let ((totmsgs rmail-total-messages)) + (with-current-buffer rmail-summary-buffer + (setq rmail-summary-currently-displayed-msgs + (make-bool-vector (1+ totmsgs) nil)) + (goto-char (point-min)) + (while (not (eobp)) + (aset rmail-summary-currently-displayed-msgs + (string-to-number (thing-at-point 'line)) + t) + (forward-line 1)))))) (defun rmail-summary-negate () - "Toggle display of messages that match the summary and those which do not." + "Negate the current summary. That is, show the messages that +are not displayed, and vice versa." (interactive) - (rmail-summary-fill-displayed-messages) + (rmail-summary-populate-displayed-messages) (rmail-new-summary "Negate" '(rmail-summary-by-regexp ".*") (lambda (msg) (if - (= (aref rmail-summary-currently-displayed-msgs msg) - ?n) - (progn - (aset rmail-summary-currently-displayed-msgs msg ?y) t) - (progn - (aset rmail-summary-currently-displayed-msgs msg ?n) nil))))) + (eq (aref rmail-summary-currently-displayed-msgs msg) + nil) + (aset rmail-summary-currently-displayed-msgs msg t) + (aset rmail-summary-currently-displayed-msgs msg nil))))) + +(defun rmail-summary--exists-1 () + "Like rmail-summary-exists, but works in both main and summary buffers." + (with-current-buffer rmail-buffer + (and rmail-summary-buffer (buffer-name rmail-summary-buffer) + rmail-summary-buffer))) ;;;###autoload (defun rmail-summary () @@ -327,14 +330,16 @@ rmail-summary-by-labels (setq labels (or rmail-last-multi-labels (error "No label specified")))) (setq rmail-last-multi-labels labels) - (if rmail-summary-apply-filters-consecutively - (rmail-summary-fill-displayed-messages)) + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) + (rmail-summary-populate-displayed-messages)) (rmail-new-summary (concat "labels " labels) (list 'rmail-summary-by-labels labels) - (if rmail-summary-apply-filters-consecutively + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) (lambda (msg l) - (and (= (aref rmail-summary-currently-displayed-msgs msg) - ?y) + (and (eq (aref rmail-summary-currently-displayed-msgs msg) + t) (rmail-message-labels-p msg l))) 'rmail-message-labels-p) (concat " \\(" @@ -349,15 +354,17 @@ rmail-summary-by-recipients only look in the To and From fields. RECIPIENTS is a regular expression." (interactive "sRecipients to summarize by: \nP") - (if rmail-summary-apply-filters-consecutively - (rmail-summary-fill-displayed-messages)) + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) + (rmail-summary-populate-displayed-messages)) (rmail-new-summary (concat "recipients " recipients) (list 'rmail-summary-by-recipients recipients primary-only) - (if rmail-summary-apply-filters-consecutively + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) (lambda (msg r &optional po) - (and (= (aref rmail-summary-currently-displayed-msgs msg) - ?y) + (and (eq (aref rmail-summary-currently-displayed-msgs msg) + t) (rmail-message-recipients-p msg r po))) 'rmail-message-recipients-p) recipients primary-only)) @@ -388,14 +395,16 @@ rmail-summary-by-regexp (setq regexp (or rmail-last-regexp (error "No regexp specified")))) (setq rmail-last-regexp regexp) - (if rmail-summary-apply-filters-consecutively - (rmail-summary-fill-displayed-messages)) + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) + (rmail-summary-populate-displayed-messages)) (rmail-new-summary (concat "regexp " regexp) (list 'rmail-summary-by-regexp regexp) - (if rmail-summary-apply-filters-consecutively + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) (lambda (msg r) - (and (= (aref rmail-summary-currently-displayed-msgs msg) - ?y) + (and (eq (aref rmail-summary-currently-displayed-msgs msg) + t) (rmail-message-regexp-p msg r))) 'rmail-message-regexp-p) regexp)) @@ -443,15 +452,17 @@ rmail-summary-by-topic (if subject ", default current subject" "") "): "))) (list (read-string prompt nil nil subject) current-prefix-arg))) - (if rmail-summary-apply-filters-consecutively - (rmail-summary-fill-displayed-messages)) + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) + (rmail-summary-populate-displayed-messages)) (rmail-new-summary (concat "about " subject) (list 'rmail-summary-by-topic subject whole-message) - (if rmail-summary-apply-filters-consecutively + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) (lambda (msg s &optional wm) - (and (= (aref rmail-summary-currently-displayed-msgs msg) - ?y) + (and (eq (aref rmail-summary-currently-displayed-msgs msg) + t) (rmail-message-subject-p msg s wm))) 'rmail-message-subject-p) subject whole-message)) @@ -477,15 +488,17 @@ rmail-summary-by-senders (if sender ", default this message's sender" "") "): "))) (list (read-string prompt nil nil sender)))) - (if rmail-summary-apply-filters-consecutively - (rmail-summary-fill-displayed-messages)) + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) + (rmail-summary-populate-displayed-messages)) (rmail-new-summary (concat "senders " senders) (list 'rmail-summary-by-senders senders) - (if rmail-summary-apply-filters-consecutively + (if (and rmail-summary-intersect-consecutive-filters + (rmail-summary--exists-1)) (lambda (msg s) - (and (= (aref rmail-summary-currently-displayed-msgs msg) - ?y) + (and (eq (aref rmail-summary-currently-displayed-msgs msg) + t) (rmail-message-senders-p msg s))) 'rmail-message-senders-p) senders))