Search code examples
emacselisp

How to switch to occur buffer in Emacs automatically?


When running on occur on a regex, the frame splits into two windows and the occur buffer is shown below. However, the keyboard focus is still in the original buffer. How can I change this behavior programmatically, such that the occur buffer becomes the current buffer? I tried this:

(defun test-occur ()
  (interactive)
  (occur "test")
  (switch-to-buffer "*Occur*"))

but it does not work.. (That is: now the occur buffer is shown both in the top and the bottom window)


Solution

  • Try this:

    (defun test-occur ()
      (interactive)
      (occur "test")
      (other-window 1))