From 15847336c39e7219e1c51c55d487f99956a06e34 Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Wed, 9 Oct 2013 10:00:28 -0600 Subject: [PATCH] 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. --- lisp/ob-tangle.el | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index f6557114b..835b2afab 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -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)) -- 2.11.4.GIT