Skip to content

Commit e4eb8c8

Browse files
committed
Fix Gnus group sorting to use gnus-group-list
* lisp/gnus/gnus-group.el (gnus-group-sort-flat): As gnus-newsrc-hashtb is now a real (unsorted) hash table, use gnus-group-list to maintain group sort order. (gnus-group-sort-selected-flat): Ditto. * lisp/gnus/gnus-start.el (gnus-subscribe-alphabetically): Simplify function using seq-find. (gnus-subscribe-killed, gnus-subscribe-zombies): Use cl-pushnew to avoid adding duplicates (can happen when un/subscribing multiple times to one group).
1 parent d86235f commit e4eb8c8

File tree

2 files changed

+44
-38
lines changed

2 files changed

+44
-38
lines changed

lisp/gnus/gnus-group.el

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,21 +3300,31 @@ If REVERSE (the prefix), reverse the sorting order."
33003300
(funcall gnus-group-sort-alist-function
33013301
(gnus-make-sort-function func) reverse)
33023302
(gnus-group-unmark-all-groups)
3303+
;; Redisplay all groups according to the newly-sorted order of
3304+
;; `gnus-group-list'.
33033305
(gnus-group-list-groups)
33043306
(gnus-dribble-touch))
33053307

33063308
(defun gnus-group-sort-flat (func reverse)
3307-
;; We peel off the dummy group from the alist.
3309+
"Sort groups in a flat list using sorting function FUNC.
3310+
If REVERSE is non-nil, reverse the sort order.
3311+
3312+
This function sets a new value for `gnus-group-list'; its return
3313+
value is disregarded."
33083314
(when func
3309-
(when (equal (gnus-info-group (car gnus-newsrc-alist)) "dummy.group")
3310-
(pop gnus-newsrc-alist))
3311-
;; Do the sorting.
3312-
(setq gnus-newsrc-alist
3313-
(sort gnus-newsrc-alist func))
3314-
(when reverse
3315-
(setq gnus-newsrc-alist (nreverse gnus-newsrc-alist)))
3316-
;; Regenerate the hash table.
3317-
(gnus-make-hashtable-from-newsrc-alist)))
3315+
(let* ((groups (remove "dummy.group" gnus-group-list))
3316+
(sorted-infos
3317+
(sort (mapcar (lambda (g)
3318+
(gnus-get-info g))
3319+
groups)
3320+
func)))
3321+
(setq gnus-group-list
3322+
(mapcar (lambda (i)
3323+
(gnus-info-group i))
3324+
sorted-infos))
3325+
(when reverse
3326+
(setq gnus-group-list (nreverse gnus-group-list)))
3327+
(setq gnus-group-list (cons "dummy.group" gnus-group-list)))))
33183328

33193329
(defun gnus-group-sort-groups-by-alphabet (&optional reverse)
33203330
"Sort the group buffer alphabetically by group name.
@@ -3377,27 +3387,26 @@ If REVERSE, sort in reverse order."
33773387
(gnus-dribble-touch)))
33783388

33793389
(defun gnus-group-sort-selected-flat (groups func reverse)
3380-
(let (entries infos)
3381-
;; First find all the group entries for these groups.
3382-
(while groups
3383-
(push (nthcdr 2 (gnus-group-entry (pop groups)))
3384-
entries))
3385-
;; Then sort the infos.
3386-
(setq infos
3387-
(sort
3388-
(mapcar
3389-
(lambda (entry) (car entry))
3390-
(setq entries (nreverse entries)))
3391-
func))
3390+
"Sort only the selected GROUPS, using FUNC.
3391+
If REVERSE is non-nil, reverse the sorting."
3392+
(let ((infos (sort
3393+
(mapcar (lambda (g)
3394+
(gnus-get-info g))
3395+
groups)
3396+
func))
3397+
sorted-groups)
33923398
(when reverse
33933399
(setq infos (nreverse infos)))
3394-
;; Go through all the infos and replace the old entries
3395-
;; with the new infos.
3396-
(while infos
3397-
(setcar (car entries) (pop infos))
3398-
(pop entries))
3399-
;; Update the hashtable.
3400-
(gnus-make-hashtable-from-newsrc-alist)))
3400+
(setq sorted-groups (mapcar (lambda (i) (gnus-info-group i)) infos))
3401+
3402+
;; Find the original locations of GROUPS in `gnus-group-list', and
3403+
;; replace each one, in order, with a group from SORTED-GROUPS.
3404+
(dolist (i (sort (mapcar (lambda (g)
3405+
(seq-position gnus-group-list g))
3406+
groups)
3407+
#'<))
3408+
(setf (nth i gnus-group-list)
3409+
(pop sorted-groups)))))
34013410

34023411
(defun gnus-group-sort-selected-groups-by-alphabet (&optional n reverse)
34033412
"Sort the group buffer alphabetically by group name.

lisp/gnus/gnus-start.el

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,9 @@ Can be used to turn version control on or off."
583583

584584
(defun gnus-subscribe-alphabetically (newgroup)
585585
"Subscribe new NEWGROUP and insert it in alphabetical order."
586-
(let ((groups (cdr gnus-newsrc-alist))
587-
before)
588-
(while (and (not before) groups)
589-
(if (string< newgroup (caar groups))
590-
(setq before (caar groups))
591-
(setq groups (cdr groups))))
586+
(let ((before (seq-find (lambda (group)
587+
(string< newgroup group))
588+
(cdr gnus-group-list))))
592589
(gnus-subscribe-newsgroup newgroup before)))
593590

594591
(defun gnus-subscribe-hierarchically (newgroup)
@@ -618,15 +615,15 @@ It is inserted in hierarchical newsgroup order if subscribed. If not,
618615
it is killed."
619616
(if (gnus-y-or-n-p (format "Subscribe new newsgroup %s? " group))
620617
(gnus-subscribe-hierarchically group)
621-
(push group gnus-killed-list)))
618+
(gnus-subscribe-killed group)))
622619

623620
(defun gnus-subscribe-zombies (group)
624621
"Make the new GROUP into a zombie group."
625-
(push group gnus-zombie-list))
622+
(cl-pushnew group gnus-zombie-list :test #'equal))
626623

627624
(defun gnus-subscribe-killed (group)
628625
"Make the new GROUP a killed group."
629-
(push group gnus-killed-list))
626+
(cl-pushnew group gnus-killed-list :test #'equal))
630627

631628
(defun gnus-subscribe-newsgroup (newsgroup &optional next)
632629
"Subscribe new NEWSGROUP.

0 commit comments

Comments
 (0)