aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/cus-edit.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/cus-edit.el')
-rw-r--r--lisp/cus-edit.el82
1 files changed, 65 insertions, 17 deletions
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 793b5cccedf..e0a76b21ff8 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -2077,7 +2077,8 @@ and `face'."
2077(defun custom-magic-reset (widget) 2077(defun custom-magic-reset (widget)
2078 "Redraw the :custom-magic property of WIDGET." 2078 "Redraw the :custom-magic property of WIDGET."
2079 (let ((magic (widget-get widget :custom-magic))) 2079 (let ((magic (widget-get widget :custom-magic)))
2080 (widget-value-set magic (widget-value magic)))) 2080 (when magic
2081 (widget-value-set magic (widget-value magic)))))
2081 2082
2082;;; The `custom' Widget. 2083;;; The `custom' Widget.
2083 2084
@@ -2465,8 +2466,9 @@ The following properties have special meanings for this widget:
2465:shown-value, if non-nil, should be a list whose `car' is the 2466:shown-value, if non-nil, should be a list whose `car' is the
2466 variable value to display in place of the current value. 2467 variable value to display in place of the current value.
2467 2468
2468:inhibit-magic, if non-nil, inhibits creating the magic 2469:custom-style describes the widget interface style; nil is the
2469 custom-state widget." 2470 default style, while `simple' means a simpler interface that
2471 inhibits the magic custom-state widget."
2470 :format "%v" 2472 :format "%v"
2471 :help-echo "Set or reset this variable." 2473 :help-echo "Set or reset this variable."
2472 :documentation-property #'custom-variable-documentation 2474 :documentation-property #'custom-variable-documentation
@@ -2552,7 +2554,7 @@ try matching its doc string against `custom-guess-doc-alist'."
2552 :on "Hide" 2554 :on "Hide"
2553 :off-image "right" 2555 :off-image "right"
2554 :off "Show Value" 2556 :off "Show Value"
2555 :action 'custom-toggle-parent 2557 :action 'custom-toggle-hide-variable
2556 nil) 2558 nil)
2557 buttons) 2559 buttons)
2558 (insert " ") 2560 (insert " ")
@@ -2572,7 +2574,7 @@ try matching its doc string against `custom-guess-doc-alist'."
2572 :off "Show" 2574 :off "Show"
2573 :on-image "down" 2575 :on-image "down"
2574 :off-image "right" 2576 :off-image "right"
2575 :action 'custom-toggle-parent 2577 :action 'custom-toggle-hide-variable
2576 t) 2578 t)
2577 buttons) 2579 buttons)
2578 (insert " ") 2580 (insert " ")
@@ -2602,7 +2604,7 @@ try matching its doc string against `custom-guess-doc-alist'."
2602 :off "Show" 2604 :off "Show"
2603 :on-image "down" 2605 :on-image "down"
2604 :off-image "right" 2606 :off-image "right"
2605 :action 'custom-toggle-parent 2607 :action 'custom-toggle-hide-variable
2606 t) 2608 t)
2607 buttons) 2609 buttons)
2608 (insert " ") 2610 (insert " ")
@@ -2631,7 +2633,7 @@ try matching its doc string against `custom-guess-doc-alist'."
2631 (unless (eq (preceding-char) ?\n) 2633 (unless (eq (preceding-char) ?\n)
2632 (widget-insert "\n")) 2634 (widget-insert "\n"))
2633 ;; Create the magic button. 2635 ;; Create the magic button.
2634 (unless (widget-get widget :inhibit-magic) 2636 (unless (eq (widget-get widget :custom-style) 'simple)
2635 (let ((magic (widget-create-child-and-convert 2637 (let ((magic (widget-create-child-and-convert
2636 widget 'custom-magic nil))) 2638 widget 'custom-magic nil)))
2637 (widget-put widget :custom-magic magic) 2639 (widget-put widget :custom-magic magic)
@@ -2667,6 +2669,31 @@ try matching its doc string against `custom-guess-doc-alist'."
2667 (custom-add-parent-links widget)) 2669 (custom-add-parent-links widget))
2668 (custom-add-see-also widget))))) 2670 (custom-add-see-also widget)))))
2669 2671
2672(defun custom-toggle-hide-variable (visibility-widget &rest ignore)
2673 "Toggle the visibility of a `custom-variable' parent widget.
2674By default, this signals an error if the parent has unsaved
2675changes. If the parent has a `simple' :custom-style property,
2676the present value is saved to its :shown-value property instead."
2677 (let ((widget (widget-get visibility-widget :parent)))
2678 (unless (eq (widget-type widget) 'custom-variable)
2679 (error "Invalid widget type"))
2680 (custom-load-widget widget)
2681 (let ((state (widget-get widget :custom-state)))
2682 (if (eq state 'hidden)
2683 (widget-put widget :custom-state 'unknown)
2684 ;; In normal interface, widget can't be hidden if modified.
2685 (when (memq state '(invalid modified set))
2686 (if (eq (widget-get widget :custom-style) 'simple)
2687 (widget-put widget :shown-value
2688 (list (widget-value
2689 (car-safe
2690 (widget-get widget :children)))))
2691 (error "There are unsaved changes")))
2692 (widget-put widget :documentation-shown nil)
2693 (widget-put widget :custom-state 'hidden))
2694 (custom-redraw widget)
2695 (widget-setup))))
2696
2670(defun custom-tag-action (widget &rest args) 2697(defun custom-tag-action (widget &rest args)
2671 "Pass :action to first child of WIDGET's parent." 2698 "Pass :action to first child of WIDGET's parent."
2672 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children)) 2699 (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
@@ -3291,17 +3318,15 @@ The following properties have special meanings for this widget:
3291 Lisp sexp), or `mismatch' (should not happen); if nil, use 3318 Lisp sexp), or `mismatch' (should not happen); if nil, use
3292 the return value of `custom-face-default-form'. 3319 the return value of `custom-face-default-form'.
3293 3320
3294:display-style, if non-nil, describes the style of display to 3321:custom-style describes the widget interface style; nil is the
3295 use. If the value is `concise', a neater interface is shown. 3322 default style, while `simple' means a simpler interface that
3323 inhibits the magic custom-state widget.
3296 3324
3297:sample-indent, if non-nil, is the number of columns to which to 3325:sample-indent, if non-nil, is the number of columns to which to
3298 indent the face sample (an integer). 3326 indent the face sample (an integer).
3299 3327
3300:shown-value, if non-nil, is the face spec to display as the value 3328:shown-value, if non-nil, is the face spec to display as the value
3301 of the widget, instead of the current face spec. 3329 of the widget, instead of the current face spec."
3302
3303:inhibit-magic, if non-nil, inhibits creating the magic
3304 custom-state widget."
3305 :sample-face 'custom-face-tag 3330 :sample-face 'custom-face-tag
3306 :help-echo "Set or reset this face." 3331 :help-echo "Set or reset this face."
3307 :documentation-property #'face-doc-string 3332 :documentation-property #'face-doc-string
@@ -3395,6 +3420,29 @@ WIDGET should be a `custom-face' widget."
3395 (setq spec `((t ,(face-attr-construct face (selected-frame)))))) 3420 (setq spec `((t ,(face-attr-construct face (selected-frame))))))
3396 (custom-pre-filter-face-spec spec))) 3421 (custom-pre-filter-face-spec spec)))
3397 3422
3423(defun custom-toggle-hide-face (visibility-widget &rest ignore)
3424 "Toggle the visibility of a `custom-face' parent widget.
3425By default, this signals an error if the parent has unsaved
3426changes. If the parent has a `simple' :custom-style property,
3427the present value is saved to its :shown-value property instead."
3428 (let ((widget (widget-get visibility-widget :parent)))
3429 (unless (eq (widget-type widget) 'custom-face)
3430 (error "Invalid widget type"))
3431 (custom-load-widget widget)
3432 (let ((state (widget-get widget :custom-state)))
3433 (if (eq state 'hidden)
3434 (widget-put widget :custom-state 'unknown)
3435 ;; In normal interface, widget can't be hidden if modified.
3436 (when (memq state '(invalid modified set))
3437 (if (eq (widget-get widget :custom-style) 'simple)
3438 (widget-put widget :shown-value
3439 (custom-face-widget-to-spec widget))
3440 (error "There are unsaved changes")))
3441 (widget-put widget :documentation-shown nil)
3442 (widget-put widget :custom-state 'hidden))
3443 (custom-redraw widget)
3444 (widget-setup))))
3445
3398(defun custom-face-value-create (widget) 3446(defun custom-face-value-create (widget)
3399 "Create a list of the display specifications for WIDGET." 3447 "Create a list of the display specifications for WIDGET."
3400 (let* ((buttons (widget-get widget :buttons)) 3448 (let* ((buttons (widget-get widget :buttons))
@@ -3402,7 +3450,7 @@ WIDGET should be a `custom-face' widget."
3402 (tag (or (widget-get widget :tag) 3450 (tag (or (widget-get widget :tag)
3403 (prin1-to-string symbol))) 3451 (prin1-to-string symbol)))
3404 (hiddenp (eq (widget-get widget :custom-state) 'hidden)) 3452 (hiddenp (eq (widget-get widget :custom-state) 'hidden))
3405 (style (widget-get widget :display-style)) 3453 (style (widget-get widget :custom-style))
3406 children) 3454 children)
3407 3455
3408 (if (eq custom-buffer-style 'tree) 3456 (if (eq custom-buffer-style 'tree)
@@ -3425,7 +3473,7 @@ WIDGET should be a `custom-face' widget."
3425 :help-echo "Hide or show this face." 3473 :help-echo "Hide or show this face."
3426 :on "Hide" :off "Show" 3474 :on "Hide" :off "Show"
3427 :on-image "down" :off-image "right" 3475 :on-image "down" :off-image "right"
3428 :action 'custom-toggle-parent 3476 :action 'custom-toggle-hide-face
3429 (not hiddenp)) 3477 (not hiddenp))
3430 buttons) 3478 buttons)
3431 ;; Face name (tag). 3479 ;; Face name (tag).
@@ -3452,7 +3500,7 @@ WIDGET should be a `custom-face' widget."
3452 (insert "\n") 3500 (insert "\n")
3453 3501
3454 ;; Magic. 3502 ;; Magic.
3455 (unless (widget-get widget :inhibit-magic) 3503 (unless (eq (widget-get widget :custom-style) 'simple)
3456 (let ((magic (widget-create-child-and-convert 3504 (let ((magic (widget-create-child-and-convert
3457 widget 'custom-magic nil))) 3505 widget 'custom-magic nil)))
3458 (widget-put widget :custom-magic magic) 3506 (widget-put widget :custom-magic magic)
@@ -3462,7 +3510,7 @@ WIDGET should be a `custom-face' widget."
3462 (widget-put widget :buttons buttons) 3510 (widget-put widget :buttons buttons)
3463 3511
3464 ;; Insert documentation. 3512 ;; Insert documentation.
3465 (unless (and hiddenp (eq style 'concise)) 3513 (unless (and hiddenp (eq style 'simple))
3466 (widget-put widget :documentation-indent 3) 3514 (widget-put widget :documentation-indent 3)
3467 (widget-add-documentation-string-button 3515 (widget-add-documentation-string-button
3468 widget :visibility-widget 'custom-visibility) 3516 widget :visibility-widget 'custom-visibility)