[-- Attachment #1: Type: text/plain, Size: 165 bytes --] Dear All, the attached patch adds support for the text (textual) and year (year-only) citation styles in the CSL org-cite processor. best wishes, András [-- Attachment #2: 0001-oc-csl-Add-support-for-the-text-and-year-citation-st.patch --] [-- Type: text/x-patch, Size: 7419 bytes --] From ce91f9332ed154fd14f36177bc6dd96cdda0690e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Simonyi?= <andras.simonyi@gmail.com> Date: Tue, 28 Sep 2021 11:45:13 +0200 Subject: [PATCH] oc-csl: Add support for the text and year citation styles * lisp/oc-csl.el (org-cite-csl--create-structure-params): Introduce this new function to map the extended list of supported citation styles and variants to the corresponding citeproc-el citation structure creation parameters. (org-cite-csl--no-affixes-p, org-cite-csl--capitalize-p, org-cite-csl--no-author-p): Remove them since their functionality is provided now by `org-cite-csl--create-structure-params'. (org-cite-csl--parse-reference): Don't generate `suppress-author' cite information as that is treated now by citeproc-el as a citation style. (org-cite-csl--create-structure): Use `org-cite-csl--create-structure-params' to generate style-dependent citation structure parameters. --- lisp/oc-csl.el | 95 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 64 insertions(+), 31 deletions(-) diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el index 645b1c0f9..51d3d3d8a 100644 --- a/lisp/oc-csl.el +++ b/lisp/oc-csl.el @@ -54,7 +54,10 @@ ;; The library supports the following citation styles: ;; +;; - author (a), including caps (c), full (f), and caps-full (cf) variants, ;; - noauthor (na), including bare (b), caps (c) and bare-caps (bc) variants, +;; - year (y), including a bare (b) variant, +;; - text (t). including caps (c), full (f), and caps-full (cf) variants, ;; - default style, including bare (b), caps (c) and bare-caps (bc) variants. ;; CSL styles recognize "locator" in citation references' suffix. For example, @@ -277,26 +280,54 @@ INFO is the export state, as a property list." (citeproc-proc-style (org-cite-csl--processor info)))) -(defun org-cite-csl--no-affixes-p (citation info) - "Non-nil when CITATION should be exported without affix. -INFO is the export data, as a property list." - (pcase (org-cite-citation-style citation info) - (`(,(or "noauthor" "na" `nil) . ,(or "bare" "b" "bare-caps" "bc")) t) - (_ nil))) - -(defun org-cite-csl--capitalize-p (citation info) - "Non-nil when CITATION should be capitalized. -INFO is the export-data, as a property list." - (pcase (org-cite-citation-style citation info) - (`(,(or "noauthor" "na" `nil) . ,(or "caps" "c" "bare-caps" "bc")) t) - (_ nil))) - -(defun org-cite-csl--no-author-p (reference info) - "Non-nil when citation REFERENCE should be exported without author. -INFO is the export data, as a property list." - (pcase (org-cite-citation-style (org-element-property :parent reference) info) - (`(,(or "noauthor" "na") . ,_) t) - (_ nil))) +(defun org-cite-csl--create-structure-params (citation info) + "Return citeproc structure creation params for CITATION object. +STYLE is the citation style, as a string or nil. INFO is the export state, as +a property list." + (let* ((style (org-cite-citation-style citation info))) + (pcase style + ;; "author" style. + (`(,(or "author" "a") . ,(or "caps" "c")) + '(:mode author-only :capitalize-first t :suppress-affixes t)) + (`(,(or "author" "a") . ,(or "full" "f")) + '(:mode author-only :ignore-et-al t :suppress-affixes t)) + (`(,(or "author" "a") . ,(or "caps-full" "cf")) + '(:mode author-only :capitalize-first t :ignore-et-al t :suppress-affixes t)) + (`(,(or "author" "a") . ,_) + '(:mode author-only :suppress-affixes t)) + ;; "noauthor" style. + (`(,(or "noauthor" "na") . ,(or "bare" "b")) + '(:mode suppress-author :suppress-affixes t)) + (`(,(or "noauthor" "na") . ,(or "caps" "c")) + '(:mode suppress-author :capitalize-first t)) + (`(,(or "noauthor" "na") . ,(or "bare-caps" "bc")) + '(:mode suppress-author :suppress-affixes t :capitalize-first t)) + (`(,(or "noauthor" "na") . ,_) + '(:mode suppress-author)) + ;; "year" style. + (`(,(or "year" "y") . ,(or "bare" "b")) + '(:mode year-only :suppress-affixes t)) + (`(,(or "year" "y") . ,_) + '(:mode year-only)) + ;; "text" style. + (`(,(or "text" "t") . ,(or "caps" "c")) + '(:mode textual :capitalize-first t)) + (`(,(or "text" "t") . ,(or "full" "f")) + '(:mode textual :ignore-et-al t)) + (`(,(or "text" "t") . ,(or "caps-full" "cf")) + '(:mode textual :ignore-et-al t :capitalize-first t)) + (`(,(or "text" "t") . ,_) + '(:mode textual)) + ;; Default "nil" style. + (`(,_ . ,(or "bare" "b")) + '(:suppress-affixes t)) + (`(,_ . ,(or "caps" "c")) + '(:capitalize-first t)) + (`(,_ . ,(or "bare-caps" "bc")) + '(:suppress-affixes t :capitalize-first t)) + (`(,_ . ,_) nil) + ;; This should not happen. + (_ (error "Invalid style: %S" style))))) (defun org-cite-csl--no-citelinks-p (info) "Non-nil when export BACKEND should not create cite-reference links." @@ -375,8 +406,8 @@ property in INFO." INFO is the export state, as a property list. -The result is a association list. Keys are: `id', `suppress-author', `prefix', -`suffix', `location', `locator' and `label'." +The result is a association list. Keys are: `id', `prefix',`suffix', +`location', `locator' and `label'." (let (label location-start locator-start location locator prefix suffix) ;; Parse suffix. Insert it in a temporary buffer to find ;; different parts: pre-label, label, locator, location (label + @@ -434,8 +465,7 @@ The result is a association list. Keys are: `id', `suppress-author', `prefix', (suffix . ,(funcall export suffix)) (locator . ,locator) (label . ,label) - (location . ,location) - (suppress-author . ,(org-cite-csl--no-author-p reference info)))))) + (location . ,location))))) (defun org-cite-csl--create-structure (citation info) "Create Citeproc structure for CITATION object. @@ -465,11 +495,11 @@ INFO is the export state, as a property list." (org-cite-adjust-note citation info) (org-cite-wrap-citation citation info)) ;; Return structure. - (citeproc-citation-create - :note-index (and footnote (org-export-get-footnote-number footnote info)) - :cites cites - :capitalize-first (or footnote (org-cite-csl--capitalize-p citation info)) - :suppress-affixes (org-cite-csl--no-affixes-p citation info)))) + (apply #'citeproc-citation-create + `(:note-index + ,(and footnote (org-export-get-footnote-number footnote info)) + :cites ,cites + ,@(org-cite-csl--create-structure-params citation info))))) (defun org-cite-csl--rendered-citations (info) "Return the rendered citations as an association list. @@ -578,8 +608,11 @@ property list." :export-bibliography #'org-cite-csl-render-bibliography :export-finalizer #'org-cite-csl-finalizer :cite-styles - '((("noauthor" "na") ("bare" "b") ("bare-caps" "bc") ("caps" "c")) - (("nil") ("bare" "b") ("bare-caps" "bc") ("caps" "c")))) + '((("author" "a") ("full" "f") ("caps" "c") ("caps-full" "cf")) + (("noauthor" "na") ("bare" "b") ("caps" "c") ("bare-caps" "bc")) + (("year" "y") ("bare" "b")) + (("text" "t") ("caps" "c") ("full" "f") ("caps-full" "cf")) + (("nil") ("bare" "b") ("caps" "c") ("bare-caps" "bc")))) (provide 'oc-csl) ;;; oc-csl.el ends here -- 2.25.1
Dear András,
András Simonyi <andras.simonyi@gmail.com> writes:
> the attached patch adds support for the text (textual) and year
> (year-only) citation styles in the CSL org-cite processor.
Applied, thank you very much!
--
Bastien
Hello, Bastien <bzg@gnu.org> writes: > Dear András, > > András Simonyi <andras.simonyi@gmail.com> writes: > >> the attached patch adds support for the text (textual) and year >> (year-only) citation styles in the CSL org-cite processor. > > Applied, thank you very much! The function `org-cite-csl--create-structure-params' probably needs to be refactored, as the pcase pattern is going to put the byte-compiler to a knee. See, e.g., a6d93cfb621356893dc69fc779894c0984cedbd1 and related thread at <http://lists.gnu.org/r/emacs-orgmode/2021-08/msg00100.html>. Regards, -- Nicolas Goaziou
On 28/09/2021 21:40, Bastien wrote: > András Simonyi writes: > >> the attached patch adds support for the text (textual) and year >> (year-only) citation styles in the CSL org-cite processor. > > Applied, thank you very much! This patch has a problem similar to ones earlier fixed by Nicolas: https://orgmode.org/list/seomi1$785$1@ciao.gmane.io "Re: citations: rx problems with emacs-26.3" Sun, 8 Aug 2021 20:34:55 +0700 Compiling single /home/ubuntu/org-mode/lisp/oc-csl.el... In toplevel form: oc-csl.el:330:10:Error: Bytecode overflow Makefile:59: recipe for target 'oc-csl.elc' failed make[2]: [oc-csl.elc] Error 1 (ignored) It is for emacs-26.3 (Ubuntu-18.04 LTS bionic).
Thanks, I'll try to put together a patch fixing the problem and send it shortly.
best wishes,
András
On Tue, 28 Sept 2021 at 17:03, Max Nikulin <manikulin@gmail.com> wrote:
>
> On 28/09/2021 21:40, Bastien wrote:
> > András Simonyi writes:
> >
> >> the attached patch adds support for the text (textual) and year
> >> (year-only) citation styles in the CSL org-cite processor.
> >
> > Applied, thank you very much!
>
> This patch has a problem similar to ones earlier fixed by Nicolas:
> https://orgmode.org/list/seomi1$785$1@ciao.gmane.io "Re: citations: rx
> problems with emacs-26.3" Sun, 8 Aug 2021 20:34:55 +0700
>
> Compiling single /home/ubuntu/org-mode/lisp/oc-csl.el...
>
> In toplevel form:
> oc-csl.el:330:10:Error: Bytecode overflow
> Makefile:59: recipe for target 'oc-csl.elc' failed
> make[2]: [oc-csl.elc] Error 1 (ignored)
>
> It is for emacs-26.3 (Ubuntu-18.04 LTS bionic).
[-- Attachment #1: Type: text/plain, Size: 1221 bytes --] Dear All, I've attached a patch with the pcase pattern refactored following Nicolas's example -- hopefully this solves the problem. best wishes, András On Tue, 28 Sept 2021 at 17:16, András Simonyi <andras.simonyi@gmail.com> wrote: > > Thanks, I'll try to put together a patch fixing the problem and send it shortly. > best wishes, > András > > On Tue, 28 Sept 2021 at 17:03, Max Nikulin <manikulin@gmail.com> wrote: > > > > On 28/09/2021 21:40, Bastien wrote: > > > András Simonyi writes: > > > > > >> the attached patch adds support for the text (textual) and year > > >> (year-only) citation styles in the CSL org-cite processor. > > > > > > Applied, thank you very much! > > > > This patch has a problem similar to ones earlier fixed by Nicolas: > > https://orgmode.org/list/seomi1$785$1@ciao.gmane.io "Re: citations: rx > > problems with emacs-26.3" Sun, 8 Aug 2021 20:34:55 +0700 > > > > Compiling single /home/ubuntu/org-mode/lisp/oc-csl.el... > > > > In toplevel form: > > oc-csl.el:330:10:Error: Bytecode overflow > > Makefile:59: recipe for target 'oc-csl.elc' failed > > make[2]: [oc-csl.elc] Error 1 (ignored) > > > > It is for emacs-26.3 (Ubuntu-18.04 LTS bionic). [-- Attachment #2: 0002-oc-csl-Refactor-code-to-help-byte-compilation.patch --] [-- Type: text/x-patch, Size: 4518 bytes --] From 2ec9af9693c236b6afae7e3d286eb8c6c87283b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20Simonyi?= <andras.simonyi@gmail.com> Date: Tue, 28 Sep 2021 18:13:11 +0200 Subject: [PATCH 2/2] oc-csl: Refactor code to help byte-compilation * lisp/oc-csl.el (org-cite-csl--create-structure-params): Refactor pcase pattern to avoid slow or in some cases non-terminating byte compilation. --- lisp/oc-csl.el | 82 +++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 44 deletions(-) diff --git a/lisp/oc-csl.el b/lisp/oc-csl.el index 51d3d3d8a..3c77e0354 100644 --- a/lisp/oc-csl.el +++ b/lisp/oc-csl.el @@ -284,50 +284,44 @@ INFO is the export state, as a property list." "Return citeproc structure creation params for CITATION object. STYLE is the citation style, as a string or nil. INFO is the export state, as a property list." - (let* ((style (org-cite-citation-style citation info))) - (pcase style - ;; "author" style. - (`(,(or "author" "a") . ,(or "caps" "c")) - '(:mode author-only :capitalize-first t :suppress-affixes t)) - (`(,(or "author" "a") . ,(or "full" "f")) - '(:mode author-only :ignore-et-al t :suppress-affixes t)) - (`(,(or "author" "a") . ,(or "caps-full" "cf")) - '(:mode author-only :capitalize-first t :ignore-et-al t :suppress-affixes t)) - (`(,(or "author" "a") . ,_) - '(:mode author-only :suppress-affixes t)) - ;; "noauthor" style. - (`(,(or "noauthor" "na") . ,(or "bare" "b")) - '(:mode suppress-author :suppress-affixes t)) - (`(,(or "noauthor" "na") . ,(or "caps" "c")) - '(:mode suppress-author :capitalize-first t)) - (`(,(or "noauthor" "na") . ,(or "bare-caps" "bc")) - '(:mode suppress-author :suppress-affixes t :capitalize-first t)) - (`(,(or "noauthor" "na") . ,_) - '(:mode suppress-author)) - ;; "year" style. - (`(,(or "year" "y") . ,(or "bare" "b")) - '(:mode year-only :suppress-affixes t)) - (`(,(or "year" "y") . ,_) - '(:mode year-only)) - ;; "text" style. - (`(,(or "text" "t") . ,(or "caps" "c")) - '(:mode textual :capitalize-first t)) - (`(,(or "text" "t") . ,(or "full" "f")) - '(:mode textual :ignore-et-al t)) - (`(,(or "text" "t") . ,(or "caps-full" "cf")) - '(:mode textual :ignore-et-al t :capitalize-first t)) - (`(,(or "text" "t") . ,_) - '(:mode textual)) - ;; Default "nil" style. - (`(,_ . ,(or "bare" "b")) - '(:suppress-affixes t)) - (`(,_ . ,(or "caps" "c")) - '(:capitalize-first t)) - (`(,_ . ,(or "bare-caps" "bc")) - '(:suppress-affixes t :capitalize-first t)) - (`(,_ . ,_) nil) - ;; This should not happen. - (_ (error "Invalid style: %S" style))))) + (let ((style (org-cite-citation-style citation info))) + (pcase style + ;; "author" style. + (`(,(or "author" "a") . ,variant) + (pcase variant + ((or "caps" "c") '(:mode author-only :capitalize-first t)) + ((or "full" "f") '(:mode author-only :ignore-et-al t)) + ((or "caps-full" "cf") '(:mode author-only :capitalize-first t :ignore-et-al t)) + (_ '(:mode author-only)))) + ;; "noauthor" style. + (`(,(or "noauthor" "na") . ,variant) + (pcase variant + ((or "bare" "b") '(:mode suppress-author :suppress-affixes t)) + ((or "caps" "c") '(:mode suppress-author :capitalize-first t)) + ((or "bare-caps" "bc") + '(:mode suppress-author :suppress-affixes t :capitalize-first t)) + (_ '(:mode suppress-author)))) + ;; "year" style. + (`(,(or "year" "y") . ,variant) + (pcase variant + ((or "bare" "b") '(:mode year-only :suppress-affixes t)) + (_ '(:mode year-only)))) + ;; "text" style. + (`(,(or "text" "t") . ,variant) + (pcase variant + ((or "caps" "c") '(:mode textual :capitalize-first t)) + ((or "full" "f") '(:mode textual :ignore-et-al t)) + ((or "caps-full" "cf") '(:mode textual :ignore-et-al t :capitalize-first t)) + (_ '(:mode textual)))) + ;; Default "nil" style. + (`(,_ . ,variant) + (pcase variant + ((or "caps" "c") '(:capitalize-first t)) + ((or "bare" "b") '(:suppress-affixes t)) + ((or "bare-caps" "bc") '(:suppress-affixes t :capitalize-first t)) + (_ nil))) + ;; This should not happen. + (_ (error "Invalid style: %S" style))))) (defun org-cite-csl--no-citelinks-p (info) "Non-nil when export BACKEND should not create cite-reference links." -- 2.25.1
On 28/09/2021 23:39, András Simonyi wrote: > > I've attached a patch with the pcase pattern refactored following > Nicolas's example -- hopefully this solves the problem. I do not see the issue any more. No pause during compilation, reasonable file size -rw-rw-r-- 1 ubuntu ubuntu 24992 Sep 28 16:48 lisp/oc-csl.el -rw-rw-r-- 1 ubuntu ubuntu 15767 Sep 28 16:48 lisp/oc-csl.elc > On Tue, 28 Sept 2021 at 17:16, András Simonyi <andras.simonyi@gmail.com> wrote: >> >> Thanks, I'll try to put together a patch fixing the problem and send it shortly. >> best wishes, >> András >> >> On Tue, 28 Sept 2021 at 17:03, Max Nikulin wrote: >>>> András Simonyi writes: >>>> >>>>> the attached patch adds support for the text (textual) and year >>>>> (year-only) citation styles in the CSL org-cite processor. >>> >>> This patch has a problem similar to ones earlier fixed by Nicolas: >>> https://orgmode.org/list/seomi1$785$1@ciao.gmane.io "Re: citations: rx >>> problems with emacs-26.3" Sun, 8 Aug 2021 20:34:55 +0700 >>> >>> Compiling single /home/ubuntu/org-mode/lisp/oc-csl.el... >>> >>> In toplevel form: >>> oc-csl.el:330:10:Error: Bytecode overflow >>> Makefile:59: recipe for target 'oc-csl.elc' failed >>> make[2]: [oc-csl.elc] Error 1 (ignored) >>> >>> It is for emacs-26.3 (Ubuntu-18.04 LTS bionic). Sorry for confusion, emacs-25.2 is shipped in ubuntu-18.04.
Hi András,
András Simonyi <andras.simonyi@gmail.com> writes:
> I've attached a patch with the pcase pattern refactored following
> Nicolas's example -- hopefully this solves the problem.
Applied - as you guess, I'm in "optimistic push" mode. Hopefully
this will help have someone review this if needed.
Thanks, and thanks to Nicolas for alerting soon enough,
--
Bastien