当我在Emacs中搜索"save-restriction“的描述时,它有一个关于”缓冲区的限制“的句子--我在下面包含了完整的描述。这个术语是什么意思?考虑到这一点,保存限制是如何工作的,什么时候应该使用它?
(save-restriction &rest BODY)
Execute BODY, saving and restoring current buffer's restrictions.
The buffer's restrictions make parts of the beginning and end invisible.
(They are set up with `narrow-to-region' and eliminated with `widen'.)
This special form, `save-restriction', saves the current buffer's restrictions
when it is entered, and restores them when it is exited.
So any `narrow-to-region' within BODY lasts only until the end of the form.
The old restrictions settings are restored
even in case of abnormal exit (throw or error).
The value returned is the value of the last form in BODY.发布于 2012-07-22 05:37:42
save-restriction用于在隐藏当前缓冲区之前保存当前缓冲区,以便能够恢复它。
‘’save restriction‘存储所有的'buffer’数据结构,特别是point-min,point-max,point-max-marker等。例如,在窄函数修改缓冲区的可见性之前,它会记住旧的配置,以便能够使用widen()恢复它。
发布于 2012-07-22 06:24:54
除非您的代码的目的是修改限制、当前缓冲区、点或窗口配置,否则您应该使用适当的保存方法来记住状态并自动为您恢复状态。
save-current-buffer保存当前缓冲区,这样你就可以切换到另一个缓冲区,而不必记得切换。back.save-excursion保存当前缓冲区及其当前点和标记,所以你可以移动点,而不必记住恢复it.save-restriction保存限制,以便你可以缩小或widen它,而不必记住恢复it.save-window-excursion保存帧上所有窗口的完整配置,除了当前缓冲区中的点的值。(附注:当我上次使用save-window-excursion时,还没有window-configuration-p方法。)
https://stackoverflow.com/questions/11596010
复制相似问题