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

Dan*_*iel 3 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.
Run Code Online (Sandbox Code Playgroud)

Nei*_*eil 10

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

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

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


ali*_*oar 4

slim-* 函数使用 save-restriction 来保存当前缓冲区,然后再隐藏它,以便能够恢复它。

“保存限制”记住所有“缓冲区”数据结构,特别是最小点、最大点、最大点标记等。例如,在窄函数修改缓冲区的可见性之前,它会记住旧的配置,以便能够使用 Widen() 恢复它。