0

Apparently I cannot find the correct word for this problem. I tried searching for:

protected

non-editable

blocked

but none of those bring up anything.

I was writing some code when my cat jumped on my keyboard. I'm not sure what keys they hit, but they copied a region and pasted it (or yanked and killed) but also made it non-editable. I cannot select it. If I try to select it in a region, the selection just skips over it. I can delete lines above it and below but I cannot delete the code that my cat copied in some strange way.

What is the correct term for this? And how do I undo it?

2
  • 1
    It is probably too late now, but in the future if you have this type of cat problem, you should use M-x lossage. It shows you the last hundred or so commands that were executed.
    – db48x
    Commented Jan 30 at 11:19
  • That's a great tip. Thank you. Commented Jan 31 at 2:33

1 Answer 1

2

Whatever happened, you can probably just undo your way back to a point before the unusual thing happened. Of course the undo buffer is not actually infinite, and so it might be too late for this simple solution. You can read elsewhere how to extend the length of the undo buffer, if you want.

Likewise, if you really want to know what mysterious command your cat managed to execute you can use M-x lossage. This shows a log of the hundred most recently–executed commands. Of course it is best to use this command right away, especially since the last seven commands will be you typing in “lossage” leaving you with at most 92 useful things in the log.

I cannot think of any commands that would do exactly as you describe, but that doesn’t mean much as there are plenty of commands that I've never used. However, it sounds like text properties were applied to the buffer to make a section of the buffer read–only and possibly intangible. Read–only text cannot be edited, and intangible text cannot be interacted with in other ways. For example, the arrow keys will cause the cursor to jump over the intangible text in one go, instead of putting the cursor inside of it. There is also the possibility that the uneditable text is an overlay instead.

You can probably just save the buffer, close it, and reopen the file. You should then find that the uneditable region is gone. There is a chance that the text of that region will actually be saved to the file, but loading the file will not make that text read–only or intangible. You can then delete it. On the other hand, if the text is an overlay then it won’t be saved to the file.

You might also be able to reset the buffer’s mode by running M-x normal-mode. Or you could run M-x fundamental-mode to reset everything back to default with no mode at all; you should end up with a buffer containing text with no special properties or overlays.

On the other hand, you might try using functions such as remove-list-of-text-properties to make the region editable again. For example, you might use M-: to evaluate the expression (remove-list-of-text-properties (point-min) (point-max) '(read-only intangible cursor-intangible)). That could fix it. In fact, you might use an even bigger sledgehammer and evaluate (set-text-properties (point-min) (point-max) nil) to remove every single text property at once. That will remove useful properties too, such as syntax highlighting, but the result would be editable and the buffer’s mode would soon reinstate such useful things.

If you want to know more about properties, you should read chapter 33.19 Text Properties of the Emacs Lisp manual, or perhaps chapter 41.9 Overlays of the same.

If anyone has any idea of commands that might do this they should add additional answers. Could be an interesting list.

2
  • "For example, the arrow keys will cause the cursor to jump over the intangible text in one go" -- exactly. This is what is happening. Commented Jan 31 at 2:34
  • Okay, closing the buffer and then re-opening it worked. Thank you. Commented Jan 31 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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