aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Bader2001-10-05 13:03:57 +0000
committerMiles Bader2001-10-05 13:03:57 +0000
commit3ea051cb610eb5b2187600ad6a795ac8138697cb (patch)
treeeaa268f59f70951ae6eaab48024b17617917b0a7
parentace64e0a1fd12d40ab1f47b2f18c7cd0524e3d8b (diff)
downloademacs-3ea051cb610eb5b2187600ad6a795ac8138697cb.tar.gz
emacs-3ea051cb610eb5b2187600ad6a795ac8138697cb.zip
(custom-face-edit-convert-widget)
(custom-face-edit-deactivate, custom-face-edit-activate) (custom-face-edit-delete, custom-face-edit-attribute-tag): New functions. (custom-face-edit): Specify a custom :convert-widget. (custom-pre-filter-face-spec, custom-post-filter-face-spec): Don't pass in default filters that map between `nil' and `off' and `unspecified' and `nil'.
-rw-r--r--lisp/cus-edit.el83
1 files changed, 70 insertions, 13 deletions
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 36edc4ea217..06135b190c0 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -2451,6 +2451,7 @@ restoring it to the state of a variable that has never been customized."
2451 :tag "Attributes" 2451 :tag "Attributes"
2452 :extra-offset 12 2452 :extra-offset 12
2453 :button-args '(:help-echo "Control whether this attribute has any effect.") 2453 :button-args '(:help-echo "Control whether this attribute has any effect.")
2454 :convert-widget 'custom-face-edit-convert-widget
2454 :args (mapcar (lambda (att) 2455 :args (mapcar (lambda (att)
2455 (list 'group 2456 (list 'group
2456 :inline t 2457 :inline t
@@ -2459,6 +2460,72 @@ restoring it to the state of a variable that has never been customized."
2459 (nth 1 att))) 2460 (nth 1 att)))
2460 custom-face-attributes)) 2461 custom-face-attributes))
2461 2462
2463(defun custom-face-edit-convert-widget (widget)
2464 "Convert :args as widget types in WIDGET."
2465 (widget-put
2466 widget
2467 :args (mapcar (lambda (arg)
2468 (widget-convert arg
2469 :deactivate 'custom-face-edit-deactivate
2470 :activate 'custom-face-edit-activate
2471 :delete 'custom-face-edit-delete))
2472 (widget-get widget :args)))
2473 widget)
2474
2475(defun custom-face-edit-deactivate (widget)
2476 "Make face widget WIDGET inactive for user modifications."
2477 (unless (widget-get widget :inactive)
2478 (let ((tag (custom-face-edit-attribute-tag widget))
2479 (from (copy-marker (widget-get widget :from)))
2480 (to (widget-get widget :to))
2481 (value (widget-value widget))
2482 (inhibit-read-only t)
2483 (inhibit-modification-hooks t))
2484 (save-excursion
2485 (goto-char from)
2486 (widget-default-delete widget)
2487 (insert tag ": *\n")
2488 (widget-put widget :inactive
2489 (cons value (cons from (- (point) from))))))))
2490
2491(defun custom-face-edit-activate (widget)
2492 "Make face widget WIDGET inactive for user modifications."
2493 (let ((inactive (widget-get widget :inactive))
2494 (inhibit-read-only t)
2495 (inhibit-modification-hooks t))
2496 (when (consp inactive)
2497 (save-excursion
2498 (goto-char (car (cdr inactive)))
2499 (delete-region (point) (+ (point) (cdr (cdr inactive))))
2500 (widget-put widget :inactive nil)
2501 (widget-apply widget :create)
2502 (widget-value-set widget (car inactive))
2503 (widget-setup)))))
2504
2505(defun custom-face-edit-delete (widget)
2506 "Remove widget from the buffer."
2507 (let ((inactive (widget-get widget :inactive))
2508 (inhibit-read-only t)
2509 (inhibit-modification-hooks t))
2510 (if (not inactive)
2511 ;; Widget is alive, we don't have to do anything special
2512 (widget-default-delete widget)
2513 ;; WIDGET is already deleted because we did so to inactivate it;
2514 ;; now just get rid of the label we put in its place.
2515 (delete-region (car (cdr inactive))
2516 (+ (car (cdr inactive)) (cdr (cdr inactive))))
2517 (widget-put widget :inactive nil))))
2518
2519
2520(defun custom-face-edit-attribute-tag (widget)
2521 "Returns the first :tag property in WIDGET or one of its children."
2522 (let ((tag (widget-get widget :tag)))
2523 (or (and (not (equal tag "")) tag)
2524 (let ((children (widget-get widget :children)))
2525 (while (and (null tag) children)
2526 (setq tag (custom-face-edit-attribute-tag (pop children))))
2527 tag))))
2528
2462;;; The `custom-display' Widget. 2529;;; The `custom-display' Widget.
2463 2530
2464(define-widget 'custom-display 'menu-choice 2531(define-widget 'custom-display 'menu-choice
@@ -2593,7 +2660,7 @@ Match frames with dark backgrounds.")
2593(defconst custom-face-selected (widget-convert 'custom-face-selected) 2660(defconst custom-face-selected (widget-convert 'custom-face-selected)
2594 "Converted version of the `custom-face-selected' widget.") 2661 "Converted version of the `custom-face-selected' widget.")
2595 2662
2596(defun custom-filter-face-spec (spec filter-index default-filter) 2663(defun custom-filter-face-spec (spec filter-index &optional default-filter)
2597 "Return a canonicalized version of SPEC using. 2664 "Return a canonicalized version of SPEC using.
2598FILTER-INDEX is the index in the entry for each attribute in 2665FILTER-INDEX is the index in the entry for each attribute in
2599`custom-face-attributes' at which the appropriate filter function can be 2666`custom-face-attributes' at which the appropriate filter function can be
@@ -2628,21 +2695,11 @@ don't specify one."
2628(defun custom-pre-filter-face-spec (spec) 2695(defun custom-pre-filter-face-spec (spec)
2629 "Return SPEC changed as necessary for editing by the face customization widget. 2696 "Return SPEC changed as necessary for editing by the face customization widget.
2630SPEC must be a full face spec." 2697SPEC must be a full face spec."
2631 (custom-filter-face-spec 2698 (custom-filter-face-spec spec 2))
2632 spec 2
2633 (lambda (value)
2634 (cond ((eq value 'unspecified) nil)
2635 ((eq value nil) 'off)
2636 (t value)))))
2637 2699
2638(defun custom-post-filter-face-spec (spec) 2700(defun custom-post-filter-face-spec (spec)
2639 "Return the customized SPEC in a form suitable for setting the face." 2701 "Return the customized SPEC in a form suitable for setting the face."
2640 (custom-filter-face-spec 2702 (custom-filter-face-spec spec 3))
2641 spec 3
2642 (lambda (value)
2643 (cond ((eq value nil) 'unspecified)
2644 ((eq value 'off) nil)
2645 (t value)))))
2646 2703
2647(defun custom-face-value-create (widget) 2704(defun custom-face-value-create (widget)
2648 "Create a list of the display specifications for WIDGET." 2705 "Create a list of the display specifications for WIDGET."