Fix `org-occur' when called non-interactively

* lisp/org.el (org-first-headline-recenter): Check if current buffer is
  actually displayed in a window before trying to recenter view.
This commit is contained in:
Nicolas Goaziou 2016-05-05 11:45:35 +02:00
parent 8638c14fbd
commit 1ca1d52e92
1 changed files with 5 additions and 3 deletions

View File

@ -7252,9 +7252,11 @@ show that drawer instead."
(defun org-first-headline-recenter () (defun org-first-headline-recenter ()
"Move cursor to the first headline and recenter the headline." "Move cursor to the first headline and recenter the headline."
(goto-char (point-min)) (let ((window (get-buffer-window)))
(when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t) (when window
(set-window-start (selected-window) (point-at-bol)))) (goto-char (point-min))
(when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
(set-window-start window (line-beginning-position))))))
;;; Saving and restoring visibility ;;; Saving and restoring visibility