Emacs:设置文本属性时如何智能处理缓冲区修改?

标签 emacs

The documentation on Text Properties说:

Since text properties are considered part of the contents of the buffer (or string), and can affect how a buffer looks on the screen, any change in buffer text properties marks the buffer as modified.



首先,我不明白那个政策。谁能解释一下?保存缓冲区时,文本 Prop 实际上并未保存在文件中。那么为什么将缓冲区标记为已修改?对我来说,缓冲区修改表示“一些更改尚未保存”。但了解政策只是为了我自己的消遣。

更重要的是,是否有一种已经建立的方法可以在代码中更改缓冲区中文本的语法文本属性,同时在这些更改之前将缓冲区修改标志设置为任何内容?我在想类似 save-excursion 的事情.
写起来很容易,但这似乎是一个常见的情况,如果可能的话,我想使用标准函数。

有关该场景的更多信息 - 我有一个模式可以进行全文扫描并在文本上设置语法表属性。打开缓冲区后,扫描会运行,但会生成缓冲区修改设置为 t 的缓冲区。

一如既往,谢谢。

最佳答案

较新版本的 Emacs 包括宏“with-silent-modifications”:

C-h f with-silent-modifications
------------------------------------------------------
with-silent-modifications is a Lisp macro in `subr.el'.

(with-silent-modifications &rest BODY)

Execute BODY, pretending it does not modify the buffer.
If BODY performs real modifications to the buffer's text, other
than cosmetic ones, undo data may become corrupted.
Typically used around modifications of text-properties which do not really
affect the buffer's content.

关于Emacs:设置文本属性时如何智能处理缓冲区修改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2699857/

相关文章:

emacs - 简单的 Emacs 键绑定(bind)

emacs - Haskell 与 emacs 组织模式 : Variable not in scope

emacs - 我怎样才能让编译缓冲区把点放在它的末尾?

java - 打开文件时如何在 emacs 中自动缩进?

emacs - 使用 ssh session 中的 emacs tramp 对远程文件进行原始编辑

emacs - 让 emacs 在启动时打开东西

emacs - 如何在 verilog 模式下使用正则表达式删除 I/O 端口声明

emacs - emacs 是用哪个编辑器写的?

emacs - 更好地控制Emacs窗口

emacs - 如何在 emacs 启动时默认启用非全局次要模式?