(Emacs) Text is read only?

前端 未结 7 892
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-04 06:56

So I was working in emacs and the suddenly, the slime-repl sbcl says text is read only. Well that\'s great because now I can\'t type anything into it. How do I fix?

相关标签:
7条回答
  • 2021-02-04 07:09

    The keyboard shortcut C-x C-q is the default binding for read-only-mode, which can be enabled or disabled with that shortcut. Describing that keyboard shortcut sequence with C-h k C-x C-q yields the following buffer printout:

    C-x C-q runs the command read-only-mode, which is an interactive
    compiled Lisp function in `simple.el'.
    
    It is bound to C-x C-q.
    
    (read-only-mode &optional ARG)
    
    Change whether the current buffer is read-only.
    With prefix argument ARG, make the buffer read-only if ARG is
    positive, otherwise make it writable.  If buffer is read-only
    and `view-read-only' is non-nil, enter view mode.
    
    Do not call this from a Lisp program unless you really intend to
    do the same thing as the C-x C-q command, including
    possibly enabling or disabling View mode.  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.
    

    So, another way to call that option would be to use: M-x read-only-mode RET

    0 讨论(0)
  • 2021-02-04 07:17

    Possible cause of such a message may be this: you are trying to print something over the REPL prompt, for example CL-US|ER> (+ 1 2). This text in the SLIME buffer is read-only. Note the space after >, it is the part of the prompt.

    0 讨论(0)
  • 2021-02-04 07:18

    "Buffer is read-only" can be cured by C-x C-q but as Drew & phils said,
    "Text is read-only" is very different -- it means some part of the buffer has a read-only property.
    Try moving away from the read-only part, e.g., to the end of the buffer.

    Emacs Lisp Manual > elisp.info > Text > Text Properties > Special Properties

     Since changing properties counts as modifying the buffer, it is not
     possible to remove a `read-only' property unless you know the
     special trick: bind `inhibit-read-only' to a non-`nil' value and
     then remove the property.  *Note Read Only Buffers::.
    

    thus to erase the entire buffer regardless:

    M-: (let ((inhibit-read-only t)) (erase-buffer)) RET
    

    or to remove all properties:

    (let ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) ()))
    
    0 讨论(0)
  • 2021-02-04 07:19

    I can't offer any insight into why you ended up with undesirable read-only text properties, but I occasionally encounter similar situations and so find the following command useful.

    Select the region in question (or C-xh for the entire buffer), and run M-x set-region-writeable to remove the read-only text properties.

    (defun set-region-writeable (begin end)
      "Removes the read-only text property from the marked region."
      ;; See http://stackoverflow.com/questions/7410125
      (interactive "r")
      (let ((modified (buffer-modified-p))
            (inhibit-read-only t))
        (remove-text-properties begin end '(read-only t))
        (set-buffer-modified-p modified)))
    
    0 讨论(0)
  • 2021-02-04 07:22

    You can change read-only mode by doing: M-x -> toggle-read-only -> RET (in other words press enter)

    0 讨论(0)
  • 2021-02-04 07:23

    Try typing C-c M-o RET (it will clear the console and add a new line), I had a problem similar to yours and for it fixed it.

    0 讨论(0)
提交回复
热议问题