summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2016-04-26 20:59:33 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2016-04-26 20:59:33 +0200
commite818699113218081967eaf7e10427a7d70f7fbd2 (patch)
tree28bf09a4d91cfc6014ac7e26b50648b2ce692e83
parent00a8275c6263e1bed38bbaf6ddece2d80557b694 (diff)
downloadorg-mode-e818699113218081967eaf7e10427a7d70f7fbd2.tar.gz
Fix storing links to headlines containing multiple links
* lisp/org.el (org-store-link): Fix storing links to headlines containing multiple links. * testing/lisp/test-org.el (test-org/store-link): New test. Reported-by: Georgiy Tugai <georgiy.tugai@gmail.com> <http://permalink.gmane.org/gmane.emacs.orgmode/106606>
-rw-r--r--lisp/org.el16
-rw-r--r--testing/lisp/test-org.el43
2 files changed, 49 insertions, 10 deletions
diff --git a/lisp/org.el b/lisp/org.el
index 075e8db..382dbdf 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -9931,17 +9931,13 @@ active region."
(if (consp link) (setq cpltxt (car link) link (cdr link)))
(setq link (or link cpltxt)
desc (or desc cpltxt))
- (cond ((equal desc "NONE") (setq desc nil))
- ((and desc (string-match org-bracket-link-analytic-regexp desc))
- (let ((d0 (match-string 3 desc))
- (p0 (match-string 5 desc)))
- (setq desc
+ (cond ((not desc))
+ ((equal desc "NONE") (setq desc nil))
+ (t (setq desc
(replace-regexp-in-string
- org-bracket-link-regexp
- (concat (or p0 d0)
- (if (equal (length (match-string 0 desc))
- (length desc)) "*" "")) desc)))))
-
+ org-bracket-link-analytic-regexp
+ (lambda (m) (or (match-string 5 m) (match-string 3 m)))
+ desc))))
;; Return the link
(if (not (and (or (org-called-interactively-p 'any)
executing-kbd-macro)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index 0c0a506..de28772 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -1848,6 +1848,49 @@ drops support for Emacs 24.1 and 24.2."
(org-open-at-point)
(eq (org-element-type (org-element-context)) 'radio-target))))
+;;;; Stored links
+
+(ert-deftest test-org/store-link ()
+ "Test `org-store-link' specifications."
+ ;; On a headline, link to that headline. Use heading as the
+ ;; description of the link.
+ (should
+ (let (org-store-link-props org-stored-links)
+ (org-test-with-temp-text-in-file "* H1"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::*H1][H1]]" file)
+ (org-store-link nil))))))
+ ;; On a headline, remove any link from description.
+ (should
+ (let (org-store-link-props org-stored-links)
+ (org-test-with-temp-text-in-file "* [[#l][d]]"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::*%s][d]]"
+ file
+ (org-link-escape "[[#l][d]]"))
+ (org-store-link nil))))))
+ (should
+ (let (org-store-link-props org-stored-links)
+ (org-test-with-temp-text-in-file "* [[l]]"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::*%s][l]]" file (org-link-escape "[[l]]"))
+ (org-store-link nil))))))
+ (should
+ (let (org-store-link-props org-stored-links)
+ (org-test-with-temp-text-in-file "* [[l1][d1]] [[l2][d2]]"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::*%s][d1 d2]]"
+ file
+ (org-link-escape "[[l1][d1]] [[l2][d2]]"))
+ (org-store-link nil))))))
+ ;; On a named element, link to that element.
+ (should
+ (let (org-store-link-props org-stored-links)
+ (org-test-with-temp-text-in-file "#+NAME: foo\nParagraph"
+ (let ((file (buffer-file-name)))
+ (equal (format "[[file:%s::foo][foo]]" file)
+ (org-store-link nil)))))))
+
;;; Node Properties