From: Alex Bochannek <alex@bochannek.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 49081@debbugs.gnu.org
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 [thread overview]
Message-ID: <m27dipoens.fsf@bochannek.com> (raw)
In-Reply-To: <875yya0zfc.fsf@gnus.org> (Lars Ingebrigtsen's message of "Sat, 19 Jun 2021 15:14:15 +0200")
[-- Attachment #1: Type: text/plain, Size: 1466 bytes --]
Lars Ingebrigtsen <larsi@gnus.org> writes:
> Alex Bochannek <alex@bochannek.com> 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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 2172 bytes --]
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
[-- Attachment #3: Type: text/plain, Size: 368 bytes --]
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.
next prev parent reply other threads:[~2021-06-19 19:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-17 23:53 bug#49081: 28.0.50; [PATCH] Feature suggestion, Gnus summary mode sorting for extra headers Alex Bochannek
2021-06-19 13:14 ` Lars Ingebrigtsen
2021-06-19 19:08 ` Alex Bochannek [this message]
2021-06-21 12:36 ` Lars Ingebrigtsen
2021-06-21 18:22 ` Alex Bochannek
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=m27dipoens.fsf@bochannek.com \
--to=alex@bochannek.com \
--cc=49081@debbugs.gnu.org \
--cc=larsi@gnus.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.