Browse Source

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.
Nicolas Goaziou 9 years ago
parent
commit
1ca1d52e92
1 changed files with 5 additions and 3 deletions
  1. 5 3
      lisp/org.el

+ 5 - 3
lisp/org.el

@@ -7252,9 +7252,11 @@ show that drawer instead."
 
 (defun org-first-headline-recenter ()
   "Move cursor to the first headline and recenter the headline."
-  (goto-char (point-min))
-  (when (re-search-forward (concat "^\\(" org-outline-regexp "\\)") nil t)
-    (set-window-start (selected-window) (point-at-bol))))
+  (let ((window (get-buffer-window)))
+    (when window
+      (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