diff options
author | Eric Abrahamsen <eric@ericabrahamsen.net> | 2020-11-11 10:48:37 -0800 |
---|---|---|
committer | Eric Abrahamsen <eric@ericabrahamsen.net> | 2020-11-13 17:25:46 -0800 |
commit | 31f94e4b1c3dc201646ec436d3e2c477f784ed21 (patch) | |
tree | 9de242880133cc8dd3758fb405e0c49191c787a1 /lisp/gnus/gnus-search.el | |
parent | bb28f8b9d1ebb4a93c66beca466cb15563075e8c (diff) | |
download | emacs-31f94e4b1c3dc201646ec436d3e2c477f784ed21.tar.gz emacs-31f94e4b1c3dc201646ec436d3e2c477f784ed21.tar.bz2 emacs-31f94e4b1c3dc201646ec436d3e2c477f784ed21.zip |
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.
Diffstat (limited to 'lisp/gnus/gnus-search.el')
-rw-r--r-- | lisp/gnus/gnus-search.el | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el index 71854a7a3ee..17f1108029c 100644 --- a/lisp/gnus/gnus-search.el +++ b/lisp/gnus/gnus-search.el @@ -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... |