Explorar o código

org-agenda: Fix infloop in `org-find-top-headline'

* lisp/org-agenda.el (org-find-top-headline): Prevent infloop when top
  headline has not level 1.

Reported-by: Adrian Bradd <adrian.bradd@gmail.com>
<http://permalink.gmane.org/gmane.emacs.orgmode/112623>
Nicolas Goaziou %!s(int64=8) %!d(string=hai) anos
pai
achega
a3747baef9
Modificáronse 1 ficheiros con 8 adicións e 7 borrados
  1. 8 7
      lisp/org-agenda.el

+ 8 - 7
lisp/org-agenda.el

@@ -7445,14 +7445,15 @@ With a prefix argument, exclude the lines of that category.
        (t (error "No category at point"))))))
 
 (defun org-find-top-headline (&optional pos)
-  "Find the topmost parent headline and return it."
+  "Find the topmost parent headline and return it.
+POS when non-nil is the marker or buffer position to start the
+search from."
   (save-excursion
-    (with-current-buffer (if pos (marker-buffer pos) (current-buffer))
-      (if pos (goto-char pos))
-      ;; Skip up to the topmost parent
-      (while (ignore-errors (outline-up-heading 1) t))
-      (ignore-errors
-	(nth 4 (org-heading-components))))))
+    (with-current-buffer (if (markerp pos) (marker-buffer pos) (current-buffer))
+      (when pos (goto-char pos))
+      ;; Skip up to the topmost parent.
+      (while (org-up-heading-safe))
+      (ignore-errors (nth 4 (org-heading-components))))))
 
 (defvar org-agenda-filtered-by-top-headline nil)
 (defun org-agenda-filter-by-top-headline (strip)