all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Clarification on hooks and custom-set-variables
@ 2015-08-05  7:17 Tassilo Horn
  2015-08-07 15:11 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Tassilo Horn @ 2015-08-05  7:17 UTC (permalink / raw)
  To: emacs-devel

Hi all,

this is related to AUCTeX bug#21188.  The problem is this: A user who
uses AUCTeX from ELPA customized `LaTeX-mode-hook' so that

  (custom-set-variables
   '(LaTeX-mode-hook '(flyspell-mode LaTeX-math-mode turn-on-reftex)))

is in his ~/.emacs.  I can reproduce the problem with this being the
only contents of ~/.emacs.

Now when he starts emacs, the value of `LaTeX-mode-hook' will be
'(LaTeX-preview-setup).  Huh, where are the configs gone?

AUCTeX uses `LaTeX-mode-hook' internally, too.  auctex-autoloads.el adds
the preview setup function

  (add-hook 'LaTeX-mode-hook #'LaTeX-preview-setup)

which in turn does

  (remove-hook 'LaTeX-mode-hook #'LaTeX-preview-setup)
  (add-hook 'LaTeX-mode-hook #'preview-mode-setup)

But `add-hook' / `remove-hook' should be harmless, and there's no place
where `LaTeX-mode-hook' would be set.

If we add a t NOW flag to the customization, it works.  After startup,
`LaTeX-mode-hook' is the customized value plus `LaTeX-preview-setup'.

The `custom-set-variables' docs don't tell me when customizations are
applied when NOW is omitted or nil.  I guess, it'll be done just when
the corresponding defcustom form is evaluated, right?

So a shot in the blue would be:

  1. Emacs starts and stores the customization value for later
     application since `LaTeX-mode-hook' isn't defined yet.
  2. `package-initialize' runs which loads auctex-autoloads.el which
     adds `LaTeX-preview-setup' to `LaTeX-mode-hook'.
  3. Eventually, latex.el gets loaded and evals the (defcustom
     LaTeX-mode-hook nil) form.  Now customization should kick in but
     maybe it skips applying the customized value because the current
     value '(LaTeX-preview-setup) differs from the default value?

Does that make sense?  Or why does the customized value get lost?  And
most importantly, how to I fix that?

Bye,
Tassilo



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

* Re: Clarification on hooks and custom-set-variables
  2015-08-05  7:17 Clarification on hooks and custom-set-variables Tassilo Horn
@ 2015-08-07 15:11 ` Stefan Monnier
  2015-08-07 15:40   ` Tassilo Horn
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2015-08-07 15:11 UTC (permalink / raw)
  To: emacs-devel

>   (custom-set-variables
>    '(LaTeX-mode-hook '(flyspell-mode LaTeX-math-mode turn-on-reftex)))
[...]
> Now when he starts emacs, the value of `LaTeX-mode-hook' will be
> '(LaTeX-preview-setup).  Huh, where are the configs gone?

Not applied (yet).  What happens after he opens a LaTeX file?

> AUCTeX uses `LaTeX-mode-hook' internally, too.  auctex-autoloads.el adds
> the preview setup function
>   (add-hook 'LaTeX-mode-hook #'LaTeX-preview-setup)

FWIW, this probably made sense back when latex-preview was a separate
package, but now you're better off calling LaTeX-preview-setup
unconditionally from AUCTeX's latex-mode.

> The `custom-set-variables' docs don't tell me when customizations are
> applied when NOW is omitted or nil.  I guess, it'll be done just when
> the corresponding defcustom form is evaluated, right?

Sound be, yes.

> Does that make sense?  Or why does the customized value get lost?  And
> most importantly, how to I fix that?

Custom just sucks at handling vars which are both set via Custom and set
by random Elisp code.  E.g. depending on the circumstances, you could
end up with only (flyspell-mode LaTeX-math-mode turn-on-reftex) in the
hook, i.e. without LaTeX-preview-setup.

The best fixes I can think of:
- don't make it a defcustom.
- split it into a defcustom (only set by the user) and a defvar (only
  set by Elisp code).


        Stefan



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

* Re: Clarification on hooks and custom-set-variables
  2015-08-07 15:11 ` Stefan Monnier
@ 2015-08-07 15:40   ` Tassilo Horn
  0 siblings, 0 replies; 3+ messages in thread
From: Tassilo Horn @ 2015-08-07 15:40 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> Now when he starts emacs, the value of `LaTeX-mode-hook' will be
>> '(LaTeX-preview-setup).  Huh, where are the configs gone?
>
> Not applied (yet).  What happens after he opens a LaTeX file?

Then it contains just `preview-mode-setup'.  That's because
`LaTeX-preview-setup' replaces itself with that.  In any case, the user
configs won't be applied.

>> AUCTeX uses `LaTeX-mode-hook' internally, too.  auctex-autoloads.el adds
>> the preview setup function
>>   (add-hook 'LaTeX-mode-hook #'LaTeX-preview-setup)
>
> FWIW, this probably made sense back when latex-preview was a separate
> package, but now you're better off calling LaTeX-preview-setup
> unconditionally from AUCTeX's latex-mode.

Indeed.

>> The `custom-set-variables' docs don't tell me when customizations are
>> applied when NOW is omitted or nil.  I guess, it'll be done just when
>> the corresponding defcustom form is evaluated, right?
>
> Sound be, yes.
>
>> Does that make sense?  Or why does the customized value get lost?
>> And most importantly, how to I fix that?
>
> Custom just sucks at handling vars which are both set via Custom and
> set by random Elisp code.  E.g. depending on the circumstances, you
> could end up with only (flyspell-mode LaTeX-math-mode turn-on-reftex)
> in the hook, i.e. without LaTeX-preview-setup.
>
> The best fixes I can think of:
> - don't make it a defcustom.

Probably that ship has sailed since it has been a defcustom for ages.

> - split it into a defcustom (only set by the user) and a defvar (only
>   set by Elisp code).

Well, in this concrete case I just go with calling `LaTeX-preview-setup'
unconditionally.

Bye,
Tassilo



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

end of thread, other threads:[~2015-08-07 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-05  7:17 Clarification on hooks and custom-set-variables Tassilo Horn
2015-08-07 15:11 ` Stefan Monnier
2015-08-07 15:40   ` Tassilo Horn

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.