Note that there are some explanatory texts on larger screens.

plurals
  1. POeval-after-load vs. mode hook
    text
    copied!<p>Is there a difference between setting things for a mode using <code>eval-after-load</code> and using the mode hook?</p> <p>I've seen some code where <code>define-key</code> is used inside a major mode hook, and some other code where <code>define-key</code> is used in <code>eval-after-load</code> form.</p> <hr> <p>Update:</p> <p>For better understanding, here is an example of using eval-after-load and mode hooks with org-mode. The code can run <strong>before</strong> <code>(load "org")</code> or <code>(require 'org)</code> or <code>(package-initialize)</code>.</p> <pre><code>;; 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 "&lt;C-M-return&gt;") 'org-insert-heading-respect-content) (define-key org-mode-map (kbd "&lt;M-right&gt;") nil) ; erasing a keybinding. (define-key org-mode-map (kbd "&lt;M-left&gt;") 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))) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload