From 832580989619d3343f06cd9a9eeed9f22ddad376 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Fri, 6 Feb 2026 20:20:49 +0100 Subject: [PATCH] Fix selected group sort with topics (bug#80341) * lisp/gnus/gnus-topic.el (gnus-group-sort-selected-topic): New function to sort selected groups into topic. (gnus-topic-mode): Use it as sort selected function in topic mode. * etc/NEWS: Announce the change. --- etc/NEWS | 3 +++ lisp/gnus/gnus-topic.el | 28 ++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 88235ce0de6..fb78b3f7b5e 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1787,6 +1787,9 @@ It is believed to no longer be useful as a method to fight spam. The The symbolic prefix is another kind of universal prefix that is used in Gnus, see "(gnus) Symbolic Prefixes" in the Gnus manual. +--- +*** Sorting selected groups is now possible with 'gnus-topic-mode'. + ** Sieve +++ diff --git a/lisp/gnus/gnus-topic.el b/lisp/gnus/gnus-topic.el index 315f1a018c9..4fb796105e2 100644 --- a/lisp/gnus/gnus-topic.el +++ b/lisp/gnus/gnus-topic.el @@ -1158,7 +1158,8 @@ articles in the topic and its subtopics." #'gnus-topic-group-indentation) (setq-local gnus-group-update-group-function #'gnus-topic-update-topics-containing-group) - (setq-local gnus-group-sort-alist-function #'gnus-group-sort-topic) + (setq-local gnus-group-sort-alist-function #'gnus-group-sort-topic + gnus-group-sort-selected-function #'gnus-group-sort-selected-topic) (setq gnus-group-change-level-function #'gnus-topic-change-level) (setq gnus-goto-missing-group-function #'gnus-topic-goto-missing-group) (add-hook 'gnus-check-bogus-groups-hook #'gnus-topic-clean-alist @@ -1173,7 +1174,8 @@ articles in the topic and its subtopics." (setq gnus-group-change-level-function nil) (remove-hook 'gnus-check-bogus-groups-hook #'gnus-topic-clean-alist) (setq gnus-group-prepare-function #'gnus-group-prepare-flat) - (setq gnus-group-sort-alist-function #'gnus-group-sort-flat)) + (setq gnus-group-sort-alist-function #'gnus-group-sort-flat + gnus-group-sort-selected-function #'gnus-group-sort-selected-flat)) (when (called-interactively-p 'any) (gnus-group-list-groups)))) @@ -1651,6 +1653,28 @@ If performed on a topic, edit the topic parameters instead." (setcar alist (delete "dummy.group" (car alist))) (gnus-topic-sort-topic (pop alist) func reverse)))) +(defun gnus-group-sort-selected-topic (groups func reverse) + "Sort selected GROUPS in the topics according to FUNC and REVERSE." + (let ((alist gnus-topic-alist)) + (while alist + ;; !!!Sometimes nil elements sneak into the alist, + ;; for some reason or other. + (setcar alist (delq nil (car alist))) + (setcar alist (delete "dummy.group" (car alist))) + (let* ((topic (pop alist)) + (inter (seq-intersection groups (cdr topic)))) + ;; Do something only if there are some selected groups in this + ;; topic. + (when inter + (let ((sorted (mapcar #'gnus-info-group + (sort (mapcar #'gnus-get-info inter) func)))) + ;; Do the reversal, if necessary. + (when reverse + (setq sorted (nreverse (cdr sorted)))) + ;; Set the topic contents as the union of the sorted + ;; selected groups and its previous contents. + (setcdr topic (seq-union sorted (cdr topic))))))))) + (defun gnus-topic-sort-topic (topic func reverse) ;; Each topic only lists the name of the group, while ;; the sort predicates expect group infos as inputs.