Browse Source

org-babel-post-tangle-hook run in code files tangled by `org-babel-tangle'

* lisp/ob-tangle.el (org-babel-post-tangle-hook): adding hook which
  can be used to call functions from inside of code files tangled by
  org-babel-tangle

  (org-babel-tangle): added call to org-babel-post-tangle-hook
Eric Schulte 14 years ago
parent
commit
abcb76891b
1 changed files with 13 additions and 1 deletions
  1. 13 1
      lisp/ob-tangle.el

+ 13 - 1
lisp/ob-tangle.el

@@ -47,6 +47,11 @@ then the name of the language is used."
 	   (string "Language name")
 	   (string "File Extension"))))
 
+(defcustom org-babel-post-tangle-hook nil
+  "Hook run in code files tangled by `org-babel-tangle'."
+  :group 'org-babel
+  :type 'hook)
+
 ;;;###autoload
 (defun org-babel-load-file (file)
   "Load the contents of the Emacs Lisp source code blocks in the
@@ -138,7 +143,7 @@ exported source code blocks by language."
                       (delete-file file-name))
                     ;; drop source-block to file
                     (with-temp-buffer
-                      (if (fboundp lang-f) (funcall lang-f))
+                      (when (fboundp lang-f) (funcall lang-f))
                       (when (and she-bang (not (member file-name she-banged)))
                         (insert (concat she-bang "\n"))
                         (setq she-banged (cons file-name she-banged)))
@@ -160,6 +165,13 @@ exported source code blocks by language."
        (org-babel-tangle-collect-blocks lang))
       (message "tangled %d code block%s" block-counter
                (if (= block-counter 1) "" "s"))
+      ;; run `org-babel-post-tangle-hook' in all tangled files
+      (when org-babel-post-tangle-hook
+	(mapc
+	 (lambda (file)
+	   (with-temp-filebuffer file
+	     (run-hooks 'org-babel-post-tangle-hook)))
+	 path-collector))
       path-collector)))
 
 (defun org-babel-tangle-clean ()