all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* does customizing a hook "add-to" the hook?
@ 2013-07-13 21:25 gottlieb
  2013-07-15  0:33 ` Michael Heerdegen
  0 siblings, 1 reply; 6+ messages in thread
From: gottlieb @ 2013-07-13 21:25 UTC (permalink / raw)
  To: help-gnu-emacs

If I use `customize-option' to customize a (normal) hook,
do the functions I add via pushing the `ins' button get added to
the default value for the hook or do they replace the default?

I wish to achieve the former (add-to) effect and realize that `add-hook'
does this, but would prefer to use customize if possible.

thanks,
allan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: does customizing a hook "add-to" the hook?
  2013-07-13 21:25 does customizing a hook "add-to" the hook? gottlieb
@ 2013-07-15  0:33 ` Michael Heerdegen
  2013-07-15  1:12   ` Michael Heerdegen
  2013-07-15 18:50   ` gottlieb
  0 siblings, 2 replies; 6+ messages in thread
From: Michael Heerdegen @ 2013-07-15  0:33 UTC (permalink / raw)
  To: help-gnu-emacs

gottlieb@nyu.edu writes:

> If I use `customize-option' to customize a (normal) hook,
> do the functions I add via pushing the `ins' button get added to
> the default value for the hook or do they replace the default?
>
> I wish to achieve the former (add-to) effect and realize that `add-hook'
> does this, but would prefer to use customize if possible.

Customizing a hook and restoring the saved value later (maybe in a
different session!) happen at different moments of time, so your question
is somewhat vague.

Here is what I think happens:

- When you customize the hook, you see all elements of the hook at that
  moment.  You can delete entries or leave them, or add others.

- If you have saved it, this is the value that will be restored later
  (whereby the current value of the hook at that moment is just
  discarded, I think) when loading `custom-file'.

- But of course, after that, lisp code can still modify that value and
  add stuff to the hook.  This doesn't change the value saved by
  customize.


All relevant hooks I know are empty when declared in the sources.  So if
you load your `custom-file' early enough when starting up Emacs (i.e.,
before modifying hooks or loading packages), you don't need to worry
about your or third party code adding stuff to the hook, that works
normally.

Is that what you meant?


Regards,

Michael.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: does customizing a hook "add-to" the hook?
  2013-07-15  0:33 ` Michael Heerdegen
@ 2013-07-15  1:12   ` Michael Heerdegen
  2013-07-15 18:50   ` gottlieb
  1 sibling, 0 replies; 6+ messages in thread
From: Michael Heerdegen @ 2013-07-15  1:12 UTC (permalink / raw)
  To: help-gnu-emacs

Michael Heerdegen <michael_heerdegen@web.de> writes:

> All relevant hooks I know are empty when declared in the sources.  So if
> you load your `custom-file' early enough when starting up Emacs (i.e.,
> before modifying hooks or loading packages), you don't need to worry
> about your or third party code adding stuff to the hook, that works
> normally.

To sum up, hooks are treated like any other variable when loading the
`custom-file', the hook variables are just set to the saved values.

These saved values are not checked in any sense.  If they include
functions that were defined when you saved the hook value, but not
defined when restoring it, you'll get an error when you run the hook.
So be careful with what you save.


Michael.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: does customizing a hook "add-to" the hook?
  2013-07-15  0:33 ` Michael Heerdegen
  2013-07-15  1:12   ` Michael Heerdegen
@ 2013-07-15 18:50   ` gottlieb
  2013-07-15 22:49     ` Michael Heerdegen
  1 sibling, 1 reply; 6+ messages in thread
From: gottlieb @ 2013-07-15 18:50 UTC (permalink / raw)
  To: help-gnu-emacs

On Sun, Jul 14 2013, Michael Heerdegen wrote:

> gottlieb@nyu.edu writes:
>
>> If I use `customize-option' to customize a (normal) hook,
>> do the functions I add via pushing the `ins' button get added to
>> the default value for the hook or do they replace the default?
>>
>> I wish to achieve the former (add-to) effect and realize that `add-hook'
>> does this, but would prefer to use customize if possible.
>
> All relevant hooks I know are empty when declared in the sources.  So if
> you load your `custom-file' early enough when starting up Emacs (i.e.,
> before modifying hooks or loading packages), you don't need to worry
> about your or third party code adding stuff to the hook, that works
> normally.

Thank you for the response.
That was exactly my concern.  Namely that I (in this order)

1.  set a hook via customize
2.  upgrade emacs
3.  run the new emacs (with my same startup files)

and then some new default would be overridden since my customization
overwrites the hook instead of adding to it.

Is it guaranteed or suggested that hook are by default empty?  I didn't
see that in the info pages.

Sorry I wasn't clearer initially.

allan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: does customizing a hook "add-to" the hook?
  2013-07-15 18:50   ` gottlieb
@ 2013-07-15 22:49     ` Michael Heerdegen
  2013-07-16 14:06       ` gottlieb
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Heerdegen @ 2013-07-15 22:49 UTC (permalink / raw)
  To: help-gnu-emacs

gottlieb@nyu.edu writes:

> > All relevant hooks I know are empty when declared in the sources.  So if
> > you load your `custom-file' early enough when starting up Emacs (i.e.,
> > before modifying hooks or loading packages), you don't need to worry
> > about your or third party code adding stuff to the hook, that works
> > normally.
>
> Thank you for the response.
> That was exactly my concern.  Namely that I (in this order)
>
> 1.  set a hook via customize
> 2.  upgrade emacs
> 3.  run the new emacs (with my same startup files)
>
> and then some new default would be overridden since my customization
> overwrites the hook instead of adding to it.
>
> Is it guaranteed or suggested that hook are by default empty?

No, it's not a convention AFAICT.  And there are examples in the sources
where this is not the case, although they are a minority.

There are probably also cases where a user indeed wants to replace an
element of a hook variable with another one or "delete" elements, so it
makes some sense that hooks are not always declared empty.

You have to be a bit careful.  There is no absolute guarantee
that your customization will work in future Emacsen.  If you want a more
finegrained control, use Lisp.  But also what you do in Lisp can be
wrong in future Emacsen.

I agree that there is a bit a disparity between the manual
((emacs) Hooks):

|    You can set a hook variable with ‘setq’ like any other Lisp
| variable, but the recommended way to add a function to a hook (either
| normal or abnormal) is to use ‘add-hook’, as shown by the following
| examples.  *Note (elisp)Hooks::, for details.

and how Customize works (setting the hook variable instead of adding).


Regards,

Michael.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: does customizing a hook "add-to" the hook?
  2013-07-15 22:49     ` Michael Heerdegen
@ 2013-07-16 14:06       ` gottlieb
  0 siblings, 0 replies; 6+ messages in thread
From: gottlieb @ 2013-07-16 14:06 UTC (permalink / raw)
  To: help-gnu-emacs

On Mon, Jul 15 2013, Michael Heerdegen wrote:

> gottlieb@nyu.edu writes:
>
>> Is it guaranteed or suggested that hook are by default empty?
>
> No, it's not a convention AFAICT.  And there are examples in the sources
> where this is not the case, although they are a minority.
>
> There are probably also cases where a user indeed wants to replace an
> element of a hook variable with another one or "delete" elements, so it
> makes some sense that hooks are not always declared empty.
>
> You have to be a bit careful.  There is no absolute guarantee
> that your customization will work in future Emacsen.  If you want a more
> finegrained control, use Lisp.  But also what you do in Lisp can be
> wrong in future Emacsen.
>
> I agree that there is a bit a disparity between the manual
> ((emacs) Hooks):
>
> |    You can set a hook variable with ‘setq’ like any other Lisp
> | variable, but the recommended way to add a function to a hook (either
> | normal or abnormal) is to use ‘add-hook’, as shown by the following
> | examples.  *Note (elisp)Hooks::, for details.
>
> and how Customize works (setting the hook variable instead of adding).

Indeed.  That disparity is exactly what triggered my question.
Thank you for clarifying.

allan



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-07-16 14:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-13 21:25 does customizing a hook "add-to" the hook? gottlieb
2013-07-15  0:33 ` Michael Heerdegen
2013-07-15  1:12   ` Michael Heerdegen
2013-07-15 18:50   ` gottlieb
2013-07-15 22:49     ` Michael Heerdegen
2013-07-16 14:06       ` gottlieb

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.