【问题标题】:(Emacs) Text is read only?(Emacs)文本是只读的?
【发布时间】:2014-08-25 05:57:35
【问题描述】:

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

【问题讨论】:

  • C-x C-q 是如何启用或禁用只读模式。但是,我还不愿意将其发布为答案,因为您可能更想知道可能导致该行为的原因,而我不熟悉您提到的库。
  • @lawlist 我想说继续并建议它作为答案,关于 如何在缓冲区中禁用只读。 OP 总是可以搜索更多内容以找出缓冲区突然变为只读的原因。这是一个单独的问题(至少在此处提供更多信息之前)。
  • 如果它说“text”是只读的(而不是“buffer”),那么可能有一个read-only text 属性在起作用?
  • @Drew “缓冲区是只读的”与“文本是只读的”有很大不同。 C-x C-q 命令切换“缓冲区是只读的”,而“文本是只读的”似乎没有任何改变,因为我的手指按错了键(我不知道我按了哪个键)。现在我必须重新启动 SLIME 并丢失我的工作。 :(
  • 是的,如果它说“文本是只读的”(这意味着错误text-read-only),那么该点上的文本就有一个只读文本属性。 Elisp 手册,节点 Special Properties,这样说:“由于更改属性算作修改缓冲区,除非您知道特殊技巧,否则无法删除 read-only 属性:将 inhibit-read-only 绑定到非 @987654329 @值,然后删除该属性。*注意只读缓冲区。"

标签: emacs lisp sbcl slime


【解决方案1】:

“缓冲区是只读的”可以通过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) ()))

【讨论】:

  • 这是唯一明白它不是只读缓冲区的答案,所以 C-x C-q 根本不能解决问题。
  • 这才是真正的答案
  • 对于新的 emacs 用户,上面的 devon 正在运行命令: eval-expression 。它的默认键定义是 M-: (通常是转义冒号)。运行 eval-expression 后,它会提示您将 lisp 表达式输入(或粘贴)到迷你缓冲区并点击
【解决方案2】:

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

【讨论】:

    【解决方案3】:

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

    选择有问题的区域(或 Cxh 表示整个缓冲区),然后运行 ​​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)))
    

    【讨论】:

    • 我更喜欢这个答案而不是这个线程上最受欢迎的答案。这真的很容易打开我的 scratch 缓冲区,粘贴这段代码,评估它,然后切换回有问题的缓冲区。然后标记区域,然后M-x set-region-writable
    • 查看stackoverflow.com/a/20027146/324105 了解此功能的略微改进版本。
    【解决方案4】:

    键盘快捷键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

    【讨论】:

      【解决方案5】:

      您可以通过以下方式更改只读模式:M-x -> toggle-read-only -> RET(换句话说,按回车键)

      【讨论】:

        【解决方案6】:

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

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

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

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

        【讨论】:

          【解决方案7】:

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-05-03
            • 1970-01-01
            • 2011-07-01
            • 2013-01-12
            相关资源
            最近更新 更多