什么是"缓冲区的限制"在保存限制中意味着什么?

时间:2012-07-21 21:33:07

标签: emacs elisp

当我在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.

2 个答案:

答案 0 :(得分:10)

除非您的代码的目的是修改限制,当前缓冲区,点或窗口配置,否则您应该使用适当的保存方法来记住状态并自动为您恢复。

  • save-current-buffer保存当前缓冲区,以便您可以切换到另一个缓冲区,而不必记得切换回来。
  • save-excursion保存当前缓冲区及其当前点并标记,因此您可以移动点而无需记住恢复它。
  • save-restriction保存限制,以便您可以缩小或widen,而无需记住恢复它。
  • save-window-excursion保存帧上所有窗口的完整配置,当前缓冲区中的point值除外。

(旁注:我上次使用save-window-excursion时没有window-configuration-p方法。)

答案 1 :(得分:2)

save-limit由narrow- *函数用于保存当前缓冲区,然后再隐藏它,以便能够恢复它。

'save-restriction'记忆所有'缓冲'数据结构,特别是point-min,point-max,point-max-marker等。例如,在窄函数修改缓冲区的可见性之前,它会记住旧配置,以便能够使用widen()恢复它。

相关问题