Subject: Bug #27362:

From: Nathan Moreau <[email-masked]>
Date: Thu, 17 Aug 2017 11:36:15 +0200

Here  is a patch that fixes the reported problem.

A minimal reproduction test:

(ert-deftest totoro ()
  (set-buffer "*scratch*")
  (insert "setq")
  (setq next-error-recenter '(4))
  (occur "setq")
  (next-error))

It seems that occur-mode-goto-occurrence should be called after
restoring the original buffer.

Nathan
From f153a4f78ef24ebc2901c51c279bb2b55ea2473d Mon Sep 17 00:00:00 2001
From: Nathan Moreau <[email-masked]>
Date: Wed, 16 Aug 2017 23:37:59 +0200
Subject: [PATCH] Fix current buffer in the call of occur-next-error.

Try to mimic the structure of compilation-next-error-function in
occur-next-error.
---
 lisp/replace.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/replace.el b/lisp/replace.el
index 09972b40db..439bb63a18 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -1273,8 +1273,8 @@ occur-next-error
      "No more matches")
     ;; In case the *Occur* buffer is visible in a nonselected window.
     (let ((win (get-buffer-window (current-buffer) t)))
-      (if win (set-window-point win (point))))
-    (occur-mode-goto-occurrence)))
+      (if win (set-window-point win (point)))))
+  (occur-mode-goto-occurrence))
 
 (defface match
   '((((class color) (min-colors 88) (background light))
-- 
2.11.0