;;; 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:
(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))))
(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))
;; 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...