ob-tangle: Respect buffer local variables

* lisp/ob-tangle.el (org-babel-tangle): Make sure buffer local
  variables from Org document are taken into consideration in tangled
  document.

Reported-by: David Dynerman <emperordali@block-party.net>
<http://permalink.gmane.org/gmane.emacs.orgmode/110577>
This commit is contained in:
Nicolas Goaziou 2016-12-03 23:55:28 +01:00
parent e72485336f
commit 026fb75ddb

View file

@ -271,25 +271,38 @@ used to limit the exported source code blocks by language."
(and (file-exists-p file-name) (and (file-exists-p file-name)
(not (member file-name (mapcar #'car path-collector))) (not (member file-name (mapcar #'car path-collector)))
(delete-file file-name)) (delete-file file-name))
;; drop source-block to file ;; Drop source-block to file. Preserve local
(with-temp-buffer ;; file variables set in original Org buffer so
(when (fboundp lang-f) (ignore-errors (funcall lang-f))) ;; that `org-babel-spec-to-string' doesn't
(when (and she-bang (not (member file-name she-banged))) ;; ignore them.
(insert (concat she-bang "\n")) (let ((org-babel-tangle-use-relative-file-links
(setq she-banged (cons file-name she-banged))) org-babel-tangle-use-relative-file-links)
(org-babel-spec-to-string spec) (org-babel-tangle-uncomment-comments
;; We avoid append-to-file as it does not work with tramp. org-babel-tangle-uncomment-comments)
(let ((content (buffer-string))) (org-babel-tangle-comment-format-beg
(with-temp-buffer org-babel-tangle-comment-format-beg)
(when (file-exists-p file-name) (org-src-preserve-indentation
(insert-file-contents file-name)) org-src-preserve-indentation)
(goto-char (point-max)) (org-babel-tangle-comment-format-end
;; Handle :padlines unless first line in file org-babel-tangle-comment-format-end))
(unless (or (string= "no" (cdr (assq :padline (nth 4 spec)))) (with-temp-buffer
(= (point) (point-min))) (when (fboundp lang-f) (ignore-errors (funcall lang-f)))
(insert "\n")) (when (and she-bang (not (member file-name she-banged)))
(insert content) (insert (concat she-bang "\n"))
(write-region nil nil file-name)))) (setq she-banged (cons file-name she-banged)))
(org-babel-spec-to-string spec)
;; We avoid append-to-file as it does not work with tramp.
(let ((content (buffer-string)))
(with-temp-buffer
(when (file-exists-p file-name)
(insert-file-contents file-name))
(goto-char (point-max))
;; Handle :padlines unless first line in file
(unless (or (string= "no" (cdr (assq :padline (nth 4 spec))))
(= (point) (point-min)))
(insert "\n"))
(insert content)
(write-region nil nil file-name)))))
;; if files contain she-bangs, then make the executable ;; if files contain she-bangs, then make the executable
(when she-bang (when she-bang
(unless tangle-mode (setq tangle-mode #o755))) (unless tangle-mode (setq tangle-mode #o755)))