0
votes

I want to bind the emacs multi-occur command to a key so that it searches a specific named buffer, e.g compilation. How do I go about this in my .emacs?

I can do

(global-set-key "\C-ho" 'multi-occur)

But that requires entering the buffer names to search. I want to just be able to press a key, enter the search text, and it only looks in the predefined buffer.

I'm an emacs ignoramus, so all help appreciated.

2

2 Answers

1
votes
(defun my-occur-in-compilation (regexp &optional nlines)
  "Show all lines matching REGEXP in the *compilation* buffer."
  (interactive (occur-read-primary-args))
  (multi-occur (list (get-buffer "*compilation*")) regexp nlines))

(global-set-key "\C-ho" 'my-occur-in-compilation)
0
votes

If you're only searching one buffer, you don't need multi-occur. Just use occur.

(defun compile-occur ()
  (interactive)
  (with-current-buffer (get-buffer "*compilation*")
    (call-interactively 'occur)))