diff --git a/lisp/org.el b/lisp/org.el index ed766f9c6..0da000738 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -10284,9 +10284,10 @@ a link." (org-search-radio-target (org-element-property :path context)) (org-link-search - (if (member type '("custom-id" "coderef")) - (org-element-property :raw-link context) - path) + (pcase type + ("custom-id" (concat "#" path)) + ("coderef" (format "(%s)" path)) + (_ path)) ;; Prevent fuzzy links from matching ;; themselves. (and (equal type "fuzzy") diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 669ad4377..6e1abc827 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -2338,6 +2338,12 @@ SCHEDULED: <2014-03-04 tue.>" "* H1\n:PROPERTIES:\n:CUSTOM_ID: custom\n:END:\n* H2\n[[#custom]]" (org-open-at-point) (looking-at-p "\\* H1"))) + ;; Handle escape characters. + (should + (org-test-with-temp-text + "* H1\n:PROPERTIES:\n:CUSTOM_ID: [%]\n:END:\n* H2\n[[#%5B%25%5D]]" + (org-open-at-point) + (looking-at-p "\\* H1"))) ;; Throw an error on false positives. (should-error (org-test-with-temp-text