Kaynağa Gözat

Merge branch 'maint'

Nicolas Goaziou 9 yıl önce
ebeveyn
işleme
1daac70fc5
2 değiştirilmiş dosya ile 54 ekleme ve 17 silme
  1. 11 17
      lisp/org.el
  2. 43 0
      testing/lisp/test-org.el

+ 11 - 17
lisp/org.el

@@ -9848,14 +9848,12 @@ active region."
 				 (buffer-file-name (buffer-base-buffer)))))
 				 (buffer-file-name (buffer-base-buffer)))))
 	   ;; Add a context search string
 	   ;; Add a context search string
 	   (when (org-xor org-context-in-file-links arg)
 	   (when (org-xor org-context-in-file-links arg)
-	     (let* ((ee (org-element-at-point))
-		    (et (org-element-type ee))
-		    (ev (plist-get (cadr ee) :value))
-		    (ek (plist-get (cadr ee) :key))
-		    (eok (and (stringp ek) (string-match "name" ek))))
+	     (let* ((element (org-element-at-point))
+		    (type (org-element-type element))
+		    (name (org-element-property :name element)))
 	       (setq txt (cond
 	       (setq txt (cond
 			  ((org-at-heading-p) nil)
 			  ((org-at-heading-p) nil)
-			  ((and (eq et 'keyword) eok) ev)
+			  (name)
 			  ((org-region-active-p)
 			  ((org-region-active-p)
 			   (buffer-substring (region-beginning) (region-end)))))
 			   (buffer-substring (region-beginning) (region-end)))))
 	       (when (or (null txt) (string-match "\\S-" txt))
 	       (when (or (null txt) (string-match "\\S-" txt))
@@ -9864,7 +9862,7 @@ active region."
 			       (condition-case nil
 			       (condition-case nil
 				   (org-make-org-heading-search-string txt)
 				   (org-make-org-heading-search-string txt)
 				 (error "")))
 				 (error "")))
-		       desc (or (and (eq et 'keyword) eok ev)
+		       desc (or name
 				(nth 4 (ignore-errors (org-heading-components)))
 				(nth 4 (ignore-errors (org-heading-components)))
 				"NONE")))))
 				"NONE")))))
 	   (when (string-match "::\\'" cpltxt)
 	   (when (string-match "::\\'" cpltxt)
@@ -9897,17 +9895,13 @@ active region."
        (when (consp link) (setq cpltxt (car link) link (cdr link)))
        (when (consp link) (setq cpltxt (car link) link (cdr link)))
        (setq link (or link cpltxt)
        (setq link (or link cpltxt)
 	     desc (or desc 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
 		      (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
        ;; Return the link
        (if (not (and (or (org-called-interactively-p 'any)
        (if (not (and (or (org-called-interactively-p 'any)
 			 executing-kbd-macro)
 			 executing-kbd-macro)

+ 43 - 0
testing/lisp/test-org.el

@@ -2109,6 +2109,49 @@ drops support for Emacs 24.1 and 24.2."
      (org-open-at-point)
      (org-open-at-point)
      (eq (org-element-type (org-element-context)) 'radio-target))))
      (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
 ;;; Node Properties