From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: [PATCH v3] Allow applying filters to summary consecutively Date: Wed, 19 Oct 2022 16:55:21 +0200 Message-ID: <87zgdruali.fsf@gmail.com> References: <87k04vj3ji.fsf@autistici.org> 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="40923"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rms@gnu.org, eliz@gnu.org, emacs-devel@gnu.org To: Andrea Monaco Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Wed Oct 19 16:58:40 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 1olAWl-000ANt-Fw for ged-emacs-devel@m.gmane-mx.org; Wed, 19 Oct 2022 16:58:39 +0200 Original-Received: from localhost ([::1]:38404 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1olAWk-0004TX-42 for ged-emacs-devel@m.gmane-mx.org; Wed, 19 Oct 2022 10:58:38 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49166) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olATk-0002Hv-A8 for emacs-devel@gnu.org; Wed, 19 Oct 2022 10:55:32 -0400 Original-Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]:34358) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1olATf-0006sO-Qp; Wed, 19 Oct 2022 10:55:32 -0400 Original-Received: by mail-wm1-x32b.google.com with SMTP id l14-20020a05600c1d0e00b003c6ecc94285so928404wms.1; Wed, 19 Oct 2022 07:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=rqpV8fc3HFGjxcAi79NbRBE/6cdMrgt1MSSKeOQaEpI=; b=a1pbjHhX+aP8djNRq15gM5CQhlcgftQEtapkHGH6x2FXamjYdf7gkwOK9M183Jaitl L7h1G6GsIJ8sPwukhB3GmZNqdEGOKba87L2OStrV5QQ49xNbiQXD7nSKeSR/+ZZGGlcB Fbgj+HHY7h/hL37Uw4T2I71bA/aof8ayYyBlXH3vEAPi/xaEhrc8y9p0p4kqylzBgirR 3xpPukfSFY3GItjC1hfw7ZCoID2O2uRaMHK6q7Mc0flmi6yjGvIYwg/1FF/2x/nMgoh9 9BlGy1gix2dpkChd6wDrmZbwdDkSPlSw3bxoAx130Do37ZJxrJ2UNElUgaV92JFwvPhx 8NSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rqpV8fc3HFGjxcAi79NbRBE/6cdMrgt1MSSKeOQaEpI=; b=OEpZRUpx0JZKDmA8OE5G2yHmKRDzNfDr/kll76cMOGJ/1PKqV5cnW6ADnkfknk6U7y d7XudR9nzBMMRm1q41ay0WwnIzwZakUicexObBNAvR0cWTbXRgcDuFS0q7PSxsWgqLWQ eDWAm4NWjmA+oUm3djV1S7IFCX26IigFc4cP0YHqi2sYVEXHu9UtMNQZHIWYax2LXFpZ WAquJe+e/98Twvm1/G5CGk2V/vi48R5u+uOs1oCSE45MCx3iaWvmbl/wJ4dq+P0Qf2ry P93Sun9fe6Q+1ekTgZPtHU9jhJuxP6fylalncFBbXyAE3O5yY+kdKqas5dfg/PTiXxOf 1eGw== X-Gm-Message-State: ACrzQf0Oh/ztdXvy6ZVUOrl4veiujaovP/C4YSIscuMug76b9erolXNl 0QJc92fMxPDc6LUkiTMeEtHzzGtpeUo= X-Google-Smtp-Source: AMsMyM6FltNhmQicn2WELpw/Z9jEzSrC8b2FBIkyD+9yscQJuGd1eLbN6QDI7i9WMgxZ8xcP08vbRg== X-Received: by 2002:a05:600c:3555:b0:3b4:c0fd:918e with SMTP id i21-20020a05600c355500b003b4c0fd918emr5834005wmq.61.1666191323491; Wed, 19 Oct 2022 07:55:23 -0700 (PDT) Original-Received: from rltb ([82.66.8.55]) by smtp.gmail.com with ESMTPSA id q1-20020adfdfc1000000b0022e049586c5sm13828846wrn.28.2022.10.19.07.55.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Oct 2022 07:55:22 -0700 (PDT) In-Reply-To: <87k04vj3ji.fsf@autistici.org> (Andrea Monaco's message of "Wed, 19 Oct 2022 16:23:13 +0200") Received-SPF: pass client-ip=2a00:1450:4864:20::32b; envelope-from=rpluim@gmail.com; helo=mail-wm1-x32b.google.com 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, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=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:298118 Archived-At: Hi Andrea, some comments below >>>>> On Wed, 19 Oct 2022 16:23:13 +0200, Andrea Monaco said: Andrea> +(defcustom rmail-summary-apply-filters-consecutively nil Andrea> + "Non-nil means that commands rmail-summary-by-* works Andrea> on the I=CA=BCd call it `rmail-summary-stack-filters' and say "Whether rmail-summary-by-* commands stack on each other." Andrea> +current summary and so can be stacked one after the other." Andrea> + :type 'boolean Andrea> + :group 'rmail-summary) This needs a :version "29.1" Andrea> +(defvar rmail-summary-currently-displayed-msgs nil Andrea> + "String made of 'y' and 'n'. At index i it tells Andrea> wether "whether" Andrea> +message i is shown on the summary or not. First character is Andrea> +ignored. Used when applying rmail-summary-by-* commands Andrea> +consecutively. Filled by Andrea> +rmail-summary-fill-displayed-messages.") Andrea> +(put 'rmail-summary-currently-displayed-msgs 'permanent-local = t) Andrea> + It=CA=BCs a string that you treat as a vector, so why not just make it a vector? Also 'fill' in Emacs normally means wrapping paragraphs of text, so perhaps `rmail-summary-populate-displayed-messages' or similar is better. Andrea> (defvar rmail-summary-font-lock-keywords Andrea> '(("^ *[0-9]+D.*" . font-lock-string-face) ; Deleted. Andrea> ("^ *[0-9]+-.*" . font-lock-type-face) ; Unread. Andrea> @@ -267,6 +281,35 @@ rmail-summary-mode-map Andrea> (defun rmail-update-summary (&rest _) Andrea> (apply (car rmail-summary-redo) (cdr rmail-summary-redo))) =20 Andrea> +(defun rmail-summary-fill-displayed-messages () Andrea> + "Fill the rmail-summary-currently-displayed-msgs string." Andrea> + (with-current-buffer rmail-buffer Andrea> + (with-current-buffer rmail-summary-buffer Andrea> + (setq rmail-summary-currently-displayed-msgs Andrea> + (make-string (1+ rmail-total-messages) ?n)) Andrea> + (goto-char (point-min)) Andrea> + (while (not (eobp)) Andrea> + (aset rmail-summary-currently-displayed-msgs Andrea> + (string-to-number (thing-at-point 'line)) Andrea> + ?y) Andrea> + (forward-line 1))))) I don=CA=BCt remember the details of rmail=CA=BCs summary line format, but I think you=CA=BCd be better served with (thing-at-point 'number) (that also avoids the `string-to-number') Andrea> + Andrea> +(defun rmail-summary-negate () Andrea> + "Negate the current summary. That is, show the messages that Andrea> +are not displayed, and vice versa." The first line of the docstring should be a single complete sentence on a single line. Andrea> + (interactive) Andrea> + (rmail-summary-fill-displayed-messages) Andrea> + (rmail-new-summary "Negate" Andrea> + '(rmail-summary-by-regexp ".*") Andrea> + (lambda (msg) Andrea> + (if Andrea> + (=3D (aref rmail-summary-currently-displayed-msgs msg) Andrea> + ?n) Andrea> + (progn Andrea> + (aset rmail-summary-currently-displayed-msgs msg ?y) t) Andrea> + (progn Andrea> + (aset rmail-summary-currently-displayed-msgs msg ?n) nil= ))))) Andrea> + If you switch `rmail-summary-currently-displayed-msgs' to a vector, you can store `nil' and `t' there directly and avoid the progn=CA=BCs (aset returns the new value) Andrea> ;;;###autoload Andrea> (defun rmail-summary () Andrea> "Display a summary of all messages, one line per message." Andrea> @@ -282,9 +325,16 @@ rmail-summary-by-labels Andrea> (setq labels (or rmail-last-multi-labels Andrea> (error "No label specified")))) Andrea> (setq rmail-last-multi-labels labels) Andrea> + (if rmail-summary-apply-filters-consecutively Andrea> + (rmail-summary-fill-displayed-messages)) Andrea> (rmail-new-summary (concat "labels " labels) Andrea> (list 'rmail-summary-by-labels labels) Andrea> - 'rmail-message-labels-p Andrea> + (if rmail-summary-apply-filters-consecutively Andrea> + (lambda (msg l) Andrea> + (and (=3D (aref rmail-summary-currently-displayed-msgs m= sg) Andrea> + ?y) Andrea> + (rmail-message-labels-p msg l))) Andrea> + 'rmail-message-labels-p) Andrea> (concat " \\(" Andrea> (mail-comma-list-regexp labels) Andrea> "\\)\\(,\\|\\'\\)"))) I think you have this same lambda about 4 times in the code, perhaps `defun' it (using "rmail-summary--" as a prefix to indicate that it=CA=BCs intended for internal usage) Robert --=20