所以我在emacs工作,突然间,slime-repl sbcl说文本是只读的。那很好,因为现在我不能输入任何东西。我该如何解决?
所以我在emacs工作,突然间,slime-repl sbcl说文本是只读的。那很好,因为现在我不能输入任何东西。我该如何解决?
“缓冲区是只读的”可以通过治愈 C-x C-q
但正如Drew&phils所说,
“文本是只读的”是非常不同的 - 这意味着
缓冲区的某些部分具有只读属性。
尝试远离只读部分,例如,移动到缓冲区的末尾。
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) ()))
这种消息的可能原因可能是:例如,您正在尝试通过REPL提示打印某些内容 CL-US|ER> (+ 1 2)
。 SLIME缓冲区中的此文本是只读的。注意后面的空格 >
,这是提示的一部分。
我无法提供任何见解 为什么 你最终得到了不受欢迎的只读文本属性,但我偶尔遇到类似的情况,因此找到以下命令很有用。
选择有问题的区域(或 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)))
键盘快捷键 C-x C-q
是默认绑定 read-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
您可以通过执行以下操作来更改只读模式: M-x
- > toggle-read-only
- > RET
(换句话说按回车键)
我通过首先打开两个帧来解决这个问题,一个打开了.lisp文件,另一个打开了slime-repl。
从带有.lisp文件的帧开始,我在一行代码上应用了C-c C-j(例如(+ 1 2))。
这会将代码行复制到slime-repl并对其进行评估。
这也以某种方式解决了“文本只读”问题。
尝试输入 C-c M-o RET
(它将清除控制台并添加一个新行),我遇到了类似于你的问题,并修复了它。