1

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

a_subscriber
  • 4,062
  • 1
  • 18
  • 56
  • 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 04 '19 at 17:23
  • But I can't delete first line. M-x normal-mode - not help for first line. – a_subscriber Jan 04 '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 04 '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 04 '19 at 18:17
  • Maybe the particular text you're trying to edit has a read-only property? That overrides read-only for the buffer as a whole. – Drew Jan 04 '19 at 18:38
  • 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 04 '19 at 18:44
  • @Drew The headline in occur buffers has the read-only text property put on it. That is true. But I've tried it: If you copy the buffer text and paste it to another buffer the read-only text property goes away. (Maybe it is filtered out.) But in the case of the OP the error message "Text is read-only" supports your assumption. What does [Occur] in the modeline say? Looks like the buffer is in Occur mode. In that case the buffer would be read-only. – Tobias Jan 04 '19 at 18:44
  • If the buffer is not read-only but there are text snippets with the read-only text property put on them you can remove that property with M-: (let ((inhibit-read-only t)) (remove-text-properties (point-min) (point-max) '(read-only nil))). – Tobias Jan 04 '19 at 18:48
  • @Tobias (In response to the message two above this one) Yes, but the OP tried to deal with that by running C-x C-q, which then turned out not to be sufficient. No wonder; in addition to the first line having the `read-only? text property, in Occur mode you are also hampered by the keymap. It's way easier to just copy the entier text to a new buffer and edit it. – Harald Hanche-Olsen Jan 04 '19 at 18:48
  • @HaraldHanche-Olsen Ah, the OP did not copy paste the text from the occur buffer but he saved the Occur buffer directly to a file. Hm, okay one shouldn't do that. Even M-x normal-mode does not clear the text properties. Your facemenu-remove-all is still needed. – Tobias Jan 04 '19 at 18:56
  • Did you try my suggestion above (sixth comment, five comments above this one unless someone removes their commend)? What happened when you did? – Harald Hanche-Olsen Jan 06 '19 at 16:04
  • Yes, sorry. "facemenu-remove-all" - this help. Thanks – a_subscriber Jan 06 '19 at 17:38
  • @HaraldHanche-Olsen Please, write your suggestion about facemenu-remove-all as an answer. @Alexei: Please accept HaraldHance-Olsen's answer to mark this question as done. – Tobias Jan 06 '19 at 21:08
  • @HaraldHanche-Olsen Why when I save occur buffer to separate file not whole lines are editable? – a_subscriber Jan 07 '19 at 11:08
  • @Tobias Done. Took me a while; I've been extremely busy. – Harald Hanche-Olsen Jan 07 '19 at 17:13

1 Answers1

3

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.

Harald Hanche-Olsen
  • 2,441
  • 13
  • 15