Browse Source

ob-tangle: org-babel-post-tangle-hook no longer kills the current buffer

* lisp/ob-tangle.el (org-babel-find-file-noselect-refresh): finds a
  file ensuing that the latest changes on disk are represented

  (org-babel-with-temp-filebuffer): now only kills the buffer of the
  tangled file, and doesn't kill said buffer if the file is already
  being visited
Eric Schulte 14 years ago
parent
commit
f6ccee2568
1 changed files with 15 additions and 5 deletions
  1. 15 5
      lisp/ob-tangle.el

+ 15 - 5
lisp/ob-tangle.el

@@ -53,18 +53,28 @@ then the name of the language is used."
   :group 'org-babel
   :type 'hook)
 
+(defun org-babel-find-file-noselect-refresh (file)
+  "Find file ensuring that the latest changes on disk are
+represented in the file."
+  (find-file-noselect file)
+  (with-current-buffer (get-file-buffer file)
+    (revert-buffer t t t)))
+
 (defmacro org-babel-with-temp-filebuffer (file &rest body)
   "Open FILE into a temporary buffer execute BODY there like
 `progn', then kill the FILE buffer returning the result of
 evaluating BODY."
   (declare (indent 1))
   (let ((temp-result (make-symbol "temp-result"))
-	(temp-file (make-symbol "temp-file")))
+	(temp-file (make-symbol "temp-file"))
+	(visited-p (make-symbol "already-visited")))
     `(let (,temp-result ,temp-file)
-       (find-file-noselect ,file)
-       (setf ,temp-file (current-buffer))
-       (setf ,temp-result (progn ,@body))
-       (kill-buffer ,temp-file)
+       (setq ,visited-p (get-file-buffer ,file ))
+       (org-babel-find-file-noselect-refresh ,file)
+       (setf ,temp-file (get-file-buffer ,file))
+       (with-current-buffer ,temp-file
+	 (setf ,temp-result (progn ,@body)))
+       (unless ,visited-p (kill-buffer ,temp-file))
        ,temp-result)))
 
 ;;;###autoload