Subject: bug#46355: 27.1; custom.el `widget-apply: Symbol’s function definition is void: nil'

From: Mauro Aranda <[email-masked]>
Date: Sun, 07 Feb 2021 09:03:33 -0300

zdm <[email-masked]> writes:

> On Emacs 27.1 using the ‘Apply and Save’ button in a ‘M-x
> customize-face’ (or ‘M-x
> customize-apropos-faces’) buffer with more than one face to customize
> causes an error
> complaining of:
>
> | widget-apply: Symbol’s function definition is void: nil
>
> Step 1:
> | M-x customize-apropos-faces RET vc RET
> Step 2:
> | Press the ‘Apply and Save’ button and ‘yes’ to the dialog box
>
> The error will occur in the echo area.

Thanks for the bug report.  This sounds like Bug#40853.  I can reproduce
this in Emacs 27.1, but not in the development branch, which has this
fix:

commit 5c39f6f1165a33f5714eedd3a413f786dffbb5a2
Author: Mauro Aranda <[email-masked]>
Date:   Fri Aug 14 16:40:40 2020 +0200

    Make sure we only act on edited widgets in Custom-save
    
    * lisp/cus-edit.el (Custom-save): Only act on edited widgets in the
    buffer.  If we attempt to redraw all widgets, we confuse
    custom-variable-modified-p, or we end up drawing State buttons for
    all options, including the hidden ones (bug#42801).

Would it be possible to you to build Emacs from the master branch and
try to see if you can reproduce it?

Alternatively, maybe you can try to redefine Custom-save as below in a
session, and see if the bug is still reproducible.  You should evaluate
the following after Step 1, and before Step 2.

(defun Custom-save (&rest _ignore)
  "Set all edited settings, then save all settings that have been set.
If a setting was edited and set before, this saves it.  If a
setting was merely edited before, this sets it then saves it."
  (interactive)
  (let (edited-widgets)
    (when (custom-command-apply
	   (lambda (child)
	     (when (memq (widget-get child :custom-state)
		         '(modified set changed rogue))
               (push child edited-widgets)
	       (widget-apply child :custom-mark-to-save)))
	   "Save all settings in this buffer? " t)
      ;; Save changes to buffer.
      (custom-save-all)
      ;; Redraw and recalculate the state when necessary.
      (dolist (widget edited-widgets)
        (widget-apply widget :custom-state-set-and-redraw)))))

That is how the function looks after the fix for Bug#40853 and
Bug#42801.