comparison lisp/cus-edit.el @ 28130:e419308bcc0c

Doc fixes. (customize-set-variable, customize-save-variable): Rename args for doc. (custom-variable-tag-face, custom-face-tag-face) (custom-group-tag-face-1, custom-group-tag-face): Modify from style which user identify as hyperlink. (hook): Don't add undefined functions to the hook. (debug-ignored-errors): Transfer message from bindings.el.
author Dave Love <fx@gnu.org>
date Sun, 12 Mar 2000 18:50:49 +0000
parents 807fc106b24c
children b243caac6505
comparison
equal deleted inserted replaced
28129:25e19c5c91f8 28130:e419308bcc0c
1 ;;; cus-edit.el --- Tools for customizating Emacs and Lisp packages. 1 ;;; cus-edit.el --- Tools for customizing Emacs and Lisp packages.
2 ;; 2 ;;
3 ;; Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc. 3 ;; Copyright (C) 1996, 1997, 1999, 2000 Free Software Foundation, Inc.
4 ;; 4 ;;
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Keywords: help, faces 6 ;; Keywords: help, faces
7 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ (probably obsolete)
8 7
9 ;; This file is part of GNU Emacs. 8 ;; This file is part of GNU Emacs.
10 9
11 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by 11 ;; it under the terms of the GNU General Public License as published by
356 ;;; Utilities. 355 ;;; Utilities.
357 356
358 (defun custom-quote (sexp) 357 (defun custom-quote (sexp)
359 "Quote SEXP iff it is not self quoting." 358 "Quote SEXP iff it is not self quoting."
360 (if (or (memq sexp '(t nil)) 359 (if (or (memq sexp '(t nil))
361 (and (symbolp sexp) 360 (keywordp sexp)
362 (eq (aref (symbol-name sexp) 0) ?:))
363 (and (listp sexp) 361 (and (listp sexp)
364 (memq (car sexp) '(lambda))) 362 (memq (car sexp) '(lambda)))
365 (stringp sexp) 363 (stringp sexp)
366 (numberp sexp) 364 (numberp sexp)
367 (vectorp sexp) 365 (vectorp sexp)
424 (nreverse result))) 422 (nreverse result)))
425 423
426 ;;; Unlispify. 424 ;;; Unlispify.
427 425
428 (defvar custom-prefix-list nil 426 (defvar custom-prefix-list nil
429 "List of prefixes that should be ignored by `custom-unlispify'") 427 "List of prefixes that should be ignored by `custom-unlispify'.")
430 428
431 (defcustom custom-unlispify-menu-entries t 429 (defcustom custom-unlispify-menu-entries t
432 "Display menu entries as words instead of symbols if non nil." 430 "Display menu entries as words instead of symbols if non nil."
433 :group 'custom-menu 431 :group 'custom-menu
434 :type 'boolean) 432 :type 'boolean)
437 "Non-nil means remove group prefixes from option names in buffer." 435 "Non-nil means remove group prefixes from option names in buffer."
438 :group 'custom-menu 436 :group 'custom-menu
439 :type 'boolean) 437 :type 'boolean)
440 438
441 (defun custom-unlispify-menu-entry (symbol &optional no-suffix) 439 (defun custom-unlispify-menu-entry (symbol &optional no-suffix)
442 "Convert symbol into a menu entry." 440 "Convert SYMBOL into a menu entry."
443 (cond ((not custom-unlispify-menu-entries) 441 (cond ((not custom-unlispify-menu-entries)
444 (symbol-name symbol)) 442 (symbol-name symbol))
445 ((get symbol 'custom-tag) 443 ((get symbol 'custom-tag)
446 (if no-suffix 444 (if no-suffix
447 (get symbol 'custom-tag) 445 (get symbol 'custom-tag)
477 "Display tag names as words instead of symbols if non nil." 475 "Display tag names as words instead of symbols if non nil."
478 :group 'custom-buffer 476 :group 'custom-buffer
479 :type 'boolean) 477 :type 'boolean)
480 478
481 (defun custom-unlispify-tag-name (symbol) 479 (defun custom-unlispify-tag-name (symbol)
482 "Convert symbol into a menu entry." 480 "Convert SYMBOL into a menu entry."
483 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names)) 481 (let ((custom-unlispify-menu-entries custom-unlispify-tag-names))
484 (custom-unlispify-menu-entry symbol t))) 482 (custom-unlispify-menu-entry symbol t)))
485 483
486 (defun custom-prefix-add (symbol prefixes) 484 (defun custom-prefix-add (symbol prefixes)
487 ;; Addd SYMBOL to list of ignored PREFIXES. 485 "Add SYMBOL to list of ignored PREFIXES."
488 (cons (or (get symbol 'custom-prefix) 486 (cons (or (get symbol 'custom-prefix)
489 (concat (symbol-name symbol) "-")) 487 (concat (symbol-name symbol) "-"))
490 prefixes)) 488 prefixes))
491 489
492 ;;; Guess. 490 ;;; Guess.
658 '(("Current" . Custom-reset-current) 656 '(("Current" . Custom-reset-current)
659 ("Saved" . Custom-reset-saved) 657 ("Saved" . Custom-reset-saved)
660 ("Erase Customization (use standard settings)" . Custom-reset-standard)) 658 ("Erase Customization (use standard settings)" . Custom-reset-standard))
661 "Alist of actions for the `Reset' button. 659 "Alist of actions for the `Reset' button.
662 The key is a string containing the name of the action, the value is a 660 The key is a string containing the name of the action, the value is a
663 lisp function taking the widget as an element which will be called 661 Lisp function taking the widget as an element which will be called
664 when the action is chosen.") 662 when the action is chosen.")
665 663
666 (defun custom-reset (event) 664 (defun custom-reset (event)
667 "Select item from reset menu." 665 "Select item from reset menu."
668 (let* ((completion-ignore-case t) 666 (let* ((completion-ignore-case t)
771 (put var 'variable-comment nil)) 769 (put var 'variable-comment nil))
772 (comment 770 (comment
773 (put var 'variable-comment comment)))) 771 (put var 'variable-comment comment))))
774 772
775 ;;;###autoload 773 ;;;###autoload
776 (defun customize-set-variable (var val &optional comment) 774 (defun customize-set-variable (variable value &optional comment)
777 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object. 775 "Set the default for VARIABLE to VALUE. VALUE is a Lisp object.
778 776
779 If VARIABLE has a `custom-set' property, that is used for setting 777 If VARIABLE has a `custom-set' property, that is used for setting
780 VARIABLE, otherwise `set-default' is used. 778 VARIABLE, otherwise `set-default' is used.
781 779
790 788
791 If given a prefix (or a COMMENT argument), also prompt for a comment." 789 If given a prefix (or a COMMENT argument), also prompt for a comment."
792 (interactive (custom-prompt-variable "Set variable: " 790 (interactive (custom-prompt-variable "Set variable: "
793 "Set customized value for %s to: " 791 "Set customized value for %s to: "
794 current-prefix-arg)) 792 current-prefix-arg))
795 (funcall (or (get var 'custom-set) 'set-default) var val) 793 (funcall (or (get variable 'custom-set) 'set-default) variable value)
796 (put var 'customized-value (list (custom-quote val))) 794 (put variable 'customized-value (list (custom-quote value)))
797 (cond ((string= comment "") 795 (cond ((string= comment "")
798 (put var 'variable-comment nil) 796 (put variable 'variable-comment nil)
799 (put var 'customized-variable-comment nil)) 797 (put variable 'customized-variable-comment nil))
800 (comment 798 (comment
801 (put var 'variable-comment comment) 799 (put variable 'variable-comment comment)
802 (put var 'customized-variable-comment comment)))) 800 (put variable 'customized-variable-comment comment))))
803 801
804 ;;;###autoload 802 ;;;###autoload
805 (defun customize-save-variable (var val &optional comment) 803 (defun customize-save-variable (var value &optional comment)
806 "Set the default for VARIABLE to VALUE, and save it for future sessions. 804 "Set the default for VARIABLE to VALUE, and save it for future sessions.
807 If VARIABLE has a `custom-set' property, that is used for setting 805 If VARIABLE has a `custom-set' property, that is used for setting
808 VARIABLE, otherwise `set-default' is used. 806 VARIABLE, otherwise `set-default' is used.
809 807
810 The `customized-value' property of the VARIABLE will be set to a list 808 The `customized-value' property of the VARIABLE will be set to a list
818 816
819 If given a prefix (or a COMMENT argument), also prompt for a comment." 817 If given a prefix (or a COMMENT argument), also prompt for a comment."
820 (interactive (custom-prompt-variable "Set and ave variable: " 818 (interactive (custom-prompt-variable "Set and ave variable: "
821 "Set and save value for %s as: " 819 "Set and save value for %s as: "
822 current-prefix-arg)) 820 current-prefix-arg))
823 (funcall (or (get var 'custom-set) 'set-default) var val) 821 (funcall (or (get var 'custom-set) 'set-default) var value)
824 (put var 'saved-value (list (custom-quote val))) 822 (put var 'saved-value (list (custom-quote value)))
825 (cond ((string= comment "") 823 (cond ((string= comment "")
826 (put var 'variable-comment nil) 824 (put var 'variable-comment nil)
827 (put var 'saved-variable-comment nil)) 825 (put var 'saved-variable-comment nil))
828 (comment 826 (comment
829 (put var 'variable-comment comment) 827 (put var 'variable-comment comment)
1040 (format "*Customize Face: %s*" 1038 (format "*Customize Face: %s*"
1041 (custom-unlispify-tag-name symbol))))) 1039 (custom-unlispify-tag-name symbol)))))
1042 1040
1043 ;;;###autoload 1041 ;;;###autoload
1044 (defun customize-face-other-window (&optional symbol) 1042 (defun customize-face-other-window (&optional symbol)
1045 "Show customization buffer for FACE in other window." 1043 "Show customization buffer for face SYMBOL in other window."
1046 (interactive (list (completing-read "Customize face: " 1044 (interactive (list (completing-read "Customize face: "
1047 obarray 'custom-facep t))) 1045 obarray 'custom-facep t)))
1048 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol)))) 1046 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol))))
1049 () 1047 ()
1050 (if (stringp symbol) 1048 (if (stringp symbol)
1607 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent) 1605 (not (eq (widget-get (widget-get (widget-get widget :parent) :parent)
1608 :custom-state) 1606 :custom-state)
1609 'hidden))) 1607 'hidden)))
1610 1608
1611 (defun custom-magic-value-create (widget) 1609 (defun custom-magic-value-create (widget)
1612 ;; Create compact status report for WIDGET. 1610 "Create compact status report for WIDGET."
1613 (let* ((parent (widget-get widget :parent)) 1611 (let* ((parent (widget-get widget :parent))
1614 (state (widget-get parent :custom-state)) 1612 (state (widget-get parent :custom-state))
1615 (hidden (eq state 'hidden)) 1613 (hidden (eq state 'hidden))
1616 (entry (assq state custom-magic-alist)) 1614 (entry (assq state custom-magic-alist))
1617 (magic (nth 1 entry)) 1615 (magic (nth 1 entry))
1733 :value-get 'widget-value-value-get 1731 :value-get 'widget-value-value-get
1734 :validate 'widget-children-validate 1732 :validate 'widget-children-validate
1735 :match (lambda (widget value) (symbolp value))) 1733 :match (lambda (widget value) (symbolp value)))
1736 1734
1737 (defun custom-convert-widget (widget) 1735 (defun custom-convert-widget (widget)
1738 ;; Initialize :value and :tag from :args in WIDGET. 1736 "Initialize :value and :tag from :args in WIDGET."
1739 (let ((args (widget-get widget :args))) 1737 (let ((args (widget-get widget :args)))
1740 (when args 1738 (when args
1741 (widget-put widget :value (widget-apply widget 1739 (widget-put widget :value (widget-apply widget
1742 :value-to-internal (car args))) 1740 :value-to-internal (car args)))
1743 (widget-put widget :tag (custom-unlispify-tag-name (car args))) 1741 (widget-put widget :tag (custom-unlispify-tag-name (car args)))
1983 (and (equal "" val) 1981 (and (equal "" val)
1984 (not (widget-get widget :comment-shown))))) 1982 (not (widget-get widget :comment-shown)))))
1985 1983
1986 ;;; The `custom-variable' Widget. 1984 ;;; The `custom-variable' Widget.
1987 1985
1988 (defface custom-variable-tag-face '((((class color) 1986 ;; When this was underlined blue, users confused it with a
1987 ;; Mosaic-style hyperlink...
1988 (defface custom-variable-tag-face `((((class color)
1989 (background dark)) 1989 (background dark))
1990 (:foreground "light blue" :underline t)) 1990 (:foreground "light blue"
1991 :bold t
1992 :family "helv"
1993 :height ,(floor (face-attribute
1994 'default :height) 0.9)))
1991 (((class color) 1995 (((class color)
1992 (background light)) 1996 (background light))
1993 (:foreground "blue" :underline t)) 1997 (:foreground "blue" :family "helv"
1994 (t (:underline t))) 1998 :bold t
1999 :height ,(floor (face-attribute
2000 'default :height) 0.9)))
2001 (t (:bold t)))
1995 "Face used for unpushable variable tags." 2002 "Face used for unpushable variable tags."
1996 :group 'custom-faces) 2003 :group 'custom-faces)
1997 2004
1998 (defface custom-variable-button-face '((t (:underline t :bold t))) 2005 (defface custom-variable-button-face '((t (:underline t :bold t)))
1999 "Face used for pushable variable tags." 2006 "Face used for pushable variable tags."
2300 (widget-put widget :custom-state 'unknown) 2307 (widget-put widget :custom-state 'unknown)
2301 (widget-put widget :custom-form 'edit) 2308 (widget-put widget :custom-form 'edit)
2302 (custom-redraw widget)) 2309 (custom-redraw widget))
2303 2310
2304 (defun custom-variable-edit-lisp (widget) 2311 (defun custom-variable-edit-lisp (widget)
2305 "Edit the lisp representation of the value of WIDGET." 2312 "Edit the Lisp representation of the value of WIDGET."
2306 (widget-put widget :custom-state 'unknown) 2313 (widget-put widget :custom-state 'unknown)
2307 (widget-put widget :custom-form 'lisp) 2314 (widget-put widget :custom-form 'lisp)
2308 (custom-redraw widget)) 2315 (custom-redraw widget))
2309 2316
2310 (defun custom-variable-set (widget) 2317 (defun custom-variable-set (widget)
2511 Match frames with dark backgrounds.") 2518 Match frames with dark backgrounds.")
2512 dark))))))) 2519 dark)))))))
2513 2520
2514 ;;; The `custom-face' Widget. 2521 ;;; The `custom-face' Widget.
2515 2522
2516 (defface custom-face-tag-face '((t (:underline t))) 2523 (defface custom-face-tag-face `((t (:bold t :family "helv"
2524 :height ,(floor (face-attribute
2525 'default :height) 0.9))))
2517 "Face used for face tags." 2526 "Face used for face tags."
2518 :group 'custom-faces) 2527 :group 'custom-faces)
2519 2528
2520 (defcustom custom-face-default-form 'selected 2529 (defcustom custom-face-default-form 'selected
2521 "Default form of displaying face definition." 2530 "Default form of displaying face definition."
2720 (widget-put widget :custom-state 'unknown) 2729 (widget-put widget :custom-state 'unknown)
2721 (widget-put widget :custom-form 'all) 2730 (widget-put widget :custom-form 'all)
2722 (custom-redraw widget)) 2731 (custom-redraw widget))
2723 2732
2724 (defun custom-face-edit-lisp (widget) 2733 (defun custom-face-edit-lisp (widget)
2725 "Edit the lisp representation of the value of WIDGET." 2734 "Edit the Lisp representation of the value of WIDGET."
2726 (widget-put widget :custom-state 'unknown) 2735 (widget-put widget :custom-state 'unknown)
2727 (widget-put widget :custom-form 'lisp) 2736 (widget-put widget :custom-form 'lisp)
2728 (custom-redraw widget)) 2737 (custom-redraw widget))
2729 2738
2730 (defun custom-face-state-set (widget) 2739 (defun custom-face-state-set (widget)
2872 :validate 'widget-children-validate 2881 :validate 'widget-children-validate
2873 :action 'widget-face-action 2882 :action 'widget-face-action
2874 :match '(lambda (widget value) (symbolp value))) 2883 :match '(lambda (widget value) (symbolp value)))
2875 2884
2876 (defun widget-face-value-create (widget) 2885 (defun widget-face-value-create (widget)
2877 ;; Create a `custom-face' child. 2886 "Create a `custom-face' child."
2878 (let* ((symbol (widget-value widget)) 2887 (let* ((symbol (widget-value widget))
2879 (custom-buffer-style 'face) 2888 (custom-buffer-style 'face)
2880 (child (widget-create-child-and-convert 2889 (child (widget-create-child-and-convert
2881 widget 'custom-face 2890 widget 'custom-face
2882 :custom-level nil 2891 :custom-level nil
2884 (custom-magic-reset child) 2893 (custom-magic-reset child)
2885 (setq custom-options (cons child custom-options)) 2894 (setq custom-options (cons child custom-options))
2886 (widget-put widget :children (list child)))) 2895 (widget-put widget :children (list child))))
2887 2896
2888 (defun widget-face-value-delete (widget) 2897 (defun widget-face-value-delete (widget)
2889 ;; Remove the child from the options. 2898 "Remove the child from the options."
2890 (let ((child (car (widget-get widget :children)))) 2899 (let ((child (car (widget-get widget :children))))
2891 (setq custom-options (delq child custom-options)) 2900 (setq custom-options (delq child custom-options))
2892 (widget-children-value-delete widget))) 2901 (widget-children-value-delete widget)))
2893 2902
2894 (defvar face-history nil 2903 (defvar face-history nil
2916 (list value) 2925 (list value)
2917 value)) 2926 value))
2918 :match (lambda (widget value) 2927 :match (lambda (widget value)
2919 (or (symbolp value) 2928 (or (symbolp value)
2920 (widget-group-match widget value))) 2929 (widget-group-match widget value)))
2930 ;; Avoid adding undefined functions to the hook, especially for
2931 ;; things like `find-file-hook' or even more basic ones, to avoid
2932 ;; chaos.
2933 :set (lambda (symbol value)
2934 (mapc (lambda (elt)
2935 (if (fboundp elt)
2936 (add-hook symbol elt)))
2937 value))
2921 :convert-widget 'custom-hook-convert-widget 2938 :convert-widget 'custom-hook-convert-widget
2922 :tag "Hook") 2939 :tag "Hook")
2923 2940
2924 (defun custom-hook-convert-widget (widget) 2941 (defun custom-hook-convert-widget (widget)
2925 ;; Handle `:options'. 2942 ;; Handle `:options'.
2957 and so forth. The remaining group tags are shown with 2974 and so forth. The remaining group tags are shown with
2958 `custom-group-tag-face'." 2975 `custom-group-tag-face'."
2959 :type '(repeat face) 2976 :type '(repeat face)
2960 :group 'custom-faces) 2977 :group 'custom-faces)
2961 2978
2962 (defface custom-group-tag-face-1 '((((class color) 2979 (defface custom-group-tag-face-1 `((((class color)
2963 (background dark)) 2980 (background dark))
2964 (:foreground "pink" :underline t)) 2981 (:foreground "pink" :family "helv"
2982 :height ,(floor (face-attribute
2983 'default :height) 0.9)
2984 :bold t))
2965 (((class color) 2985 (((class color)
2966 (background light)) 2986 (background light))
2967 (:foreground "red" :underline t)) 2987 (:foreground "red" :bold t
2968 (t (:underline t))) 2988 :height ,(floor (face-attribute
2989 'default :height) 0.9)))
2990 (t (:bold t)))
2969 "Face used for group tags.") 2991 "Face used for group tags.")
2970 2992
2971 (defface custom-group-tag-face '((((class color) 2993 (defface custom-group-tag-face `((((class color)
2972 (background dark)) 2994 (background dark))
2973 (:foreground "light blue" :underline t)) 2995 (:foreground "light blue" :bold t
2996 :height ,(floor (face-attribute
2997 'default :height) 0.9)))
2974 (((class color) 2998 (((class color)
2975 (background light)) 2999 (background light))
2976 (:foreground "blue" :underline t)) 3000 (:foreground "blue" :bold t
2977 (t (:underline t))) 3001 :height ,(floor (face-attribute
3002 'default :height) 0.9)))
3003 (t (:bold t)))
2978 "Face used for low level group tags." 3004 "Face used for low level group tags."
2979 :group 'custom-faces) 3005 :group 'custom-faces)
2980 3006
2981 (define-widget 'custom-group 'custom 3007 (define-widget 'custom-group 'custom
2982 "Customize group." 3008 "Customize group."
3739 (set (make-local-variable 'widget-link-suffix) "")) 3765 (set (make-local-variable 'widget-link-suffix) ""))
3740 (make-local-hook 'widget-edit-functions) 3766 (make-local-hook 'widget-edit-functions)
3741 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t) 3767 (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)
3742 (run-hooks 'custom-mode-hook)) 3768 (run-hooks 'custom-mode-hook))
3743 3769
3770 (add-to-list
3771 'debug-ignored-errors
3772 "^No user options have changed defaults in recent Emacs versions$")
3773
3744 ;;; The End. 3774 ;;; The End.
3745 3775
3746 (provide 'cus-edit) 3776 (provide 'cus-edit)
3747 3777
3748 ;;; cus-edit.el ends here 3778 ;;; cus-edit.el ends here