2

I am running emacs 24 with the Inferior Python mode for the interpreter. See below for all the minor modes in effect. Basically the problem is that particular lines (say at the prompt) remain read-only even when I mark toggle "read-only-mode" and I can edit the rest of the buffer.

I am not able to figure out why this might be happening. I have tried toggle-read-only as well. It seems like something related with the font-lock or something else since the behavior happens only at the python prompt lines.

The buffer is running the following minor-modes.

Enabled minor modes: Auto-Composition Auto-Compression Auto-Encryption     
Column-Number Compilation-Shell Diff-Auto-Refine Electric-Indent           
Electric-Pair File-Name-Shadow Font-Lock Global-Company Global-Ede         
Global-Eldoc Global-Font-Lock Global-Semantic-Decoration                   
Global-Semantic-Highlight-Func Global-Semantic-Idle-Completions            
Global-Semantic-Idle-Scheduler Global-Semantic-Idle-Summary                
Global-Semantic-Mru-Bookmark Global-Semantic-Show-Unmatched-Syntax         
Global-Semanticdb Ido-Everywhere Line-Number Mouse-Wheel Recentf           
Semantic Shell-Dirtrack Tooltip Winner                                     
4

You can use the following commands to set the read-only text property for the marked region. The code is based on https://stackoverflow.com/questions/7410125

(defun set-region-read-only (begin end)
  "Sets the read-only text property on the marked region.

Use `set-region-writeable' to remove this property."
  ;; See https://stackoverflow.com/questions/7410125
  (interactive "r")
  (with-silent-modifications
    (put-text-property begin end 'read-only t)))

(defun set-region-writeable (begin end)
  "Removes the read-only text property from the marked region.

Use `set-region-read-only' to set this property."
  ;; See https://stackoverflow.com/questions/7410125
  (interactive "r")
  (with-silent-modifications
    (remove-text-properties begin end '(read-only t))))
| improve this answer | |
1

That zone of text probably has a non-nil value for text property read-only.

Commands such as read-only-mode (and toggle-read-only) have no effect on this, as their doc tells you. C-h f read-only-mode says:

Also, note that this command works by setting the variable buffer-read-only, which does not affect read-only regions caused by text properties. To ignore read-only status in a Lisp program (whether due to text properties or buffer state), bind `inhibit-read-only' temporarily to a non-nil value.

To see the text properties at a given position, use C-u C-x = at that position.

To be able to tell you just what you might want to do in your context, let us know what you are really trying to do, which might include why. Are you doing something by program (Lisp)? If so, what? Or are you trying to do something only interactively? If so, what?

| improve this answer | |
  • This is exactly what is going on in the Python interpreter. The prompt is set to read only because it would make little sense to delete the it. If you want to edit the buffer for some reason, you can save it to a file and then load that. – erikstokes Mar 18 '15 at 1:11
  • 1
    Hi Drew thanks for the response. I was trying to remove a giant line single line text that I had accidentally printed but did not want to lose the session. And I wanted to remove the line because it was making emacs really slow. @erikstokes The problem was that somehow the entire line in the prompt was set to read only and only the characters '>>>' that comprise the prompt. – Pushpendre Mar 18 '15 at 2:53

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.