From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alex Bochannek Newsgroups: gmane.emacs.bugs Subject: bug#49081: 28.0.50; [PATCH] Feature suggestion, Gnus summary mode sorting for extra headers Date: Sat, 19 Jun 2021 12:08:55 -0700 Message-ID: References: <875yya0zfc.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="17769"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (darwin) Cc: 49081@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 19 21:09:16 2021 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 1lugLC-0004OK-R6 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Jun 2021 21:09:14 +0200 Original-Received: from localhost ([::1]:41030 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lugLB-0000VN-SC for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 19 Jun 2021 15:09:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40948) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lugL0-0000Uj-PH for bug-gnu-emacs@gnu.org; Sat, 19 Jun 2021 15:09:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49267) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lugL0-0002Tv-Hz for bug-gnu-emacs@gnu.org; Sat, 19 Jun 2021 15:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lugL0-0005Se-Dh for bug-gnu-emacs@gnu.org; Sat, 19 Jun 2021 15:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alex Bochannek Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 Jun 2021 19:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49081 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 49081-submit@debbugs.gnu.org id=B49081.162412974020984 (code B ref 49081); Sat, 19 Jun 2021 19:09:02 +0000 Original-Received: (at 49081) by debbugs.gnu.org; 19 Jun 2021 19:09:00 +0000 Original-Received: from localhost ([127.0.0.1]:60813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lugKy-0005SO-DU for submit@debbugs.gnu.org; Sat, 19 Jun 2021 15:09:00 -0400 Original-Received: from ns.lapseofthought.com ([50.0.39.240]:42708 helo=mail.lapseofthought.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lugKx-0005SG-FL for 49081@debbugs.gnu.org; Sat, 19 Jun 2021 15:09:00 -0400 Original-Received: from awb-mbp.local (unknown [IPv6:2601:646:4200:b470:e50d:205c:630:add7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.lapseofthought.com (Postfix) with ESMTPSA id 4G6lh84RlJz3pdpY; Sat, 19 Jun 2021 12:08:56 -0700 (PDT) In-Reply-To: <875yya0zfc.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 19 Jun 2021 15:14:15 +0200") Authentication-Results: ORIGINATING; auth=pass smtp.auth=alex smtp.mailfrom=alex@bochannek.com 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" Xref: news.gmane.io gmane.emacs.bugs:208765 Archived-At: --=-=-= Content-Type: text/plain Lars Ingebrigtsen writes: > Alex Bochannek writes: > >> Since I was able to get the Newsgroups extra header working for >> `nnvirtual' groups, I would like to not only limit, but also sort by the >> extra headers. > > Looks good; applied with one minor tweak: > >> +(defun gnus-article-sort-by-newsgroups (h1 h2) >> + "Sort articles by newsgroups." >> + (gnus-string< >> + (let ((extract (funcall >> + gnus-extract-address-components >> + (or (cdr (assq 'Newsgroups (mail-header-extra h1))) "")))) >> + (or (car extract) (cadr extract))) >> + (let ((extract (funcall >> + gnus-extract-address-components >> + (or (cdr (assq 'Newsgroups (mail-header-extra h2))) "")))) >> + (or (car extract) (cadr extract))))) > > I rewrote that to: > > (defun gnus-article-sort-by-newsgroups (h1 h2) > "Sort articles by newsgroups." > (let ((ex > (lambda (h) > (let ((extract > (funcall gnus-extract-address-components > (or (cdr (assq 'Newsgroups (mail-header-extra h))) > "")))) > (or (car extract) (cadr extract)))))) > (gnus-string< (funcall ex h1) (funcall ex h2)))) > > To avoid the duplication -- let me know if I messed up that bit. Looks good, thank you! I originally had duplicated that code from `gnus-article-sort-by-recipient' and it's probably a good idea to make that into a utility function. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/lisp/gnus/gnus-sum.el b/lisp/gnus/gnus-sum.el index 908c10c11d..788676c7c8 100644 --- a/lisp/gnus/gnus-sum.el +++ b/lisp/gnus/gnus-sum.el @@ -5085,15 +5085,10 @@ gnus-thread-sort-by-author (defsubst gnus-article-sort-by-recipient (h1 h2) "Sort articles by recipient." - (gnus-string< - (let ((extract (funcall - gnus-extract-address-components - (or (cdr (assq 'To (mail-header-extra h1))) "")))) - (or (car extract) (cadr extract))) - (let ((extract (funcall - gnus-extract-address-components - (or (cdr (assq 'To (mail-header-extra h2))) "")))) - (or (car extract) (cadr extract))))) + (let ((ex + (lambda (h) + (gnus-article-sort-extract-extra 'To h)))) + (gnus-string< (funcall ex h1) (funcall ex h2)))) (defun gnus-thread-sort-by-recipient (h1 h2) "Sort threads by root recipient." @@ -5188,15 +5183,11 @@ gnus-thread-sort-by-most-recent-date "Sort threads such that the thread with the most recently dated article comes first." (> (gnus-thread-latest-date h1) (gnus-thread-latest-date h2))) -(defun gnus-article-sort-by-newsgroups (h1 h2) +(defsubst gnus-article-sort-by-newsgroups (h1 h2) "Sort articles by newsgroups." (let ((ex - (lambda (h) - (let ((extract - (funcall gnus-extract-address-components - (or (cdr (assq 'Newsgroups (mail-header-extra h))) - "")))) - (or (car extract) (cadr extract)))))) + (lambda (h) + (gnus-article-sort-extract-extra 'Newsgroups h)))) (gnus-string< (funcall ex h1) (funcall ex h2)))) (defun gnus-thread-sort-by-newsgroups (h1 h2) @@ -5204,6 +5195,12 @@ gnus-thread-sort-by-newsgroups (gnus-article-sort-by-newsgroups (gnus-thread-header h1) (gnus-thread-header h2))) +(defsubst gnus-article-sort-extract-extra (Name header) + (let ((extract + (funcall gnus-extract-address-components + (or (cdr (assq name (mail-header-extra header))) + "")))) + (or (car extract) (cadr extract)))) ; Since this is called not only to sort the top-level threads, but ; also in recursive sorts to order the articles within a thread, each --=-=-= Content-Type: text/plain A similar pattern is used by `gnus-article-sort-by-author', but I didn't see an easy way to unify these without also passing around functions by header type. Also, I haven't used `defsubst' before, so I leave it up to you if it makes sense to use that for the `gnus-article-sort-by-newsgroups' and `gnus-article-sort-by-newsgroups', respectively. Thanks! -- Alex. --=-=-=--