emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters
@ 2021-09-20 11:56 András Simonyi
  2021-09-20 12:29 ` Timothy
  2021-09-26 10:37 ` Bastien
  0 siblings, 2 replies; 4+ messages in thread
From: András Simonyi @ 2021-09-20 11:56 UTC (permalink / raw)
  To: emacs-orgmode list

[-- Attachment #1: Type: text/plain, Size: 543 bytes --]

Dear All,

this is the first item in a series of oc-csl patches which I've
accumulated and am planning to send this week. (My first attempt to
send a patch, so please be patient and forgiving :-) )

This particular change removes the itemgetter constructor function
defined in oc-csl.el and uses the one now provided by citeproc-el
which has the same functionality but also supports org-bibtex
bibliographies. In addition to being a bit more featureful this change
also avoids unnecessary code duplication.

best wishes,
András

[-- Attachment #2: 0035-oc-csl-Use-citeproc-el-to-create-CSL-processor-itemg.patch --]
[-- Type: text/x-patch, Size: 3233 bytes --]

From 7cc7047516970d9e7da32e23bb11b35c8dbfae6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A1s=20Simonyi?= <andras.simonyi@gmail.com>
Date: Mon, 20 Sep 2021 12:41:20 +0200
Subject: [PATCH] oc-csl: Use citeproc-el to create CSL processor
 itemgetters

* lisp/oc-csl.el (org-cite-csl--processor): Citeproc-el now provides an
itemgetter constructor with all the required functionality and some more, so we
use it to create the itemgetter instead of `org-cite-csl--itemgetter' to avoid
code duplication and make use of the additional features, in particular the
ability to access bibliographies in `org-bibtex' format
(see <https://gewhere.github.io/org-bibtex>).
(org-cite-csl--itemgetter): Is removed since it is no longer used.
---
 lisp/oc-csl.el | 31 ++-----------------------------
 1 file changed, 2 insertions(+), 29 deletions(-)

diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el
index b5074dcf1..645b1c0f9 100644
--- a/lisp/oc-csl.el
+++ b/lisp/oc-csl.el
@@ -99,6 +99,7 @@
 (declare-function citeproc-append-citations "ext:citeproc")
 (declare-function citeproc-render-citations "ext:citeproc")
 (declare-function citeproc-render-bib "ext:citeproc")
+(declare-function citeproc-hash-itemgetter-from-any "ext:citeproc")
 
 (declare-function org-element-interpret-data "org-element" (data))
 (declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion with-affiliated))
@@ -336,34 +337,6 @@ or raise an error if the variable is unset."
     (other
      (user-error "Cannot handle relative style file name" other))))
 
-(defun org-cite-csl--itemgetter (bibliography)
-  "Return Citeproc's \"itemgetter\" function for BIBLIOGRAPHY files.
-The function handles \".bib\", \".bibtex\" and \".json\" files."
-  (let ((cache (make-hash-table :test #'equal)))
-    (dolist (file bibliography)
-      (pcase (file-name-extension file)
-        ("json"
-         (let ((json-array-type 'list)
-               (json-key-type 'symbol))
-           (dolist (item (json-read-file file))
-             (puthash (cdr (assq 'id item)) item cache))))
-        ((and (or "bib" "bibtex") ext)
-         (with-temp-buffer
-	   (insert-file-contents file)
-	   (goto-char (point-min))
-	   (bibtex-set-dialect (if (string= ext "bib") 'biblatex 'BibTeX) t)
-	   (bibtex-map-entries
-	    (lambda (key &rest _)
-              (puthash key
-                       (citeproc-bt-entry-to-csl (bibtex-parse-entry))
-                       cache)))))
-        (ext
-         (user-error "Unknown bibliography extension: %S" ext))))
-    (lambda (itemids)
-      (mapcar (lambda (id)
-                (cons id (gethash id cache)))
-              itemids))))
-
 (defun org-cite-csl--locale-getter ()
   "Return a locale getter.
 The getter looks for locales in `org-cite-csl-locales-dir' directory.  If it
@@ -391,7 +364,7 @@ property in INFO."
              (processor
               (citeproc-create
                (org-cite-csl--style-file info)
-               (org-cite-csl--itemgetter bibliography)
+               (citeproc-hash-itemgetter-from-any bibliography)
                (org-cite-csl--locale-getter)
                locale)))
         (plist-put info :cite-citeproc-processor processor)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters
  2021-09-20 11:56 [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters András Simonyi
@ 2021-09-20 12:29 ` Timothy
  2021-09-20 14:22   ` András Simonyi
  2021-09-26 10:37 ` Bastien
  1 sibling, 1 reply; 4+ messages in thread
From: Timothy @ 2021-09-20 12:29 UTC (permalink / raw)
  To: András Simonyi; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 737 bytes --]

Hi  András,

Great to see this patch from you 🙂.

> this is the first item in a series of oc-csl patches which I’ve
> accumulated and am planning to send this week. (My first attempt to
> send a patch, so please be patient and forgiving :-) )

This may be your first attempt sending a patch, but it all looks good to me.
Simply attaching a `.patch' file is all that’s needed, and you seem to be
following our commit message guidelines, which is good to see.

Regarding the content of this patch and the few you have planned that follow —
would it be fair to say that overall you’re trying to update `oc-csl' based on
changes you’ve made to `citeproc-el' since `oc-csl' was written?

All the best,
Timothy

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters
  2021-09-20 12:29 ` Timothy
@ 2021-09-20 14:22   ` András Simonyi
  0 siblings, 0 replies; 4+ messages in thread
From: András Simonyi @ 2021-09-20 14:22 UTC (permalink / raw)
  To: Timothy; +Cc: emacs-orgmode list

Hi Timothy,

> Regarding the content of this patch and the few you have planned that follow —
> would it be fair to say that overall you’re trying to update `oc-csl' based on
> changes you’ve made to `citeproc-el' since `oc-csl' was written?

yes exactly, basically all of my patches are directed towards keeping
oc-csl in sync with the changes/improvements in citeproc-el.
bes wishes,
András


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters
  2021-09-20 11:56 [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters András Simonyi
  2021-09-20 12:29 ` Timothy
@ 2021-09-26 10:37 ` Bastien
  1 sibling, 0 replies; 4+ messages in thread
From: Bastien @ 2021-09-26 10:37 UTC (permalink / raw)
  To: András Simonyi; +Cc: emacs-orgmode list

Hi András,

András Simonyi <andras.simonyi@gmail.com> writes:

> this is the first item in a series of oc-csl patches which I've
> accumulated and am planning to send this week. (My first attempt to
> send a patch, so please be patient and forgiving :-) )

Thanks for your patch! I just applied it in the main branch.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-26 10:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-20 11:56 [PATCH] org-cite: Use citeproc-el to create CSL processor itemgetters András Simonyi
2021-09-20 12:29 ` Timothy
2021-09-20 14:22   ` András Simonyi
2021-09-26 10:37 ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).