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: [PATCH] Allow applying filters to summary consecutively (was: Summary by thread in rmail) Date: Sun, 09 Oct 2022 22:33:01 +0200 Message-ID: <874jwc91qa.fsf@autistici.org> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36862"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sun Oct 09 22:34:09 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 1ohczx-0009Kb-4R for ged-emacs-devel@m.gmane-mx.org; Sun, 09 Oct 2022 22:34:09 +0200 Original-Received: from localhost ([::1]:59674 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ohczv-00043T-QH for ged-emacs-devel@m.gmane-mx.org; Sun, 09 Oct 2022 16:34:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohcz9-00038V-FI for emacs-devel@gnu.org; Sun, 09 Oct 2022 16:33:19 -0400 Original-Received: from devianza.investici.org ([198.167.222.108]:25793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ohcz6-0002Zl-Or; Sun, 09 Oct 2022 16:33:19 -0400 Original-Received: from mx2.investici.org (unknown [127.0.0.1]) by devianza.investici.org (Postfix) with ESMTP id 4Mltz33GvPz6vMN; Sun, 9 Oct 2022 20:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1665347583; bh=5WX3ouogxVYrOr3z+Bxgr3WRaK5aWkQb4bc48iFThpQ=; h=From:To:Cc:Subject:In-Reply-To:Date:From; b=miJdS8gZ4AnSx2XSz/USUvU3vIy1+fL0Tv1qmhDI7FVp2RSl/2LmUw/IsIuvgfIDj ndAHU4/xWinzOockg8bykYdSWVAZOrHV2P+KiiDp7mQlzZJGVk4z5ryLjl0ErG+OBd yj6Gu7gpifxF4ATd8GqluE2UBO2yCrqrpzRrsIzE= Original-Received: from [198.167.222.108] (mx2.investici.org [198.167.222.108]) (Authenticated sender: andrea.monaco@autistici.org) by localhost (Postfix) with ESMTPSA id 4Mltz31Csdz6vMM; Sun, 9 Oct 2022 20:33:03 +0000 (UTC) In-Reply-To: (message from Richard Stallman on Thu, 06 Oct 2022 18:04:51 -0400) Received-SPF: pass client-ip=198.167.222.108; envelope-from=andrea.monaco@autistici.org; helo=devianza.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: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:297291 Archived-At: This patch adds optional argument keep-filtering to rmail-summary-by-* commands. When t, the filter works on the currently displayed summary. I also wrote a command rmail-summary-negate to invert the current selection of displayed messages. Andrea Monaco diff --git a/lisp/mail/rmailsum.el b/lisp/mail/rmailsum.el index b959f45250..24cad60bda 100644 --- a/lisp/mail/rmailsum.el +++ b/lisp/mail/rmailsum.el @@ -50,6 +50,13 @@ rmail-summary-line-count-flag :type 'boolean :group 'rmail-summary) +(defvar rmail-summary-currently-displayed-msgs nil + "String made of 'y' and 'n'. At index i it tells wether +message i is shown on the summary or not. First character is +ignored. Used when applying rmail-summary-by-* commands +consecutively.") +(put 'rmail-summary-currently-displayed-msgs 'permanent-local t) + (defvar rmail-summary-font-lock-keywords '(("^ *[0-9]+D.*" . font-lock-string-face) ; Deleted. ("^ *[0-9]+-.*" . font-lock-type-face) ; Unread. @@ -267,6 +274,33 @@ 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." + (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))))) + +(defun rmail-summary-negate () + "Invert the current set of displayed messages in the summary." + (interactive) + (rmail-summary-fill-displayed-messages) + (rmail-new-summary "Negate" + '(rmail-summary-by-regexp ".*" t) + (lambda (msg) + (if + (char-equal (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))))) ;;;###autoload (defun rmail-summary () "Display a summary of all messages, one line per message." @@ -274,7 +308,7 @@ rmail-summary (rmail-new-summary "All" '(rmail-summary) nil)) ;;;###autoload -(defun rmail-summary-by-labels (labels) +(defun rmail-summary-by-labels (labels &optional keep-filtering) "Display a summary of all messages with one or more LABELS. LABELS should be a string containing the desired labels, separated by commas." (interactive "sLabels to summarize by: ") @@ -282,25 +316,40 @@ rmail-summary-by-labels (setq labels (or rmail-last-multi-labels (error "No label specified")))) (setq rmail-last-multi-labels labels) + (if keep-filtering + (rmail-summary-fill-displayed-messages)) (rmail-new-summary (concat "labels " labels) - (list 'rmail-summary-by-labels labels) - 'rmail-message-labels-p + (list 'rmail-summary-by-labels labels keep-filtering) + (if keep-filtering + (lambda (msg l) + (and (char-equal (aref rmail-summary-currently-displayed-msgs msg) + ?y) + (rmail-message-labels-p msg l))) + 'rmail-message-labels-p) (concat " \\(" (mail-comma-list-regexp labels) "\\)\\(,\\|\\'\\)"))) ;;;###autoload -(defun rmail-summary-by-recipients (recipients &optional primary-only) +(defun rmail-summary-by-recipients (recipients &optional primary-only keep-filtering) "Display a summary of all messages with the given RECIPIENTS. Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY is non-nil (prefix arg given), only look in the To and From fields. RECIPIENTS is a regular expression." (interactive "sRecipients to summarize by: \nP") + (if keep-filtering + (rmail-summary-fill-displayed-messages)) (rmail-new-summary (concat "recipients " recipients) - (list 'rmail-summary-by-recipients recipients primary-only) - 'rmail-message-recipients-p recipients primary-only)) + (list 'rmail-summary-by-recipients recipients primary-only keep-filtering) + (if keep-filtering + (lambda (msg r) + (and (char-equal (aref rmail-summary-currently-displayed-msgs msg) + ?y) + (rmail-message-recipients-p msg r))) + 'rmail-message-recipients-p) + recipients primary-only)) (defun rmail-message-recipients-p (msg recipients &optional primary-only) (rmail-apply-in-message msg 'rmail-message-recipients-p-1 @@ -318,7 +367,7 @@ rmail-message-recipients-p-1 ;; Also, the optional WHOLE-MESSAGE argument of r-s-by-topic would ;; seem more natural here. ;;;###autoload -(defun rmail-summary-by-regexp (regexp) +(defun rmail-summary-by-regexp (regexp &optional keep-filtering) "Display a summary of all messages according to regexp REGEXP. If the regular expression is found in the header of the message \(including in the date and other lines, as well as the subject line), @@ -328,9 +377,16 @@ rmail-summary-by-regexp (setq regexp (or rmail-last-regexp (error "No regexp specified")))) (setq rmail-last-regexp regexp) + (if keep-filtering + (rmail-summary-fill-displayed-messages)) (rmail-new-summary (concat "regexp " regexp) - (list 'rmail-summary-by-regexp regexp) - 'rmail-message-regexp-p + (list 'rmail-summary-by-regexp regexp keep-filtering) + (if keep-filtering + (lambda (msg r) + (and (char-equal (aref rmail-summary-currently-displayed-msgs msg) + ?y) + (rmail-message-regexp-p msg r))) + 'rmail-message-regexp-p) regexp)) (defun rmail-message-regexp-p (msg regexp) @@ -363,7 +419,7 @@ rmail-message-regexp-p-1 (rmail--decode-and-apply 're-search-forward regexp nil t))) ;;;###autoload -(defun rmail-summary-by-topic (subject &optional whole-message) +(defun rmail-summary-by-topic (subject &optional whole-message keep-filtering) "Display a summary of all messages with the given SUBJECT. Normally checks just the Subject field of headers; but with prefix argument WHOLE-MESSAGE is non-nil, looks in the whole message. @@ -376,10 +432,18 @@ rmail-summary-by-topic (if subject ", default current subject" "") "): "))) (list (read-string prompt nil nil subject) current-prefix-arg))) + (if keep-filtering + (rmail-summary-fill-displayed-messages)) (rmail-new-summary (concat "about " subject) - (list 'rmail-summary-by-topic subject whole-message) - 'rmail-message-subject-p subject whole-message)) + (list 'rmail-summary-by-topic subject whole-message keep-filtering) + (if keep-filtering + (lambda (msg s wo) + (and (char-equal (aref rmail-summary-currently-displayed-msgs msg) + ?y) + (rmail-message-subject-p msg s wo))) + 'rmail-message-subject-p) + subject whole-message)) (defun rmail-message-subject-p (msg subject &optional whole-message) (if whole-message @@ -389,7 +453,7 @@ rmail-message-subject-p (string-match subject (rmail-simplified-subject msg)))) ;;;###autoload -(defun rmail-summary-by-senders (senders) +(defun rmail-summary-by-senders (senders &optional keep-filtering) "Display a summary of all messages whose \"From\" field matches SENDERS. SENDERS is a regular expression. The default for SENDERS matches the sender of the current message." @@ -402,9 +466,18 @@ rmail-summary-by-senders (if sender ", default this message's sender" "") "): "))) (list (read-string prompt nil nil sender)))) + (if keep-filtering + (rmail-summary-fill-displayed-messages)) (rmail-new-summary (concat "senders " senders) - (list 'rmail-summary-by-senders senders) 'rmail-message-senders-p senders)) + (list 'rmail-summary-by-senders senders keep-filtering) + (if keep-filtering + (lambda (msg s) + (and (char-equal (aref rmail-summary-currently-displayed-msgs msg) + ?y) + (rmail-message-senders-p msg s))) + 'rmail-message-senders-p) + senders)) (defun rmail-message-senders-p (msg senders) (string-match senders (or (rmail-get-header "From" msg) "")))