aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorAndrew G Cohen2022-03-22 12:11:14 +0800
committerAndrew G Cohen2022-03-23 08:13:28 +0800
commiteb25ae3f2db2543bc4c31fbddb4c719e43913ff8 (patch)
tree614540978c75303d2ad21755d1434427a421e9ac /lisp
parentc14ce74f3316357489e8dc7de3a75648b6a12757 (diff)
downloademacs-eb25ae3f2db2543bc4c31fbddb4c719e43913ff8.tar.gz
emacs-eb25ae3f2db2543bc4c31fbddb4c719e43913ff8.zip
Refactor gnus/nnselect artlist saving and getting
* lisp/gnus/nnselect.el (nnselect-generate-run): New function that replaces nnselect-run. (nnselect-store-artlist): New function. (nnselect-get-artlist): Update function. (nnselect-request-group, nnselect-request-thread) (nnselect-request-create-group, nnselect-request-group-scan): Use the new functions. * doc/misc/gnus.texi (Selection Groups): Document artlist storage and retrieval.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/gnus/nnselect.el107
1 files changed, 70 insertions, 37 deletions
diff --git a/lisp/gnus/nnselect.el b/lisp/gnus/nnselect.el
index d6289f13395..3a93c9e3ddc 100644
--- a/lisp/gnus/nnselect.el
+++ b/lisp/gnus/nnselect.el
@@ -110,6 +110,7 @@
110 selection))) 110 selection)))
111 111
112(make-obsolete 'nnselect-group-server 'gnus-group-server "28.1") 112(make-obsolete 'nnselect-group-server 'gnus-group-server "28.1")
113(make-obsolete 'nnselect-run 'nnselect-generate-artlist "29.1")
113 114
114;; Data type article list. 115;; Data type article list.
115 116
@@ -231,11 +232,6 @@ as `(keyfunc member)' and the corresponding element is just
231 `(gnus-group-prefixed-name 232 `(gnus-group-prefixed-name
232 (gnus-group-short-name ,group) '(nnselect "nnselect"))) 233 (gnus-group-short-name ,group) '(nnselect "nnselect")))
233 234
234(defmacro nnselect-get-artlist (group)
235 "Retrieve the list of articles for GROUP."
236 `(when (gnus-nnselect-group-p ,group)
237 (nnselect-uncompress-artlist
238 (gnus-group-get-parameter ,group 'nnselect-artlist t))))
239 235
240(defmacro nnselect-add-novitem (novitem) 236(defmacro nnselect-add-novitem (novitem)
241 "Add NOVITEM to the list of headers." 237 "Add NOVITEM to the list of headers."
@@ -271,6 +267,63 @@ If this variable is nil, or if the provided function returns nil,
271 :version "28.1" 267 :version "28.1"
272 :type '(repeat function)) 268 :type '(repeat function))
273 269
270(defun nnselect-generate-artlist (group &optional specs)
271 "Generate the artlist for GROUP using SPECS.
272SPECS should be an alist including an 'nnselect-function and an
273'nnselect-args. The former applied to the latter should create
274the artlist. If SPECS is nil retrieve the specs from the group
275parameters."
276 (let* ((specs
277 (or specs (gnus-group-get-parameter group 'nnselect-specs t)))
278 (function (alist-get 'nnselect-function specs))
279 (args (alist-get 'nnselect-args specs)))
280 (condition-case-unless-debug err
281 (funcall function args)
282 ;; Don't swallow gnus-search errors; the user should be made
283 ;; aware of them.
284 (gnus-search-error
285 (signal (car err) (cdr err)))
286 (error
287 (gnus-error
288 3
289 "nnselect-generate-artlist: %s on %s gave error %s" function args err)
290 []))))
291
292(defmacro nnselect-get-artlist (group)
293 "Get the list of articles for GROUP.
294If the group parameter 'nnselect-get-artlist-override-function is
295non-nil call this function with argument GROUP to get the
296artlist; if the group parameter 'nnselect-always-regenerate is
297non-nil, regenerate the artlist; otherwise retrieve the artlist
298directly from the group parameters."
299 `(when (gnus-nnselect-group-p group)
300 (let ((override (gnus-group-get-parameter
301 ,group
302 'nnselect-get-artlist-override-function)))
303 (cond
304 (override (funcall override ,group))
305 ((gnus-group-get-parameter ,group 'nnselect-always-regenerate)
306 (nnselect-generate-artlist ,group))
307 (t
308 (nnselect-uncompress-artlist
309 (gnus-group-get-parameter ,group 'nnselect-artlist t)))))))
310
311(defmacro nnselect-store-artlist (group artlist)
312 "Store the ARTLIST for GROUP.
313If the group parameter 'nnselect-store-artlist-override-function
314is non-nil call this function on GROUP and ARTLIST; if the group
315parameter 'nnselect-always-regenerate is non-nil don't store the
316artlist; otherwise store the ARTLIST in the group parameters."
317 `(let ((override (gnus-group-get-parameter
318 ,group
319 'nnselect-store-artlist-override-function)))
320 (cond
321 (override (funcall override ,group ,artlist))
322 ((gnus-group-get-parameter ,group 'nnselect-always-regenerate) t)
323 (t
324 (gnus-group-set-parameter ,group 'nnselect-artlist
325 (nnselect-compress-artlist ,artlist))))))
326
274;; Gnus backend interface functions. 327;; Gnus backend interface functions.
275 328
276(deffoo nnselect-open-server (server &optional definitions) 329(deffoo nnselect-open-server (server &optional definitions)
@@ -296,11 +349,8 @@ If this variable is nil, or if the provided function returns nil,
296 ;; Check for cached select result or run the selection and cache 349 ;; Check for cached select result or run the selection and cache
297 ;; the result. 350 ;; the result.
298 (unless nnselect-artlist 351 (unless nnselect-artlist
299 (gnus-group-set-parameter 352 (nnselect-store-artlist group
300 group 'nnselect-artlist 353 (setq nnselect-artlist (nnselect-generate-artlist group)))
301 (nnselect-compress-artlist (setq nnselect-artlist
302 (nnselect-run
303 (gnus-group-get-parameter group 'nnselect-specs t)))))
304 (nnselect-request-update-info 354 (nnselect-request-update-info
305 group (or info (gnus-get-info group)))) 355 group (or info (gnus-get-info group))))
306 (if (zerop (setq length (nnselect-artlist-length nnselect-artlist))) 356 (if (zerop (setq length (nnselect-artlist-length nnselect-artlist)))
@@ -671,10 +721,7 @@ If this variable is nil, or if the provided function returns nil,
671 (append (sort old-arts #'<) 721 (append (sort old-arts #'<)
672 (number-sequence first last)) 722 (number-sequence first last))
673 nil t)) 723 nil t))
674 (gnus-group-set-parameter 724 (nnselect-store-artlist group gnus-newsgroup-selection)
675 group
676 'nnselect-artlist
677 (nnselect-compress-artlist gnus-newsgroup-selection))
678 (when (>= last first) 725 (when (>= last first)
679 (let (new-marks) 726 (let (new-marks)
680 (pcase-dolist (`(,artgroup . ,artids) 727 (pcase-dolist (`(,artgroup . ,artids)
@@ -721,6 +768,7 @@ If this variable is nil, or if the provided function returns nil,
721 (message "Creating nnselect group %s" group) 768 (message "Creating nnselect group %s" group)
722 (let* ((group (gnus-group-prefixed-name group '(nnselect "nnselect"))) 769 (let* ((group (gnus-group-prefixed-name group '(nnselect "nnselect")))
723 (specs (assq 'nnselect-specs args)) 770 (specs (assq 'nnselect-specs args))
771 (otherargs (assq-delete-all 'nnselect-specs args))
724 (function-spec 772 (function-spec
725 (or (alist-get 'nnselect-function specs) 773 (or (alist-get 'nnselect-function specs)
726 (intern (completing-read "Function: " obarray #'functionp)))) 774 (intern (completing-read "Function: " obarray #'functionp))))
@@ -730,10 +778,12 @@ If this variable is nil, or if the provided function returns nil,
730 (nnselect-specs (list (cons 'nnselect-function function-spec) 778 (nnselect-specs (list (cons 'nnselect-function function-spec)
731 (cons 'nnselect-args args-spec)))) 779 (cons 'nnselect-args args-spec))))
732 (gnus-group-set-parameter group 'nnselect-specs nnselect-specs) 780 (gnus-group-set-parameter group 'nnselect-specs nnselect-specs)
733 (gnus-group-set-parameter 781 (dolist (arg otherargs)
734 group 'nnselect-artlist 782 (gnus-group-set-parameter group (car arg) (cdr arg)))
735 (nnselect-compress-artlist (or (alist-get 'nnselect-artlist args) 783 (nnselect-store-artlist
736 (nnselect-run nnselect-specs)))) 784 group
785 (or (alist-get 'nnselect-artlist args)
786 (nnselect-generate-artlist group nnselect-specs)))
737 (nnselect-request-update-info group (gnus-get-info group))) 787 (nnselect-request-update-info group (gnus-get-info group)))
738 t) 788 t)
739 789
@@ -765,13 +815,10 @@ If this variable is nil, or if the provided function returns nil,
765 815
766(deffoo nnselect-request-group-scan (group &optional _server _info) 816(deffoo nnselect-request-group-scan (group &optional _server _info)
767 (let* ((group (nnselect-add-prefix group)) 817 (let* ((group (nnselect-add-prefix group))
768 (artlist (nnselect-uncompress-artlist (nnselect-run 818 (artlist (nnselect-generate-artlist group)))
769 (gnus-group-get-parameter group 'nnselect-specs t)))))
770 (gnus-set-active group (cons 1 (nnselect-artlist-length 819 (gnus-set-active group (cons 1 (nnselect-artlist-length
771 artlist))) 820 artlist)))
772 (gnus-group-set-parameter 821 (nnselect-store-artlist group artlist)))
773 group 'nnselect-artlist
774 (nnselect-compress-artlist artlist))))
775 822
776;; Add any undefined required backend functions 823;; Add any undefined required backend functions
777 824
@@ -786,20 +833,6 @@ If this variable is nil, or if the provided function returns nil,
786 (eq 'nnselect (car gnus-command-method)))) 833 (eq 'nnselect (car gnus-command-method))))
787 834
788 835
789(defun nnselect-run (specs)
790 "Apply nnselect-function to nnselect-args from SPECS.
791Return an article list."
792 (let ((func (alist-get 'nnselect-function specs))
793 (args (alist-get 'nnselect-args specs)))
794 (condition-case-unless-debug err
795 (funcall func args)
796 ;; Don't swallow gnus-search errors; the user should be made
797 ;; aware of them.
798 (gnus-search-error
799 (signal (car err) (cdr err)))
800 (error (gnus-error 3 "nnselect-run: %s on %s gave error %s" func args err)
801 []))))
802
803(defun nnselect-search-thread (header) 836(defun nnselect-search-thread (header)
804 "Make an nnselect group containing the thread with article HEADER. 837 "Make an nnselect group containing the thread with article HEADER.
805The current server will be searched. If the registry is 838The current server will be searched. If the registry is