tangled links use relative paths by default

* lisp/ob-tangle.el (org-babel-tangle-use-relative-file-links):
  Controls the use of relative paths in files and links in tangled
  source code.
  (org-babel-spec-to-string): Optionally use relative paths in files
  and links.
This commit is contained in:
Eric Schulte 2013-10-09 10:00:28 -06:00
parent 2829fdad0b
commit 15847336c3
1 changed files with 18 additions and 2 deletions

View File

@ -54,6 +54,11 @@ then the name of the language is used."
(string "Language name")
(string "File Extension"))))
(defcustom org-babel-tangle-use-relative-file-links t
"Use relative path names in links from tangled source back the Org-mode file."
:group 'org-babel-tangle
:type 'boolean)
(defcustom org-babel-post-tangle-hook nil
"Hook run in code files tangled by `org-babel-tangle'."
:group 'org-babel
@ -305,8 +310,19 @@ that the appropriate major-mode is set. SPEC has the form:
\(start-line file link source-name params body comment)"
(let* ((start-line (nth 0 spec))
(file (nth 1 spec))
(link (nth 2 spec))
(file (if org-babel-tangle-use-relative-file-links
(file-relative-name (nth 1 spec))
(nth 1 spec)))
(link (let ((link (nth 2 spec)))
(if org-babel-tangle-use-relative-file-links
(when (string-match "^\\(file:\\|docview:\\)\\(.*\\)" link)
(let* ((type (match-string 1 link))
(path (match-string 2 link))
(origpath path)
(case-fold-search nil))
(setq path (file-relative-name path))
(concat type path)))
link)))
(source-name (nth 3 spec))
(body (nth 5 spec))
(comment (nth 6 spec))