(defun custom-magic-reset (widget)
"Redraw the :custom-magic property of WIDGET."
(let ((magic (widget-get widget :custom-magic)))
- (widget-value-set magic (widget-value magic))))
+ (when magic
+ (widget-value-set magic (widget-value magic)))))
;;; The `custom' Widget.
:shown-value, if non-nil, should be a list whose `car' is the
variable value to display in place of the current value.
-:inhibit-magic, if non-nil, inhibits creating the magic
- custom-state widget."
+:custom-style describes the widget interface style; nil is the
+ default style, while `simple' means a simpler interface that
+ inhibits the magic custom-state widget."
:format "%v"
:help-echo "Set or reset this variable."
:documentation-property #'custom-variable-documentation
:on "Hide"
:off-image "right"
:off "Show Value"
- :action 'custom-toggle-parent
+ :action 'custom-toggle-hide-variable
nil)
buttons)
(insert " ")
:off "Show"
:on-image "down"
:off-image "right"
- :action 'custom-toggle-parent
+ :action 'custom-toggle-hide-variable
t)
buttons)
(insert " ")
:off "Show"
:on-image "down"
:off-image "right"
- :action 'custom-toggle-parent
+ :action 'custom-toggle-hide-variable
t)
buttons)
(insert " ")
(unless (eq (preceding-char) ?\n)
(widget-insert "\n"))
;; Create the magic button.
- (unless (widget-get widget :inhibit-magic)
+ (unless (eq (widget-get widget :custom-style) 'simple)
(let ((magic (widget-create-child-and-convert
widget 'custom-magic nil)))
(widget-put widget :custom-magic magic)
(custom-add-parent-links widget))
(custom-add-see-also widget)))))
+(defun custom-toggle-hide-variable (visibility-widget &rest ignore)
+ "Toggle the visibility of a `custom-variable' parent widget.
+By default, this signals an error if the parent has unsaved
+changes. If the parent has a `simple' :custom-style property,
+the present value is saved to its :shown-value property instead."
+ (let ((widget (widget-get visibility-widget :parent)))
+ (unless (eq (widget-type widget) 'custom-variable)
+ (error "Invalid widget type"))
+ (custom-load-widget widget)
+ (let ((state (widget-get widget :custom-state)))
+ (if (eq state 'hidden)
+ (widget-put widget :custom-state 'unknown)
+ ;; In normal interface, widget can't be hidden if modified.
+ (when (memq state '(invalid modified set))
+ (if (eq (widget-get widget :custom-style) 'simple)
+ (widget-put widget :shown-value
+ (list (widget-value
+ (car-safe
+ (widget-get widget :children)))))
+ (error "There are unsaved changes")))
+ (widget-put widget :documentation-shown nil)
+ (widget-put widget :custom-state 'hidden))
+ (custom-redraw widget)
+ (widget-setup))))
+
(defun custom-tag-action (widget &rest args)
"Pass :action to first child of WIDGET's parent."
(apply 'widget-apply (car (widget-get (widget-get widget :parent) :children))
Lisp sexp), or `mismatch' (should not happen); if nil, use
the return value of `custom-face-default-form'.
-:display-style, if non-nil, describes the style of display to
- use. If the value is `concise', a neater interface is shown.
+:custom-style describes the widget interface style; nil is the
+ default style, while `simple' means a simpler interface that
+ inhibits the magic custom-state widget.
:sample-indent, if non-nil, is the number of columns to which to
indent the face sample (an integer).
:shown-value, if non-nil, is the face spec to display as the value
- of the widget, instead of the current face spec.
-
-:inhibit-magic, if non-nil, inhibits creating the magic
- custom-state widget."
+ of the widget, instead of the current face spec."
:sample-face 'custom-face-tag
:help-echo "Set or reset this face."
:documentation-property #'face-doc-string
(setq spec `((t ,(face-attr-construct face (selected-frame))))))
(custom-pre-filter-face-spec spec)))
+(defun custom-toggle-hide-face (visibility-widget &rest ignore)
+ "Toggle the visibility of a `custom-face' parent widget.
+By default, this signals an error if the parent has unsaved
+changes. If the parent has a `simple' :custom-style property,
+the present value is saved to its :shown-value property instead."
+ (let ((widget (widget-get visibility-widget :parent)))
+ (unless (eq (widget-type widget) 'custom-face)
+ (error "Invalid widget type"))
+ (custom-load-widget widget)
+ (let ((state (widget-get widget :custom-state)))
+ (if (eq state 'hidden)
+ (widget-put widget :custom-state 'unknown)
+ ;; In normal interface, widget can't be hidden if modified.
+ (when (memq state '(invalid modified set))
+ (if (eq (widget-get widget :custom-style) 'simple)
+ (widget-put widget :shown-value
+ (custom-face-widget-to-spec widget))
+ (error "There are unsaved changes")))
+ (widget-put widget :documentation-shown nil)
+ (widget-put widget :custom-state 'hidden))
+ (custom-redraw widget)
+ (widget-setup))))
+
(defun custom-face-value-create (widget)
"Create a list of the display specifications for WIDGET."
(let* ((buttons (widget-get widget :buttons))
(tag (or (widget-get widget :tag)
(prin1-to-string symbol)))
(hiddenp (eq (widget-get widget :custom-state) 'hidden))
- (style (widget-get widget :display-style))
+ (style (widget-get widget :custom-style))
children)
(if (eq custom-buffer-style 'tree)
:help-echo "Hide or show this face."
:on "Hide" :off "Show"
:on-image "down" :off-image "right"
- :action 'custom-toggle-parent
+ :action 'custom-toggle-hide-face
(not hiddenp))
buttons)
;; Face name (tag).
(insert "\n")
;; Magic.
- (unless (widget-get widget :inhibit-magic)
+ (unless (eq (widget-get widget :custom-style) 'simple)
(let ((magic (widget-create-child-and-convert
widget 'custom-magic nil)))
(widget-put widget :custom-magic magic)
(widget-put widget :buttons buttons)
;; Insert documentation.
- (unless (and hiddenp (eq style 'concise))
+ (unless (and hiddenp (eq style 'simple))
(widget-put widget :documentation-indent 3)
(widget-add-documentation-string-button
widget :visibility-widget 'custom-visibility)