Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Elisp question: when 'require' needed?

6 views
Skip to first unread message

Oleksandr Gavenko

unread,
Jan 14, 2011, 4:41:54 AM1/14/11
to help-gn...@gnu.org
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)'?


Oleksandr Gavenko

unread,
Jan 14, 2011, 4:48:10 AM1/14/11
to help-gn...@gnu.org
On 14.01.2011 11:41, Oleksandr Gavenko wrote:
>
> (add-hook grep-setup-hook (lambda nil
> (add-to-list grep-find-ignored-directories "build")
> (add-to-list grep-find-ignored-directories "dist")
> ))
>
Sorry, I forget add quoter before grep-setup-hook.


Oleksandr Gavenko

unread,
Jan 14, 2011, 4:57:08 AM1/14/11
to help-gn...@gnu.org
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.


0 new messages