emacs - 保存限制中的 "buffer' s 限制是什么意思?

标签 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.

最佳答案

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

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

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

    关于emacs - 保存限制中的 "buffer' s 限制是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11596010/

    相关文章:

    r - 如何指定emacs中ESS session 打开的R版本?

    lisp - emacs lisp 列出带有 glob 扩展的文件

    emacs - elisp 中的 lambda 宏

    emacs - elisp - 获取相对于脚本的文件路径

    emacs - emacs gud 中的 lldb 不更新 'up' 的源文件

    emacs - emacs:Orgmode,如何从一行代码中创建一个列表

    emacs - emacs * compilation *缓冲区中的换行

    emacs - Emacs 中的原始缩进

    git - Emacs:为什么 shell 命令 "git log"有效,但 "git shortlog"无效?

    emacs - 如何克服 emacs lisp 闭包缺少局部变量的问题