Browse Source

Merge branch 'maint'

Nicolas Goaziou 9 years ago
parent
commit
194b754597
2 changed files with 74 additions and 39 deletions
  1. 32 25
      lisp/org.el
  2. 42 14
      testing/lisp/test-org.el

+ 32 - 25
lisp/org.el

@@ -11564,21 +11564,20 @@ order.")
 		      (let ((re (format org-complex-heading-regexp-format
 		      (let ((re (format org-complex-heading-regexp-format
 					(regexp-quote heading)))
 					(regexp-quote heading)))
 			    (target
 			    (target
-			     (org-link-display-format
-			      (if (not org-refile-use-outline-path) heading
-				(mapconcat
-				 #'org-protect-slash
-				 (append
-				  (pcase org-refile-use-outline-path
-				    (`file (list (file-name-nondirectory
-						  (buffer-file-name
-						   (buffer-base-buffer)))))
-				    (`full-file-path
-				     (list (buffer-file-name
-					    (buffer-base-buffer))))
-				    (_ nil))
-				  (org-get-outline-path t))
-				 "/")))))
+			     (if (not org-refile-use-outline-path) heading
+			       (mapconcat
+				#'org-protect-slash
+				(append
+				 (pcase org-refile-use-outline-path
+				   (`file (list (file-name-nondirectory
+						 (buffer-file-name
+						  (buffer-base-buffer)))))
+				   (`full-file-path
+				    (list (buffer-file-name
+					   (buffer-base-buffer))))
+				   (_ nil))
+				 (org-get-outline-path t t))
+				"/"))))
 			(push (list target f re (org-refile-marker (point)))
 			(push (list target f re (org-refile-marker (point)))
 			      tgs)))
 			      tgs)))
 		    (when (= (point) begin)
 		    (when (= (point) begin)
@@ -11602,8 +11601,7 @@ Outline path is a list of strings, in reverse order.  When
 optional argument USE-CACHE is non-nil, make use of a cache.  See
 optional argument USE-CACHE is non-nil, make use of a cache.  See
 `org-get-outline-path' for details.
 `org-get-outline-path' for details.
 
 
-Assume buffer is widened."
-  (org-back-to-heading t)
+Assume buffer is widened and point is on a headline."
   (or (and use-cache (cdr (assq (point) org-outline-path-cache)))
   (or (and use-cache (cdr (assq (point) org-outline-path-cache)))
       (let ((p (point))
       (let ((p (point))
 	    (heading (progn
 	    (heading (progn
@@ -11611,9 +11609,10 @@ Assume buffer is widened."
 		       (if (not (match-end 4)) ""
 		       (if (not (match-end 4)) ""
 			 ;; Remove statistics cookies.
 			 ;; Remove statistics cookies.
 			 (org-trim
 			 (org-trim
-			  (replace-regexp-in-string
-			   "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
-			   (org-match-string-no-properties 4)))))))
+			  (org-link-display-format
+			   (replace-regexp-in-string
+			    "\\[[0-9]+%\\]\\|\\[[0-9]+/[0-9]+\\]" ""
+			    (org-match-string-no-properties 4))))))))
 	(if (org-up-heading-safe)
 	(if (org-up-heading-safe)
 	    (let ((path (cons heading (org--get-outline-path-1 use-cache))))
 	    (let ((path (cons heading (org--get-outline-path-1 use-cache))))
 	      (when use-cache
 	      (when use-cache
@@ -11626,9 +11625,16 @@ Assume buffer is widened."
 	    (when use-cache (setq org-outline-path-cache (list (cons p path))))
 	    (when use-cache (setq org-outline-path-cache (list (cons p path))))
 	    path)))))
 	    path)))))
 
 
-(defun org-get-outline-path (&optional use-cache)
+(defun org-get-outline-path (&optional with-self use-cache)
   "Return the outline path to the current entry.
   "Return the outline path to the current entry.
 
 
+An outline path is a list of ancestors for current headline, as
+a list of strings.  Statistics cookies are removed and links are
+replaced with their description, if any, or their path otherwise.
+
+When optional argument WITH-SELF is non-nil, the path also
+includes the current headline.
+
 When optional argument USE-CACHE is non-nil, cache outline paths
 When optional argument USE-CACHE is non-nil, cache outline paths
 between calls to this function so as to avoid backtracking.  This
 between calls to this function so as to avoid backtracking.  This
 argument is useful when planning to find more than one outline
 argument is useful when planning to find more than one outline
@@ -11636,10 +11642,11 @@ path in the same document.  In that case, there are two
 conditions to satisfy:
 conditions to satisfy:
   - `org-outline-path-cache' is set to nil before starting the
   - `org-outline-path-cache' is set to nil before starting the
     process;
     process;
-  - outline paths are computed by increasing buffer positions.
-
-Return value is a list of strings."
-  (org-with-wide-buffer (reverse (org--get-outline-path-1 use-cache))))
+  - outline paths are computed by increasing buffer positions."
+  (org-with-wide-buffer
+   (and (or (and with-self (org-back-to-heading t))
+	    (org-up-heading-safe))
+	(reverse (org--get-outline-path-1 use-cache)))))
 
 
 (defun org-format-outline-path (path &optional width prefix separator)
 (defun org-format-outline-path (path &optional width prefix separator)
   "Format the outline path PATH for display.
   "Format the outline path PATH for display.

+ 42 - 14
testing/lisp/test-org.el

@@ -1410,39 +1410,67 @@
 
 
 (ert-deftest test-org/get-outline-path ()
 (ert-deftest test-org/get-outline-path ()
   "Test `org-get-outline-path' specifications."
   "Test `org-get-outline-path' specifications."
+  ;; Top-level headlines have no outline path.
+  (should-not
+   (org-test-with-temp-text "* H"
+     (org-get-outline-path)))
+  ;; Otherwise, outline path is the path leading to the headline.
   (should
   (should
    (equal '("H")
    (equal '("H")
-	  (org-test-with-temp-text "* H"
-	    (org-get-outline-path))))
-  (should
-   (equal '("H" "S")
 	  (org-test-with-temp-text "* H\n** S<point>"
 	  (org-test-with-temp-text "* H\n** S<point>"
 	    (org-get-outline-path))))
 	    (org-get-outline-path))))
   ;; Find path even when point is not on a headline.
   ;; Find path even when point is not on a headline.
   (should
   (should
-   (equal '("H" "S")
+   (equal '("H")
 	  (org-test-with-temp-text "* H\n** S\nText<point>"
 	  (org-test-with-temp-text "* H\n** S\nText<point>"
 	    (org-get-outline-path))))
 	    (org-get-outline-path))))
-  ;; Using cache is transparent to the user.
+  ;; TODO keywords, tags and statistics cookies are ignored.
+  (should
+   (equal '("H")
+	  (org-test-with-temp-text "* TODO H [0/1] :tag:\n** S<point>"
+	    (org-get-outline-path))))
+  ;; Links are replaced with their description or their path.
+  (should
+   (equal '("Org")
+	  (org-test-with-temp-text
+	      "* [[http://orgmode.org][Org]]\n** S<point>"
+	    (org-get-outline-path))))
+  (should
+   (equal '("http://orgmode.org")
+	  (org-test-with-temp-text
+	      "* [[http://orgmode.org]]\n** S<point>"
+	    (org-get-outline-path))))
+  ;; When WITH-SELF is non-nil, include current heading.
+  (should
+   (equal '("H")
+	  (org-test-with-temp-text "* H"
+	    (org-get-outline-path t))))
   (should
   (should
    (equal '("H" "S")
    (equal '("H" "S")
+	  (org-test-with-temp-text "* H\n** S\nText<point>"
+	    (org-get-outline-path t))))
+  ;; Using cache is transparent to the user.
+  (should
+   (equal '("H")
 	  (org-test-with-temp-text "* H\n** S<point>"
 	  (org-test-with-temp-text "* H\n** S<point>"
 	    (setq org-outline-path-cache nil)
 	    (setq org-outline-path-cache nil)
-	    (org-get-outline-path t))))
+	    (org-get-outline-path nil t))))
   ;; Do not corrupt cache when finding outline path in distant part of
   ;; Do not corrupt cache when finding outline path in distant part of
   ;; the buffer.
   ;; the buffer.
   (should
   (should
-   (equal '("H2" "S2")
-	  (org-test-with-temp-text "* H\n** S\n* H2\n** S2"
+   (equal '("H2")
+	  (org-test-with-temp-text "* H\n** S<point>\n* H2\n** S2"
 	    (setq org-outline-path-cache nil)
 	    (setq org-outline-path-cache nil)
-	    (org-get-outline-path t)
+	    (org-get-outline-path nil t)
 	    (search-forward "S2")
 	    (search-forward "S2")
-	    (org-get-outline-path t))))
+	    (org-get-outline-path nil t))))
   ;; Do not choke on empty headlines.
   ;; Do not choke on empty headlines.
   (should
   (should
-   (org-test-with-temp-text "* "
-     (setq org-outline-path-cache nil)
-     (org-get-outline-path t))))
+   (org-test-with-temp-text "* H\n** <point>"
+     (org-get-outline-path)))
+  (should
+   (org-test-with-temp-text "* \n** H<point>"
+     (org-get-outline-path))))
 
 
 (ert-deftest test-org/format-outline-path ()
 (ert-deftest test-org/format-outline-path ()
   "Test `org-format-outline-path' specifications."
   "Test `org-format-outline-path' specifications."