In file I disable Read-only mode (by C-x C-q): enter image description here

But if I want to edit buffer I get message:

Text is read- only

enter image description here

  • 2
    The *occur* buffer is only a list of lines matching the pattern you searched for. Why do you want to edit that? If you do want to edit the text, perhaps in order to do something useful with it, just copy it into a new buffer. Then you can edit to your heart's content. … Oh wait, I missed some important information from the title of your question. It appears you have saved the occur buffer into a file, and wish to edit it? Then perhaps changing away from occur mode by running M-x normal-mode RET will do the trick. – Harald Hanche-Olsen Jan 4 '19 at 17:23
  • But I can't delete first line. M-x normal-mode - not help for first line. – a_subscriber Jan 4 '19 at 17:59
  • It's not clear what you're trying to do. Can you tell us step by step what you've done and what you want to happen? Saving the results of M-x occur creates a plain text file. You should be able to edit that file normally when you re-open it, and it should not be in occur-mode when you do. Something else is going on here I think. – Tyler Jan 4 '19 at 18:17
  • It looks like you still have occur-mode on. But your mode-line format looks strange for me. So I am not sure about that. – Tobias Jan 4 '19 at 18:17
  • 1
    Indeed, the first line has the text property read-only turned on, as you can see if you place the cursor on the line and run M-x describe-text-properties RET. You can remove them by selecting all the text, then going to the Edit menu and selecting Text PropertiesRemove Text Properties. That runs facemenu-remove-all, which you can also run with M-a facemenu-remove-all RET. – Harald Hanche-Olsen Jan 4 '19 at 18:44

The *Occur* buffer will be in a major mode unsurprisingly called occur-mode. This mode, or perhaps the code that prepares it, or a combination of the two, do a number of things, including these:

  • the buffer is marked read-only
  • it gets its own keymap, with most keys marked undefined
  • the first line is given some text properties

The best way to deal with the first two items is to get the buffer out of Occur mode and into some other mode: Perhaps text mode or fundamental mode will do: Just type M-x text-mode RET or M-x fundamental-mode RET (you don't have to type it all, thanks to tab completion). Or you can use M-x normal-mode and let emacs pick the mode based on the ending of the file name (and possibly the contents, but probably not in this case).

You now have a reasonable keymap, and the buffer is not readonly.

To get rid of the text properties in the first line, mark the first line, or the entire buffer if you wish (C-x h is handy for this), then go to the Edit menu and select Text Properties ▶ Remove Text Properties.

Note that the way to discover the existing properties is Edit ▶ Text Properties ▶ Describe Properties. If you do that, after first placing the cursor in the first line of the *Occur* buffer, you will see this:

There are text properties here:
  face                 underline
  occur-title          #<buffer tt.txt>
  read-only            t

That last one, read-only t, is your culprit.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.