使用eval-after-load
並使用模式掛鉤爲模式設置東西有區別嗎?eval-after-load vs.模式掛鉤
我已經看到一些代碼,其中define-key
被用在一個主要的模式鉤子裏面,還有一些代碼被用在eval-after-load
的窗體中。
更新:
爲了更好地理解,下面是使用的例子EVAL-後負荷和模式鉤與組織模式。代碼可以在(load "org")
或(require 'org)
或(package-initialize)
之前運行。包裹在eval-after-load
;; 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)))
+1 for *「org」,因爲C-h f org-mode RET表示組織模式在org.el *中定義。我正在努力獲得'eval-after-load'來實際評估'nxml-mode',並且這個提示很有用! – 2014-10-12 19:40:08