help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: add-hook


From: Drew Adams
Subject: RE: add-hook
Date: Fri, 25 Jan 2013 11:18:57 -0800

> In one of my setup files I have this: 
>
> (eval-after-load 'ruby-mode
>   '(add-hook
>      'ruby-mode-hook
>      (function
>       (lambda ()
>        (ruby-electric-mode t)))))
>
> Other places, I just do the add-hook.

You don't need the `eval-after-load' (or the `function').

> The reason I'm asking is because I need to do:
> (eval-after-load 'grep '(add-to-list 'grep-files-aliases ...))
> because if I don't, I get an error that says grep-files-aliases
> is not defined.
>
> It appears as if add-hook has smarts that add-to-list does not

Good question.  Let's ask Emacs...

Yes - see the last paragraph of `C-h f add-hook':

,----
| add-hook is a compiled Lisp function in `subr.el'.
| (add-hook HOOK FUNCTION &optional APPEND LOCAL)
| 
| Add to the value of HOOK the function FUNCTION.
| FUNCTION is not added if already present.
| FUNCTION is added (if necessary) at the beginning of the hook list
| unless the optional argument APPEND is non-nil, in which case
| FUNCTION is added at the end.
| 
| The optional fourth argument, LOCAL, if non-nil, says to modify
| the hook's buffer-local value rather than its global value.
| This makes the hook buffer-local, and it makes t a member of the
| buffer-local value.  That acts as a flag to run the hook
| functions of the global value as well as in the local value.
| 
| HOOK should be a symbol, and FUNCTION may be any valid function.  If
| HOOK is void, it is first set to nil.  If HOOK's value is a single
| function, it is changed to a list of functions.
`----

If HOOK is void then it is initialized to nil.

(add-hook 'ruby-mode-hook (lambda () (ruby-electric-mode t)))




reply via email to

[Prev in Thread] Current Thread [Next in Thread]