all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrea Monaco <andrea.monaco@autistici.org>
To: emacs-devel@gnu.org
Cc: rms@gnu.org
Subject: [PATCH] Allow applying filters to summary consecutively (was: Summary by thread in rmail)
Date: Sun, 09 Oct 2022 22:33:01 +0200	[thread overview]
Message-ID: <874jwc91qa.fsf@autistici.org> (raw)
In-Reply-To: <E1ogYz5-0001tF-6s@fencepost.gnu.org> (message from Richard Stallman on Thu, 06 Oct 2022 18:04:51 -0400)


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) "")))



  parent reply	other threads:[~2022-10-09 20:33 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-05 18:31 Summary by thread in rmail Andrea Monaco
2022-10-05 18:49 ` Eli Zaretskii
2022-10-05 23:40 ` Emanuel Berg
2022-10-06 22:04 ` Richard Stallman
2022-10-07 10:17   ` Andrea Monaco
2022-10-07 11:24     ` Emanuel Berg
2022-10-09 20:33   ` Andrea Monaco [this message]
2022-10-10  7:31     ` [PATCH] Allow applying filters to summary consecutively (was: Summary by thread in rmail) Eli Zaretskii
2022-10-10  8:38       ` Andrea Monaco
2022-10-10  8:57         ` Eli Zaretskii
2022-10-11  7:16           ` [PATCH v2] " Andrea Monaco
2022-10-11  8:13             ` [PATCH v2] Allow applying filters to summary consecutively Robert Pluim
2022-10-12  9:35               ` Andrea Monaco
2022-10-12 11:03                 ` Robert Pluim
2022-10-12 12:56                 ` Eli Zaretskii
2022-10-12 18:13                   ` Andrea Monaco
2022-10-12 18:22                     ` Eli Zaretskii
2022-10-12 22:02                 ` Richard Stallman
2022-10-19 14:23                   ` [PATCH v3] " Andrea Monaco
2022-10-19 14:55                     ` Robert Pluim
2022-10-20 15:45                       ` Andrea Monaco
2022-10-20 16:02                         ` Robert Pluim
2022-10-20 19:00                           ` Andrea Monaco
2022-10-21 19:42                             ` Richard Stallman
2022-10-21 19:38                     ` Richard Stallman
2022-10-27 14:27                     ` Eli Zaretskii
2022-10-27 15:22                       ` Andrea Monaco
2022-10-28 13:26                       ` Andrea Monaco
2022-11-06  7:34                         ` Eli Zaretskii
2022-11-07 14:13                           ` Andrea Monaco
2022-11-08  5:02                             ` Richard Stallman
2022-11-08  8:04                               ` Andrea Monaco
2022-11-14  3:13                                 ` Richard Stallman
2022-11-10  4:04                             ` Richard Stallman
2022-11-10  8:06                               ` Eli Zaretskii
2022-11-10  8:53                                 ` Robert Pluim
2022-11-11  4:36                                 ` Richard Stallman
2022-11-11  8:06                                   ` Eli Zaretskii
2022-11-11 14:59                                     ` Juanma Barranquero
2022-11-11 17:23                                       ` Eli Zaretskii
2022-11-11 17:32                                       ` [External] : " Drew Adams
2022-11-11 18:00                                     ` Gregory Heytings
2022-11-11 18:19                                       ` Eli Zaretskii
2022-11-11 18:52                                         ` Gregory Heytings
2022-11-11 18:54                                           ` Gregory Heytings
2022-11-11 19:34                                             ` Eli Zaretskii
2022-11-11 19:33                                           ` Eli Zaretskii
2022-11-11 20:50                                             ` Gregory Heytings
2022-11-12  3:37                                               ` Richard Stallman
2022-11-12  7:52                                                 ` Eli Zaretskii
2022-11-12  6:57                                               ` Eli Zaretskii
2022-11-12 16:30                                                 ` Gregory Heytings
2022-11-12 17:44                                                   ` Andrea Monaco
2022-11-12 18:13                                                     ` Gregory Heytings
2022-11-14  3:13                                                       ` Richard Stallman
2022-11-14  8:39                                                         ` Gregory Heytings
2022-11-15  4:18                                                           ` Richard Stallman
2022-11-15  9:56                                                             ` Gregory Heytings
2022-11-16  3:15                                                               ` Richard Stallman
2022-11-16  3:15                                                               ` Richard Stallman
2022-11-24 18:25                                                                 ` Andrea Monaco
2022-11-28 21:38                                                                   ` Richard Stallman
2022-11-15 17:00                                                             ` [External] : " Drew Adams
2022-11-14  3:13                                                     ` Richard Stallman
2022-11-15  9:35                                                       ` Gregory Heytings
2022-11-16  3:15                                                         ` Richard Stallman
2022-11-19 14:47                                                           ` Gregory Heytings
2022-11-20 17:37                                                             ` Richard Stallman
2022-11-20 19:36                                                               ` Gregory Heytings
2022-11-22 12:14                                                                 ` Richard Stallman
2022-11-22 12:58                                                                   ` Gregory Heytings
2022-11-28 21:38                                                                     ` Richard Stallman
2022-11-23 20:57                                                               ` chad
2022-11-24  6:39                                                                 ` Eli Zaretskii
2022-11-28 21:38                                                                   ` Richard Stallman
2022-11-26  0:51                                                                 ` Richard Stallman
2022-11-11 18:22                                       ` [External] : " Drew Adams
2022-11-12  3:35                                     ` Richard Stallman
2022-11-12  7:47                                       ` Eli Zaretskii
2022-11-14  3:13                                         ` Richard Stallman
2022-11-17 13:34                             ` Eli Zaretskii
2022-10-27 13:58             ` [PATCH v2] Allow applying filters to summary consecutively (was: Summary by thread in rmail) Eli Zaretskii
2022-10-10 22:03     ` [PATCH] " Richard Stallman

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

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

  git send-email \
    --in-reply-to=874jwc91qa.fsf@autistici.org \
    --to=andrea.monaco@autistici.org \
    --cc=emacs-devel@gnu.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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.