Effective February 22, 2024, Google Groups will no longer support new Usenet content. Posting and subscribing will be disallowed, and new content from Usenet peers will not appear. Viewing and searching of historical data will still be supported as it is done today.

Elisp question: when 'require' needed?

6 views
Skip to first unread message

Oleksandr Gavenko

unread,
Jan 14, 2011, 11: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, 11: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, 11: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.


Reply all
Reply to author
Forward
0 new messages