【问题标题】:emacs remove region read-onlyemacs 以只读方式删除区域
【发布时间】:2013-11-16 20:18:39
【问题描述】:

Emacs specific region read only 密切相关,您如何删除缓冲区中文本区域的只读属性。

例如,如果您在 emacs 中使用 python shell 并意外打印出一个巨大的列表,并希望从缓冲区中删除输出。

【问题讨论】:

  • 很想知道是什么条件使 Python shell 的输出成为只读的。
  • @AndreasRöhler 而且不是每一行,只有十分之一左右。它是 2 层深度嵌套元组的列表,混合了列表、整数和 ndarray。我认为标记为只读的特定行是数组打印出来的第一行。
  • AFAIU 这不应该发生在 python-mode 方面。想看一些示例代码。无论如何,解决方案都是有趣且有用的:)
  • @AndreasRöhler 一个月后联系我,我会有更多时间。我的猜测是,comint 试图太聪明了。刚启动 shell 将提供一些 shell 缓冲区的只读位(尝试按 ctrl-k In[] 提示符)。
  • 假设这个想法是为了保护提示不被用户不情愿地删除。记得看过它,但现在无法得到它,既不是普通的 comint,也不是 python 模式。好吧...也许让我们关闭它。

标签: emacs elisp


【解决方案1】:

我使用以下内容。它类似于 tcaswell 的回答,但处理缓冲区修改问题。

(defun set-region-read-only (begin end)
  "Sets the read-only text property on the marked region.

Use `set-region-writeable' to remove this property."
  ;; See https://stackoverflow.com/questions/7410125
  (interactive "r")
  (with-silent-modifications
    (put-text-property begin end 'read-only t)))

(defun set-region-writeable (begin end)
  "Removes the read-only text property from the marked region.

Use `set-region-read-only' to set this property."
  ;; See https://stackoverflow.com/questions/7410125
  (interactive "r")
  (with-silent-modifications
    (remove-text-properties begin end '(read-only t))))

【讨论】:

    【解决方案2】:

    按照the documentation 中只读下的神秘评论,删除只读区域您只需要:

    (defun remove-region-read-only (begin end)
      (interactive "r")
      (let ((inhibit-read-only t))
        (remove-text-properties begin end '(read-only t)))
      )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-24
      • 1970-01-01
      • 2012-05-22
      • 2012-08-26
      相关资源
      最近更新 更多