annotate lisp/custom/custom.el @ 116:9f59509498e1 r20-1b10

Import from CVS: tag r20-1b10
author cvs
date Mon, 13 Aug 2007 09:23:06 +0200
parents 8619ce7e4c50
children 7d55a9ba150c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1 ;;; custom.el -- Tools for declaring and initializing options.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6 ;; Keywords: help, faces
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
7 ;; Version: 1.68
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
9
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
10 ;;; Commentary:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
11 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
12 ;; If you want to use this code, please visit the URL above.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
13 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
14 ;; This file only contain the code needed to declare and initialize
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
15 ;; user options. The code to customize options is autoloaded from
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
16 ;; `cus-edit.el'.
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
17
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
18 ;; The code implementing face declarations is in `cus-face.el'
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
19
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
20 ;;; Code:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
21
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
22 (require 'widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
23
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
24 (define-widget-keywords :prefix :tag :load :link :options :type :group)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
25
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
26 ;; These autoloads should be deleted when the file is added to Emacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
27
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
28 (unless (fboundp 'load-gc)
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
29 ;; From cus-edit.el
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
30 (autoload 'customize "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
31 (autoload 'customize-variable "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
32 (autoload 'customize-face "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
33 (autoload 'customize-apropos "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
34 (autoload 'customize-customized "cus-edit" nil t)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
35 (autoload 'custom-buffer-create "cus-edit")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
36 (autoload 'custom-menu-update "cus-edit")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
37 (autoload 'custom-make-dependencies "cus-edit")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
38 ;; From cus-face.el
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
39 (autoload 'custom-declare-face "cus-face")
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
40 (autoload 'custom-set-faces "cus-face"))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
41
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
42 ;;; The `defcustom' Macro.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
43
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
44 (defun custom-declare-variable (symbol value doc &rest args)
100
4be1180a9e89 Import from CVS: tag r20-1b2
cvs
parents: 98
diff changeset
45 "Like `defcustom', but SYMBOL and VALUE are evaluated as normal arguments."
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
46 (unless (and (default-boundp symbol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
47 (not (get symbol 'saved-value)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
48 (set-default symbol (if (get symbol 'saved-value)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
49 (eval (car (get symbol 'saved-value)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
50 (eval value))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
51 (put symbol 'factory-value (list value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
52 (when doc
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
53 (put symbol 'variable-documentation doc))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
54 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
55 (let ((arg (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
56 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
57 (unless (symbolp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
58 (error "Junk in args %S" args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
59 (let ((keyword arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
60 (value (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
61 (unless args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
62 (error "Keyword %s is missing an argument" keyword))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
63 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
64 (cond ((eq keyword :type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
65 (put symbol 'custom-type value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
66 ((eq keyword :options)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
67 (if (get symbol 'custom-options)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
68 ;; Slow safe code to avoid duplicates.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
69 (mapcar (lambda (option)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
70 (custom-add-option symbol option))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
71 value)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
72 ;; Fast code for the common case.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
73 (put symbol 'custom-options (copy-list value))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
74 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
75 (custom-handle-keyword symbol keyword value
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
76 'custom-variable))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
77 (run-hooks 'custom-define-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
78 symbol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
79
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
80 (defmacro defcustom (symbol value doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
81 "Declare SYMBOL as a customizable variable that defaults to VALUE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
82 DOC is the variable documentation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
83
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
84 Neither SYMBOL nor VALUE needs to be quoted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
85 If SYMBOL is not already bound, initialize it to VALUE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
86 The remaining arguments should have the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
87
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
88 [KEYWORD VALUE]...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
89
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
90 The following KEYWORD's are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
91
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92 :type VALUE should be a widget type.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
93 :options VALUE should be a list of valid members of the widget type.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
94 :group VALUE should be a customization group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
95 Add SYMBOL to that group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
96
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
97 Read the section about customization in the emacs lisp manual for more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
98 information."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
99 `(eval-and-compile
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
100 (custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
101
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
102 ;;; The `defface' Macro.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
103
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
104 (defmacro defface (face spec doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
105 "Declare FACE as a customizable face that defaults to SPEC.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
106 FACE does not need to be quoted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
107
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
108 Third argument DOC is the face documentation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
109
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
110 If FACE has been set with `custom-set-face', set the face attributes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
111 as specified by that function, otherwise set the face attributes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
112 according to SPEC.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
113
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
114 The remaining arguments should have the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
115
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
116 [KEYWORD VALUE]...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
117
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
118 The following KEYWORD's are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
119
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
120 :group VALUE should be a customization group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
121 Add FACE to that group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
122
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
123 SPEC should be an alist of the form ((DISPLAY ATTS)...).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
124
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
125 ATTS is a list of face attributes and their values. The possible
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
126 attributes are defined in the variable `custom-face-attributes'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
127 Alternatively, ATTS can be a face in which case the attributes of that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
128 face is used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
129
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
130 The ATTS of the first entry in SPEC where the DISPLAY matches the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
131 frame should take effect in that frame. DISPLAY can either be the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
132 symbol `t', which will match all frames, or an alist of the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
133 \((REQ ITEM...)...)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
134
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
135 For the DISPLAY to match a FRAME, the REQ property of the frame must
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
136 match one of the ITEM. The following REQ are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
137
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
138 `type' (the value of (window-system))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
139 Should be one of `x' or `tty'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
140
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
141 `class' (the frame's color support)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
142 Should be one of `color', `grayscale', or `mono'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
143
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
144 `background' (what color is used for the background text)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
145 Should be one of `light' or `dark'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
146
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
147 Read the section about customization in the emacs lisp manual for more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
148 information."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
149 `(custom-declare-face (quote ,face) ,spec ,doc ,@args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
150
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
151 ;;; The `defgroup' Macro.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
152
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
153 (defun custom-declare-group (symbol members doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
154 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
155 (put symbol 'custom-group (nconc members (get symbol 'custom-group)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
156 (when doc
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
157 (put symbol 'group-documentation doc))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
158 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
159 (let ((arg (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
160 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
161 (unless (symbolp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
162 (error "Junk in args %S" args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
163 (let ((keyword arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
164 (value (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
165 (unless args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
166 (error "Keyword %s is missing an argument" keyword))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
167 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
168 (cond ((eq keyword :prefix)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
169 (put symbol 'custom-prefix value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
170 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
171 (custom-handle-keyword symbol keyword value
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
172 'custom-group))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
173 (run-hooks 'custom-define-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
174 symbol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
175
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
176 (defmacro defgroup (symbol members doc &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
177 "Declare SYMBOL as a customization group containing MEMBERS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
178 SYMBOL does not need to be quoted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
179
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
180 Third arg DOC is the group documentation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
181
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
182 MEMBERS should be an alist of the form ((NAME WIDGET)...) where
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
183 NAME is a symbol and WIDGET is a widget is a widget for editing that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
184 symbol. Useful widgets are `custom-variable' for editing variables,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
185 `custom-face' for edit faces, and `custom-group' for editing groups.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
186
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
187 The remaining arguments should have the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
188
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
189 [KEYWORD VALUE]...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
190
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
191 The following KEYWORD's are defined:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
192
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
193 :group VALUE should be a customization group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
194 Add SYMBOL to that group.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
195
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
196 Read the section about customization in the emacs lisp manual for more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
197 information."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
198 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
199
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
200 (defun custom-add-to-group (group option widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
201 "To existing GROUP add a new OPTION of type WIDGET,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
202 If there already is an entry for that option, overwrite it."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
203 (let* ((members (get group 'custom-group))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
204 (old (assq option members)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
205 (if old
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
206 (setcar (cdr old) widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
207 (put group 'custom-group (nconc members (list (list option widget)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
208
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
209 ;;; Properties.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
210
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
211 (defun custom-handle-all-keywords (symbol args type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
212 "For customization option SYMBOL, handle keyword arguments ARGS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
213 Third argument TYPE is the custom option type."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
214 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
215 (let ((arg (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
216 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
217 (unless (symbolp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
218 (error "Junk in args %S" args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
219 (let ((keyword arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
220 (value (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
221 (unless args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
222 (error "Keyword %s is missing an argument" keyword))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
223 (setq args (cdr args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
224 (custom-handle-keyword symbol keyword value type)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
225
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
226 (defun custom-handle-keyword (symbol keyword value type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
227 "For customization option SYMBOL, handle KEYWORD with VALUE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
228 Fourth argument TYPE is the custom option type."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
229 (cond ((eq keyword :group)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
230 (custom-add-to-group value symbol type))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
231 ((eq keyword :link)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
232 (custom-add-link symbol value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
233 ((eq keyword :load)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
234 (custom-add-load symbol value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
235 ((eq keyword :tag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
236 (put symbol 'custom-tag value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
237 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
238 (error "Unknown keyword %s" symbol))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
239
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
240 (defun custom-add-option (symbol option)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
241 "To the variable SYMBOL add OPTION.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
242
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
243 If SYMBOL is a hook variable, OPTION should be a hook member.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
244 For other types variables, the effect is undefined."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
245 (let ((options (get symbol 'custom-options)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
246 (unless (member option options)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
247 (put symbol 'custom-options (cons option options)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
248
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
249 (defun custom-add-link (symbol widget)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
250 "To the custom option SYMBOL add the link WIDGET."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
251 (let ((links (get symbol 'custom-links)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
252 (unless (member widget links)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
253 (put symbol 'custom-links (cons widget links)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
254
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
255 (defun custom-add-load (symbol load)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
256 "To the custom option SYMBOL add the dependency LOAD.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
257 LOAD should be either a library file name, or a feature name."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
258 (let ((loads (get symbol 'custom-loads)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
259 (unless (member load loads)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
260 (put symbol 'custom-loads (cons load loads)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
261
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
262 ;;; Initializing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
263
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
264 (defun custom-set-variables (&rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
265 "Initialize variables according to user preferences.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
266
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
267 The arguments should be a list where each entry has the form:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
268
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
269 (SYMBOL VALUE [NOW])
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
270
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
271 The unevaluated VALUE is stored as the saved value for SYMBOL.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
272 If NOW is present and non-nil, VALUE is also evaluated and bound as
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
273 the default value for the SYMBOL."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
274 (while args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
275 (let ((entry (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
276 (if (listp entry)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
277 (let ((symbol (nth 0 entry))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
278 (value (nth 1 entry))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
279 (now (nth 2 entry)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
280 (put symbol 'saved-value (list value))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
281 (when now
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
282 (put symbol 'force-value t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
283 (set-default symbol (eval value)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
284 (setq args (cdr args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
285 ;; Old format, a plist of SYMBOL VALUE pairs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
286 (let ((symbol (nth 0 args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
287 (value (nth 1 args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
288 (put symbol 'saved-value (list value)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
289 (setq args (cdr (cdr args)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
290
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
291 ;;; Meta Customization
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
292
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
293 (defcustom custom-define-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
294 "Hook called after defining each customize option."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
295 :group 'customize
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
296 :type 'hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
297
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
298 ;;; Menu support
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
299
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
300 (defconst custom-help-menu
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
301 `("Customize"
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
302 ,(if (string-match "XEmacs" emacs-version)
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
303 '("Emacs" :filter (lambda (&rest junk)
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
304 (cdr (custom-menu-create 'emacs))))
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
305 ["Update menu..." custom-menu-update t])
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
306 ["Group..." customize t]
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
307 ["Variable..." customize-variable t]
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
308 ["Face..." customize-face t]
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
309 ["Saved..." customize-customized t]
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
310 ["Apropos..." customize-apropos t])
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
311 "Customize menu")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
312
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
313 (defun custom-menu-reset ()
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
314 "Reset customize menu."
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
315 (remove-hook 'custom-define-hook 'custom-menu-reset)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
316 (if (string-match "XEmacs" emacs-version)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
317 (when (fboundp 'add-submenu)
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 106
diff changeset
318 (add-submenu '("Options") custom-help-menu))
106
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
319 (define-key global-map [menu-bar help-menu customize-menu]
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
320 (cons (car custom-help-menu)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
321 (easy-menu-create-keymaps (car custom-help-menu)
8ff55ebd4be9 Import from CVS: tag r20-1b5
cvs
parents: 102
diff changeset
322 (cdr custom-help-menu))))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
323
112
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
324 (if (string-match "XEmacs" emacs-version)
48d667d6f17f Import from CVS: tag r20-1b8
cvs
parents: 110
diff changeset
325 (autoload 'custom-menu-create "cus-edit")
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 106
diff changeset
326 (custom-menu-reset))
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 106
diff changeset
327
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
328 ;;; The End.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
329
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
330 (provide 'custom)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
331
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
332 ;; custom.el ends here