For example, evil is autoload,

Some blogs/threads will use

(require 'evil)
(evil-mode 1)

to enable evil mode.

AFAIK, Elisp is lisp2 and evil-mode is also a function, so doesn't need setq.

(defadvice evil-mode (after start-evil activate)
  "Enable Evil in Fundamental mode."
  (if evil-mode
      (progn
        (when (eq (default-value 'major-mode) 'fundamental-mode)
          ;; changed back by `evil-local-mode'
          (setq-default major-mode 'turn-on-evil-mode))
        (ad-enable-regexp "^evil")
        (ad-activate-regexp "^evil")
        (with-no-warnings (evil-esc-mode 1)))
    (when (eq (default-value 'major-mode) 'turn-on-evil-mode)
      (setq-default major-mode 'fundamental-mode))
    (ad-disable-regexp "^evil")
    (ad-update-regexp "^evil")
    (with-no-warnings (evil-esc-mode -1))))

But, because of autoload,

(evil-mode 1)

Without require, it also works fine(at least for me)

(If anywhere below is wrong, please correct me, thx)

My question is when must I use require if the required package is autoloaded

up vote 3 down vote accepted

You're correct -- if an autoload declaration for evil-mode has been evaluated, then there is no need to (require 'evil) prior to (evil-mode 1)

Individual users may or may not need to (require 'evil) though. It's a question of how the library has been installed. On its own an ;;;###autoload cookie does nothing; but if you installed evil using package.el, then they will have been parsed and turned into a file of autoload declarations, which Emacs will load when packages are initialised.

If you install a library without using a package manager, then you may need to require it, or else write your own autoload declaration for the functions you might be calling.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.