Skip to main content
6 of 6
Adapt @clemera 's suggestion
Stefan
  • 26.7k
  • 3
  • 52
  • 88

An occur buffer is just a buffer in read-only mode, that doesn't mean that it cannot be manipulated.

Something as straightforward like this can help you:

(defun occur-kill-line()
  "Quick and dirty discard line from occur resultset.
from https://emacs.stackexchange.com/a/52865/13589"
  (interactive)
  (let ((inhibit-read-only t))
    (kill-whole-line)
    (delete-blank-lines)))

invoking this function will kill the current line in occur buffer. Pressing g will revert the buffer.

Adding this:

(define-key occur-mode-map (kbd "k") 'occur-kill-line)

will bind k to occur-kill-line to occur-mode-map making it available as occur command just pressing k.

Muihlinn
  • 2.7k
  • 1
  • 15
  • 22