瀏覽代碼

babel: tangle works when buffer name and file name differ

  Thanks to "w t" from the mailing list for reporting this bug and
  providing reproduction information.
Eric Schulte 14 年之前
父節點
當前提交
c5e3660fa9
共有 2 個文件被更改,包括 15 次插入4 次删除
  1. 8 1
      contrib/babel/lisp/org-babel-tangle.el
  2. 7 3
      contrib/babel/lisp/org-babel.el

+ 8 - 1
contrib/babel/lisp/org-babel-tangle.el

@@ -71,7 +71,14 @@ specify a default export file for all source blocks.  Optional
 argument LANG can be used to limit the exported source code
 blocks by language."
   (interactive "fFile to tangle: \nP")
-  (save-window-excursion (find-file file) (org-babel-tangle target-file lang)))
+  (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 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."

+ 7 - 3
contrib/babel/lisp/org-babel.el

@@ -562,14 +562,18 @@ with C-c C-c."
 (defmacro org-babel-map-source-blocks (file &rest body)
   "Evaluate BODY forms on each source-block in FILE."
   (declare (indent 1))
-  `(let ((visited-p (get-buffer (file-name-nondirectory ,file))))
+  `(let ((visited-p (get-file-buffer (expand-file-name ,file)))
+	 to-be-removed)
      (save-window-excursion
-       (find-file ,file) (goto-char (point-min))
+       (find-file ,file)
+       (setq to-be-removed (current-buffer))
+       (goto-char (point-min))
        (while (re-search-forward org-babel-src-block-regexp nil t)
          (goto-char (match-beginning 0))
          (save-match-data ,@body)
          (goto-char (match-end 0))))
-     (unless visited-p (kill-buffer (file-name-nondirectory ,file)))))
+     (unless visited-p
+       (kill-buffer to-be-removed))))
 
 (defun org-babel-params-from-properties (&optional lang)
   "Return an association list of any source block params which