[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 7e2d909 1/3: oc: Allow declaring cite styles as a f
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 7e2d909 1/3: oc: Allow declaring cite styles as a function |
Date: |
Sun, 12 Dec 2021 09:57:31 -0500 (EST) |
branch: externals/org
commit 7e2d9091d01faf81679887b34d452de8b0e7cc2e
Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Commit: Nicolas Goaziou <mail@nicolasgoaziou.fr>
oc: Allow declaring cite styles as a function
* lisp/oc.el (org-cite-register-processor): Allow a function
as :cite-styles value.
(org-cite-supported-styles): Propagate change above.
* testing/lisp/test-oc.el (test-org-cite/supported-styles): Add test.
---
etc/ORG-NEWS | 6 ++++++
lisp/oc.el | 8 +++++++-
testing/lisp/test-oc.el | 8 ++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 81459eb..80f6b71 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -97,6 +97,12 @@ argument.
** Miscellaneous
+*** Citation processors can declare styles dynamically
+
+When a citation processor is registered, it is now possible to set
+~:cite-styles~ key to a function, which will be called whenever the
+list of styles is required.
+
*** Org also searches for CSL style files in default directory
When CSL style file name is relative, Org first looks into
diff --git a/lisp/oc.el b/lisp/oc.el
index e6190e4..3ee5ae6 100644
--- a/lisp/oc.el
+++ b/lisp/oc.el
@@ -409,6 +409,9 @@ optional keys can be set:
The \"nil\" style denotes the processor fall-back style. It
should have a corresponding entry in the value.
+ The value can also be a function. It will be called without
+ any argument and should return a list structured as the above.
+
Return a non-nil value on a successful operation."
(declare (indent 1))
(unless (and name (symbolp name))
@@ -680,7 +683,10 @@ strings."
(let ((collection
(seq-mapcat
(lambda (name)
- (org-cite-processor-cite-styles (org-cite-get-processor name)))
+ (pcase (org-cite-processor-cite-styles
+ (org-cite-get-processor name))
+ ((and (pred functionp) f) (funcall f))
+ (static-data static-data)))
(or processors
(mapcar (pcase-lambda (`(,_ . (,name . ,_))) name)
org-cite-export-processors))))
diff --git a/testing/lisp/test-oc.el b/testing/lisp/test-oc.el
index 722b0fb..4c288e9 100644
--- a/testing/lisp/test-oc.el
+++ b/testing/lisp/test-oc.el
@@ -306,6 +306,14 @@
(org-cite-register-processor 'test
:cite-styles '((("foo" "f")) ((""))))
(org-cite-supported-styles))))
+ ;; Also support functions generating the list.
+ (should
+ (equal '((("foo" "f")) (("")))
+ (let ((org-cite--processors nil)
+ (org-cite-export-processors '((t test))))
+ (org-cite-register-processor 'test
+ :cite-styles (lambda () '((("foo" "f")) (("")))))
+ (org-cite-supported-styles))))
;; Explicitly provide a processor.
(should
(equal '((("")))