(Emacs)文字是只读的吗?

Fde*_*ral 14 lisp emacs sbcl slime

所以我在emacs工作,突然,slime-repl sbcl说文本是只读的.那很好,因为现在我不能输入任何东西.我该如何解决?

dev*_*von 14

"缓冲区是只读的"可以通过,C-x C-q但正如Drew&phils所说,
"Text是只读的"是非常不同的 - 它意味着缓冲区的某些部分具有只读属性.
尝试远离只读部分,例如,移动到缓冲区的末尾.

Emacs Lisp手册> elisp.info>文本>文本属性>特殊属性

 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::.
Run Code Online (Sandbox Code Playgroud)

因此,无论如何擦除整个缓冲区:

M-: (let ((inhibit-read-only t)) (erase-buffer)) RET
Run Code Online (Sandbox Code Playgroud)

或删除所有属性:

(let ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) ()))
Run Code Online (Sandbox Code Playgroud)

  • 这是唯一能够理解它不是只读缓冲区的答案,因此Cx Cq根本无法解决问题. (4认同)
  • 对于新的 emacs 用户,上面的 devon 正在运行命令: eval-expression 。它的默认键定义是 M-:(通常是转义冒号)。运行 eval-expression 后,它会提示您输入(或粘贴)您的 lisp 表达式到迷你缓冲区并点击 <return> (2认同)

phi*_*ils 5

我无法提供任何见解来解释为什么您最终会得到不需要的只读文本属性,但我偶尔会遇到类似的情况,因此发现以下命令很有用。

选择有问题的区域(或C-xh整个缓冲区),然后运行M-x set-region-writeable以删除只读文本属性。

(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)))
Run Code Online (Sandbox Code Playgroud)


Ham*_*ter -1

您可以通过执行以下操作来更改只读模式:M-x-> toggle-read-only-> RET(换句话说,按 Enter 键)