Subject: bug#35689: Customizable char-fold

From: [email-masked]
Date: Thu, 16 May 2019 10:47:47 -0400

Juri Linkov <[email-masked]> writes:

>> We don't gave defcustoms inside eval-and/when-compile anywhere else.
>> Do we really need this?  For starters, it would defeat cus-dep.el, I think.
>
> Indeed, better to try and simplify this.  The goal is to pre-compile
> the default char-table because its calculation is compute-intensive,
> and to recalculate a new value of char-table only in case
> when customized values differ from the default values.
>
> I can't find a standard way of doing this.  So instead of using eval-and-compile
> I'll try to recalculate the value explicitly when variables are customized:
>
>   (when (or (get 'char-fold-include-base  'customized-value)
>             (get 'char-fold-include-alist 'customized-value)
>             (get 'char-fold-exclude-alist 'customized-value))
>     (setq char-fold-table (char-fold-make-table)))

Instead of looking at symbol property values, which can make for a
confusing time when setting variables outside of customize, I think it
would be nicer to do something like this:

    (eval-and-compile (defconst char-fold--include-base-default ...))

    (defcustom char-fold-include-base char-fold--include-base-default
      :initialize #'custom-initialize-changed
      :set (lambda (sym val)
             (set-default sym val)
             ;; FIXME: Maybe delay this until after-init-time,
             ;; to avoid redundant calls to char-fold-make-table.
             (setq char-fold-table (char-fold-make-table)))
      ...)

    (eval-and-compile
      (defun char-fold-make-table ()
         ...
         (or (bound-and-true-p 'char-fold-include-base)
             char-fold--include-base-default)
         ...))