1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-03 08:30:03 +00:00

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.
This commit is contained in:
Carsten Dominik 2011-03-25 08:05:21 +01:00
parent 078c01bf3b
commit 71e91e3d33

View File

@ -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))))))))