emacs-devel
[Top][All Lists]
Advanced

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

Re: multiple queries to delete excess backup version w/ custom


From: martin rudalics
Subject: Re: multiple queries to delete excess backup version w/ custom
Date: Thu, 10 Jan 2008 10:51:57 +0100
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

> You might want to implement the function that saves as a call to the
> function that merely marks for saving, followed by a call to to
> custom-save-all, rather than duplicate the code.
>
> If you invent a :custom-mark-for-saving, you will no longer need a
> :custom-save method.

I've attached a patch against the trunk to handle the problem along
these lines.  The patch tries to resolve this problem when erasing
customizations as well.  In particular the patch should

- handle saving and erasing customizations _as before_, but

- when saving or erasing more than one setting, save the buffer to your
  customization file _once only_.

To avoid regression, it would be very valuable if a few people confirmed
that the patch gives good results.  Please try it.
*** cus-edit.el.~1.340.~        Sun Jan  6 10:39:00 2008
--- cus-edit.el Thu Jan 10 10:17:42 2008
***************
*** 826,841 ****
  
  (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)
!   (if (custom-command-apply
!        (lambda (child)
!        (when (memq (widget-get child :custom-state)
!                    '(modified set changed rogue))
!          (widget-apply child :custom-save)))
!        "Save all settings in this buffer? " t)
!       (custom-save-all)))
  
  (defun custom-reset (widget &optional event)
    "Select item from reset menu."
--- 826,844 ----
  
  (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)
!   (when (custom-command-apply
!        (lambda (child)
!          (when (memq (widget-get child :custom-state)
!                      '(modified set changed rogue))
!            (widget-apply child :custom-mark-to-save)))
!        "Save all settings in this buffer? " t)
!     ;; Save changes to buffer and redraw.
!     (custom-save-all)
!     (dolist (child custom-options)
!       (widget-apply child :custom-state-set-and-redraw))))
  
  (defun custom-reset (widget &optional event)
    "Select item from reset menu."
***************
*** 865,884 ****
         (widget-apply widget :custom-reset-saved)))
     "Reset all settings (current values and buffer text) to saved values? "))
  
  (defun Custom-reset-standard (&rest ignore)
!   "Erase all customization (either current or saved) for the group members.
  The immediate result is to restore them to their standard values.
  This operation eliminates any saved values for the group members,
  making them as if they had never been customized at all."
    (interactive)
!   (custom-command-apply
!    (lambda (widget)
!      (and (or (null (widget-get widget :custom-standard-value))
!             (widget-apply widget :custom-standard-value))
!         (memq (widget-get widget :custom-state)
!               '(modified set changed saved rogue))
!         (widget-apply widget :custom-reset-standard)))
!    "Erase all customizations for settings in this buffer? " t))
  
  ;;; The Customize Commands
  
--- 868,934 ----
         (widget-apply widget :custom-reset-saved)))
     "Reset all settings (current values and buffer text) to saved values? "))
  
+ ;; The next two variables are bound to '(t) by `Custom-reset-standard'
+ ;; and `custom-group-reset-standard'.  If these variables are nil, both
+ ;; `custom-variable-reset-standard' and `custom-face-reset-standard'
+ ;; save, reset and redraw the handled widget immediately.  Otherwise,
+ ;; they add the widget to the corresponding list and leave it to
+ ;; `custom-reset-standard-save-and-update' to save, reset and redraw it.
+ (defvar custom-reset-standard-variables-list nil)
+ (defvar custom-reset-standard-faces-list nil)
+ 
+ ;; The next function was excerpted from `custom-variable-reset-standard'
+ ;; and `custom-face-reset-standard' and is used to avoid calling
+ ;; `custom-save-all' repeatedly (and thus saving settings to file one by
+ ;; one) when erasing all customizations.
+ (defun custom-reset-standard-save-and-update ()
+   "Save settings and redraw after erasing customizations."
+   (when (or (and custom-reset-standard-variables-list
+                (not (eq custom-reset-standard-variables-list  '(t))))
+           (and custom-reset-standard-faces-list
+                (not (eq custom-reset-standard-faces-list '(t)))))
+     ;; Save settings to file.
+     (custom-save-all)
+     ;; Set state of and redraw variables.
+     (dolist (widget custom-reset-standard-variables-list)
+       (unless (eq widget t)
+       (widget-put widget :custom-state 'unknown)
+       (custom-redraw widget)))
+     ;; Set state of and redraw faces.
+     (dolist (widget custom-reset-standard-faces-list)
+       (unless (eq widget t)
+       (let* ((symbol (widget-value widget))
+              (child (car (widget-get widget :children)))
+              (value (get symbol 'face-defface-spec))
+              (comment-widget (widget-get widget :comment-widget)))
+         (put symbol 'face-comment nil)
+         (widget-value-set child
+                           (custom-pre-filter-face-spec
+                            (list (list t (custom-face-attributes-get
+                                           symbol nil)))))
+         ;; This call manages the comment visibility
+         (widget-value-set comment-widget "")
+         (custom-face-state-set widget)
+         (custom-redraw-magic widget))))))
+ 
  (defun Custom-reset-standard (&rest ignore)
!   "Erase all customizations (either current or saved) in current buffer.
  The immediate result is to restore them to their standard values.
  This operation eliminates any saved values for the group members,
  making them as if they had never been customized at all."
    (interactive)
!   ;; Bind these temporarily.
!   (let ((custom-reset-standard-variables-list '(t))
!       (custom-reset-standard-faces-list '(t)))
!     (custom-command-apply
!      (lambda (widget)
!        (and (or (null (widget-get widget :custom-standard-value))
!               (widget-apply widget :custom-standard-value))
!           (memq (widget-get widget :custom-state)
!                 '(modified set changed saved rogue))
!           (widget-apply widget :custom-mark-to-reset-standard)))
!      "Erase all customizations for settings in this buffer? " t)
!     (custom-reset-standard-save-and-update)))
  
  ;;; The Customize Commands
  
***************
*** 1535,1541 ****
        (widget-insert "Editing a setting changes only the text in this buffer."
                     (if init-file
                         "
! To set apply your changes, use the Save or Set buttons.
  Saving a change normally works by editing your init file."
                       "
  Currently, these settings cannot be saved for future Emacs sessions,
--- 1585,1591 ----
        (widget-insert "Editing a setting changes only the text in this buffer."
                     (if init-file
                         "
! To apply your changes, use the Save or Set buttons.
  Saving a change normally works by editing your init file."
                       "
  Currently, these settings cannot be saved for future Emacs sessions,
***************
*** 2441,2451 ****
    :value-create 'custom-variable-value-create
    :action 'custom-variable-action
    :custom-set 'custom-variable-set
!   :custom-save 'custom-variable-save
    :custom-reset-current 'custom-redraw
    :custom-reset-saved 'custom-variable-reset-saved
    :custom-reset-standard 'custom-variable-reset-standard
!   :custom-standard-value 'custom-variable-standard-value)
  
  (defun custom-variable-type (symbol)
    "Return a widget suitable for editing the value of SYMBOL.
--- 2491,2503 ----
    :value-create 'custom-variable-value-create
    :action 'custom-variable-action
    :custom-set 'custom-variable-set
!   :custom-mark-to-save 'custom-variable-mark-to-save
    :custom-reset-current 'custom-redraw
    :custom-reset-saved 'custom-variable-reset-saved
    :custom-reset-standard 'custom-variable-reset-standard
!   :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard
!   :custom-standard-value 'custom-variable-standard-value
!   :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw)
  
  (defun custom-variable-type (symbol)
    "Return a widget suitable for editing the value of SYMBOL.
***************
*** 2807,2814 ****
      (custom-variable-state-set widget)
      (custom-redraw-magic widget)))
  
! (defun custom-variable-save (widget)
!   "Set and save the value for the variable being edited by WIDGET."
    (let* ((form (widget-get widget :custom-form))
         (state (widget-get widget :custom-state))
         (child (car (widget-get widget :children)))
--- 2859,2866 ----
      (custom-variable-state-set widget)
      (custom-redraw-magic widget)))
  
! (defun custom-variable-mark-to-save (widget)
!   "Set value and mark for saving the variable edited by WIDGET."
    (let* ((form (widget-get widget :custom-form))
         (state (widget-get widget :custom-state))
         (child (car (widget-get widget :children)))
***************
*** 2846,2855 ****
           (put symbol 'variable-comment comment)
           (put symbol 'saved-variable-comment comment)))
      (put symbol 'customized-value nil)
!     (put symbol 'customized-variable-comment nil)
!     (custom-save-all)
!     (custom-variable-state-set widget)
!     (custom-redraw-magic widget)))
  
  (defun custom-variable-reset-saved (widget)
    "Restore the saved value for the variable being edited by WIDGET.
--- 2898,2915 ----
           (put symbol 'variable-comment comment)
           (put symbol 'saved-variable-comment comment)))
      (put symbol 'customized-value nil)
!     (put symbol 'customized-variable-comment nil)))
! 
! (defsubst custom-variable-state-set-and-redraw (widget)
!   "Set state of variable widget WIDGET and redraw with current settings."
!   (custom-variable-state-set widget)
!   (custom-redraw-magic widget))
! 
! (defun custom-variable-save (widget)
!   "Save value of variable edited by widget WIDGET."
!   (custom-variable-mark-to-save widget)
!   (custom-save-all)
!   (custom-variable-state-set-and-redraw widget))
  
  (defun custom-variable-reset-saved (widget)
    "Restore the saved value for the variable being edited by WIDGET.
***************
*** 2875,2886 ****
      ;; This call will possibly make the comment invisible
      (custom-redraw widget)))
  
! (defun custom-variable-reset-standard (widget)
!   "Restore the standard setting for the variable being edited by WIDGET.
! This operation eliminates any saved setting for the variable,
! restoring it to the state of a variable that has never been customized.
! The value that was current before this operation
! becomes the backup value, so you can get it again."
    (let* ((symbol (widget-value widget)))
      (if (get symbol 'standard-value)
        (custom-variable-backup-value widget)
--- 2935,2944 ----
      ;; This call will possibly make the comment invisible
      (custom-redraw widget)))
  
! (defun custom-variable-mark-to-reset-standard (widget)
!   "Mark to restore standard setting for the variable edited by widget WIDGET.
! If `custom-reset-standard-variables-list' is nil, save, reset and
! redraw the widget immediately."
    (let* ((symbol (widget-value widget)))
      (if (get symbol 'standard-value)
        (custom-variable-backup-value widget)
***************
*** 2890,2902 ****
      (put symbol 'customized-variable-comment nil)
      (custom-push-theme 'theme-value symbol 'user 'reset)
      (custom-theme-recalc-variable symbol)
!     (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))
!       (put symbol 'saved-value nil)
!       (put symbol 'saved-variable-comment nil)
!       (custom-save-all))
!     (widget-put widget :custom-state 'unknown)
!     ;; This call will possibly make the comment invisible
!     (custom-redraw widget)))
  
  (defun custom-variable-backup-value (widget)
    "Back up the current value for WIDGET's variable.
--- 2948,2979 ----
      (put symbol 'customized-variable-comment nil)
      (custom-push-theme 'theme-value symbol 'user 'reset)
      (custom-theme-recalc-variable symbol)
!     (if (and custom-reset-standard-variables-list
!            (or (get symbol 'saved-value) (get symbol 
'saved-variable-comment)))
!       (progn
!         (put symbol 'saved-value nil)
!         (put symbol 'saved-variable-comment nil)
!         ;; Append this to `custom-reset-standard-variables-list' to
!         ;; have `custom-reset-standard-save-and-update' save setting
!         ;; to the file, update the widget's state, and redraw it.
!         (setq custom-reset-standard-variables-list
!               (cons widget custom-reset-standard-variables-list)))
!       (when (or (get symbol 'saved-value) (get symbol 
'saved-variable-comment))
!       (put symbol 'saved-value nil)
!       (put symbol 'saved-variable-comment nil)
!       (custom-save-all))
!       (widget-put widget :custom-state 'unknown)
!       ;; This call will possibly make the comment invisible
!       (custom-redraw widget))))
! 
! (defun custom-variable-reset-standard (widget)
!   "Restore standard setting for the variable edited by WIDGET.
! This operation eliminates any saved setting for the variable,
! restoring it to the state of a variable that has never been customized.
! The value that was current before this operation
! becomes the backup value, so you can get it again."
!   (let (custom-reset-standard-variables-list)
!     (custom-variable-mark-to-reset-standard widget)))
  
  (defun custom-variable-backup-value (widget)
    "Back up the current value for WIDGET's variable.
***************
*** 3172,3182 ****
    :custom-category 'face
    :custom-form nil ; defaults to value of `custom-face-default-form'
    :custom-set 'custom-face-set
!   :custom-save 'custom-face-save
    :custom-reset-current 'custom-redraw
    :custom-reset-saved 'custom-face-reset-saved
    :custom-reset-standard 'custom-face-reset-standard
    :custom-standard-value 'custom-face-standard-value
    :custom-menu 'custom-face-menu-create)
  
  (define-widget 'custom-face-all 'editable-list
--- 3249,3261 ----
    :custom-category 'face
    :custom-form nil ; defaults to value of `custom-face-default-form'
    :custom-set 'custom-face-set
!   :custom-mark-to-save 'custom-face-mark-to-save
    :custom-reset-current 'custom-redraw
    :custom-reset-saved 'custom-face-reset-saved
    :custom-reset-standard 'custom-face-reset-standard
+   :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard
    :custom-standard-value 'custom-face-standard-value
+   :custom-state-set-and-redraw 'custom-face-state-set-and-redraw
    :custom-menu 'custom-face-menu-create)
  
  (define-widget 'custom-face-all 'editable-list
***************
*** 3321,3326 ****
--- 3400,3406 ----
           ;; Update buttons.
           (widget-put widget :buttons buttons)
           ;; Insert documentation.
+          (widget-put widget :documentation-indent 3)
           (widget-add-documentation-string-button
            widget :visibility-widget 'custom-visibility)
  
***************
*** 3510,3517 ****
      (custom-face-state-set widget)
      (custom-redraw-magic widget)))
  
! (defun custom-face-save (widget)
!   "Save in `.emacs' the face attributes in WIDGET."
    (let* ((symbol (widget-value widget))
         (child (car (widget-get widget :children)))
         (value (custom-post-filter-face-spec (widget-value child)))
--- 3590,3597 ----
      (custom-face-state-set widget)
      (custom-redraw-magic widget)))
  
! (defun custom-face-mark-to-save (widget)
!   "Mark for saving the face edited by WIDGET."
    (let* ((symbol (widget-value widget))
         (child (car (widget-get widget :children)))
         (value (custom-post-filter-face-spec (widget-value child)))
***************
*** 3532,3541 ****
      (put symbol 'customized-face nil)
      (put symbol 'face-comment comment)
      (put symbol 'customized-face-comment nil)
!     (put symbol 'saved-face-comment comment)
!     (custom-save-all)
!     (custom-face-state-set widget)
!     (custom-redraw-magic widget)))
  
  ;; For backward compatibility.
  (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
--- 3612,3629 ----
      (put symbol 'customized-face nil)
      (put symbol 'face-comment comment)
      (put symbol 'customized-face-comment nil)
!     (put symbol 'saved-face-comment comment)))
! 
! (defsubst custom-face-state-set-and-redraw (widget)
!   "Set state of face widget WIDGET and redraw with current settings."
!   (custom-face-state-set widget)
!   (custom-redraw-magic widget))
! 
! (defun custom-face-save (widget)
!   "Save the face edited by WIDGET."
!   (custom-face-mark-to-save widget)
!   (custom-save-all)
!   (custom-face-state-set-and-redraw widget))
  
  ;; For backward compatibility.
  (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save
***************
*** 3564,3573 ****
  (defun custom-face-standard-value (widget)
    (get (widget-value widget) 'face-defface-spec))
  
! (defun custom-face-reset-standard (widget)
!   "Restore WIDGET to the face's standard attribute values.
! This operation eliminates any saved attributes for the face,
! restoring it to the state of a face that has never been customized."
    (let* ((symbol (widget-value widget))
         (child (car (widget-get widget :children)))
         (value (get symbol 'face-defface-spec))
--- 3652,3661 ----
  (defun custom-face-standard-value (widget)
    (get (widget-value widget) 'face-defface-spec))
  
! (defun custom-face-mark-to-reset-standard (widget)
!   "Restore widget WIDGET to the face's standard attribute values.
! If `custom-reset-standard-faces-list' is nil, save, reset and
! redraw the widget immediately."
    (let* ((symbol (widget-value widget))
         (child (car (widget-get widget :children)))
         (value (get symbol 'face-defface-spec))
***************
*** 3579,3597 ****
      (custom-push-theme 'theme-face symbol 'user 'reset)
      (face-spec-set symbol value t)
      (custom-theme-recalc-face symbol)
!     (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
!       (put symbol 'saved-face nil)
!       (put symbol 'saved-face-comment nil)
!       (custom-save-all))
!     (put symbol 'face-comment nil)
!     (widget-value-set child
!                     (custom-pre-filter-face-spec
!                      (list (list t (custom-face-attributes-get
!                                     symbol nil)))))
!     ;; This call manages the comment visibility
!     (widget-value-set comment-widget "")
!     (custom-face-state-set widget)
!     (custom-redraw-magic widget)))
  
  ;;; The `face' Widget.
  
--- 3667,3703 ----
      (custom-push-theme 'theme-face symbol 'user 'reset)
      (face-spec-set symbol value t)
      (custom-theme-recalc-face symbol)
!     (if (and custom-reset-standard-faces-list
!            (or (get symbol 'saved-face) (get symbol 'saved-face-comment)))
!       ;; Do this later.
!       (progn
!         (put symbol 'saved-face nil)
!         (put symbol 'saved-face-comment nil)
!         ;; Append this to `custom-reset-standard-faces-list' and have
!         ;; `custom-reset-standard-save-and-update' save setting to the
!         ;; file, update the widget's state, and redraw it.
!         (setq custom-reset-standard-faces-list
!               (cons widget custom-reset-standard-faces-list)))
!       (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment))
!       (put symbol 'saved-face nil)
!       (put symbol 'saved-face-comment nil)
!       (custom-save-all))
!       (put symbol 'face-comment nil)
!       (widget-value-set child
!                       (custom-pre-filter-face-spec
!                        (list (list t (custom-face-attributes-get
!                                       symbol nil)))))
!       ;; This call manages the comment visibility
!       (widget-value-set comment-widget "")
!       (custom-face-state-set widget)
!       (custom-redraw-magic widget))))
! 
! (defun custom-face-reset-standard (widget)
!   "Restore WIDGET to the face's standard attribute values.
! This operation eliminates any saved attributes for the face,
! restoring it to the state of a face that has never been customized."
!   (let (custom-reset-standard-faces-list)
!     (custom-face-mark-to-reset-standard widget)))
  
  ;;; The `face' Widget.
  
***************
*** 3736,3745 ****
    :action 'custom-group-action
    :custom-category 'group
    :custom-set 'custom-group-set
!   :custom-save 'custom-group-save
    :custom-reset-current 'custom-group-reset-current
    :custom-reset-saved 'custom-group-reset-saved
    :custom-reset-standard 'custom-group-reset-standard
    :custom-menu 'custom-group-menu-create)
  
  (defun custom-group-sample-face-get (widget)
--- 3842,3853 ----
    :action 'custom-group-action
    :custom-category 'group
    :custom-set 'custom-group-set
!   :custom-mark-to-save 'custom-group-mark-to-save
    :custom-reset-current 'custom-group-reset-current
    :custom-reset-saved 'custom-group-reset-saved
    :custom-reset-standard 'custom-group-reset-standard
+   :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard
+   :custom-state-set-and-redraw 'custom-group-state-set-and-redraw
    :custom-menu 'custom-group-menu-create)
  
  (defun custom-group-sample-face-get (widget)
***************
*** 4034,4044 ****
      (when (eq (widget-get child :custom-state) 'modified)
        (widget-apply child :custom-set))))
  
! (defun custom-group-save (widget)
!   "Save all modified group members."
    (dolist (child (widget-get widget :children))
      (when (memq (widget-get child :custom-state) '(modified set))
!       (widget-apply child :custom-save))))
  
  (defun custom-group-reset-current (widget)
    "Reset all modified group members."
--- 4142,4164 ----
      (when (eq (widget-get child :custom-state) 'modified)
        (widget-apply child :custom-set))))
  
! (defun custom-group-mark-to-save (widget)
!   "Mark all modified group members for saving."
    (dolist (child (widget-get widget :children))
      (when (memq (widget-get child :custom-state) '(modified set))
!       (widget-apply child :custom-mark-to-save))))
! 
! (defsubst custom-group-state-set-and-redraw (widget)
!   "Set state of group widget WIDGET and redraw with current settings."
!   (dolist (child (widget-get widget :children))
!     (when (memq (widget-get child :custom-state) '(modified set))
!       (widget-apply child :custom-state-set-and-redraw))))
! 
! (defun custom-group-save (widget)
!   "Save all modified group members."
!   (custom-group-mark-to-save widget)
!   (custom-save-all)
!   (custom-group-state-set-and-redraw widget))
  
  (defun custom-group-reset-current (widget)
    "Reset all modified group members."
***************
*** 4054,4063 ****
  
  (defun custom-group-reset-standard (widget)
    "Reset all modified, set, or saved group members."
    (dolist (child (widget-get widget :children))
      (when (memq (widget-get child :custom-state)
                '(modified set saved))
!       (widget-apply child :custom-reset-standard))))
  
  (defun custom-group-state-update (widget)
    "Update magic."
--- 4174,4190 ----
  
  (defun custom-group-reset-standard (widget)
    "Reset all modified, set, or saved group members."
+   (let ((custom-reset-standard-variables-list '(t))
+       (custom-reset-standard-faces-list '(t)))
+     (custom-group-mark-to-reset-standard widget)
+     (custom-reset-standard-save-and-update)))
+ 
+ (defun custom-group-mark-to-reset-standard (widget)
+   "Mark to reset all modified, set, or saved group members."
    (dolist (child (widget-get widget :children))
      (when (memq (widget-get child :custom-state)
                '(modified set saved))
!       (widget-apply child :custom-mark-to-reset-standard))))
  
  (defun custom-group-state-update (widget)
    "Update magic."

reply via email to

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