Hello,

Bastien <b...@gnu.org> writes:

> If someone wants to work on this, help is welcome.

> Let's keep the bug open in the meantime.

Unless I'm mistaken, the following patch should fix the issue.


Regards,

-- 
Nicolas Goaziou
>From 4d62387fe035d9aa3d1dc96d12d40c53dca2afe5 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaz...@gmail.com>
Date: Fri, 28 Mar 2014 19:24:38 +0100
Subject: [PATCH] Make Org links compatible with URI syntax

* lisp/org.el (org-make-link-regexps): Allow optional double slashes
  after type.  Small refactoring.

* testing/lisp/test-org-element.el (test-org-element/link-parser):
  Update test.

This patch allows to write both [[file:/file.org]] and [[file:///file.org]].
See bug#16751.
---
 lisp/org.el                      | 43 ++++++++++++++++++----------------------
 testing/lisp/test-org-element.el |  6 ++----
 2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index bb83eb7..53f142e 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5658,34 +5658,29 @@ stacked delimiters is N.  Escaping delimiters is not possible."
   "Update the link regular expressions.
 This should be called after the variable `org-link-types' has changed."
   (setq org-link-types-re
-	(concat
-	 "\\`\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):")
+	(concat "\\`" (regexp-opt org-link-types t) ":\\(?://\\)")
 	org-link-re-with-space
-	(concat
-	 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
-	 "\\([^" org-non-link-chars " ]"
-	 "[^" org-non-link-chars "]*"
-	 "[^" org-non-link-chars " ]\\)>?")
+	(concat "<?" (regexp-opt org-link-types t) ":\\(?://\\)"
+		"\\([^" org-non-link-chars " ]"
+		"[^" org-non-link-chars "]*"
+		"[^" org-non-link-chars " ]\\)>?")
 	org-link-re-with-space2
-	(concat
-	 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
-	 "\\([^" org-non-link-chars " ]"
-	 "[^\t\n\r]*"
-	 "[^" org-non-link-chars " ]\\)>?")
+	(concat "<?" (regexp-opt org-link-types t) ":\\(?://\\)?"
+		"\\([^" org-non-link-chars " ]"
+		"[^\t\n\r]*"
+		"[^" org-non-link-chars " ]\\)>?")
 	org-link-re-with-space3
-	(concat
-	 "<?\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
-	 "\\([^" org-non-link-chars " ]"
-	 "[^\t\n\r]*\\)")
+	(concat "<?" (regexp-opt org-link-types t) ":\\(?://\\)?"
+		"\\([^" org-non-link-chars " ]"
+		"[^\t\n\r]*\\)")
 	org-angle-link-re
-	(concat
-	 "<\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
-	 "\\([^" org-non-link-chars " ]"
-	 "[^" org-non-link-chars "]*"
-	 "\\)>")
+	(concat "<" (regexp-opt org-link-types t) ":\\(?://\\)?"
+		"\\([^" org-non-link-chars " ]"
+		"[^" org-non-link-chars "]*"
+		"\\)>")
 	org-plain-link-re
 	(concat
-	 "\\<\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):"
+	 "\\<" (regexp-opt org-link-types t) ":\\(?://\\)?"
 	 (org-re "\\([^ \t\n()<>]+\\(?:([[:word:]0-9_]+)\\|\\([^[:punct:] \t\n]\\|/\\)\\)\\)"))
 	;;	 "\\([^]\t\n\r<>() ]+[^]\t\n\r<>,.;() ]\\)")
 	org-bracket-link-regexp
@@ -5693,7 +5688,7 @@ This should be called after the variable `org-link-types' has changed."
 	org-bracket-link-analytic-regexp
 	(concat
 	 "\\[\\["
-	 "\\(\\(" (mapconcat 'regexp-quote org-link-types "\\|") "\\):\\)?"
+	 "\\(" (regexp-opt org-link-types t) ":\\(?://\\)?\\)?"
 	 "\\([^]]+\\)"
 	 "\\]"
 	 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
@@ -5701,7 +5696,7 @@ This should be called after the variable `org-link-types' has changed."
 	org-bracket-link-analytic-regexp++
 	(concat
 	 "\\[\\["
-	 "\\(\\(" (mapconcat 'regexp-quote (cons "coderef" org-link-types) "\\|") "\\):\\)?"
+	 "\\(" (regexp-opt (cons "coderef" org-link-types) t) ":\\(?://\\)?\\)?"
 	 "\\([^]]+\\)"
 	 "\\]"
 	 "\\(\\[" "\\([^]]+\\)" "\\]\\)?"
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index def1659..72eea22 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1362,12 +1362,10 @@ e^{i\\pi}+1=0
   ;; ... with expansion.
   (should
    (equal
-    "//orgmode.org/worg"
+    "orgmode.org/worg"
     (org-test-with-temp-text "[[Org:worg]]"
       (let ((org-link-abbrev-alist '(("Org" . "http://orgmode.org/";))))
-	(org-element-property
-	 :path
-	 (org-element-map (org-element-parse-buffer) 'link 'identity nil t))))))
+	(org-element-property :path (org-element-context))))))
   ;; ... with translation.
   (should
    (equal
-- 
1.9.1

Reply via email to