summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2013-10-09 10:00:28 -0600
committerEric Schulte <schulte.eric@gmail.com>2013-10-09 10:29:01 -0600
commit15847336c39e7219e1c51c55d487f99956a06e34 (patch)
treec00cf02081079aaf58eecd16a73bec9410f2b340
parent2829fdad0be5f3a5d294ab73dcc8357f7cae6feb (diff)
downloadorg-mode-15847336c39e7219e1c51c55d487f99956a06e34.tar.gz
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.
-rw-r--r--lisp/ob-tangle.el20
1 files changed, 18 insertions, 2 deletions
diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el
index f655711..835b2af 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))