Browse Source

org.el (org-babel-load-file): Set `exported-file' correctly

* org.el (org-babel-load-file): Set `exported-file' correctly,
in case the file as been tangled using a buffer-local value.

* ob-tangle.el (org-babel-tangle-file): Return the list of
tangled files.

Thanks to Sam Flint for reporting this.
Bastien Guerry 7 years ago
parent
commit
56d405a41c
2 changed files with 11 additions and 8 deletions
  1. 9 7
      lisp/ob-tangle.el
  2. 2 1
      lisp/org.el

+ 9 - 7
lisp/ob-tangle.el

@@ -144,16 +144,18 @@ evaluating BODY."
 Source code blocks are extracted with `org-babel-tangle'.
 Optional argument TARGET-FILE can be used to specify a default
 export file for all source blocks.  Optional argument LANG can be
-used to limit the exported source code blocks by language."
+used to limit the exported source code blocks by language.
+Return a list whose CAR is the tangled file name."
   (interactive "fFile to tangle: \nP")
   (let ((visited-p (get-file-buffer (expand-file-name file)))
 	to-be-removed)
-    (save-window-excursion
-      (find-file file)
-      (setq to-be-removed (current-buffer))
-      (org-babel-tangle nil target-file lang))
-    (unless visited-p
-      (kill-buffer to-be-removed))))
+    (prog1
+	(save-window-excursion
+	  (find-file file)
+	  (setq to-be-removed (current-buffer))
+	  (org-babel-tangle nil target-file lang))
+      (unless visited-p
+	(kill-buffer to-be-removed)))))
 
 (defun org-babel-tangle-publish (_ filename pub-dir)
   "Tangle FILENAME and place the results in PUB-DIR."

+ 2 - 1
lisp/org.el

@@ -198,7 +198,8 @@ file to byte-code before it is loaded."
     ;; tangle if the org-mode file is newer than the elisp file
     (unless (and (file-exists-p exported-file)
 		 (> (funcall age file) (funcall age exported-file)))
-      (org-babel-tangle-file file exported-file "emacs-lisp"))
+      (setq exported-file
+	    (car (org-babel-tangle-file file exported-file "emacs-lisp"))))
     (message "%s %s"
 	     (if compile
 		 (progn (byte-compile-file exported-file 'load)