diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index 4fe444532..b50d42d9b 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -474,9 +474,9 @@ non-nil, return the full association list to be used by file) (if (and org-babel-tangle-use-relative-file-links (string-match org-link-types-re link) - (string= (match-string 0 link) "file")) + (string= (match-string 1 link) "file")) (concat "file:" - (file-relative-name (match-string 1 link) + (file-relative-name (substring link (match-end 0)) (file-name-directory (cdr (assq :tangle params))))) link) diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el index ff4aa704b..6f45c7152 100644 --- a/lisp/ox-texinfo.el +++ b/lisp/ox-texinfo.el @@ -1047,7 +1047,10 @@ DESC is the description part of the link, or the empty string. INFO is a plist holding contextual information. See `org-export-data'." (let* ((type (org-element-property :type link)) - (raw-path (org-element-property :path link)) + (raw-path + (replace-regexp-in-string + "[@{}]" "@\\&" + (org-element-property :path link))) ;; Ensure DESC really exists, or set it to nil. (desc (and (not (string= desc "")) desc)) (path (org-texinfo--sanitize-content diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el index 35490f538..803456fd8 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -122,6 +122,43 @@ echo 1 (search-forward "[H:2]]" nil t)))) (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 () "Test `org-babel-tangle-jump-to-org' specifications." ;; Standard test.