Re: Buffer-local defcustom with :set directive

Steven Allen <[email protected]> Fri, 19 Jun 2026 11:26:23 -0700
Newsgroups gmane.emacs.help
Message-ID <[email protected]>
uzibalqa <[email protected]> writes:

> Have been looking at the some (defcustom code that includes a :set directive
> using (lambda (variable value).
>
> With the :set directive there is always a variable declaration such as:
>
> (set variable value)
> (set-default variable value)
> (custom-set-default variable value)
> (set-default-toplevel-value variable value)
>
> It is evident that the variable must always be set when using the :set
> directive.  But is net a requirement when :set is missing.
>
> I want to have the custom variable to be buffer local.  How would the
> variable setting declaration be?
>
> (defcustom htpl-anzd 'backlight
>   "HTPL overlay face style."
>   :type '(choice
>            (const :tag "Off - No light" off)
>            (const :tag "Normal - LED Box (Hot Magenta)" normal)
>            (const :tag "Backlight - LED Hot Magenta" backlight))
>   :group 'htpl
>   :set (lambda (variable value)
>           (set variable value)
>           (htpl-initialisations)))

You probably want `custom-set-default'. It'll set the variable in
`custom-local-buffer' when that variable is set in the local
customization buffer, and globally when unset.