Bladeren bron

Fix bug with resolving outline-path targets when two headings are the same

* lisp/org.el (org-find-olp): Use the level of the correct match to
continue search.

The problem was that a second match of an identical headline on
another level would corrupt the value of LEVEL that is used to set up
the next search stop.

Chao LU writes:

> For org capture template, if I set an template like this:
> ("i" "INBOX" entry (file+olp (concat org-private-dir "/iPrv.org")
>                    "INBOX" "test") "* %?" :prepend t)
>
> And for the iPrv.org, I have this structure:
> * INBOX
> ** test
>
> Then it works.
>
> But if the first level and the second level happen to have the same
> title (it does happen to me sometimes), like:
> * INBOX
> ** INBOX
>
> ("i" "INBOX" entry (file+olp (concat org-private-dir "/iPrv.org")
>                     "INBOX" "INBOX") "* %?" :prepend t)
> Then Org will prompt an error.
Carsten Dominik 14 jaren geleden
bovenliggende
commit
71e91e3d33
1 gewijzigde bestanden met toevoegingen van 3 en 3 verwijderingen
  1. 3 3
      lisp/org.el

+ 3 - 3
lisp/org.el

@@ -14180,7 +14180,7 @@ only headings."
 	 (level 1)
 	 (lmin 1)
 	 (lmax 1)
-	 limit re end found pos heading cnt)
+	 limit re end found pos heading cnt flevel)
     (unless buffer (error "File not found :%s" file))
     (with-current-buffer buffer
       (save-excursion
@@ -14195,13 +14195,13 @@ only headings."
 	    (while (re-search-forward re end t)
 	      (setq level (- (match-end 1) (match-beginning 1)))
 	      (if (and (>= level lmin) (<= level lmax))
-		  (setq found (match-beginning 0) cnt (1+ cnt))))
+		  (setq found (match-beginning 0) flevel level cnt (1+ cnt))))
 	    (when (= cnt 0) (error "Heading not found on level %d: %s"
 				   lmax heading))
 	    (when (> cnt 1) (error "Heading not unique on level %d: %s"
 				   lmax heading))
 	    (goto-char found)
-	    (setq lmin (1+ level) lmax (+ lmin (if org-odd-levels-only 1 0)))
+	    (setq lmin (1+ flevel) lmax (+ lmin (if org-odd-levels-only 1 0)))
 	    (setq end (save-excursion (org-end-of-subtree t t))))
 	  (when (org-on-heading-p)
 	    (move-marker (make-marker) (point))))))))