forked from mirrors/org-mode
ob-tangle: Restore handling of relative file links
* lisp/ob-tangle.el (org-babel-tangle-single-block): Fix regression
from v9.0.2 that resulted in org-babel-tangle-use-relative-file-links
being ignored.
* testing/lisp/test-ob-tangle.el
(ob-tangle/comment-links-relative-file): Add test.
As of 7b148e2d0
(ob-tangle: Respect buffer local variables,
2016-12-10), the condition in org-babel-tangle-single-block that
checks whether to return a file link with a relative target always
returns nil because the full org-link-types-re match, including the
final colon, is compared with "file" (no colon). Also, were this
condition to succeed, "file:" would be used as the file name.
Adjust the condition and fix the extracted file name.
Reported-by: Jeremias Gonzalez <jgonzalez49@ucmerced.edu>
https://orgmode.org/list/6fb12326-52d3-7177-eff5-62603261b388@ucmerced.edu
This commit is contained in:
parent
706970efb1
commit
3ebee03310
|
@ -471,9 +471,9 @@ non-nil, return the full association list to be used by
|
||||||
file)
|
file)
|
||||||
(if (and org-babel-tangle-use-relative-file-links
|
(if (and org-babel-tangle-use-relative-file-links
|
||||||
(string-match org-link-types-re link)
|
(string-match org-link-types-re link)
|
||||||
(string= (match-string 0 link) "file"))
|
(string= (match-string 1 link) "file"))
|
||||||
(concat "file:"
|
(concat "file:"
|
||||||
(file-relative-name (match-string 1 link)
|
(file-relative-name (substring link (match-end 0))
|
||||||
(file-name-directory
|
(file-name-directory
|
||||||
(cdr (assq :tangle params)))))
|
(cdr (assq :tangle params)))))
|
||||||
link)
|
link)
|
||||||
|
|
|
@ -120,6 +120,43 @@ echo 1
|
||||||
(search-forward "[H:2]]" nil t))))
|
(search-forward "[H:2]]" nil t))))
|
||||||
(delete-file "test-ob-tangle.el")))))
|
(delete-file "test-ob-tangle.el")))))
|
||||||
|
|
||||||
|
(ert-deftest ob-tangle/comment-links-relative-file ()
|
||||||
|
"Test relative file name handling when commenting with links."
|
||||||
|
(should
|
||||||
|
(org-test-with-temp-text-in-file
|
||||||
|
"* H
|
||||||
|
#+header: :tangle \"test-ob-tangle.el\" :comments link
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
1
|
||||||
|
#+end_src"
|
||||||
|
(unwind-protect
|
||||||
|
(let ((org-babel-tangle-use-relative-file-links t))
|
||||||
|
(org-babel-tangle)
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents "test-ob-tangle.el")
|
||||||
|
(buffer-string)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(search-forward
|
||||||
|
(concat "[file:" (file-name-nondirectory file))
|
||||||
|
nil t)))
|
||||||
|
(delete-file "test-ob-tangle.el"))))
|
||||||
|
(should
|
||||||
|
(org-test-with-temp-text-in-file
|
||||||
|
"* H
|
||||||
|
#+header: :tangle \"test-ob-tangle.el\" :comments link
|
||||||
|
#+begin_src emacs-lisp
|
||||||
|
1
|
||||||
|
#+end_src"
|
||||||
|
(unwind-protect
|
||||||
|
(let ((org-babel-tangle-use-relative-file-links nil))
|
||||||
|
(org-babel-tangle)
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents "test-ob-tangle.el")
|
||||||
|
(buffer-string)
|
||||||
|
(goto-char (point-min))
|
||||||
|
(search-forward (concat "[file:" file) nil t)))
|
||||||
|
(delete-file "test-ob-tangle.el")))))
|
||||||
|
|
||||||
(ert-deftest ob-tangle/jump-to-org ()
|
(ert-deftest ob-tangle/jump-to-org ()
|
||||||
"Test `org-babel-tangle-jump-to-org' specifications."
|
"Test `org-babel-tangle-jump-to-org' specifications."
|
||||||
;; Standard test.
|
;; Standard test.
|
||||||
|
|
Loading…
Reference in New Issue