diff options
author | Eric Schulte <schulte.eric@gmail.com> | 2011-03-14 09:31:33 -0600 |
---|---|---|
committer | Eric Schulte <schulte.eric@gmail.com> | 2011-03-14 09:31:33 -0600 |
commit | a793b7762515897451fc02d301d0591c6c7072d1 (patch) | |
tree | b39812257271c8badb447f9341738bdb09383efe | |
parent | 4fc3e71f10f238cd2461b785b8ec1b0ecb4ec16b (diff) | |
download | org-mode-a793b7762515897451fc02d301d0591c6c7072d1.tar.gz |
ob-tangle: new hook for pre-processing code block bodies on tangling
* lisp/ob-tangle.el (org-babel-tangle-body-hook): Hook for changing
the contents of a code block body on export.
(org-babel-tangle-collect-blocks): Apply
`org-babel-tangle-body-hook' to the collected bodies of code blocks.
-rw-r--r-- | lisp/ob-tangle.el | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 4e203be..138084f 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -63,6 +63,11 @@ then the name of the language is used." :group 'org-babel :type 'hook) +(defcustom org-babel-tangle-body-hook nil + "Hook run over the contents of each code block body." + :group 'org-babel + :type 'hook) + (defcustom org-babel-tangle-pad-newline t "Switch indicating whether to pad tangled code with newlines." :group 'org-babel @@ -307,22 +312,27 @@ code blocks by language." (assignments-cmd (intern (concat "org-babel-variable-assignments:" src-lang))) (body - ((lambda (body) - (if (assoc :no-expand params) - body - (if (fboundp expand-cmd) - (funcall expand-cmd body params) - (org-babel-expand-body:generic - body params - (and (fboundp assignments-cmd) - (funcall assignments-cmd params)))))) - (if (and (cdr (assoc :noweb params)) - (let ((nowebs (split-string - (cdr (assoc :noweb params))))) - (or (member "yes" nowebs) - (member "tangle" nowebs)))) - (org-babel-expand-noweb-references info) - (nth 1 info)))) + ((lambda (body) ;; run the tangle-body-hook + (with-temp-buffer + (insert body) + (run-hooks 'org-babel-tangle-body-hook) + (buffer-string))) + ((lambda (body) ;; expand the body in language specific manner + (if (assoc :no-expand params) + body + (if (fboundp expand-cmd) + (funcall expand-cmd body params) + (org-babel-expand-body:generic + body params + (and (fboundp assignments-cmd) + (funcall assignments-cmd params)))))) + (if (and (cdr (assoc :noweb params)) ;; expand noweb refs + (let ((nowebs (split-string + (cdr (assoc :noweb params))))) + (or (member "yes" nowebs) + (member "tangle" nowebs)))) + (org-babel-expand-noweb-references info) + (nth 1 info))))) (comment (when (or (string= "both" (cdr (assoc :comments params))) (string= "org" (cdr (assoc :comments params)))) |