(Emacs)文字是只读的吗?

时间:2014-07-04 00:17:33

标签: emacs lisp sbcl slime

所以我在emacs工作,突然,slime-repl sbcl说文本是只读的。那很好,因为现在我无法输入任何内容。我该如何解决?

7 个答案:

答案 0 :(得分:11)

“缓冲区是只读的”可以通过C-x C-q来治愈,但是作为Drew&菲尔斯说,
“文本是只读的”是非常不同的 - 这意味着 缓冲区的某些部分具有只读属性 尝试远离只读部分,例如,移动到缓冲区的末尾。

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::.

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

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

或删除所有属性:

(let ((inhibit-read-only t)) (set-text-properties (point-min) (point-max) ()))

答案 1 :(得分:3)

此类消息的可能原因可能是:您正在尝试通过REPL提示打印某些内容,例如CL-US|ER> (+ 1 2)。 SLIME缓冲区中的此文本是只读的。请注意>之后的空格,它是提示的一部分。

答案 2 :(得分:1)

我无法深入了解为什么最终会出现不受欢迎的只读文本属性,但我偶尔会遇到类似的情况,因此请查看以下命令。

选择有问题的区域(或整个缓冲区的 Cx h ),并运行 Mx 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)))

答案 3 :(得分:0)

键盘快捷键C-x C-qread-only-mode的默认绑定,可以使用该快捷方式启用或禁用。用C-h k C-x C-q描述键盘快捷键序列会产生以下缓冲区打印输出:

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.

因此,调用该选项的另一种方法是使用:M-x read-only-mode RET

答案 4 :(得分:0)

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

答案 5 :(得分:0)

我通过首先打开两个帧来解决这个问题,一个打开了.lisp文件,另一个打开了slime-repl。

在带有.lisp文件的帧中,我在一行代码上应用了C-c C-j(例如(+ 1 2))。

这会将代码行复制到slime-repl并对其进行评估。

这也以某种方式解决了“文本只读”问题。

答案 6 :(得分:0)

尝试输入C-c M-o RET(它将清除控制台并添加一个新行),我遇到了与您类似的问题并修复了它。