diff options
| author | Richard M. Stallman | 2002-09-16 15:20:20 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2002-09-16 15:20:20 +0000 |
| commit | bde4f35405acfa091950acb5e9207f68b1486b31 (patch) | |
| tree | b1eebbe54bdbf4d58d5ec58473a13b0f30cfc4a5 | |
| parent | 8f50b630a14e8ab15aa4e65d5c61b32e958a3607 (diff) | |
| download | emacs-bde4f35405acfa091950acb5e9207f68b1486b31.tar.gz emacs-bde4f35405acfa091950acb5e9207f68b1486b31.zip | |
(custom-variable-backup-value): New function.
(custom-variable-reset-backup): New function.
(custom-variable-menu): Add item for custom-variable-reset-backup.
(custom-variable-set, custom-variable-reset-saved)
(custom-variable-reset-standard): Call custom-variable-backup-value.
| -rw-r--r-- | lisp/cus-edit.el | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 9c8e6ce740b..99152e85dbf 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el | |||
| @@ -2303,6 +2303,9 @@ Otherwise, look up symbol in `custom-guess-type-alist'." | |||
| 2303 | (and (get (widget-value widget) 'standard-value) | 2303 | (and (get (widget-value widget) 'standard-value) |
| 2304 | (memq (widget-get widget :custom-state) | 2304 | (memq (widget-get widget :custom-state) |
| 2305 | '(modified set changed saved rogue))))) | 2305 | '(modified set changed saved rogue))))) |
| 2306 | ("Use Backup Value" custom-variable-reset-backup | ||
| 2307 | (lambda (widget) | ||
| 2308 | (get (widget-value widget) 'backup-value))) | ||
| 2306 | ("---" ignore ignore) | 2309 | ("---" ignore ignore) |
| 2307 | ("Add Comment" custom-comment-show custom-comment-invisible-p) | 2310 | ("Add Comment" custom-comment-show custom-comment-invisible-p) |
| 2308 | ("---" ignore ignore) | 2311 | ("---" ignore ignore) |
| @@ -2369,6 +2372,7 @@ Optional EVENT is the location for the menu." | |||
| 2369 | (setq comment nil) | 2372 | (setq comment nil) |
| 2370 | ;; Make the comment invisible by hand if it's empty | 2373 | ;; Make the comment invisible by hand if it's empty |
| 2371 | (custom-comment-hide comment-widget)) | 2374 | (custom-comment-hide comment-widget)) |
| 2375 | (custom-variable-backup-value widget) | ||
| 2372 | (funcall set symbol (eval (setq val (widget-value child)))) | 2376 | (funcall set symbol (eval (setq val (widget-value child)))) |
| 2373 | (put symbol 'customized-value (list val)) | 2377 | (put symbol 'customized-value (list val)) |
| 2374 | (put symbol 'variable-comment comment) | 2378 | (put symbol 'variable-comment comment) |
| @@ -2378,6 +2382,7 @@ Optional EVENT is the location for the menu." | |||
| 2378 | (setq comment nil) | 2382 | (setq comment nil) |
| 2379 | ;; Make the comment invisible by hand if it's empty | 2383 | ;; Make the comment invisible by hand if it's empty |
| 2380 | (custom-comment-hide comment-widget)) | 2384 | (custom-comment-hide comment-widget)) |
| 2385 | (custom-variable-backup-value widget) | ||
| 2381 | (funcall set symbol (setq val (widget-value child))) | 2386 | (funcall set symbol (setq val (widget-value child))) |
| 2382 | (put symbol 'customized-value (list (custom-quote val))) | 2387 | (put symbol 'customized-value (list (custom-quote val))) |
| 2383 | (put symbol 'variable-comment comment) | 2388 | (put symbol 'variable-comment comment) |
| @@ -2426,13 +2431,16 @@ Optional EVENT is the location for the menu." | |||
| 2426 | (custom-redraw-magic widget))) | 2431 | (custom-redraw-magic widget))) |
| 2427 | 2432 | ||
| 2428 | (defun custom-variable-reset-saved (widget) | 2433 | (defun custom-variable-reset-saved (widget) |
| 2429 | "Restore the saved value for the variable being edited by WIDGET." | 2434 | "Restore the saved value for the variable being edited by WIDGET. |
| 2435 | The value that was current before this operation | ||
| 2436 | becomes the backup value, so you can get it again." | ||
| 2430 | (let* ((symbol (widget-value widget)) | 2437 | (let* ((symbol (widget-value widget)) |
| 2431 | (set (or (get symbol 'custom-set) 'set-default)) | 2438 | (set (or (get symbol 'custom-set) 'set-default)) |
| 2432 | (value (get symbol 'saved-value)) | 2439 | (value (get symbol 'saved-value)) |
| 2433 | (comment (get symbol 'saved-variable-comment))) | 2440 | (comment (get symbol 'saved-variable-comment))) |
| 2434 | (cond ((or value comment) | 2441 | (cond ((or value comment) |
| 2435 | (put symbol 'variable-comment comment) | 2442 | (put symbol 'variable-comment comment) |
| 2443 | (custom-variable-backup-value widget) | ||
| 2436 | (condition-case nil | 2444 | (condition-case nil |
| 2437 | (funcall set symbol (eval (car value))) | 2445 | (funcall set symbol (eval (car value))) |
| 2438 | (error nil))) | 2446 | (error nil))) |
| @@ -2447,11 +2455,15 @@ Optional EVENT is the location for the menu." | |||
| 2447 | (defun custom-variable-reset-standard (widget) | 2455 | (defun custom-variable-reset-standard (widget) |
| 2448 | "Restore the standard setting for the variable being edited by WIDGET. | 2456 | "Restore the standard setting for the variable being edited by WIDGET. |
| 2449 | This operation eliminates any saved setting for the variable, | 2457 | This operation eliminates any saved setting for the variable, |
| 2450 | restoring it to the state of a variable that has never been customized." | 2458 | restoring it to the state of a variable that has never been customized. |
| 2459 | The value that was current before this operation | ||
| 2460 | becomes the backup value, so you can get it again." | ||
| 2451 | (let* ((symbol (widget-value widget)) | 2461 | (let* ((symbol (widget-value widget)) |
| 2452 | (set (or (get symbol 'custom-set) 'set-default))) | 2462 | (set (or (get symbol 'custom-set) 'set-default))) |
| 2453 | (if (get symbol 'standard-value) | 2463 | (if (get symbol 'standard-value) |
| 2454 | (funcall set symbol (eval (car (get symbol 'standard-value)))) | 2464 | (progn |
| 2465 | (custom-variable-backup-value widget) | ||
| 2466 | (funcall set symbol (eval (car (get symbol 'standard-value))))) | ||
| 2455 | (error "No standard setting known for %S" symbol)) | 2467 | (error "No standard setting known for %S" symbol)) |
| 2456 | (put symbol 'variable-comment nil) | 2468 | (put symbol 'variable-comment nil) |
| 2457 | (put symbol 'customized-value nil) | 2469 | (put symbol 'customized-value nil) |
| @@ -2464,6 +2476,42 @@ restoring it to the state of a variable that has never been customized." | |||
| 2464 | ;; This call will possibly make the comment invisible | 2476 | ;; This call will possibly make the comment invisible |
| 2465 | (custom-redraw widget))) | 2477 | (custom-redraw widget))) |
| 2466 | 2478 | ||
| 2479 | (defun custom-variable-backup-value (widget) | ||
| 2480 | "Back up the current value for WIDGET's variable. | ||
| 2481 | The backup value is kept in the car of the `backup-value' property." | ||
| 2482 | (let* ((symbol (widget-value widget)) | ||
| 2483 | (get (or (get symbol 'custom-get) 'default-value)) | ||
| 2484 | (type (custom-variable-type symbol)) | ||
| 2485 | (conv (widget-convert type)) | ||
| 2486 | (value (if (default-boundp symbol) | ||
| 2487 | (funcall get symbol) | ||
| 2488 | (widget-get conv :value)))) | ||
| 2489 | (put symbol 'backup-value (list value)))) | ||
| 2490 | |||
| 2491 | (defun custom-variable-reset-backup (widget) | ||
| 2492 | "Restore the backup value for the variable being edited by WIDGET. | ||
| 2493 | The value that was current before this operation | ||
| 2494 | becomes the backup value, so you can use this operation repeatedly | ||
| 2495 | to switch between two values." | ||
| 2496 | (let* ((symbol (widget-value widget)) | ||
| 2497 | (set (or (get symbol 'custom-set) 'set-default)) | ||
| 2498 | (value (get symbol 'backup-value)) | ||
| 2499 | (comment-widget (widget-get widget :comment-widget)) | ||
| 2500 | (comment (widget-value comment-widget))) | ||
| 2501 | (if value | ||
| 2502 | (progn | ||
| 2503 | (custom-variable-backup-value widget) | ||
| 2504 | (condition-case nil | ||
| 2505 | (funcall set symbol (car value)) | ||
| 2506 | (error nil))) | ||
| 2507 | (error "No backup value for %s" symbol)) | ||
| 2508 | (put symbol 'customized-value (list (car value))) | ||
| 2509 | (put symbol 'variable-comment comment) | ||
| 2510 | (put symbol 'customized-variable-comment comment) | ||
| 2511 | (custom-variable-state-set widget) | ||
| 2512 | ;; This call will possibly make the comment invisible | ||
| 2513 | (custom-redraw widget))) | ||
| 2514 | |||
| 2467 | ;;; The `custom-face-edit' Widget. | 2515 | ;;; The `custom-face-edit' Widget. |
| 2468 | 2516 | ||
| 2469 | (define-widget 'custom-face-edit 'checklist | 2517 | (define-widget 'custom-face-edit 'checklist |