[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Elisp question: when 'require' needed?
From: |
Oleksandr Gavenko |
Subject: |
Re: Elisp question: when 'require' needed? |
Date: |
Fri, 14 Jan 2011 11:57:08 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.13) Gecko/20101207 Thunderbird/3.1.7 |
On 14.01.2011 11:41, Oleksandr Gavenko wrote:
I wont update in .emacs 'grep-find-ignored-directories':
(add-to-list grep-find-ignored-directories "build")
(add-to-list grep-find-ignored-directories "dist")
(add-to-list grep-find-ignored-directories "lib")
It defined in grep.el as:
(defcustom grep-find-ignored-directories
vc-directory-exclusion-list ...)
If I dont put
(require 'grep)
before add-to-list I get
Symbol's value as variable is void: grep-find-ignored-directories
But adding a lot of 'require' slow down start up time.
To resolve this I can use:
(add-hook grep-setup-hook (lambda nil
(add-to-list grep-find-ignored-directories "build")
(add-to-list grep-find-ignored-directories "dist")
))
What usual pattern for common case?
Put 'require' or 'add-hook'.
With 'require' code look more linear but load time increased.
With 'add-hook' code become some messy.
Is there standard for setup-hook name?
Is there requirement put to *.el file such hook?
Who invoke setup-hook?
Is it called automatically?
Is there requirement invoke it only once?
Also 'grep-setup-hook' declared as ###autoload.
So if I wrote '(add-hook grep-setup-hook ...)' Emacs read grep.el,
so it is more simply use '(require 'grep)'?
I found such doc on add-to-list:
If you want to use `add-to-list' on a variable that is not defined
until a certain package is loaded, you should put the call to `add-to-list'
into a hook function that will be run only after loading the package.
`eval-after-load' provides one way to do this. In some cases
other hooks, such as major mode hooks, can do the job.