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.
This commit is contained in:
Eric Schulte 2010-06-02 07:18:36 -06:00
parent 47a6c25df3
commit c5e3660fa9
2 changed files with 15 additions and 4 deletions

View file

@ -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."

View file

@ -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