forked from mirrors/org-mode
ob-tangle.el: Fix single block tangle
lisp/ob-tangle.el (org-babel-tangle-single-block): Fix the result when `only-this-block' is `t' to match what is expected by `org-babel-tangle'. (org-babel-effective-tangled-filename): Extract the computation of filename of tangled src block. (org-babel-tangle-collect-blocks): Use `org-babel-effective-tangled-filename'.
This commit is contained in:
parent
bfc3d18b04
commit
6e5b39acd1
|
@ -350,6 +350,22 @@ that the appropriate major-mode is set. SPEC has the form:
|
|||
(org-fill-template
|
||||
org-babel-tangle-comment-format-end link-data)))))
|
||||
|
||||
(defun org-babel-effective-tangled-filename (buffer-fn src-lang src-tfile)
|
||||
"Return effective tangled filename of a source-code block.
|
||||
BUFFER-FN is the name of the buffer, SRC-LANG the language of the
|
||||
block and SRC-TFILE is the value of the :tangle header argument,
|
||||
as computed by `org-babel-tangle-single-block'."
|
||||
(let ((base-name (cond
|
||||
((string= "yes" src-tfile)
|
||||
;; Use the buffer name
|
||||
(file-name-sans-extension buffer-fn))
|
||||
((> (length src-tfile) 0) src-tfile)))
|
||||
(ext (or (cdr (assoc src-lang org-babel-tangle-lang-exts)) src-lang)))
|
||||
(when base-name
|
||||
;; decide if we want to add ext to base-name
|
||||
(if (and ext (string= "yes" src-tfile))
|
||||
(concat base-name "." ext) base-name))))
|
||||
|
||||
(defun org-babel-tangle-collect-blocks (&optional lang-re tangle-file)
|
||||
"Collect source blocks in the current Org file.
|
||||
Return an association list of language and source-code block
|
||||
|
@ -378,17 +394,8 @@ be used to limit the collected code blocks by target file."
|
|||
;; file name.
|
||||
(let* ((block (org-babel-tangle-single-block counter))
|
||||
(src-tfile (cdr (assq :tangle (nth 4 block))))
|
||||
(base-name (cond
|
||||
((string= "yes" src-tfile)
|
||||
;; buffer name
|
||||
(file-name-sans-extension
|
||||
(nth 1 block)))
|
||||
((> (length src-tfile) 0) src-tfile)))
|
||||
(ext (or (cdr (assoc src-lang org-babel-tangle-lang-exts)) src-lang))
|
||||
(file-name (when base-name
|
||||
;; decide if we want to add ext to base-name
|
||||
(if (and ext (string= "yes" src-tfile))
|
||||
(concat base-name "." ext) base-name)))
|
||||
(file-name (org-babel-effective-tangled-filename
|
||||
(nth 1 block) src-lang src-tfile))
|
||||
(by-fn (assoc file-name blocks)))
|
||||
(if by-fn (setcdr by-fn (cons (cons src-lang block) (cdr by-fn)))
|
||||
(push (cons file-name (list (cons src-lang block))) blocks)))))))
|
||||
|
@ -482,7 +489,10 @@ non-nil, return the full association list to be used by
|
|||
(org-trim (org-remove-indentation body)))
|
||||
comment)))
|
||||
(if only-this-block
|
||||
(list (cons src-lang (list result)))
|
||||
(let* ((src-tfile (cdr (assq :tangle (nth 4 result))))
|
||||
(file-name (org-babel-effective-tangled-filename
|
||||
(nth 1 result) src-lang src-tfile)))
|
||||
(list (cons file-name (list (cons src-lang result)))))
|
||||
result)))
|
||||
|
||||
(defun org-babel-tangle-comment-links (&optional info)
|
||||
|
|
Loading…
Reference in New Issue