>From ce7b8d8d1eafa6f2e6d0e247661000fc5272a24c Mon Sep 17 00:00:00 2001 From: TEC Date: Sat, 7 May 2022 14:02:44 +0800 Subject: [PATCH 06/10] ox-latex: Refactor source block transcode fun sigs * lisp/ox-latex.el (org-latex-src-block--listings, org-latex-src-block--engraved, org-latex-src-block--minted, org-latex-src-block--custom): Refactor these --backend functions to use cl-defun with keys instead of having an 11-argument signature. (org-latex-src-block): Adjust for the change in signature of the --backend functions, and refactor the `cond' statement to use `pcase'. --- lisp/ox-latex.el | 82 +++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index 13ba6cd8c..4421bb8f5 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -3188,37 +3188,37 @@ (defun org-latex-src-block (src-block _contents info) contextual information." (when (org-string-nw-p (org-element-property :value src-block)) (let* ((lang (org-element-property :language src-block)) - (caption (org-element-property :caption src-block)) - (caption-above-p (org-latex--caption-above-p src-block info)) - (label (org-element-property :name src-block)) - (custom-env (and lang - (cadr (assq (intern lang) - org-latex-custom-lang-environments)))) - (num-start (org-export-get-loc src-block info)) - (retain-labels (org-element-property :retain-labels src-block)) - (attributes (org-export-read-attribute :attr_latex src-block)) - (float (plist-get attributes :float)) - (listings (plist-get info :latex-listings))) - (cond - ((or (not lang) (not listings)) - (org-latex-src-block--verbatim src-block info lang caption caption-above-p label - num-start retain-labels attributes float)) - (custom-env - (org-latex-src-block--custom src-block info lang caption caption-above-p label - num-start retain-labels attributes float custom-env)) - ((eq listings 'minted) - (org-latex-src-block--minted src-block info lang caption caption-above-p label - num-start retain-labels attributes float)) - ((eq listings 'engraved) - (org-latex-src-block--engraved src-block info lang caption caption-above-p label - num-start retain-labels attributes float)) - (t - (org-latex-src-block--listings src-block info lang caption caption-above-p label - num-start retain-labels attributes float)))))) - -(defun org-latex-src-block--verbatim - (src-block info _lang caption caption-above-p _label - _num-start _retain-labels _attributes float) + (caption (org-element-property :caption src-block)) + (caption-above-p (org-latex--caption-above-p src-block info)) + (label (org-element-property :name src-block)) + (custom-env (and lang + (cadr (assq (intern lang) + org-latex-custom-lang-environments)))) + (num-start (org-export-get-loc src-block info)) + (retain-labels (org-element-property :retain-labels src-block)) + (attributes (org-export-read-attribute :attr_latex src-block)) + (float (plist-get attributes :float)) + (listings (plist-get info :latex-listings))) + (funcall + (pcase listings + ((or (pred not) (guard (not lang))) #'org-latex-src-block--verbatim) + ((guard custom-env) #'org-latex-src-block--custom) + ('minted #'org-latex-src-block--minted) + ('engraved #'org-latex-src-block--engraved) + (_ #'org-latex-src-block--listings)) + :src-block src-block + :info info + :lang lang + :caption caption + :caption-above-p caption-above-p + :label label + :num-start num-start + :retain-labels retain-labels + :attributes attributes + :float float)))) + +(cl-defun org-latex-src-block--verbatim + (&key src-block info caption caption-above-p float &allow-other-keys) "Transcode a SRC-BLOCK element from Org to LaTeX, using verbatim. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." @@ -3237,9 +3237,8 @@ (defun org-latex-src-block--verbatim (if caption-above-p "" (concat "\n" caption-str)))) (t verbatim)))) -(defun org-latex-src-block--custom - (src-block info _lang caption caption-above-p _label - _num-start _retain-labels attributes float custom-env) +(cl-defun org-latex-src-block--custom + (&key src-block info caption caption-above-p attributes float custom-env &allow-other-keys) "Transcode a SRC-BLOCK element from Org to LaTeX, using a custom environment. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." @@ -3259,9 +3258,8 @@ (defun org-latex-src-block--custom (?l . ,(org-latex--label src-block info)) (?o . ,(or (plist-get attributes :options) ""))))))) -(defun org-latex-src-block--minted - (src-block info lang caption caption-above-p _label - num-start retain-labels attributes float) +(cl-defun org-latex-src-block--minted + (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys) "Transcode a SRC-BLOCK element from Org to LaTeX, using minted. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." @@ -3347,9 +3345,8 @@ (defun org-latex-src--engrave-code (content lang) engraved-code) (user-error "Cannot engrave code as `engrave-faces-latex' is unavailible."))) -(defun org-latex-src-block--engraved - (src-block info lang caption caption-above-p _label - num-start retain-labels attributes float) +(cl-defun org-latex-src-block--engraved + (&key src-block info lang caption caption-above-p num-start retain-labels attributes float &allow-other-keys) "Transcode a SRC-BLOCK element from Org to LaTeX, using engrave-faces-latex. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." @@ -3409,9 +3406,8 @@ (defun org-latex-src-block--engraved (org-latex-src--engrave-code content lang)))) (format float-env body))) -(defun org-latex-src-block--listings - (src-block info lang caption caption-above-p label - num-start retain-labels attributes float) +(cl-defun org-latex-src-block--listings + (&key src-block info lang caption caption-above-p label num-start retain-labels attributes float &allow-other-keys) "Transcode a SRC-BLOCK element from Org to LaTeX, using listings. LANG, CAPTION, CAPTION-ABOVE-P, LABEL, NUM-START, RETAIN-LABELS, ATTRIBUTES and FLOAT are extracted from SRC-BLOCK and INFO in `org-latex-src-block'." -- 2.35.3