2

The Emacs occur buffer is editable, but it does not make it easy to delete lines. One normally gets something like this:

2 matches for "Wyk" in buffer: diary 59:%%(diary-anniversary 5 15 2014) Nicholas Wyk 61:%% van Wyk 

To delete the above lines one has to position one's cursor after each line number and invoke C-k. The line numbers themselves are given the read-only text property, so even if the buffer is made read-write, C-k will refuse to delete the line if the cursor is before the line number. It would be easier if line numbers were not shown.

Is there a better way?

5
  • 2
    If you put the cursor on that column and type C-x C-n then the cursor will start on that column when you change lines. Then it's pretty trivial. C-u C-x C-n to clear the goal column. Commented Feb 8 at 9:26
  • 1
    N.b. If you just wanted to delete all lines matching the pattern, you wouldn't use occur, but rather M-x flush-lines (and see also its inverse, keep-lines). Commented Feb 8 at 9:28
  • 1
    I'm still not quite clear: are you talking about deleting the lines in the diary buffer` or in the *Occur* buffer? I assumed the latter (and based my edit to your question on that assumption) but I'm doubting myself. Commented Feb 8 at 17:25
  • I am wanting to delete lines in the occur buffer. In this case I was editing my diary file. Commented Feb 9 at 4:52
  • 1
    Okay - thanks for clarifying! I don't have to live in doubt any more :-) Commented Feb 9 at 18:15

1 Answer 1

2

So the question is not about occur-edit-mode, but rather editing only the *Occur* buffer's contents.

To delete the above lines one has to position one's cursor after each line number

If you put the cursor on that column and type C-xC-n then the cursor will start on that column when you change lines. That should minimise the annoyance of having to go to that column. C-uC-xC-n clears the goal column.


You might also like the winnow package, which provides a convenient UI to flush-lines and keep-lines to remove lines based on regexp matching, but without read-only text properties inhibiting the changes. You can enable its UI for occur-mode like so:

(add-hook 'occur-mode-hook #'winnow-mode) 

Edit: It may be necessary to patch winnow.el to enable it to work with occur-mode (and/or any other modes not derived from compilation-mode).

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.