[Top][All Lists]

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

RE: About how misspelled word are displayed

From: Drew Adams
Subject: RE: About how misspelled word are displayed
Date: Fri, 12 May 2017 15:08:44 -0700 (PDT)

> Evaluating (customize-set-variable option value) uses the :set property
> of OPTION, but doesn't check that VALUE has the type specified in the
> (defcustom option ...)  expression.

Correct.  Likewise, `custom-set-variables'.  They assume that
when used non-interactively the new value is of the right type.

This is perhaps a holdover from their Customize pedigree: if
written by Customize, `custom-set-variables' uses a valid type,
and `customize-set-variable' was probably expected to be used
mostly interactively (and interactively it does provide some
type checking).

Please consider filing an enhancement request that would make
them optionally check the type (e.g. by an optional argument):
`M-x report-emacs-bug'.

This needs to be optional not only for backward compatibility
but also because this checking can slow things down considerably,
and it is not needed at all for a `custom-set-variables' set by

While waiting (... ;-)) you can define your own function,
similar to `customize-set-variable' but which does the type
checking.  Here is the type-checking code from `set-variable':

(let ((type  (get variable 'custom-type)))
  (when type    ; Match with custom type.
    (require 'cus-edit)
    (setq type  (widget-convert type))
    (unless (widget-apply type :match value)
      (error "Value `%S' does not match type %S of %S"
             value (car type) variable))))

> On the other hand, evaluating (set-variable option value) does
> this type-checking, but ignores the :set property of OPTION.


See these threads:

Emacs Dev has several times discussed removing `set-variable' altogether.
I'm in favor of keeping it - at least as long as it does things
that `customize-set-variable' does not do.

> So, is there a recommended way of setting an
> option using Emacs Lisp directly (without going through customization
> buffers), which ensures that the :set, :type, :initialize, and other
> specifications of the option are respected?

Not that I know of - not ready-made.  See above.

reply via email to

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