Best Occur Configuration Ever

Here is the best Occur configuration that I’ve ever had on my machine.

  • Alternate search result background color
  • Multiple Occur buffers
  • n and p navigate search results
  • Jump near buffer top
(defun help/occur-mode-hook-fn ()
  "HELP customizations."
  (interactive)
  (turn-on-stripe-buffer-mode)
  (occur-rename-buffer))
(add-hook 'occur-mode-hook #'help/occur-mode-hook-fn)
(define-key occur-mode-map (kbd "n") #'next-logical-line)
(define-key occur-mode-map (kbd "p") #'previous-logical-line)
(defun help/recenter-line-near-top-fn ()
  "Move current line near top"
  (interactive)
  (let ((recenter-positions '(5)))
    (recenter-top-bottom)))
(add-hook 'occur-mode-find-occurrence-hook #'help/recenter-line-near-top-fn)

Addendum: <2017-05-04 Thu 11:26>

stripe-buffer mode provides the buffer striping.

Thank you Greg for reminding me to point that out.

2 thoughts on “Best Occur Configuration Ever”

Leave a Reply

Your email address will not be published. Required fields are marked *