Save instantiated gnus-search engines in an alist

So we aren't re-instantiating (and potentially configuring) them with
every search.

* lisp/gnus/gnus-search.el (gnus-search-engine-instance-alist): New
variable holding server->engine mapping.
(gnus-search-server-to-engine): See if we've already instantiated this
server. If so, return it. If not, instantiate it and save in the above
variable.
(gnus-search-shutdown): Shutdown function clearing the above alist.
This commit is contained in:
Eric Abrahamsen 2020-11-11 10:48:37 -08:00
parent bb28f8b9d1
commit 31f94e4b1c

View file

@ -90,9 +90,19 @@
;;; Internal Variables:
;; When Gnus servers are implemented as objects or structs, give them
;; a `search-engine' slot and get rid of this variable.
(defvar gnus-search-engine-instance-alist nil
"Mapping between servers and instantiated search engines.")
(defvar gnus-search-history ()
"Internal history of Gnus searches.")
(defun gnus-search-shutdown ()
(setq gnus-search-engine-instance-alist nil))
(gnus-add-shutdown #'gnus-search-shutdown 'gnus)
(define-error 'gnus-search-parse-error "Gnus search parsing error")
;;; User Customizable Variables:
@ -1964,7 +1974,9 @@ remaining string, then adds all that to the top-level spec."
(defun gnus-search-server-to-engine (srv)
(let* ((method (gnus-server-to-method srv))
(engine-config (assoc 'gnus-search-engine (cddr method)))
(server (or (nth 1 engine-config)
(server (or (cdr-safe
(assoc-string srv gnus-search-engine-instance-alist t))
(nth 1 engine-config)
(cdr-safe (assoc (car method) gnus-search-default-engines))
(when-let ((old (assoc 'nnir-search-engine
(cddr method))))
@ -1988,17 +2000,19 @@ remaining string, then adds all that to the top-level spec."
(make-instance server))
(t nil)))
(if inst
(when (cddr engine-config)
;; We're not being completely backward-compatible here,
;; because we're not checking for nnir-specific config
;; options in the server definition.
(pcase-dolist (`(,key ,value) (cddr engine-config))
(condition-case nil
(setf (slot-value inst key) value)
((invalid-slot-name invalid-slot-type)
(nnheader-message
5 "Invalid search engine parameter: (%s %s)"
key value)))))
(unless (assoc-string srv gnus-search-engine-instance-alist t)
(when (cddr engine-config)
;; We're not being completely backward-compatible here,
;; because we're not checking for nnir-specific config
;; options in the server definition.
(pcase-dolist (`(,key ,value) (cddr engine-config))
(condition-case nil
(setf (slot-value inst key) value)
((invalid-slot-name invalid-slot-type)
(nnheader-message
5 "Invalid search engine parameter: (%s %s)"
key value)))))
(push (cons srv inst) gnus-search-engine-instance-alist))
(error "No search engine defined for %s" srv))
inst))
@ -2112,7 +2126,8 @@ article came from is also searched."
;; If the value contains spaces, make sure it's
;; quoted.
(when (and (memql status '(exact finished))
(string-match-p " " str))
(or (string-match-p " " str)
in-string))
(unless (looking-at-p "\\s\"")
(insert "\""))
;; Unless we already have an opening quote...