emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 31f94e4: Save instantiated gnus-search engines in an alist


From: Eric Abrahamsen
Subject: master 31f94e4: Save instantiated gnus-search engines in an alist
Date: Fri, 13 Nov 2020 20:39:21 -0500 (EST)

branch: master
commit 31f94e4b1c3dc201646ec436d3e2c477f784ed21
Author: Eric Abrahamsen <eric@ericabrahamsen.net>
Commit: Eric Abrahamsen <eric@ericabrahamsen.net>

    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.
---
 lisp/gnus/gnus-search.el | 41 ++++++++++++++++++++++++++++-------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/lisp/gnus/gnus-search.el b/lisp/gnus/gnus-search.el
index 71854a7..17f1108 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...



reply via email to

[Prev in Thread] Current Thread [Next in Thread]