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

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

bug#27348: 24.5; [PATCH] let defvars benefit from defcustom keywords and


From: Drew Adams
Subject: bug#27348: 24.5; [PATCH] let defvars benefit from defcustom keywords and persistence
Date: Mon, 12 Jun 2017 14:34:35 -0700 (PDT)

This is an enhancement request, with a patch.

  [NOTE: I suggested this enhancement to emacs-devel in 2009.  There was
   exactly one reply, with only this text: "YAGNI".
   http://lists.gnu.org/archive/html/emacs-devel/2009-10/msg00668.html
   http://lists.gnu.org/archive/html/emacs-devel/2015-10/msg01481.html]

The ability to type-check, provide :set and :initialize trigger
functions, automatically :require libraries, add links to doc, associate
with one or more :groups, etc. - these are useful things to be able to
do with at least some defvars, not just with defcustoms.  Similarly, the
ability to persist non-option variables in a user's custom file can be
useful.

In sum, this enhancement makes it possible to uncouple interactive
customization from the other features that `custom.el' offers, in
particular, type-checking and persistence, and to provide the latter for
non-option variables.

Patch description:

1. New `defcustom' keyword `:not-custom-var'.  If non-nil, the variable
   does not satisfy `custom-variable-p'.  This means that users cannot
   customize it interactively, and it is not available for other
   interactive use (completion, `set-variable', inclusion in
   `apropos-user-option' output, etc.).

   Anyone and any code can still use `custom*' and other functions that
   do not check `custom-variable-p', to treat such a variable as a
   defcustom.  Similarly, users can still use `M-:', `C-x C-e' etc. to
   customize it.  See also #5, below.

2. New `defcustom' keyword `:not-custom-var'.  It causes property
   `not-custom-var' to be put on the variable symbol.  This property is
   what governs the behavior of `custom-variable-p'.

3. New macro `defvarc'.  It just invokes `defcustom', passing non-nil
   `:not-custom-var'.  The idea is to have a macro with a name similar
   to `defvar'.  Using it can make the non-customizable nature more
   apparent than using `defcustom' with explicit `:not-custom-var'.

   [Another possibility would be to directly modify `defvar', so that it
   optionally accepts `defcustom' keywords etc., but maybe that would
   not be acceptable immediately.  (For one thing, the cases of no
   initial value and no doc, `(defvar foo)' and `(defvar foo 4)', would
   still need to be supported.)]

4. `custom-variable-p' respects not only whether the variable has a
   non-nil `not-custom-var' property but also whether (new) global
   variable `custom-vars-all-customizable' is non-nil.  If either is
   true then the variable is not customizable (the predicate returns
   nil).

5. New macro `with-user-vars'.  It temporarily allows a set of variables
   to be customizable.  It takes as its first argument either a list of
   variables or the symbol `all', meaning all variables.  For `all', it
   just binds `custom-vars-all-customizable' to `t'.  For a list of
   variables, it sets property `not-custom-var' to `t' for each one.
   (The original property values are restored when done.)

I'm open as to how such a feature gets implemented.  That includes names
of things (`defvarc', for example) and whether or not to include this or
that part.  And I'm open to changes to the particular code in the patch.
There might be better ways to realize such a feature - what I came up
with is a pretty simple, naive approach.

FWIW: I haven't understood why apparently no one else has thought this
kind of thing could improve Emacs.  I've long thought that the power of
defcustom keywords and persistence should be freed from their coupling
with interactive customizing.  That combination is great, of course, but
it should not be obligatory - I see no reason why a non-user variable
should not take advantage of defcustom features.


In GNU Emacs 24.5.1 (i686-pc-mingw32)
 of 2015-04-11 on LEG570
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=/c/usr --host=i686-pc-mingw32'

Attachment: custom-2017-06-12.patch
Description: Binary data


reply via email to

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