[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 78783f4 48/85: ob-core.el: Add ability to use closu
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 78783f4 48/85: ob-core.el: Add ability to use closures as default header arguments |
Date: |
Mon, 27 Sep 2021 15:57:48 -0400 (EDT) |
branch: externals/org
commit 78783f4e47901255695031dae0efcbb301a40878
Author: Matt Huszagh <huszaghmatt@gmail.com>
Commit: Bastien <bzg@gnu.org>
ob-core.el: Add ability to use closures as default header arguments
* lisp/ob-core.el (org-babel-default-header-args): Document ability to
use functions.
(eval-default-headers): New function to generate default header
arguments, which adds the ability to evaluate function arguments at
runtime.
(org-babel-get-src-block-info): Use new header argument evaluate
function when retreiving src block info.
* lisp/ob-exp.el (org-babel-exp-src-block): Must use new
eval-default-headers when exporting as well.
The closures are evaluated at runtime.
---
lisp/ob-core.el | 32 ++++++++++++++++++++++++++++++--
lisp/ob-exp.el | 2 +-
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index f3b495f..f325228 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -472,7 +472,23 @@ For the format of SAFE-LIST, see
`org-babel-safe-header-args'."
(defvar org-babel-default-header-args
'((:session . "none") (:results . "replace") (:exports . "code")
(:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
- "Default arguments to use when evaluating a source block.")
+ "Default arguments to use when evaluating a source block.
+
+This is a list in which each element is an alist. Each key
+corresponds to a header argument, and each value to that header's
+value. The value can either be a string or a closure that
+evaluates to a string at runtime. For instance, imagine you'd
+like to set the file name output of a latex source block to a
+sha1 of its contents. We could achieve this with:
+
+(defun org-src-sha ()
+ (let ((elem (org-element-at-point)))
+ (concat (sha1 (org-element-property :value elem)) \".svg\")))
+
+(setq org-babel-default-header-args:latex
+ `((:results . \"file link replace\")
+ (:file . (lambda () (org-src-sha)))))")
+
(put 'org-babel-default-header-args 'safe-local-variable
(org-babel-header-args-safe-fn org-babel-safe-header-args))
@@ -583,6 +599,18 @@ the outer-most code block.")
(defvar *this*)
+(defun eval-default-headers (headers)
+ "Compute default header list set with HEADERS.
+
+ Evaluate all default header arguments set to functions prior to
+ returning the list of header arguments."
+ (let ((lst nil))
+ (dolist (elem (eval headers t))
+ (if (listp (cdr elem))
+ (push `(,(car elem) . ,(funcall (cdr elem))) lst)
+ (push elem lst)))
+ lst))
+
(defun org-babel-get-src-block-info (&optional light datum)
"Extract information from a source block or inline source block.
@@ -614,7 +642,7 @@ a list with the following pattern:
(apply #'org-babel-merge-params
(if inline org-babel-default-inline-header-args
org-babel-default-header-args)
- (and (boundp lang-headers) (eval lang-headers t))
+ (and (boundp lang-headers) (eval-default-headers
lang-headers))
(append
;; If DATUM is provided, make sure we get node
;; properties applicable to its location within
diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index e9b304b..151ae71 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -104,7 +104,7 @@ Assume point is at block opening line."
(apply #'org-babel-merge-params
org-babel-default-header-args
(and (boundp lang-headers)
- (symbol-value lang-headers))
+ (eval-default-headers lang-headers))
(append (org-babel-params-from-properties lang)
(list raw-params)))))))
(setf hash (org-babel-sha1-hash info :export)))
- [elpa] externals/org 26b0297 20/85: Merge branch 'bugfix', (continued)
- [elpa] externals/org 26b0297 20/85: Merge branch 'bugfix', ELPA Syncer, 2021/09/27
- [elpa] externals/org 45a5f17 21/85: org-manual.org: Augment TODO keywords example, ELPA Syncer, 2021/09/27
- [elpa] externals/org 35690cd 36/85: org-src.el (org-src--contents-for-write-back): Do not indent blank lines, ELPA Syncer, 2021/09/27
- [elpa] externals/org faf1ba8 34/85: Merge branch 'bugfix', ELPA Syncer, 2021/09/27
- [elpa] externals/org 63a5af9 63/85: Backport commit 85e9e5f61 from Emacs, ELPA Syncer, 2021/09/27
- [elpa] externals/org 5e58af5 52/85: oc-csl: Use citeproc-el to create CSL processor itemgetters, ELPA Syncer, 2021/09/27
- [elpa] externals/org be0cdd1 40/85: org-mouse: Support intermediate-state checkboxes, ELPA Syncer, 2021/09/27
- [elpa] externals/org db67c7e 55/85: Move some ob-*el files to the new org-contrib repo, ELPA Syncer, 2021/09/27
- [elpa] externals/org 2aa2615 59/85: Document new agenda faces in the ORG-NEWS, ELPA Syncer, 2021/09/27
- [elpa] externals/org b80b0a5 51/85: org-clock.el: Make org-notify support macOS notification, ELPA Syncer, 2021/09/27
- [elpa] externals/org 78783f4 48/85: ob-core.el: Add ability to use closures as default header arguments,
ELPA Syncer <=
- [elpa] externals/org b2da9ea 64/85: Backport commit 0da8118dc from Emacs, ELPA Syncer, 2021/09/27
- [elpa] externals/org 7d67719 68/85: org-manual: comment about latex code-block export, ELPA Syncer, 2021/09/27
- [elpa] externals/org 80798fc 72/85: oc.el (org-cite-register-processor): Silence a compiler warning, ELPA Syncer, 2021/09/27
- [elpa] externals/org 593740c 74/85: etc/ORG-NEWS: Mention the citation engine and reorder items, ELPA Syncer, 2021/09/27
- [elpa] externals/org c76a7ee 76/85: org: Refactor width in `org-display-inline-images', ELPA Syncer, 2021/09/27
- [elpa] externals/org e816ae1 75/85: org: Display proportional image widths, ELPA Syncer, 2021/09/27
- [elpa] externals/org 981bcbf 80/85: Merge branch 'bugfix', ELPA Syncer, 2021/09/27
- [elpa] externals/org c90f96c 77/85: org: Support displaying X% width images, ELPA Syncer, 2021/09/27
- [elpa] externals/org 4594423 79/85: doc/org-manual.org: Fix typo, ELPA Syncer, 2021/09/27
- [elpa] externals/org 09dc3fa 83/85: org-protocol.el: decode "+" in query part as space, ELPA Syncer, 2021/09/27