首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加载后与模式挂钩

加载后与模式挂钩
EN

Stack Overflow用户
提问于 2010-04-29 09:20:27
回答 1查看 17.8K关注 0票数 80

使用eval-after-load设置模式与使用模式挂钩是否有区别?

我看到了一些在主要模式钩子中使用define-key的代码,以及在eval-after-load表单中使用define-key的其他一些代码。

更新:

为了更好地理解,下面是一个示例,说明如何在组织模式中使用加载后评估和模式挂钩。代码可以在之前运行 (load "org")(require 'org)(package-initialize)

代码语言:javascript
复制
;; The following two lines of code set some org-mode options.
;; Usually, these can be outside (eval-after-load ...) and work.
;; In cases that doesn't work, try using setq-default or set-variable
;; and putting them in (eval-after-load ...), if the
;; doc for the variables don't say what to do.
;; Or use Customize interface.
(setq org-hide-leading-stars t)
(setq org-return-follows-link t)

;; "org" because C-h f org-mode RET says that org-mode is defined in org.el
(eval-after-load "org"
  '(progn
     ;; Establishing your own keybindings for org-mode.
     ;; Variable org-mode-map is available only after org.el or org.elc is loaded.
     (define-key org-mode-map (kbd "<C-M-return>") 'org-insert-heading-respect-content)
     (define-key org-mode-map (kbd "<M-right>") nil) ; erasing a keybinding.
     (define-key org-mode-map (kbd "<M-left>") nil) ; erasing a keybinding.

     (defun my-org-mode-hook ()
       ;; The following two lines of code is run from the mode hook.
       ;; These are for buffer-specific things.
       ;; In this setup, you want to enable flyspell-mode
       ;; and run org-reveal for every org buffer.
       (flyspell-mode 1)
       (org-reveal))
     (add-hook 'org-mode-hook 'my-org-mode-hook)))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-04-29 09:30:05

包装在eval-after-load中的代码将只执行一次,因此通常用于执行一次性设置,例如设置默认的全局值和行为。一个示例可能是为特定模式设置默认密钥映射。在eval-after-load代码中,没有“当前缓冲区”的概念。

模式挂钩对每个启用模式的缓冲区执行一次,因此它们用于每个缓冲区配置。因此,模式挂钩比eval-after-load代码运行得晚;这使它们能够根据诸如是否在当前缓冲区中启用其他模式等信息采取行动。

票数 112
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2736087

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档