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

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

bug#62106: 29.0.60; Emacs 29 changing user option values (?)


From: Drew Adams
Subject: bug#62106: 29.0.60; Emacs 29 changing user option values (?)
Date: Sat, 11 Mar 2023 17:09:42 +0000

> > Dunno what the intention was - could we use `setopt' here?
> 
> `setopt' does not really help. Using `customize-save-variable' instead
> of `customize-set-variable' does the trick.
> 
> Pushed to the emacs-29 branch, closing the bug. Pls reply if it doesn't
> work as expected.

Thanks for working on this.  Without studying this at all, I'm guessing that 
`customize-save-variable' is the wrong thing to do.  Doesn't that mean that 
you're not only changing a user-option value, but you're also doing so 
permanently (persistently)?  If so, isn't that even _worse_?

Wouldn't this be better - pseudo-saving, i.e., making Customize treat a changed 
option as if it were unchanged, _without_ saving it?

(put SYMBOL 'saved-value
            (list (custom-quote (default-value SYMBOL)))))
_________

FWIW, I define these functions (commands), based on that.

;; Use this one anywhere.
;;
(defun customize-consider-all-vars-unchanged ()
  "Consider all customizable variables as saved, without saving them."
  (interactive)
  (when (interactive-p) (message "Please wait..."))
  (mapatoms
   (lambda (symbol)
     (when (and (or (custom-variable-p symbol)
                    (user-variable-p symbol))
                (default-boundp symbol) ; Value neither saved nor standard.
                (not (member (list (custom-quote (default-value symbol)))
                             (list (get symbol 'saved-value)
                                   (get symbol 'standard-value)))))
       ;; Pretend the current value has been saved.
       (put symbol 'saved-value (list (custom-quote (default-value symbol)))))
     (put symbol 'customized-value nil)
     (when (get symbol 'customized-variable-comment)
       (put symbol 'saved-variable-comment
                   (get symbol 'customized-variable-comment)))
     (put symbol 'customized-variable-comment nil)))
  (message "All variables are now considered unchanged (\"saved\"),\
 but they were not saved."))

________________

;; Use this in the Customize UI.
;;
(defun Custom-consider-unchanged (&rest _IGNORED)
  "Consider all preferences here as being unchanged now.
This does not save the current values; it just considers them to be
unchanged values.  If no further changes are made to any of these
preferences, then after doing this, `customize-customize' will not
display any of these preferences, since they were considered
unchanged."
  (interactive)
  (if (not (y-or-n-p "All of these values will be considered \
unchanged now, without being saved.  Continue? "))
      (message nil)
    (message "Please wait...")
    (let ((children  custom-options))
      (dolist (child  children)
        (let ((symbol  (widget-get-tag-or-value child)))
          (cond ((custom-facep symbol)
                 (custom-consider-face-unchanged child))
                ((custom-variable-p symbol)
                 (custom-consider-variable-unchanged child))))))
    (message "Current values here are now considered unchanged.\
  They were not saved.")))

;; Inspired from `custom-variable-save'.
;; Due to a `cus-edit.el' bug (hidden widgets are not saved), we need to 
temporarily
;; show hidden widgets.
;;
;; Should we (put symbol 'saved-value...) only if not
;; (eq (widget-get widget :custom-state) 'standard), as in `custom-face-save'?
;;
(defun custom-consider-variable-unchanged (widget)
  "Consider this variable as being unchanged now.
This does not save the current value; it just considers the value to
be unchanged.  If no further changes are made to this variable, then
after doing this, `customize-customize' will not display this
variable, since it was considered unchanged."
  (message "Please wait...")
  (let ((form      (widget-get widget :custom-form))
        (hidden-p  (eq (widget-get widget :custom-state) 'hidden)))
    (when hidden-p                      ; Show it.
      (widget-put widget :custom-state 'unknown)
      (custom-redraw widget)
      (setq form  (widget-get widget :custom-form)))
    (let ((child   (car (widget-get widget :children)))
          (symbol  (widget-value widget)))
      (cond ((memq form '(lisp mismatch))
             (put symbol 'saved-value (list (widget-value child))))
            (t (put symbol 'saved-value
                           (list (custom-quote (widget-value child))))))
      (put symbol 'customized-value nil)
      (put symbol 'customized-variable-comment nil))
    (widget-put widget :custom-state 'saved)
    (when hidden-p                      ; Hide it again.
      (widget-put widget :documentation-shown nil)
      (widget-put widget :custom-state 'hidden)
      (custom-redraw widget)))
  (custom-redraw-magic widget)
  (message "Current variable value is now considered unchanged.\
  It was not saved."))
_______

https://www.emacswiki.org/emacs/download/cus-edit%2b.el





reply via email to

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