Browse Source

oc: Opportunistically load processors

* lisp/oc.el (org-cite--get-processor): Try requiring 'oc-NAME where
name is the name of the processor used.
(org-cite-register-processor): Do not use `org-cite--get-processor' to
avoid circular requires.

Suggested-by: Timothy <tecosaur@gmail.com>
<http://lists.gnu.org/r/emacs-orgmode/2021-11/msg00664.html>
Nicolas Goaziou 3 năm trước cách đây
mục cha
commit
0bf211a340
1 tập tin đã thay đổi với 7 bổ sung4 xóa
  1. 7 4
      lisp/oc.el

+ 7 - 4
lisp/oc.el

@@ -326,6 +326,9 @@ processors.")
 (defun org-cite--get-processor (name)
   "Return citation processor named after symbol NAME.
 Return nil if no such processor is found."
+  ;; Opportunistically try to load the library providing the
+  ;; processor.
+  (require (intern (concat "oc-" (symbol-name name))) nil t)
   (seq-find (lambda (p) (eq name (org-cite-processor-name p)))
 	    org-cite--processors))
 
@@ -419,10 +422,10 @@ Return a non-nil value on a successful operation."
   (declare (indent 1))
   (unless (and name (symbolp name))
     (error "Invalid processor name: %S" name))
-  (when (org-cite--get-processor name)
-    (org-cite-unregister-processor name))
-  (push (apply #'org-cite--make-processor :name name body)
-	org-cite--processors))
+  (setq org-cite--processors
+        (cons (apply #'org-cite--make-processor :name name body)
+              (seq-remove (lambda (p) (eq name (org-cite-processor-name p)))
+                          org-cite--processors))))
 
 (defun org-cite-unregister-processor (name)
   "Unregister citation processor NAME.