Commit | Line | Data |
---|---|---|
e8af40ee | 1 | ;;; cus-edit.el --- tools for customizing Emacs and Lisp packages |
d543e20b | 2 | ;; |
0d30b337 | 3 | ;; Copyright (C) 1996, 1997, 1999, 2000, 2001, 2002, 2003, 2004, |
2614ccc3 | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
d543e20b PA |
5 | ;; |
6 | ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | |
c942535f | 7 | ;; Maintainer: FSF |
d543e20b | 8 | ;; Keywords: help, faces |
d543e20b | 9 | |
f2b98a56 RS |
10 | ;; This file is part of GNU Emacs. |
11 | ||
eb3fa2cf | 12 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
f2b98a56 | 13 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
14 | ;; the Free Software Foundation, either version 3 of the License, or |
15 | ;; (at your option) any later version. | |
f2b98a56 RS |
16 | |
17 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;; GNU General Public License for more details. | |
21 | ||
22 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 23 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
f2b98a56 | 24 | |
d543e20b PA |
25 | ;;; Commentary: |
26 | ;; | |
6d528fc5 | 27 | ;; This file implements the code to create and edit customize buffers. |
c942535f | 28 | ;; |
d543e20b PA |
29 | ;; See `custom.el'. |
30 | ||
ab678382 RS |
31 | ;; No commands should have names starting with `custom-' because |
32 | ;; that interferes with completion. Use `customize-' for commands | |
33 | ;; that the user will run with M-x, and `Custom-' for interactive commands. | |
34 | ||
9f5d3236 | 35 | ;; The identity of a customize option is represented by a Lisp symbol. |
62bf2fd1 | 36 | ;; The following values are associated with an option. |
9f5d3236 RS |
37 | |
38 | ;; 0. The current value. | |
39 | ||
40 | ;; This is the value of the option as seen by "the rest of Emacs". | |
41 | ||
42 | ;; Usually extracted by 'default-value', but can be extracted with | |
43 | ;; different means if the option symbol has the 'custom-get' | |
44 | ;; property. Similarly, set-default (or the 'custom-set' property) | |
45 | ;; can set it. | |
46 | ||
47 | ;; 1. The widget value. | |
48 | ||
62bf2fd1 | 49 | ;; This is the value shown in the widget in a customize buffer. |
9f5d3236 RS |
50 | |
51 | ;; 2. The customized value. | |
52 | ||
53 | ;; This is the last value given to the option through customize. | |
54 | ||
55 | ;; It is stored in the 'customized-value' property of the option, in a | |
62bf2fd1 | 56 | ;; cons-cell whose car evaluates to the customized value. |
9f5d3236 RS |
57 | |
58 | ;; 3. The saved value. | |
59 | ||
60 | ;; This is last value saved from customize. | |
61 | ||
62 | ;; It is stored in the 'saved-value' property of the option, in a | |
62bf2fd1 | 63 | ;; cons-cell whose car evaluates to the saved value. |
9f5d3236 RS |
64 | |
65 | ;; 4. The standard value. | |
66 | ||
67 | ;; This is the value given in the 'defcustom' declaration. | |
68 | ||
69 | ;; It is stored in the 'standard-value' property of the option, in a | |
62bf2fd1 | 70 | ;; cons-cell whose car evaluates to the standard value. |
9f5d3236 RS |
71 | |
72 | ;; 5. The "think" value. | |
62bf2fd1 LT |
73 | |
74 | ;; This is what customize thinks the current value should be. | |
75 | ||
76 | ;; This is the customized value, if any such value exists, otherwise | |
9f5d3236 | 77 | ;; the saved value, if that exists, and as a last resort the standard |
62bf2fd1 | 78 | ;; value. |
9f5d3236 RS |
79 | |
80 | ;; The reason for storing values unevaluated: This is so you can have | |
81 | ;; values that depend on the environment. For example, you can have a | |
62bf2fd1 | 82 | ;; variable that has one value when Emacs is running under a window |
9f5d3236 | 83 | ;; system, and another value on a tty. Since the evaluation is only done |
62bf2fd1 | 84 | ;; when the variable is first initialized, this is only relevant for the |
9f5d3236 RS |
85 | ;; saved (and standard) values, but affect others values for |
86 | ;; compatibility. | |
87 | ||
88 | ;; You can see (and modify and save) this unevaluated value by selecting | |
70482877 | 89 | ;; "Show Saved Lisp Expression" from the Lisp interface. This will |
9f5d3236 RS |
90 | ;; give you the unevaluated saved value, if any, otherwise the |
91 | ;; unevaluated standard value. | |
92 | ||
93 | ;; The possible states for a customize widget are: | |
94 | ||
95 | ;; 0. unknown | |
96 | ||
97 | ;; The state has not been determined yet. | |
98 | ||
99 | ;; 1. modified | |
100 | ||
101 | ;; The widget value is different from the current value. | |
102 | ||
103 | ;; 2. changed | |
62bf2fd1 LT |
104 | |
105 | ;; The current value is different from the "think" value. | |
9f5d3236 RS |
106 | |
107 | ;; 3. set | |
108 | ||
109 | ;; The "think" value is the customized value. | |
110 | ||
111 | ;; 4. saved | |
112 | ||
113 | ;; The "think" value is the saved value. | |
114 | ||
115 | ;; 5. standard | |
116 | ||
117 | ;; The "think" value is the standard value. | |
118 | ||
119 | ;; 6. rogue | |
120 | ||
62bf2fd1 | 121 | ;; There is no standard value. This means that the variable was |
f63d5a0e LT |
122 | ;; not defined with defcustom, nor handled in cus-start.el. Most |
123 | ;; standard interactive Custom commands do not let you create a | |
124 | ;; Custom buffer containing such variables. However, such Custom | |
125 | ;; buffers can be created, for instance, by calling | |
126 | ;; `customize-apropos' with a prefix arg or by calling | |
f32a1cb5 | 127 | ;; `customize-option' non-interactively. |
9f5d3236 RS |
128 | |
129 | ;; 7. hidden | |
130 | ||
131 | ;; There is no widget value. | |
132 | ||
133 | ;; 8. mismatch | |
134 | ||
135 | ;; The widget value is not valid member of the :type specified for the | |
62bf2fd1 | 136 | ;; option. |
9f5d3236 | 137 | |
d543e20b PA |
138 | ;;; Code: |
139 | ||
140 | (require 'cus-face) | |
141 | (require 'wid-edit) | |
a0247dcf SM |
142 | |
143 | (defvar custom-versions-load-alist) ; from cus-load | |
144 | (defvar recentf-exclude) ; from recentf.el | |
6d528fc5 PA |
145 | |
146 | (condition-case nil | |
147 | (require 'cus-load) | |
148 | (error nil)) | |
d543e20b | 149 | |
9097aeb7 PA |
150 | (condition-case nil |
151 | (require 'cus-start) | |
152 | (error nil)) | |
153 | ||
bd042c03 | 154 | (put 'custom-define-hook 'custom-type 'hook) |
25ac13b5 | 155 | (put 'custom-define-hook 'standard-value '(nil)) |
bd042c03 PA |
156 | (custom-add-to-group 'customize 'custom-define-hook 'custom-variable) |
157 | ||
d543e20b PA |
158 | ;;; Customization Groups. |
159 | ||
160 | (defgroup emacs nil | |
161 | "Customization of the One True Editor." | |
162 | :link '(custom-manual "(emacs)Top")) | |
163 | ||
164 | ;; Most of these groups are stolen from `finder.el', | |
165 | (defgroup editing nil | |
166 | "Basic text editing facilities." | |
167 | :group 'emacs) | |
168 | ||
169 | (defgroup abbrev nil | |
170 | "Abbreviation handling, typing shortcuts, macros." | |
171 | :tag "Abbreviations" | |
172 | :group 'editing) | |
173 | ||
174 | (defgroup matching nil | |
175 | "Various sorts of searching and matching." | |
176 | :group 'editing) | |
177 | ||
178 | (defgroup emulations nil | |
179 | "Emulations of other editors." | |
6ea2832e | 180 | :link '(custom-manual "(emacs)Emulation") |
d543e20b PA |
181 | :group 'editing) |
182 | ||
183 | (defgroup mouse nil | |
184 | "Mouse support." | |
185 | :group 'editing) | |
186 | ||
187 | (defgroup outlines nil | |
188 | "Support for hierarchical outlining." | |
189 | :group 'editing) | |
190 | ||
191 | (defgroup external nil | |
192 | "Interfacing to external utilities." | |
193 | :group 'emacs) | |
194 | ||
d543e20b PA |
195 | (defgroup processes nil |
196 | "Process, subshell, compilation, and job control support." | |
197 | :group 'external | |
198 | :group 'development) | |
199 | ||
4599e8cd RS |
200 | (defgroup convenience nil |
201 | "Convenience features for faster editing." | |
202 | :group 'emacs) | |
203 | ||
d543e20b PA |
204 | (defgroup programming nil |
205 | "Support for programming in other languages." | |
206 | :group 'emacs) | |
207 | ||
208 | (defgroup languages nil | |
209 | "Specialized modes for editing programming languages." | |
210 | :group 'programming) | |
211 | ||
212 | (defgroup lisp nil | |
213 | "Lisp support, including Emacs Lisp." | |
3e721a14 | 214 | :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) |
d543e20b PA |
215 | :group 'languages |
216 | :group 'development) | |
217 | ||
218 | (defgroup c nil | |
219 | "Support for the C language and related languages." | |
3e721a14 | 220 | :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) |
6ea2832e | 221 | :link '(custom-manual "(ccmode)") |
d543e20b PA |
222 | :group 'languages) |
223 | ||
224 | (defgroup tools nil | |
225 | "Programming tools." | |
226 | :group 'programming) | |
227 | ||
228 | (defgroup oop nil | |
229 | "Support for object-oriented programming." | |
230 | :group 'programming) | |
231 | ||
232 | (defgroup applications nil | |
233 | "Applications written in Emacs." | |
234 | :group 'emacs) | |
235 | ||
236 | (defgroup calendar nil | |
237 | "Calendar and time management support." | |
238 | :group 'applications) | |
239 | ||
240 | (defgroup mail nil | |
241 | "Modes for electronic-mail handling." | |
242 | :group 'applications) | |
243 | ||
244 | (defgroup news nil | |
245 | "Support for netnews reading and posting." | |
6ea2832e | 246 | :link '(custom-manual "(gnus)") |
d543e20b PA |
247 | :group 'applications) |
248 | ||
249 | (defgroup games nil | |
250 | "Games, jokes and amusements." | |
251 | :group 'applications) | |
252 | ||
253 | (defgroup development nil | |
254 | "Support for further development of Emacs." | |
255 | :group 'emacs) | |
256 | ||
257 | (defgroup docs nil | |
258 | "Support for Emacs documentation." | |
259 | :group 'development) | |
260 | ||
261 | (defgroup extensions nil | |
262 | "Emacs Lisp language extensions." | |
263 | :group 'development) | |
264 | ||
265 | (defgroup internal nil | |
266 | "Code for Emacs internals, build process, defaults." | |
267 | :group 'development) | |
268 | ||
269 | (defgroup maint nil | |
270 | "Maintenance aids for the Emacs development group." | |
271 | :tag "Maintenance" | |
272 | :group 'development) | |
273 | ||
274 | (defgroup environment nil | |
275 | "Fitting Emacs with its environment." | |
276 | :group 'emacs) | |
277 | ||
278 | (defgroup comm nil | |
279 | "Communications, networking, remote access to files." | |
280 | :tag "Communication" | |
281 | :group 'environment) | |
282 | ||
283 | (defgroup hardware nil | |
284 | "Support for interfacing with exotic hardware." | |
285 | :group 'environment) | |
286 | ||
287 | (defgroup terminals nil | |
288 | "Support for terminal types." | |
289 | :group 'environment) | |
290 | ||
291 | (defgroup unix nil | |
292 | "Front-ends/assistants for, or emulators of, UNIX features." | |
293 | :group 'environment) | |
294 | ||
d543e20b PA |
295 | (defgroup i18n nil |
296 | "Internationalization and alternate character-set support." | |
6ea2832e | 297 | :link '(custom-manual "(emacs)International") |
d543e20b PA |
298 | :group 'environment |
299 | :group 'editing) | |
300 | ||
86bd10bc PA |
301 | (defgroup x nil |
302 | "The X Window system." | |
303 | :group 'environment) | |
304 | ||
d543e20b PA |
305 | (defgroup frames nil |
306 | "Support for Emacs frames and window systems." | |
307 | :group 'environment) | |
308 | ||
309 | (defgroup data nil | |
310 | "Support editing files of data." | |
311 | :group 'emacs) | |
312 | ||
482e54f3 RS |
313 | (defgroup files nil |
314 | "Support editing files." | |
315 | :group 'emacs) | |
316 | ||
d543e20b PA |
317 | (defgroup wp nil |
318 | "Word processing." | |
319 | :group 'emacs) | |
320 | ||
321 | (defgroup tex nil | |
322 | "Code related to the TeX formatter." | |
3e721a14 | 323 | :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces) |
d543e20b PA |
324 | :group 'wp) |
325 | ||
326 | (defgroup faces nil | |
327 | "Support for multiple fonts." | |
328 | :group 'emacs) | |
329 | ||
330 | (defgroup hypermedia nil | |
331 | "Support for links between text or other media types." | |
332 | :group 'emacs) | |
333 | ||
334 | (defgroup help nil | |
335 | "Support for on-line help systems." | |
336 | :group 'emacs) | |
337 | ||
d3d4df42 DL |
338 | (defgroup multimedia nil |
339 | "Non-textual support, specifically images and sound." | |
340 | :group 'emacs) | |
341 | ||
d543e20b PA |
342 | (defgroup local nil |
343 | "Code local to your site." | |
344 | :group 'emacs) | |
345 | ||
346 | (defgroup customize '((widgets custom-group)) | |
347 | "Customization of the Customization support." | |
d543e20b | 348 | :prefix "custom-" |
bd042c03 PA |
349 | :group 'help) |
350 | ||
351 | (defgroup custom-faces nil | |
352 | "Faces used by customize." | |
353 | :group 'customize | |
d543e20b PA |
354 | :group 'faces) |
355 | ||
da5ec617 PA |
356 | (defgroup custom-browse nil |
357 | "Control customize browser." | |
358 | :prefix "custom-" | |
359 | :group 'customize) | |
360 | ||
6aaedd12 | 361 | (defgroup custom-buffer nil |
da5ec617 | 362 | "Control customize buffers." |
6aaedd12 PA |
363 | :prefix "custom-" |
364 | :group 'customize) | |
365 | ||
366 | (defgroup custom-menu nil | |
da5ec617 | 367 | "Control customize menus." |
6aaedd12 PA |
368 | :prefix "custom-" |
369 | :group 'customize) | |
370 | ||
bd042c03 PA |
371 | (defgroup alloc nil |
372 | "Storage allocation and gc for GNU Emacs Lisp interpreter." | |
373 | :tag "Storage Allocation" | |
374 | :group 'internal) | |
375 | ||
376 | (defgroup undo nil | |
377 | "Undoing changes in buffers." | |
6ea2832e | 378 | :link '(custom-manual "(emacs)Undo") |
bd042c03 PA |
379 | :group 'editing) |
380 | ||
0518917a | 381 | (defgroup mode-line nil |
bd042c03 PA |
382 | "Content of the modeline." |
383 | :group 'environment) | |
384 | ||
bd042c03 PA |
385 | (defgroup editing-basics nil |
386 | "Most basic editing facilities." | |
387 | :group 'editing) | |
388 | ||
389 | (defgroup display nil | |
390 | "How characters are displayed in buffers." | |
391 | :group 'environment) | |
392 | ||
393 | (defgroup execute nil | |
394 | "Executing external commands." | |
395 | :group 'processes) | |
396 | ||
397 | (defgroup installation nil | |
398 | "The Emacs installation." | |
399 | :group 'environment) | |
400 | ||
401 | (defgroup dired nil | |
402 | "Directory editing." | |
403 | :group 'environment) | |
404 | ||
405 | (defgroup limits nil | |
406 | "Internal Emacs limits." | |
407 | :group 'internal) | |
408 | ||
409 | (defgroup debug nil | |
410 | "Debugging Emacs itself." | |
411 | :group 'development) | |
412 | ||
bd042c03 PA |
413 | (defgroup keyboard nil |
414 | "Input from the keyboard." | |
415 | :group 'environment) | |
416 | ||
417 | (defgroup mouse nil | |
418 | "Input from the mouse." | |
419 | :group 'environment) | |
420 | ||
421 | (defgroup menu nil | |
422 | "Input from the menus." | |
423 | :group 'environment) | |
424 | ||
153bd017 JD |
425 | (defgroup dnd nil |
426 | "Handling data from drag and drop." | |
427 | :group 'environment) | |
428 | ||
bd042c03 | 429 | (defgroup auto-save nil |
040ee34f | 430 | "Preventing accidental loss of data." |
482e54f3 | 431 | :group 'files) |
bd042c03 PA |
432 | |
433 | (defgroup processes-basics nil | |
434 | "Basic stuff dealing with processes." | |
435 | :group 'processes) | |
436 | ||
25ac13b5 PA |
437 | (defgroup mule nil |
438 | "MULE Emacs internationalization." | |
70bc91bc | 439 | :group 'i18n) |
25ac13b5 | 440 | |
bd042c03 PA |
441 | (defgroup windows nil |
442 | "Windows within a frame." | |
6ea2832e | 443 | :link '(custom-manual "(emacs)Windows") |
86bd10bc | 444 | :group 'environment) |
bd042c03 | 445 | |
f3093f77 CY |
446 | ;;; Custom mode keymaps |
447 | ||
448 | (defvar custom-mode-map | |
449 | ;; This keymap should be dense, but a dense keymap would prevent inheriting | |
450 | ;; "\r" bindings from the parent map. | |
451 | ;; Actually, this misfeature of dense keymaps was fixed on 2001-11-26. | |
452 | (let ((map (make-keymap))) | |
453 | (set-keymap-parent map widget-keymap) | |
454 | (define-key map [remap self-insert-command] 'Custom-no-edit) | |
455 | (define-key map "\^m" 'Custom-newline) | |
456 | (define-key map " " 'scroll-up) | |
457 | (define-key map "\177" 'scroll-down) | |
458 | (define-key map "\C-c\C-c" 'Custom-set) | |
459 | (define-key map "\C-x\C-s" 'Custom-save) | |
460 | (define-key map "q" 'Custom-buffer-done) | |
461 | (define-key map "u" 'Custom-goto-parent) | |
462 | (define-key map "n" 'widget-forward) | |
463 | (define-key map "p" 'widget-backward) | |
464 | map) | |
6aec3b9d | 465 | "Keymap for `Custom-mode'.") |
f3093f77 CY |
466 | |
467 | (defvar custom-mode-link-map | |
468 | (let ((map (make-keymap))) | |
469 | (set-keymap-parent map custom-mode-map) | |
470 | (define-key map [down-mouse-2] nil) | |
471 | (define-key map [down-mouse-1] 'mouse-drag-region) | |
472 | (define-key map [mouse-2] 'widget-move-and-invoke) | |
473 | map) | |
6aec3b9d | 474 | "Local keymap for links in `Custom-mode'.") |
f3093f77 | 475 | |
34cf517c MR |
476 | (defvar custom-field-keymap |
477 | (let ((map (copy-keymap widget-field-keymap))) | |
478 | (define-key map "\C-c\C-c" 'Custom-set) | |
479 | (define-key map "\C-x\C-s" 'Custom-save) | |
480 | map) | |
481 | "Keymap used inside editable fields in customization buffers.") | |
482 | ||
483 | (widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap) | |
f3093f77 | 484 | |
d543e20b PA |
485 | ;;; Utilities. |
486 | ||
d543e20b PA |
487 | (defun custom-split-regexp-maybe (regexp) |
488 | "If REGEXP is a string, split it to a list at `\\|'. | |
12bafdaa | 489 | You can get the original back from the result with: |
d543e20b PA |
490 | (mapconcat 'identity result \"\\|\") |
491 | ||
492 | IF REGEXP is not a string, return it unchanged." | |
493 | (if (stringp regexp) | |
12bafdaa | 494 | (split-string regexp "\\\\|") |
d543e20b PA |
495 | regexp)) |
496 | ||
bd042c03 | 497 | (defun custom-variable-prompt () |
3a495e15 | 498 | "Prompt for a custom variable, defaulting to the variable at point. |
bd042c03 | 499 | Return a list suitable for use in `interactive'." |
3e721a14 JL |
500 | (let* ((v (variable-at-point)) |
501 | (default (and (symbolp v) (custom-variable-p v) (symbol-name v))) | |
502 | (enable-recursive-minibuffers t) | |
503 | val) | |
504 | (setq val (completing-read | |
0a57ffed RS |
505 | (if default (format "Customize variable (default %s): " default) |
506 | "Customize variable: ") | |
3e721a14 | 507 | obarray 'custom-variable-p t nil nil default)) |
bd042c03 | 508 | (list (if (equal val "") |
5b5cdd97 RS |
509 | (if (symbolp v) v nil) |
510 | (intern val))))) | |
bd042c03 | 511 | |
6d528fc5 PA |
512 | (defun custom-menu-filter (menu widget) |
513 | "Convert MENU to the form used by `widget-choose'. | |
514 | MENU should be in the same format as `custom-variable-menu'. | |
515 | WIDGET is the widget to apply the filter entries of MENU on." | |
516 | (let ((result nil) | |
517 | current name action filter) | |
d3d4df42 | 518 | (while menu |
6d528fc5 PA |
519 | (setq current (car menu) |
520 | name (nth 0 current) | |
521 | action (nth 1 current) | |
522 | filter (nth 2 current) | |
523 | menu (cdr menu)) | |
524 | (if (or (null filter) (funcall filter widget)) | |
525 | (push (cons name action) result) | |
526 | (push name result))) | |
527 | (nreverse result))) | |
528 | ||
bd042c03 PA |
529 | ;;; Unlispify. |
530 | ||
d543e20b | 531 | (defvar custom-prefix-list nil |
2365594b | 532 | "List of prefixes that should be ignored by `custom-unlispify'.") |
d543e20b PA |
533 | |
534 | (defcustom custom-unlispify-menu-entries t | |
10cb6e7b | 535 | "Display menu entries as words instead of symbols if non-nil." |
6aaedd12 | 536 | :group 'custom-menu |
d543e20b PA |
537 | :type 'boolean) |
538 | ||
cda987f4 RS |
539 | (defcustom custom-unlispify-remove-prefixes nil |
540 | "Non-nil means remove group prefixes from option names in buffer." | |
541 | :group 'custom-menu | |
42b4edc5 | 542 | :group 'custom-buffer |
cda987f4 RS |
543 | :type 'boolean) |
544 | ||
d543e20b | 545 | (defun custom-unlispify-menu-entry (symbol &optional no-suffix) |
2365594b | 546 | "Convert SYMBOL into a menu entry." |
d543e20b PA |
547 | (cond ((not custom-unlispify-menu-entries) |
548 | (symbol-name symbol)) | |
549 | ((get symbol 'custom-tag) | |
550 | (if no-suffix | |
551 | (get symbol 'custom-tag) | |
552 | (concat (get symbol 'custom-tag) "..."))) | |
553 | (t | |
d9f67134 | 554 | (with-current-buffer (get-buffer-create " *Custom-Work*") |
d543e20b PA |
555 | (erase-buffer) |
556 | (princ symbol (current-buffer)) | |
557 | (goto-char (point-min)) | |
3b2f3d30 SM |
558 | ;; FIXME: Boolean variables are not predicates, so they shouldn't |
559 | ;; end with `-p'. -stef | |
560 | ;; (when (and (eq (get symbol 'custom-type) 'boolean) | |
561 | ;; (re-search-forward "-p\\'" nil t)) | |
562 | ;; (replace-match "" t t) | |
563 | ;; (goto-char (point-min))) | |
cda987f4 RS |
564 | (if custom-unlispify-remove-prefixes |
565 | (let ((prefixes custom-prefix-list) | |
566 | prefix) | |
567 | (while prefixes | |
568 | (setq prefix (car prefixes)) | |
569 | (if (search-forward prefix (+ (point) (length prefix)) t) | |
d3d4df42 | 570 | (progn |
cda987f4 RS |
571 | (setq prefixes nil) |
572 | (delete-region (point-min) (point))) | |
573 | (setq prefixes (cdr prefixes)))))) | |
d543e20b PA |
574 | (subst-char-in-region (point-min) (point-max) ?- ?\ t) |
575 | (capitalize-region (point-min) (point-max)) | |
d3d4df42 | 576 | (unless no-suffix |
d543e20b PA |
577 | (goto-char (point-max)) |
578 | (insert "...")) | |
579 | (buffer-string))))) | |
580 | ||
581 | (defcustom custom-unlispify-tag-names t | |
10cb6e7b | 582 | "Display tag names as words instead of symbols if non-nil." |
6aaedd12 | 583 | :group 'custom-buffer |
d543e20b PA |
584 | :type 'boolean) |
585 | ||
586 | (defun custom-unlispify-tag-name (symbol) | |
2365594b | 587 | "Convert SYMBOL into a menu entry." |
d543e20b PA |
588 | (let ((custom-unlispify-menu-entries custom-unlispify-tag-names)) |
589 | (custom-unlispify-menu-entry symbol t))) | |
590 | ||
591 | (defun custom-prefix-add (symbol prefixes) | |
2365594b | 592 | "Add SYMBOL to list of ignored PREFIXES." |
d543e20b PA |
593 | (cons (or (get symbol 'custom-prefix) |
594 | (concat (symbol-name symbol) "-")) | |
595 | prefixes)) | |
596 | ||
bd042c03 PA |
597 | ;;; Guess. |
598 | ||
599 | (defcustom custom-guess-name-alist | |
600 | '(("-p\\'" boolean) | |
11f0cdf8 | 601 | ("-flag\\'" boolean) |
bd042c03 PA |
602 | ("-hook\\'" hook) |
603 | ("-face\\'" face) | |
604 | ("-file\\'" file) | |
605 | ("-function\\'" function) | |
606 | ("-functions\\'" (repeat function)) | |
607 | ("-list\\'" (repeat sexp)) | |
608 | ("-alist\\'" (repeat (cons sexp sexp)))) | |
609 | "Alist of (MATCH TYPE). | |
610 | ||
d3d4df42 | 611 | MATCH should be a regexp matching the name of a symbol, and TYPE should |
bd042c03 PA |
612 | be a widget suitable for editing the value of that symbol. The TYPE |
613 | of the first entry where MATCH matches the name of the symbol will be | |
d3d4df42 | 614 | used. |
bd042c03 PA |
615 | |
616 | This is used for guessing the type of variables not declared with | |
617 | customize." | |
618 | :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type"))) | |
3ee07367 | 619 | :group 'custom-buffer) |
d543e20b | 620 | |
bd042c03 PA |
621 | (defcustom custom-guess-doc-alist |
622 | '(("\\`\\*?Non-nil " boolean)) | |
623 | "Alist of (MATCH TYPE). | |
d543e20b | 624 | |
bd042c03 PA |
625 | MATCH should be a regexp matching a documentation string, and TYPE |
626 | should be a widget suitable for editing the value of a variable with | |
627 | that documentation string. The TYPE of the first entry where MATCH | |
628 | matches the name of the symbol will be used. | |
d543e20b | 629 | |
bd042c03 PA |
630 | This is used for guessing the type of variables not declared with |
631 | customize." | |
632 | :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type"))) | |
3ee07367 | 633 | :group 'custom-buffer) |
d543e20b | 634 | |
bd042c03 PA |
635 | (defun custom-guess-type (symbol) |
636 | "Guess a widget suitable for editing the value of SYMBOL. | |
d3d4df42 | 637 | This is done by matching SYMBOL with `custom-guess-name-alist' and |
bd042c03 PA |
638 | if that fails, the doc string with `custom-guess-doc-alist'." |
639 | (let ((name (symbol-name symbol)) | |
640 | (names custom-guess-name-alist) | |
641 | current found) | |
642 | (while names | |
643 | (setq current (car names) | |
644 | names (cdr names)) | |
645 | (when (string-match (nth 0 current) name) | |
646 | (setq found (nth 1 current) | |
647 | names nil))) | |
648 | (unless found | |
649 | (let ((doc (documentation-property symbol 'variable-documentation)) | |
650 | (docs custom-guess-doc-alist)) | |
d3d4df42 | 651 | (when doc |
bd042c03 PA |
652 | (while docs |
653 | (setq current (car docs) | |
654 | docs (cdr docs)) | |
655 | (when (string-match (nth 0 current) doc) | |
656 | (setq found (nth 1 current) | |
657 | docs nil)))))) | |
658 | found)) | |
d543e20b | 659 | |
25ac13b5 PA |
660 | ;;; Sorting. |
661 | ||
ba5b643e | 662 | ;;;###autoload |
da5ec617 | 663 | (defcustom custom-browse-sort-alphabetically nil |
ba5b643e | 664 | "If non-nil, sort customization group alphabetically in `custom-browse'." |
da5ec617 PA |
665 | :type 'boolean |
666 | :group 'custom-browse) | |
667 | ||
668 | (defcustom custom-browse-order-groups nil | |
669 | "If non-nil, order group members within each customization group. | |
670 | If `first', order groups before non-groups. | |
671 | If `last', order groups after non-groups." | |
672 | :type '(choice (const first) | |
673 | (const last) | |
674 | (const :tag "none" nil)) | |
675 | :group 'custom-browse) | |
676 | ||
c953515e PA |
677 | (defcustom custom-browse-only-groups nil |
678 | "If non-nil, show group members only within each customization group." | |
679 | :type 'boolean | |
680 | :group 'custom-browse) | |
681 | ||
ba5b643e | 682 | ;;;###autoload |
477ca0e8 | 683 | (defcustom custom-buffer-sort-alphabetically nil |
ba5b643e | 684 | "If non-nil, sort each customization group alphabetically in Custom buffer." |
944c91b6 | 685 | :type 'boolean |
6aaedd12 | 686 | :group 'custom-buffer) |
25ac13b5 | 687 | |
da5ec617 PA |
688 | (defcustom custom-buffer-order-groups 'last |
689 | "If non-nil, order group members within each customization group. | |
690 | If `first', order groups before non-groups. | |
691 | If `last', order groups after non-groups." | |
692 | :type '(choice (const first) | |
693 | (const last) | |
694 | (const :tag "none" nil)) | |
6aaedd12 | 695 | :group 'custom-buffer) |
25ac13b5 | 696 | |
ba5b643e | 697 | ;;;###autoload |
944c91b6 | 698 | (defcustom custom-menu-sort-alphabetically nil |
ba5b643e | 699 | "If non-nil, sort each customization group alphabetically in menus." |
944c91b6 | 700 | :type 'boolean |
6aaedd12 | 701 | :group 'custom-menu) |
25ac13b5 | 702 | |
da5ec617 PA |
703 | (defcustom custom-menu-order-groups 'first |
704 | "If non-nil, order group members within each customization group. | |
705 | If `first', order groups before non-groups. | |
706 | If `last', order groups after non-groups." | |
707 | :type '(choice (const first) | |
708 | (const last) | |
709 | (const :tag "none" nil)) | |
6aaedd12 PA |
710 | :group 'custom-menu) |
711 | ||
b4854a23 KH |
712 | ;;;###autoload (add-hook 'same-window-regexps "\\`\\*Customiz.*\\*\\'") |
713 | ||
da5ec617 PA |
714 | (defun custom-sort-items (items sort-alphabetically order-groups) |
715 | "Return a sorted copy of ITEMS. | |
716 | ITEMS should be a `custom-group' property. | |
717 | If SORT-ALPHABETICALLY non-nil, sort alphabetically. | |
718 | If ORDER-GROUPS is `first' order groups before non-groups, if `last' order | |
719 | groups after non-groups, if nil do not order groups at all." | |
720 | (sort (copy-sequence items) | |
721 | (lambda (a b) | |
722 | (let ((typea (nth 1 a)) (typeb (nth 1 b)) | |
359476e0 | 723 | (namea (nth 0 a)) (nameb (nth 0 b))) |
da5ec617 PA |
724 | (cond ((not order-groups) |
725 | ;; Since we don't care about A and B order, maybe sort. | |
726 | (when sort-alphabetically | |
727 | (string-lessp namea nameb))) | |
728 | ((eq typea 'custom-group) | |
729 | ;; If B is also a group, maybe sort. Otherwise, order A and B. | |
730 | (if (eq typeb 'custom-group) | |
731 | (when sort-alphabetically | |
732 | (string-lessp namea nameb)) | |
733 | (eq order-groups 'first))) | |
734 | ((eq typeb 'custom-group) | |
735 | ;; Since A cannot be a group, order A and B. | |
736 | (eq order-groups 'last)) | |
737 | (sort-alphabetically | |
738 | ;; Since A and B cannot be groups, sort. | |
739 | (string-lessp namea nameb))))))) | |
25ac13b5 | 740 | |
d543e20b PA |
741 | ;;; Custom Mode Commands. |
742 | ||
9db1942d CY |
743 | ;; This variable is used by `custom-tool-bar-map', or directly by |
744 | ;; `custom-buffer-create-internal' if the toolbar is not present and | |
745 | ;; `custom-buffer-verbose-help' is non-nil. | |
746 | ||
747 | (defvar custom-commands | |
748 | '(("Set for current session" Custom-set t | |
749 | "Apply all settings in this buffer to the current session" | |
750 | "index") | |
751 | ("Save for future sessions" Custom-save | |
752 | (or custom-file user-init-file) | |
753 | "Apply all settings in this buffer and save them for future Emacs sessions." | |
754 | "save") | |
755 | ("Undo edits" Custom-reset-current t | |
756 | "Restore all settings in this buffer to reflect their current values." | |
757 | "refresh") | |
758 | ("Reset to saved" Custom-reset-saved t | |
759 | "Restore all settings in this buffer to their saved values (if any)." | |
760 | "undo") | |
761 | ("Erase customizations" Custom-reset-standard | |
762 | (or custom-file user-init-file) | |
763 | "Un-customize all settings in this buffer and save them with standard values." | |
764 | "delete") | |
765 | ("Help for Customize" Custom-help t | |
766 | "Get help for using Customize." | |
767 | "help") | |
768 | ("Exit" Custom-buffer-done t "Exit Customize." "exit"))) | |
769 | ||
770 | (defun Custom-help () | |
771 | "Read the node on Easy Customization in the Emacs manual." | |
d543e20b | 772 | (interactive) |
9db1942d | 773 | (info "(emacs)Easy Customization")) |
d543e20b | 774 | |
d3d4df42 | 775 | (defvar custom-reset-menu |
70482877 LT |
776 | '(("Undo Edits" . Custom-reset-current) |
777 | ("Reset to Saved" . Custom-reset-saved) | |
9db1942d | 778 | ("Erase Customizations (use standard values)" . Custom-reset-standard)) |
d543e20b PA |
779 | "Alist of actions for the `Reset' button. |
780 | The key is a string containing the name of the action, the value is a | |
2365594b | 781 | Lisp function taking the widget as an element which will be called |
d543e20b PA |
782 | when the action is chosen.") |
783 | ||
9db1942d CY |
784 | (defvar custom-options nil |
785 | "Customization widgets in the current buffer.") | |
786 | ||
787 | (defun custom-command-apply (fun query &optional strong-query) | |
788 | "Call function FUN on all widgets in `custom-options'. | |
789 | If there is more than one widget, ask user for confirmation using | |
790 | the query string QUERY, using `y-or-n-p' if STRONG-QUERY is nil, | |
791 | and `yes-or-no-p' otherwise." | |
792 | (if (or (and (= 1 (length custom-options)) | |
793 | (memq (widget-type (car custom-options)) | |
794 | '(custom-variable custom-face))) | |
795 | (funcall (if strong-query 'yes-or-no-p 'y-or-n-p) query)) | |
796 | (progn (mapc fun custom-options) t) | |
797 | (message "Aborted") | |
798 | nil)) | |
799 | ||
800 | (defun Custom-set (&rest ignore) | |
801 | "Set the current value of all edited settings in the buffer." | |
802 | (interactive) | |
803 | (custom-command-apply | |
804 | (lambda (child) | |
805 | (when (eq (widget-get child :custom-state) 'modified) | |
806 | (widget-apply child :custom-set))) | |
807 | "Set all values according to this buffer? ")) | |
808 | ||
809 | (defun Custom-save (&rest ignore) | |
810 | "Set all edited settings, then save all settings that have been set. | |
5ae87ed4 MR |
811 | If a setting was edited and set before, this saves it. If a |
812 | setting was merely edited before, this sets it then saves it." | |
9db1942d | 813 | (interactive) |
5ae87ed4 MR |
814 | (when (custom-command-apply |
815 | (lambda (child) | |
816 | (when (memq (widget-get child :custom-state) | |
817 | '(modified set changed rogue)) | |
818 | (widget-apply child :custom-mark-to-save))) | |
819 | "Save all settings in this buffer? " t) | |
820 | ;; Save changes to buffer and redraw. | |
821 | (custom-save-all) | |
822 | (dolist (child custom-options) | |
823 | (widget-apply child :custom-state-set-and-redraw)))) | |
9db1942d CY |
824 | |
825 | (defun custom-reset (widget &optional event) | |
d543e20b PA |
826 | "Select item from reset menu." |
827 | (let* ((completion-ignore-case t) | |
eaa99205 | 828 | (answer (widget-choose "Reset settings" |
d543e20b PA |
829 | custom-reset-menu |
830 | event))) | |
831 | (if answer | |
832 | (funcall answer)))) | |
833 | ||
ab678382 | 834 | (defun Custom-reset-current (&rest ignore) |
67177975 | 835 | "Reset all edited settings in the buffer to show their current values." |
d543e20b | 836 | (interactive) |
9db1942d CY |
837 | (custom-command-apply |
838 | (lambda (widget) | |
839 | (if (memq (widget-get widget :custom-state) '(modified changed)) | |
840 | (widget-apply widget :custom-reset-current))) | |
841 | "Reset all settings' buffer text to show current values? ")) | |
d543e20b | 842 | |
ab678382 | 843 | (defun Custom-reset-saved (&rest ignore) |
67177975 RS |
844 | "Reset all edited or set settings in the buffer to their saved value. |
845 | This also shows the saved values in the buffer." | |
d543e20b | 846 | (interactive) |
9db1942d CY |
847 | (custom-command-apply |
848 | (lambda (widget) | |
849 | (if (memq (widget-get widget :custom-state) '(modified set changed rogue)) | |
850 | (widget-apply widget :custom-reset-saved))) | |
851 | "Reset all settings (current values and buffer text) to saved values? ")) | |
d543e20b | 852 | |
5ae87ed4 MR |
853 | ;; The next two variables are bound to '(t) by `Custom-reset-standard' |
854 | ;; and `custom-group-reset-standard'. If these variables are nil, both | |
855 | ;; `custom-variable-reset-standard' and `custom-face-reset-standard' | |
856 | ;; save, reset and redraw the handled widget immediately. Otherwise, | |
857 | ;; they add the widget to the corresponding list and leave it to | |
858 | ;; `custom-reset-standard-save-and-update' to save, reset and redraw it. | |
859 | (defvar custom-reset-standard-variables-list nil) | |
860 | (defvar custom-reset-standard-faces-list nil) | |
861 | ||
862 | ;; The next function was excerpted from `custom-variable-reset-standard' | |
863 | ;; and `custom-face-reset-standard' and is used to avoid calling | |
864 | ;; `custom-save-all' repeatedly (and thus saving settings to file one by | |
865 | ;; one) when erasing all customizations. | |
866 | (defun custom-reset-standard-save-and-update () | |
867 | "Save settings and redraw after erasing customizations." | |
868 | (when (or (and custom-reset-standard-variables-list | |
869 | (not (eq custom-reset-standard-variables-list '(t)))) | |
870 | (and custom-reset-standard-faces-list | |
871 | (not (eq custom-reset-standard-faces-list '(t))))) | |
872 | ;; Save settings to file. | |
873 | (custom-save-all) | |
874 | ;; Set state of and redraw variables. | |
875 | (dolist (widget custom-reset-standard-variables-list) | |
876 | (unless (eq widget t) | |
877 | (widget-put widget :custom-state 'unknown) | |
878 | (custom-redraw widget))) | |
879 | ;; Set state of and redraw faces. | |
880 | (dolist (widget custom-reset-standard-faces-list) | |
881 | (unless (eq widget t) | |
882 | (let* ((symbol (widget-value widget)) | |
883 | (child (car (widget-get widget :children))) | |
884 | (value (get symbol 'face-defface-spec)) | |
885 | (comment-widget (widget-get widget :comment-widget))) | |
886 | (put symbol 'face-comment nil) | |
887 | (widget-value-set child | |
888 | (custom-pre-filter-face-spec | |
889 | (list (list t (custom-face-attributes-get | |
890 | symbol nil))))) | |
891 | ;; This call manages the comment visibility | |
892 | (widget-value-set comment-widget "") | |
893 | (custom-face-state-set widget) | |
894 | (custom-redraw-magic widget)))))) | |
895 | ||
ab678382 | 896 | (defun Custom-reset-standard (&rest ignore) |
5ae87ed4 | 897 | "Erase all customizations (either current or saved) in current buffer. |
50137744 RS |
898 | The immediate result is to restore them to their standard values. |
899 | This operation eliminates any saved values for the group members, | |
19d63704 | 900 | making them as if they had never been customized at all." |
d543e20b | 901 | (interactive) |
5ae87ed4 MR |
902 | ;; Bind these temporarily. |
903 | (let ((custom-reset-standard-variables-list '(t)) | |
904 | (custom-reset-standard-faces-list '(t))) | |
905 | (custom-command-apply | |
906 | (lambda (widget) | |
907 | (and (or (null (widget-get widget :custom-standard-value)) | |
908 | (widget-apply widget :custom-standard-value)) | |
909 | (memq (widget-get widget :custom-state) | |
910 | '(modified set changed saved rogue)) | |
911 | (widget-apply widget :custom-mark-to-reset-standard))) | |
912 | "Erase all customizations for settings in this buffer? " t) | |
913 | (custom-reset-standard-save-and-update))) | |
d543e20b PA |
914 | |
915 | ;;; The Customize Commands | |
916 | ||
d3d4df42 | 917 | (defun custom-prompt-variable (prompt-var prompt-val &optional comment) |
6d528fc5 PA |
918 | "Prompt for a variable and a value and return them as a list. |
919 | PROMPT-VAR is the prompt for the variable, and PROMPT-VAL is the | |
920 | prompt for the value. The %s escape in PROMPT-VAL is replaced with | |
921 | the name of the variable. | |
922 | ||
923 | If the variable has a `variable-interactive' property, that is used as if | |
924 | it were the arg to `interactive' (which see) to interactively read the value. | |
925 | ||
926 | If the variable has a `custom-type' property, it must be a widget and the | |
d3d4df42 DL |
927 | `:prompt-value' property of that widget will be used for reading the value. |
928 | ||
10cb6e7b | 929 | If optional COMMENT argument is non-nil, also prompt for a comment and return |
d3d4df42 | 930 | it as the third element in the list." |
6d528fc5 | 931 | (let* ((var (read-variable prompt-var)) |
d3d4df42 DL |
932 | (minibuffer-help-form '(describe-variable var)) |
933 | (val | |
6d528fc5 PA |
934 | (let ((prop (get var 'variable-interactive)) |
935 | (type (get var 'custom-type)) | |
936 | (prompt (format prompt-val var))) | |
937 | (unless (listp type) | |
938 | (setq type (list type))) | |
939 | (cond (prop | |
940 | ;; Use VAR's `variable-interactive' property | |
941 | ;; as an interactive spec for prompting. | |
9db1942d CY |
942 | (call-interactively `(lambda (arg) |
943 | (interactive ,prop) | |
944 | arg))) | |
6d528fc5 PA |
945 | (type |
946 | (widget-prompt-value type | |
947 | prompt | |
948 | (if (boundp var) | |
949 | (symbol-value var)) | |
950 | (not (boundp var)))) | |
951 | (t | |
d3d4df42 DL |
952 | (eval-minibuffer prompt)))))) |
953 | (if comment | |
954 | (list var val | |
955 | (read-string "Comment: " (get var 'variable-comment))) | |
956 | (list var val)))) | |
6d528fc5 PA |
957 | |
958 | ;;;###autoload | |
7ec8d2c6 | 959 | (defun customize-set-value (variable value &optional comment) |
4f9b9060 | 960 | "Set VARIABLE to VALUE, and return VALUE. VALUE is a Lisp object. |
6d528fc5 PA |
961 | |
962 | If VARIABLE has a `variable-interactive' property, that is used as if | |
963 | it were the arg to `interactive' (which see) to interactively read the value. | |
964 | ||
965 | If VARIABLE has a `custom-type' property, it must be a widget and the | |
d3d4df42 DL |
966 | `:prompt-value' property of that widget will be used for reading the value. |
967 | ||
968 | If given a prefix (or a COMMENT argument), also prompt for a comment." | |
6d528fc5 | 969 | (interactive (custom-prompt-variable "Set variable: " |
d3d4df42 DL |
970 | "Set %s to value: " |
971 | current-prefix-arg)) | |
ee1f522d | 972 | |
d3d4df42 | 973 | (cond ((string= comment "") |
7ec8d2c6 | 974 | (put variable 'variable-comment nil)) |
d3d4df42 | 975 | (comment |
7ec8d2c6 PJ |
976 | (put variable 'variable-comment comment))) |
977 | (set variable value)) | |
6d528fc5 PA |
978 | |
979 | ;;;###autoload | |
2365594b | 980 | (defun customize-set-variable (variable value &optional comment) |
4f9b9060 PA |
981 | "Set the default for VARIABLE to VALUE, and return VALUE. |
982 | VALUE is a Lisp object. | |
6d528fc5 PA |
983 | |
984 | If VARIABLE has a `custom-set' property, that is used for setting | |
985 | VARIABLE, otherwise `set-default' is used. | |
986 | ||
6d528fc5 PA |
987 | If VARIABLE has a `variable-interactive' property, that is used as if |
988 | it were the arg to `interactive' (which see) to interactively read the value. | |
989 | ||
990 | If VARIABLE has a `custom-type' property, it must be a widget and the | |
d3d4df42 DL |
991 | `:prompt-value' property of that widget will be used for reading the value. |
992 | ||
993 | If given a prefix (or a COMMENT argument), also prompt for a comment." | |
6d528fc5 | 994 | (interactive (custom-prompt-variable "Set variable: " |
d3d4df42 DL |
995 | "Set customized value for %s to: " |
996 | current-prefix-arg)) | |
4f9b9060 | 997 | (custom-load-symbol variable) |
8ed50a66 | 998 | (custom-push-theme 'theme-value variable 'user 'set (custom-quote value)) |
2365594b DL |
999 | (funcall (or (get variable 'custom-set) 'set-default) variable value) |
1000 | (put variable 'customized-value (list (custom-quote value))) | |
d3d4df42 | 1001 | (cond ((string= comment "") |
2365594b DL |
1002 | (put variable 'variable-comment nil) |
1003 | (put variable 'customized-variable-comment nil)) | |
d3d4df42 | 1004 | (comment |
2365594b | 1005 | (put variable 'variable-comment comment) |
4f9b9060 PA |
1006 | (put variable 'customized-variable-comment comment))) |
1007 | value) | |
6d528fc5 | 1008 | |
4ee1cf9f | 1009 | ;;;###autoload |
7ec8d2c6 | 1010 | (defun customize-save-variable (variable value &optional comment) |
4ee1cf9f | 1011 | "Set the default for VARIABLE to VALUE, and save it for future sessions. |
4f9b9060 PA |
1012 | Return VALUE. |
1013 | ||
4ee1cf9f PA |
1014 | If VARIABLE has a `custom-set' property, that is used for setting |
1015 | VARIABLE, otherwise `set-default' is used. | |
1016 | ||
4ee1cf9f PA |
1017 | If VARIABLE has a `variable-interactive' property, that is used as if |
1018 | it were the arg to `interactive' (which see) to interactively read the value. | |
1019 | ||
1020 | If VARIABLE has a `custom-type' property, it must be a widget and the | |
d3d4df42 DL |
1021 | `:prompt-value' property of that widget will be used for reading the value. |
1022 | ||
1023 | If given a prefix (or a COMMENT argument), also prompt for a comment." | |
901cd78b | 1024 | (interactive (custom-prompt-variable "Set and save variable: " |
d3d4df42 DL |
1025 | "Set and save value for %s as: " |
1026 | current-prefix-arg)) | |
7ec8d2c6 PJ |
1027 | (funcall (or (get variable 'custom-set) 'set-default) variable value) |
1028 | (put variable 'saved-value (list (custom-quote value))) | |
c5d290fb | 1029 | (custom-push-theme 'theme-value variable 'user 'set (custom-quote value)) |
d3d4df42 | 1030 | (cond ((string= comment "") |
7ec8d2c6 PJ |
1031 | (put variable 'variable-comment nil) |
1032 | (put variable 'saved-variable-comment nil)) | |
d3d4df42 | 1033 | (comment |
7ec8d2c6 PJ |
1034 | (put variable 'variable-comment comment) |
1035 | (put variable 'saved-variable-comment comment))) | |
fe4acc60 CY |
1036 | (put variable 'customized-value nil) |
1037 | (put variable 'customized-variable-comment nil) | |
4f9b9060 PA |
1038 | (custom-save-all) |
1039 | value) | |
4ee1cf9f | 1040 | |
d543e20b | 1041 | ;;;###autoload |
5dd0cad0 RS |
1042 | (defun customize () |
1043 | "Select a customization buffer which you can use to set user options. | |
1044 | User options are structured into \"groups\". | |
1045 | Initially the top-level group `Emacs' and its immediate subgroups | |
1046 | are shown; the contents of those subgroups are initially hidden." | |
1047 | (interactive) | |
dc2e979f | 1048 | (customize-group 'emacs)) |
5dd0cad0 | 1049 | |
87434e7a SM |
1050 | ;;;###autoload |
1051 | (defun customize-mode (mode) | |
1052 | "Customize options related to the current major mode. | |
1053 | If a prefix \\[universal-argument] was given (or if the current major mode has no known group), | |
1054 | then prompt for the MODE to customize." | |
1055 | (interactive | |
1056 | (list | |
1057 | (let ((completion-regexp-list '("-mode\\'")) | |
1058 | (group (custom-group-of-mode major-mode))) | |
1059 | (if (and group (not current-prefix-arg)) | |
1060 | major-mode | |
1061 | (intern | |
1062 | (completing-read (if group | |
1063 | (format "Major mode (default %s): " major-mode) | |
1064 | "Major mode: ") | |
1065 | obarray | |
1066 | 'custom-group-of-mode | |
1067 | t nil nil (if group (symbol-name major-mode)))))))) | |
1068 | (customize-group (custom-group-of-mode mode))) | |
1069 | ||
a0247dcf SM |
1070 | (defun customize-read-group () |
1071 | (let ((completion-ignore-case t)) | |
1072 | (completing-read "Customize group (default emacs): " | |
1073 | obarray | |
1074 | (lambda (symbol) | |
1075 | (or (and (get symbol 'custom-loads) | |
1076 | (not (get symbol 'custom-autoload))) | |
1077 | (get symbol 'custom-group))) | |
1078 | t))) | |
87434e7a | 1079 | |
5dd0cad0 | 1080 | ;;;###autoload |
a0247dcf | 1081 | (defun customize-group (&optional group) |
5dd0cad0 | 1082 | "Customize GROUP, which must be a customization group." |
a0247dcf | 1083 | (interactive (list (customize-read-group))) |
5dd0cad0 RS |
1084 | (when (stringp group) |
1085 | (if (string-equal "" group) | |
1086 | (setq group 'emacs) | |
1087 | (setq group (intern group)))) | |
241d3080 RS |
1088 | (let ((name (format "*Customize Group: %s*" |
1089 | (custom-unlispify-tag-name group)))) | |
1090 | (if (get-buffer name) | |
a0247dcf SM |
1091 | (pop-to-buffer name) |
1092 | (custom-buffer-create | |
1093 | (list (list group 'custom-group)) | |
1094 | name | |
1095 | (concat " for group " | |
1096 | (custom-unlispify-tag-name group)))))) | |
d543e20b | 1097 | |
6d528fc5 | 1098 | ;;;###autoload |
9db1942d CY |
1099 | (defun customize-group-other-window (&optional group) |
1100 | "Customize GROUP, which must be a customization group, in another window." | |
a0247dcf SM |
1101 | (interactive (list (customize-read-group))) |
1102 | (let ((pop-up-windows t) | |
1103 | (same-window-buffer-names nil) | |
1104 | (same-window-regexps nil)) | |
1105 | (customize-group group))) | |
6d528fc5 | 1106 | |
9097aeb7 PA |
1107 | ;;;###autoload |
1108 | (defalias 'customize-variable 'customize-option) | |
38d58078 | 1109 | |
d543e20b | 1110 | ;;;###autoload |
38d58078 RS |
1111 | (defun customize-option (symbol) |
1112 | "Customize SYMBOL, which must be a user option variable." | |
bd042c03 | 1113 | (interactive (custom-variable-prompt)) |
161c7127 RS |
1114 | (unless symbol |
1115 | (error "No variable specified")) | |
dcb380c0 LT |
1116 | (let ((basevar (indirect-variable symbol))) |
1117 | (custom-buffer-create (list (list basevar 'custom-variable)) | |
1118 | (format "*Customize Option: %s*" | |
1119 | (custom-unlispify-tag-name basevar))) | |
1120 | (unless (eq symbol basevar) | |
1121 | (message "`%s' is an alias for `%s'" symbol basevar)))) | |
d543e20b | 1122 | |
ffec8c5a MR |
1123 | ;;;###autoload |
1124 | (defalias 'customize-variable-other-window 'customize-option-other-window) | |
1125 | ||
1126 | ;;;###autoload | |
1127 | (defun customize-option-other-window (symbol) | |
1128 | "Customize SYMBOL, which must be a user option variable. | |
1129 | Show the buffer in another window, but don't select it." | |
1130 | (interactive (custom-variable-prompt)) | |
161c7127 RS |
1131 | (unless symbol |
1132 | (error "No variable specified")) | |
dcb380c0 LT |
1133 | (let ((basevar (indirect-variable symbol))) |
1134 | (custom-buffer-create-other-window | |
1135 | (list (list basevar 'custom-variable)) | |
1136 | (format "*Customize Option: %s*" (custom-unlispify-tag-name basevar))) | |
1137 | (unless (eq symbol basevar) | |
1138 | (message "`%s' is an alias for `%s'" symbol basevar)))) | |
ffec8c5a | 1139 | |
bba50f8a | 1140 | (defvar customize-changed-options-previous-release "21.1" |
e418be26 KH |
1141 | "Version for `customize-changed-options' to refer back to by default.") |
1142 | ||
4e9c705e BW |
1143 | ;; Packages will update this variable, so make it available. |
1144 | ;;;###autoload | |
1145 | (defvar customize-package-emacs-version-alist nil | |
7eb944cf RS |
1146 | "Alist mapping versions of a package to Emacs versions. |
1147 | We use this for packages that have their own names, but are released | |
1148 | as part of Emacs itself. | |
1149 | ||
1150 | Each elements looks like this: | |
994019df BW |
1151 | |
1152 | (PACKAGE (PVERSION . EVERSION)...) | |
1153 | ||
7eb944cf RS |
1154 | Here PACKAGE is the name of a package, as a symbol. After |
1155 | PACKAGE come one or more elements, each associating a | |
1156 | package version PVERSION with the first Emacs version | |
1157 | EVERSION in which it (or a subsequent version of PACKAGE) | |
1158 | was first released. Both PVERSION and EVERSION are strings. | |
1159 | PVERSION should be a string that this package used in | |
1160 | the :package-version keyword for `defcustom', `defgroup', | |
1161 | and `defface'. | |
1162 | ||
1163 | For example, the MH-E package updates this alist as follows: | |
994019df BW |
1164 | |
1165 | (add-to-list 'customize-package-emacs-version-alist | |
1166 | '(MH-E (\"6.0\" . \"22.1\") (\"6.1\" . \"22.1\") | |
1167 | (\"7.0\" . \"22.1\") (\"7.1\" . \"22.1\") | |
1168 | (\"7.2\" . \"22.1\") (\"7.3\" . \"22.1\") | |
1169 | (\"7.4\" . \"22.1\") (\"8.0\" . \"22.1\"))) | |
1170 | ||
1171 | The value of PACKAGE needs to be unique and it needs to match the | |
1172 | PACKAGE value appearing in the :package-version keyword. Since | |
1173 | the user might see the value in a error message, a good choice is | |
1174 | the official name of the package, such as MH-E or Gnus.") | |
4e9c705e | 1175 | |
bba50f8a RS |
1176 | ;;;###autoload |
1177 | (defalias 'customize-changed 'customize-changed-options) | |
1178 | ||
c32de15e | 1179 | ;;;###autoload |
8c89fb87 | 1180 | (defun customize-changed-options (&optional since-version) |
bba50f8a | 1181 | "Customize all settings whose meanings have changed in Emacs itself. |
e418be26 | 1182 | This includes new user option variables and faces, and new |
bba50f8a RS |
1183 | customization groups, as well as older options and faces whose meanings |
1184 | or default values have changed since the previous major Emacs release. | |
e418be26 | 1185 | |
bba50f8a RS |
1186 | With argument SINCE-VERSION (a string), customize all settings |
1187 | that were added or redefined since that version." | |
e418be26 | 1188 | |
2071d184 LT |
1189 | (interactive |
1190 | (list | |
1191 | (read-from-minibuffer | |
1192 | (format "Customize options changed, since version (default %s): " | |
1193 | customize-changed-options-previous-release)))) | |
f50dc5d2 | 1194 | (if (equal since-version "") |
26c67de8 DL |
1195 | (setq since-version nil) |
1196 | (unless (condition-case nil | |
1197 | (numberp (read since-version)) | |
1198 | (error nil)) | |
1199 | (signal 'wrong-type-argument (list 'numberp since-version)))) | |
e418be26 KH |
1200 | (unless since-version |
1201 | (setq since-version customize-changed-options-previous-release)) | |
cba752d0 MR |
1202 | |
1203 | ;; Load the information for versions since since-version. We use | |
1204 | ;; custom-load-symbol for this. | |
1205 | (put 'custom-versions-load-alist 'custom-loads nil) | |
1206 | (dolist (elt custom-versions-load-alist) | |
2ee398c4 MR |
1207 | (if (customize-version-lessp since-version (car elt)) |
1208 | (dolist (load (cdr elt)) | |
1209 | (custom-add-load 'custom-versions-load-alist load)))) | |
cba752d0 MR |
1210 | (custom-load-symbol 'custom-versions-load-alist) |
1211 | (put 'custom-versions-load-alist 'custom-loads nil) | |
1212 | ||
1213 | (let (found) | |
1214 | (mapatoms | |
1215 | (lambda (symbol) | |
4e9c705e BW |
1216 | (let* ((package-version (get symbol 'custom-package-version)) |
1217 | (version | |
1218 | (or (and package-version | |
1219 | (customize-package-emacs-version symbol | |
1220 | package-version)) | |
1221 | (get symbol 'custom-version)))) | |
cba752d0 MR |
1222 | (if version |
1223 | (when (customize-version-lessp since-version version) | |
1224 | (if (or (get symbol 'custom-group) | |
1225 | (get symbol 'group-documentation)) | |
1226 | (push (list symbol 'custom-group) found)) | |
1227 | (if (custom-variable-p symbol) | |
1228 | (push (list symbol 'custom-variable) found)) | |
1229 | (if (custom-facep symbol) | |
1230 | (push (list symbol 'custom-face) found))))))) | |
1231 | (if found | |
1232 | (custom-buffer-create (custom-sort-items found t 'first) | |
1233 | "*Customize Changed Options*") | |
1234 | (error "No user option defaults have been changed since Emacs %s" | |
1235 | since-version)))) | |
f50dc5d2 | 1236 | |
4e9c705e | 1237 | (defun customize-package-emacs-version (symbol package-version) |
7eb944cf RS |
1238 | "Return the Emacs version in which SYMBOL's meaning last changed. |
1239 | PACKAGE-VERSION has the form (PACKAGE . VERSION). We use | |
4e9c705e | 1240 | `customize-package-emacs-version-alist' to find the version of |
7eb944cf | 1241 | Emacs that is associated with version VERSION of PACKAGE." |
4e9c705e BW |
1242 | (let (package-versions emacs-version) |
1243 | ;; Use message instead of error since we want user to be able to | |
1244 | ;; see the rest of the symbols even if a package author has | |
1245 | ;; botched things up. | |
1246 | (cond ((not (listp package-version)) | |
1247 | (message "Invalid package-version value for %s" symbol)) | |
1248 | ((setq package-versions (assq (car package-version) | |
1249 | customize-package-emacs-version-alist)) | |
1250 | (setq emacs-version | |
994019df | 1251 | (cdr (assoc (cdr package-version) package-versions))) |
4e9c705e | 1252 | (unless emacs-version |
994019df BW |
1253 | (message "%s version %s not found in %s" symbol |
1254 | (cdr package-version) | |
4e9c705e BW |
1255 | "customize-package-emacs-version-alist"))) |
1256 | (t | |
7eb944cf | 1257 | (message "Package %s version %s lists no corresponding Emacs version" |
4e9c705e | 1258 | (car package-version) |
7eb944cf | 1259 | (cdr package-version)))) |
4e9c705e BW |
1260 | emacs-version)) |
1261 | ||
f50dc5d2 | 1262 | (defun customize-version-lessp (version1 version2) |
26c67de8 DL |
1263 | ;; Why are the versions strings, and given that they are, why aren't |
1264 | ;; they converted to numbers and compared as such here? -- fx | |
1265 | ||
e418be26 KH |
1266 | ;; In case someone made a mistake and left out the quotes |
1267 | ;; in the :version value. | |
1268 | (if (numberp version2) | |
1269 | (setq version2 (prin1-to-string version2))) | |
f50dc5d2 | 1270 | (let (major1 major2 minor1 minor2) |
26c67de8 DL |
1271 | (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version1) |
1272 | (setq major1 (read (or (match-string 1 version1) | |
1273 | "0"))) | |
1274 | (setq minor1 (read (or (match-string 3 version1) | |
1275 | "0"))) | |
1276 | (string-match "\\([0-9]+\\)\\(\\.\\([0-9]+\\)\\)?" version2) | |
1277 | (setq major2 (read (or (match-string 1 version2) | |
1278 | "0"))) | |
1279 | (setq minor2 (read (or (match-string 3 version2) | |
1280 | "0"))) | |
f50dc5d2 KH |
1281 | (or (< major1 major2) |
1282 | (and (= major1 major2) | |
1283 | (< minor1 minor2))))) | |
c942535f | 1284 | |
d543e20b | 1285 | ;;;###autoload |
a0247dcf | 1286 | (defun customize-face (&optional face) |
3127aa13 | 1287 | "Customize FACE, which should be a face name or nil. |
c40f3193 GM |
1288 | If FACE is nil, customize all faces. If FACE is actually a |
1289 | face-alias, customize the face it is aliased to. | |
d29a536a GM |
1290 | |
1291 | Interactively, when point is on text which has a face specified, | |
3127aa13 | 1292 | suggest to customize that face, if it's customizable." |
a0247dcf | 1293 | (interactive (list (read-face-name "Customize face" "all faces" t))) |
cdd50dea RS |
1294 | (if (member face '(nil "")) |
1295 | (setq face (face-list))) | |
1296 | (if (and (listp face) (null (cdr face))) | |
1297 | (setq face (car face))) | |
a0247dcf SM |
1298 | (if (listp face) |
1299 | (custom-buffer-create | |
1300 | (custom-sort-items | |
1301 | (mapcar (lambda (s) (list s 'custom-face)) face) | |
1302 | t nil) | |
1303 | "*Customize Faces*") | |
1304 | ;; If FACE is actually an alias, customize the face it is aliased to. | |
1305 | (if (get face 'face-alias) | |
1306 | (setq face (get face 'face-alias))) | |
1307 | (unless (facep face) | |
1308 | (error "Invalid face %S" face)) | |
1309 | (custom-buffer-create | |
1310 | (list (list face 'custom-face)) | |
1311 | (format "*Customize Face: %s*" | |
1312 | (custom-unlispify-tag-name face))))) | |
d543e20b | 1313 | |
bd042c03 | 1314 | ;;;###autoload |
701f49d2 | 1315 | (defun customize-face-other-window (&optional face) |
3127aa13 | 1316 | "Show customization buffer for face FACE in other window. |
c40f3193 | 1317 | If FACE is actually a face-alias, customize the face it is aliased to. |
d29a536a GM |
1318 | |
1319 | Interactively, when point is on text which has a face specified, | |
3127aa13 | 1320 | suggest to customize that face, if it's customizable." |
a0247dcf SM |
1321 | (interactive (list (read-face-name "Customize face" "all faces" t))) |
1322 | (let ((pop-up-windows t) | |
1323 | (same-window-buffer-names nil) | |
1324 | (same-window-regexps nil)) | |
1325 | (customize-face face))) | |
bd042c03 | 1326 | |
0b97da8f RS |
1327 | (defalias 'customize-customized 'customize-unsaved) |
1328 | ||
d543e20b | 1329 | ;;;###autoload |
0b97da8f RS |
1330 | (defun customize-unsaved () |
1331 | "Customize all user options set in this session but not saved." | |
6d528fc5 PA |
1332 | (interactive) |
1333 | (let ((found nil)) | |
1334 | (mapatoms (lambda (symbol) | |
d3d4df42 DL |
1335 | (and (or (get symbol 'customized-face) |
1336 | (get symbol 'customized-face-comment)) | |
6d528fc5 | 1337 | (custom-facep symbol) |
a1a4fa22 | 1338 | (push (list symbol 'custom-face) found)) |
d3d4df42 DL |
1339 | (and (or (get symbol 'customized-value) |
1340 | (get symbol 'customized-variable-comment)) | |
6d528fc5 | 1341 | (boundp symbol) |
a1a4fa22 | 1342 | (push (list symbol 'custom-variable) found)))) |
da5ec617 | 1343 | (if (not found) |
0b97da8f | 1344 | (error "No user options are set but unsaved") |
da5ec617 | 1345 | (custom-buffer-create (custom-sort-items found t nil) |
0b97da8f | 1346 | "*Customize Unsaved*")))) |
6d528fc5 PA |
1347 | |
1348 | ;;;###autoload | |
963c2e09 | 1349 | (defun customize-rogue () |
c111d7ae | 1350 | "Customize all user variables modified outside customize." |
963c2e09 PA |
1351 | (interactive) |
1352 | (let ((found nil)) | |
1353 | (mapatoms (lambda (symbol) | |
1354 | (let ((cval (or (get symbol 'customized-value) | |
1355 | (get symbol 'saved-value) | |
1356 | (get symbol 'standard-value)))) | |
1357 | (when (and cval ;Declared with defcustom. | |
1358 | (default-boundp symbol) ;Has a value. | |
3127aa13 | 1359 | (not (equal (eval (car cval)) |
963c2e09 PA |
1360 | ;; Which does not match customize. |
1361 | (default-value symbol)))) | |
1362 | (push (list symbol 'custom-variable) found))))) | |
1363 | (if (not found) | |
1364 | (error "No rogue user options") | |
1365 | (custom-buffer-create (custom-sort-items found t nil) | |
1366 | "*Customize Rogue*")))) | |
1367 | ;;;###autoload | |
6d528fc5 PA |
1368 | (defun customize-saved () |
1369 | "Customize all already saved user options." | |
d543e20b PA |
1370 | (interactive) |
1371 | (let ((found nil)) | |
1372 | (mapatoms (lambda (symbol) | |
d3d4df42 DL |
1373 | (and (or (get symbol 'saved-face) |
1374 | (get symbol 'saved-face-comment)) | |
d543e20b | 1375 | (custom-facep symbol) |
a1a4fa22 | 1376 | (push (list symbol 'custom-face) found)) |
d3d4df42 DL |
1377 | (and (or (get symbol 'saved-value) |
1378 | (get symbol 'saved-variable-comment)) | |
d543e20b | 1379 | (boundp symbol) |
a1a4fa22 | 1380 | (push (list symbol 'custom-variable) found)))) |
da5ec617 PA |
1381 | (if (not found ) |
1382 | (error "No saved user options") | |
1383 | (custom-buffer-create (custom-sort-items found t nil) | |
1384 | "*Customize Saved*")))) | |
d543e20b PA |
1385 | |
1386 | ;;;###autoload | |
1387 | (defun customize-apropos (regexp &optional all) | |
0322b9c3 | 1388 | "Customize all loaded options, faces and groups matching REGEXP. |
a1a4fa22 PA |
1389 | If ALL is `options', include only options. |
1390 | If ALL is `faces', include only faces. | |
1391 | If ALL is `groups', include only groups. | |
27b87810 | 1392 | If ALL is t (interactively, with prefix arg), include variables |
06cdb5db LT |
1393 | that are not customizable options, as well as faces and groups |
1394 | \(but we recommend using `apropos-variable' instead)." | |
bd18cd19 | 1395 | (interactive "sCustomize (regexp): \nP") |
d543e20b PA |
1396 | (let ((found nil)) |
1397 | (mapatoms (lambda (symbol) | |
1398 | (when (string-match regexp (symbol-name symbol)) | |
a1a4fa22 PA |
1399 | (when (and (not (memq all '(faces options))) |
1400 | (get symbol 'custom-group)) | |
1401 | (push (list symbol 'custom-group) found)) | |
1402 | (when (and (not (memq all '(options groups))) | |
1403 | (custom-facep symbol)) | |
1404 | (push (list symbol 'custom-face) found)) | |
1405 | (when (and (not (memq all '(groups faces))) | |
1406 | (boundp symbol) | |
27b87810 | 1407 | (eq (indirect-variable symbol) symbol) |
d543e20b | 1408 | (or (get symbol 'saved-value) |
3a495e15 | 1409 | (custom-variable-p symbol) |
27b87810 LT |
1410 | (and (not (memq all '(nil options))) |
1411 | (get symbol 'variable-documentation)))) | |
a1a4fa22 PA |
1412 | (push (list symbol 'custom-variable) found))))) |
1413 | (if (not found) | |
da435d1c GM |
1414 | (error "No %s matching %s" |
1415 | (if (eq all t) | |
1416 | "items" | |
1417 | (format "customizable %s" | |
1418 | (if (memq all '(options faces groups)) | |
1419 | (symbol-name all) | |
1420 | "items"))) | |
1421 | regexp) | |
81711dba EZ |
1422 | (custom-buffer-create |
1423 | (custom-sort-items found t custom-buffer-order-groups) | |
1424 | "*Customize Apropos*")))) | |
a1a4fa22 PA |
1425 | |
1426 | ;;;###autoload | |
1427 | (defun customize-apropos-options (regexp &optional arg) | |
0322b9c3 | 1428 | "Customize all loaded customizable options matching REGEXP. |
06cdb5db | 1429 | With prefix arg, include variables that are not customizable options |
8ed10e73 | 1430 | \(but it is better to use `apropos-variable' if you want to find those)." |
bd18cd19 | 1431 | (interactive "sCustomize options (regexp): \nP") |
a1a4fa22 PA |
1432 | (customize-apropos regexp (or arg 'options))) |
1433 | ||
1434 | ;;;###autoload | |
1435 | (defun customize-apropos-faces (regexp) | |
0322b9c3 | 1436 | "Customize all loaded faces matching REGEXP." |
bd18cd19 | 1437 | (interactive "sCustomize faces (regexp): \n") |
a1a4fa22 PA |
1438 | (customize-apropos regexp 'faces)) |
1439 | ||
1440 | ;;;###autoload | |
1441 | (defun customize-apropos-groups (regexp) | |
0322b9c3 | 1442 | "Customize all loaded groups matching REGEXP." |
bd18cd19 | 1443 | (interactive "sCustomize groups (regexp): \n") |
a1a4fa22 | 1444 | (customize-apropos regexp 'groups)) |
d543e20b | 1445 | |
6d528fc5 PA |
1446 | ;;; Buffer. |
1447 | ||
944c91b6 PA |
1448 | (defcustom custom-buffer-style 'links |
1449 | "Control the presentation style for customization buffers. | |
1450 | The value should be a symbol, one of: | |
1451 | ||
1452 | brackets: groups nest within each other with big horizontal brackets. | |
1453 | links: groups have links to subgroups." | |
1454 | :type '(radio (const brackets) | |
1455 | (const links)) | |
1456 | :group 'custom-buffer) | |
1457 | ||
97733c3d RS |
1458 | (defcustom custom-buffer-done-kill nil |
1459 | "*Non-nil means exiting a Custom buffer should kill it." | |
1460 | :type 'boolean | |
bf247b6e | 1461 | :version "22.1" |
d3d4df42 DL |
1462 | :group 'custom-buffer) |
1463 | ||
944c91b6 PA |
1464 | (defcustom custom-buffer-indent 3 |
1465 | "Number of spaces to indent nested groups." | |
1466 | :type 'integer | |
1467 | :group 'custom-buffer) | |
1468 | ||
40627755 SM |
1469 | (defun custom-get-fresh-buffer (name) |
1470 | "Get a fresh new buffer with name NAME. | |
a153acb7 SM |
1471 | If the buffer already exist, clean it up to be like new. |
1472 | Beware: it's not quite like new. Good enough for custom, but maybe | |
1473 | not for everybody." | |
1474 | ;; To be more complete, we should also kill all permanent-local variables, | |
1475 | ;; but it's not needed for custom. | |
40627755 | 1476 | (let ((buf (get-buffer name))) |
fd1c38f4 | 1477 | (when (and buf (buffer-local-value 'buffer-file-name buf)) |
a153acb7 SM |
1478 | ;; This will check if the file is not saved. |
1479 | (kill-buffer buf) | |
1480 | (setq buf nil)) | |
40627755 SM |
1481 | (if (null buf) |
1482 | (get-buffer-create name) | |
1483 | (with-current-buffer buf | |
1484 | (kill-all-local-variables) | |
a153acb7 | 1485 | (run-hooks 'kill-buffer-hook) |
f5a9b180 SM |
1486 | ;; Delete overlays before erasing the buffer so the overlay hooks |
1487 | ;; don't get run spuriously when we erase the buffer. | |
40627755 SM |
1488 | (let ((ols (overlay-lists))) |
1489 | (dolist (ol (nconc (car ols) (cdr ols))) | |
1490 | (delete-overlay ol))) | |
f5a9b180 | 1491 | (erase-buffer) |
40627755 SM |
1492 | buf)))) |
1493 | ||
d543e20b | 1494 | ;;;###autoload |
3aec85bf | 1495 | (defun custom-buffer-create (options &optional name description) |
d543e20b | 1496 | "Create a buffer containing OPTIONS. |
86bd10bc | 1497 | Optional NAME is the name of the buffer. |
d543e20b PA |
1498 | OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where |
1499 | SYMBOL is a customization option, and WIDGET is a widget for editing | |
1500 | that option." | |
40627755 | 1501 | (pop-to-buffer (custom-get-fresh-buffer (or name "*Customization*"))) |
3aec85bf | 1502 | (custom-buffer-create-internal options description)) |
bd042c03 | 1503 | |
6d528fc5 | 1504 | ;;;###autoload |
3aec85bf | 1505 | (defun custom-buffer-create-other-window (options &optional name description) |
5f97a49d RS |
1506 | "Create a buffer containing OPTIONS, and display it in another window. |
1507 | The result includes selecting that window. | |
86bd10bc | 1508 | Optional NAME is the name of the buffer. |
bd042c03 PA |
1509 | OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where |
1510 | SYMBOL is a customization option, and WIDGET is a widget for editing | |
1511 | that option." | |
86bd10bc | 1512 | (unless name (setq name "*Customization*")) |
5f97a49d | 1513 | (let ((pop-up-windows t) |
b4854a23 KH |
1514 | (same-window-buffer-names nil) |
1515 | (same-window-regexps nil)) | |
40627755 | 1516 | (pop-to-buffer (custom-get-fresh-buffer name)) |
5f97a49d | 1517 | (custom-buffer-create-internal options description))) |
9097aeb7 PA |
1518 | |
1519 | (defcustom custom-reset-button-menu nil | |
1520 | "If non-nil, only show a single reset button in customize buffers. | |
1521 | This button will have a menu with all three reset operations." | |
1522 | :type 'boolean | |
6aaedd12 | 1523 | :group 'custom-buffer) |
bd042c03 | 1524 | |
c42c5c7c KS |
1525 | (defcustom custom-buffer-verbose-help t |
1526 | "If non-nil, include explanatory text in the customization buffer." | |
1527 | :type 'boolean | |
1528 | :group 'custom-buffer) | |
1529 | ||
d3d4df42 | 1530 | (defun Custom-buffer-done (&rest ignore) |
97733c3d | 1531 | "Exit current Custom buffer according to `custom-buffer-done-kill'." |
d3d4df42 | 1532 | (interactive) |
97733c3d | 1533 | (quit-window custom-buffer-done-kill)) |
d3d4df42 | 1534 | |
87911bdb CY |
1535 | (defvar custom-button nil |
1536 | "Face used for buttons in customization buffers.") | |
1537 | ||
85a5eb0e CY |
1538 | (defvar custom-button-mouse nil |
1539 | "Mouse face used for buttons in customization buffers.") | |
1540 | ||
87911bdb CY |
1541 | (defvar custom-button-pressed nil |
1542 | "Face used for pressed buttons in customization buffers.") | |
1543 | ||
d3d4df42 DL |
1544 | (defcustom custom-raised-buttons (not (equal (face-valid-attribute-values :box) |
1545 | '(("unspecified" . unspecified)))) | |
1546 | "If non-nil, indicate active buttons in a `raised-button' style. | |
1547 | Otherwise use brackets." | |
1548 | :type 'boolean | |
1549 | :version "21.1" | |
87911bdb CY |
1550 | :group 'custom-buffer |
1551 | :set (lambda (variable value) | |
1552 | (custom-set-default variable value) | |
1553 | (setq custom-button | |
1554 | (if value 'custom-button 'custom-button-unraised)) | |
85a5eb0e CY |
1555 | (setq custom-button-mouse |
1556 | (if value 'custom-button-mouse 'highlight)) | |
87911bdb CY |
1557 | (setq custom-button-pressed |
1558 | (if value | |
1559 | 'custom-button-pressed | |
1560 | 'custom-button-pressed-unraised)))) | |
d3d4df42 | 1561 | |
3aec85bf | 1562 | (defun custom-buffer-create-internal (options &optional description) |
6aec3b9d | 1563 | (Custom-mode) |
9db1942d CY |
1564 | (let ((init-file (or custom-file user-init-file))) |
1565 | ;; Insert verbose help at the top of the custom buffer. | |
1566 | (when custom-buffer-verbose-help | |
1567 | (widget-insert "Editing a setting changes only the text in this buffer." | |
1568 | (if init-file | |
1569 | " | |
5ae87ed4 | 1570 | To apply your changes, use the Save or Set buttons. |
9db1942d CY |
1571 | Saving a change normally works by editing your init file." |
1572 | " | |
1573 | Currently, these settings cannot be saved for future Emacs sessions, | |
1574 | possibly because you started Emacs with `-q'.") | |
1575 | "\nFor details, see ") | |
1576 | (widget-create 'custom-manual | |
1577 | :tag "Saving Customizations" | |
1578 | "(emacs)Saving Customizations") | |
1579 | (widget-insert " in the ") | |
1580 | (widget-create 'custom-manual | |
1581 | :tag "Emacs manual" | |
1582 | :help-echo "Read the Emacs manual." | |
1583 | "(emacs)Top") | |
1584 | (widget-insert ".")) | |
1585 | ;; Insert custom command buttons if the toolbar is not in use. | |
1586 | ||
1587 | (widget-insert "\n") | |
d0da8f91 GM |
1588 | ;; tool-bar is not dumped in builds without x. |
1589 | (when (not (and (bound-and-true-p tool-bar-mode) (display-graphic-p))) | |
9db1942d CY |
1590 | (if custom-buffer-verbose-help |
1591 | (widget-insert "\n | |
1592 | Operate on all settings in this buffer that are not marked HIDDEN:\n")) | |
1593 | (let ((button (lambda (tag action active help icon) | |
1594 | (widget-insert " ") | |
1595 | (if (eval active) | |
1596 | (widget-create 'push-button :tag tag | |
1597 | :help-echo help :action action)))) | |
1598 | (commands custom-commands)) | |
1599 | (apply button (pop commands)) ; Set for current session | |
1600 | (apply button (pop commands)) ; Save for future sessions | |
1601 | (if custom-reset-button-menu | |
1602 | (progn | |
1603 | (widget-insert " ") | |
1604 | (widget-create 'push-button | |
1605 | :tag "Reset buffer" | |
1606 | :help-echo "Show a menu with reset operations." | |
1607 | :mouse-down-action 'ignore | |
1608 | :action 'custom-reset)) | |
1609 | (widget-insert "\n") | |
1610 | (apply button (pop commands)) ; Undo edits | |
1611 | (apply button (pop commands)) ; Reset to saved | |
1612 | (apply button (pop commands)) ; Erase customization | |
1613 | (widget-insert " ") | |
1614 | (pop commands) ; Help (omitted) | |
1615 | (apply button (pop commands))))) ; Exit | |
1616 | (widget-insert "\n\n")) | |
1617 | ||
1618 | ;; Now populate the custom buffer. | |
25ac13b5 | 1619 | (message "Creating customization items...") |
fadbdfea | 1620 | (buffer-disable-undo) |
d3d4df42 | 1621 | (setq custom-options |
d543e20b PA |
1622 | (if (= (length options) 1) |
1623 | (mapcar (lambda (entry) | |
1624 | (widget-create (nth 1 entry) | |
c32de15e | 1625 | :documentation-shown t |
d543e20b PA |
1626 | :custom-state 'unknown |
1627 | :tag (custom-unlispify-tag-name | |
1628 | (nth 0 entry)) | |
1629 | :value (nth 0 entry))) | |
1630 | options) | |
1631 | (let ((count 0) | |
1632 | (length (length options))) | |
1633 | (mapcar (lambda (entry) | |
6b292312 DL |
1634 | (prog2 |
1635 | (message "Creating customization items ...%2d%%" | |
1636 | (/ (* 100.0 count) length)) | |
1637 | (widget-create (nth 1 entry) | |
d543e20b PA |
1638 | :tag (custom-unlispify-tag-name |
1639 | (nth 0 entry)) | |
1640 | :value (nth 0 entry)) | |
6b292312 DL |
1641 | (setq count (1+ count)) |
1642 | (unless (eq (preceding-char) ?\n) | |
1643 | (widget-insert "\n")) | |
1644 | (widget-insert "\n"))) | |
1645 | options)))) | |
d543e20b PA |
1646 | (unless (eq (preceding-char) ?\n) |
1647 | (widget-insert "\n")) | |
a9bcbf3f | 1648 | (message "Creating customization items ...done") |
1833b7b3 | 1649 | (message "Resetting customization items...") |
944c91b6 | 1650 | (unless (eq custom-buffer-style 'tree) |
fadbdfea | 1651 | (mapc 'custom-magic-reset custom-options)) |
1833b7b3 | 1652 | (message "Resetting customization items...done") |
d543e20b PA |
1653 | (message "Creating customization setup...") |
1654 | (widget-setup) | |
fadbdfea | 1655 | (buffer-enable-undo) |
d543e20b | 1656 | (goto-char (point-min)) |
1833b7b3 | 1657 | (message "Creating customization setup...done")) |
d543e20b | 1658 | |
944c91b6 PA |
1659 | ;;; The Tree Browser. |
1660 | ||
1661 | ;;;###autoload | |
4ee1cf9f | 1662 | (defun customize-browse (&optional group) |
944c91b6 | 1663 | "Create a tree browser for the customize hierarchy." |
cda987f4 | 1664 | (interactive) |
4ee1cf9f PA |
1665 | (unless group |
1666 | (setq group 'emacs)) | |
1667 | (let ((name "*Customize Browser*")) | |
40627755 | 1668 | (pop-to-buffer (custom-get-fresh-buffer name))) |
6aec3b9d | 1669 | (Custom-mode) |
b758ae9a RS |
1670 | (widget-insert (format "\ |
1671 | %s buttons; type RET or click mouse-1 | |
1672 | on a button to invoke its action. | |
1673 | Invoke [+] to expand a group, and [-] to collapse an expanded group.\n" | |
1674 | (if custom-raised-buttons | |
1675 | "`Raised' text indicates" | |
1676 | "Square brackets indicate"))) | |
1677 | ||
1678 | ||
4ee1cf9f PA |
1679 | (if custom-browse-only-groups |
1680 | (widget-insert "\ | |
c953515e | 1681 | Invoke the [Group] button below to edit that item in another window.\n\n") |
d3d4df42 DL |
1682 | (widget-insert "Invoke the ") |
1683 | (widget-create 'item | |
4ee1cf9f PA |
1684 | :format "%t" |
1685 | :tag "[Group]" | |
1686 | :tag-glyph "folder") | |
1687 | (widget-insert ", ") | |
d3d4df42 | 1688 | (widget-create 'item |
4ee1cf9f PA |
1689 | :format "%t" |
1690 | :tag "[Face]" | |
1691 | :tag-glyph "face") | |
1692 | (widget-insert ", and ") | |
d3d4df42 | 1693 | (widget-create 'item |
4ee1cf9f PA |
1694 | :format "%t" |
1695 | :tag "[Option]" | |
1696 | :tag-glyph "option") | |
1697 | (widget-insert " buttons below to edit that | |
c953515e | 1698 | item in another window.\n\n")) |
4ee1cf9f | 1699 | (let ((custom-buffer-style 'tree)) |
d3d4df42 | 1700 | (widget-create 'custom-group |
4ee1cf9f PA |
1701 | :custom-last t |
1702 | :custom-state 'unknown | |
1703 | :tag (custom-unlispify-tag-name group) | |
1704 | :value group)) | |
f134b461 | 1705 | (widget-setup) |
4ee1cf9f | 1706 | (goto-char (point-min))) |
944c91b6 | 1707 | |
c953515e | 1708 | (define-widget 'custom-browse-visibility 'item |
1edec9cf | 1709 | "Control visibility of items in the customize tree browser." |
da5ec617 | 1710 | :format "%[[%t]%]" |
c953515e | 1711 | :action 'custom-browse-visibility-action) |
944c91b6 | 1712 | |
c953515e | 1713 | (defun custom-browse-visibility-action (widget &rest ignore) |
944c91b6 PA |
1714 | (let ((custom-buffer-style 'tree)) |
1715 | (custom-toggle-parent widget))) | |
1716 | ||
192e44fc | 1717 | (define-widget 'custom-browse-group-tag 'custom-group-link |
944c91b6 | 1718 | "Show parent in other window when activated." |
cd6c0940 | 1719 | :tag "Group" |
da5ec617 | 1720 | :tag-glyph "folder" |
c953515e | 1721 | :action 'custom-browse-group-tag-action) |
944c91b6 | 1722 | |
c953515e | 1723 | (defun custom-browse-group-tag-action (widget &rest ignore) |
944c91b6 PA |
1724 | (let ((parent (widget-get widget :parent))) |
1725 | (customize-group-other-window (widget-value parent)))) | |
1726 | ||
192e44fc | 1727 | (define-widget 'custom-browse-variable-tag 'custom-group-link |
944c91b6 | 1728 | "Show parent in other window when activated." |
cd6c0940 | 1729 | :tag "Option" |
da5ec617 | 1730 | :tag-glyph "option" |
c953515e | 1731 | :action 'custom-browse-variable-tag-action) |
944c91b6 | 1732 | |
c953515e | 1733 | (defun custom-browse-variable-tag-action (widget &rest ignore) |
944c91b6 PA |
1734 | (let ((parent (widget-get widget :parent))) |
1735 | (customize-variable-other-window (widget-value parent)))) | |
1736 | ||
192e44fc | 1737 | (define-widget 'custom-browse-face-tag 'custom-group-link |
944c91b6 | 1738 | "Show parent in other window when activated." |
cd6c0940 | 1739 | :tag "Face" |
da5ec617 | 1740 | :tag-glyph "face" |
c953515e | 1741 | :action 'custom-browse-face-tag-action) |
944c91b6 | 1742 | |
c953515e | 1743 | (defun custom-browse-face-tag-action (widget &rest ignore) |
944c91b6 PA |
1744 | (let ((parent (widget-get widget :parent))) |
1745 | (customize-face-other-window (widget-value parent)))) | |
1746 | ||
c953515e | 1747 | (defconst custom-browse-alist '((" " "space") |
da5ec617 PA |
1748 | (" | " "vertical") |
1749 | ("-\\ " "top") | |
1750 | (" |-" "middle") | |
1751 | (" `-" "bottom"))) | |
1752 | ||
c953515e | 1753 | (defun custom-browse-insert-prefix (prefix) |
da5ec617 | 1754 | "Insert PREFIX. On XEmacs convert it to line graphics." |
d3d4df42 | 1755 | ;; Fixme: do graphics. |
a7f58f4b | 1756 | (if nil ; (featurep 'xemacs) |
d3d4df42 | 1757 | (progn |
da5ec617 PA |
1758 | (insert "*") |
1759 | (while (not (string-equal prefix "")) | |
1760 | (let ((entry (substring prefix 0 3))) | |
1761 | (setq prefix (substring prefix 3)) | |
1762 | (let ((overlay (make-overlay (1- (point)) (point) nil t nil)) | |
c953515e | 1763 | (name (nth 1 (assoc entry custom-browse-alist)))) |
da5ec617 PA |
1764 | (overlay-put overlay 'end-glyph (widget-glyph-find name entry)) |
1765 | (overlay-put overlay 'start-open t) | |
1766 | (overlay-put overlay 'end-open t))))) | |
1767 | (insert prefix))) | |
1768 | ||
d543e20b PA |
1769 | ;;; Modification of Basic Widgets. |
1770 | ;; | |
1771 | ;; We add extra properties to the basic widgets needed here. This is | |
62a918ca | 1772 | ;; fine, as long as we are careful to stay within our own namespace. |
d543e20b PA |
1773 | ;; |
1774 | ;; We want simple widgets to be displayed by default, but complex | |
1775 | ;; widgets to be hidden. | |
1776 | ||
1777 | (widget-put (get 'item 'widget-type) :custom-show t) | |
1778 | (widget-put (get 'editable-field 'widget-type) | |
1779 | :custom-show (lambda (widget value) | |
1780 | (let ((pp (pp-to-string value))) | |
1781 | (cond ((string-match "\n" pp) | |
1782 | nil) | |
1783 | ((> (length pp) 40) | |
1784 | nil) | |
1785 | (t t))))) | |
1786 | (widget-put (get 'menu-choice 'widget-type) :custom-show t) | |
1787 | ||
1788 | ;;; The `custom-manual' Widget. | |
1789 | ||
1790 | (define-widget 'custom-manual 'info-link | |
1791 | "Link to the manual entry for this customization option." | |
1792 | :help-echo "Read the manual entry for this option." | |
f3093f77 CY |
1793 | :keymap custom-mode-link-map |
1794 | :follow-link 'mouse-face | |
73e60f53 CY |
1795 | :button-face 'custom-link |
1796 | :mouse-face 'highlight | |
e1ec62a5 | 1797 | :pressed-face 'highlight |
d543e20b PA |
1798 | :tag "Manual") |
1799 | ||
1800 | ;;; The `custom-magic' Widget. | |
1801 | ||
6aaedd12 PA |
1802 | (defgroup custom-magic-faces nil |
1803 | "Faces used by the magic button." | |
1804 | :group 'custom-faces | |
1805 | :group 'custom-buffer) | |
1806 | ||
d478e69d MB |
1807 | (defface custom-invalid '((((class color)) |
1808 | (:foreground "yellow1" :background "red1")) | |
1809 | (t | |
1810 | (:weight bold :slant italic :underline t))) | |
6aaedd12 PA |
1811 | "Face used when the customize item is invalid." |
1812 | :group 'custom-magic-faces) | |
d478e69d MB |
1813 | ;; backward-compatibility alias |
1814 | (put 'custom-invalid-face 'face-alias 'custom-invalid) | |
d543e20b | 1815 | |
d478e69d MB |
1816 | (defface custom-rogue '((((class color)) |
1817 | (:foreground "pink" :background "black")) | |
1818 | (t | |
1819 | (:underline t))) | |
6aaedd12 PA |
1820 | "Face used when the customize item is not defined for customization." |
1821 | :group 'custom-magic-faces) | |
d478e69d MB |
1822 | ;; backward-compatibility alias |
1823 | (put 'custom-rogue-face 'face-alias 'custom-rogue) | |
d543e20b | 1824 | |
d478e69d MB |
1825 | (defface custom-modified '((((min-colors 88) (class color)) |
1826 | (:foreground "white" :background "blue1")) | |
ea81d57e | 1827 | (((class color)) |
d478e69d | 1828 | (:foreground "white" :background "blue")) |
2dfa4c57 | 1829 | (t |
d478e69d MB |
1830 | (:slant italic :bold))) |
1831 | "Face used when the customize item has been modified." | |
1832 | :group 'custom-magic-faces) | |
1833 | ;; backward-compatibility alias | |
1834 | (put 'custom-modified-face 'face-alias 'custom-modified) | |
1835 | ||
1836 | (defface custom-set '((((min-colors 88) (class color)) | |
1837 | (:foreground "blue1" :background "white")) | |
1838 | (((class color)) | |
1839 | (:foreground "blue" :background "white")) | |
1840 | (t | |
1841 | (:slant italic))) | |
6aaedd12 PA |
1842 | "Face used when the customize item has been set." |
1843 | :group 'custom-magic-faces) | |
d478e69d MB |
1844 | ;; backward-compatibility alias |
1845 | (put 'custom-set-face 'face-alias 'custom-set) | |
1846 | ||
1847 | (defface custom-changed '((((min-colors 88) (class color)) | |
1848 | (:foreground "white" :background "blue1")) | |
1849 | (((class color)) | |
1850 | (:foreground "white" :background "blue")) | |
1851 | (t | |
1852 | (:slant italic))) | |
6aaedd12 PA |
1853 | "Face used when the customize item has been changed." |
1854 | :group 'custom-magic-faces) | |
d478e69d MB |
1855 | ;; backward-compatibility alias |
1856 | (put 'custom-changed-face 'face-alias 'custom-changed) | |
d543e20b | 1857 | |
d820f1fb CY |
1858 | (defface custom-themed '((((min-colors 88) (class color)) |
1859 | (:foreground "white" :background "blue1")) | |
1860 | (((class color)) | |
1861 | (:foreground "white" :background "blue")) | |
1862 | (t | |
1863 | (:slant italic))) | |
1864 | "Face used when the customize item has been set by a theme." | |
1865 | :group 'custom-magic-faces) | |
1866 | ||
d478e69d | 1867 | (defface custom-saved '((t (:underline t))) |
6aaedd12 PA |
1868 | "Face used when the customize item has been saved." |
1869 | :group 'custom-magic-faces) | |
d478e69d MB |
1870 | ;; backward-compatibility alias |
1871 | (put 'custom-saved-face 'face-alias 'custom-saved) | |
d543e20b | 1872 | |
2dfa4c57 RS |
1873 | (defconst custom-magic-alist |
1874 | '((nil "#" underline "\ | |
167eefc5 | 1875 | UNINITIALIZED, you should not see this.") |
2dfa4c57 | 1876 | (unknown "?" italic "\ |
167eefc5 | 1877 | UNKNOWN, you should not see this.") |
2dfa4c57 | 1878 | (hidden "-" default "\ |
167eefc5 | 1879 | HIDDEN, invoke \"Show\" in the previous line to show." "\ |
cbc7d892 | 1880 | group now hidden, invoke \"Show\", above, to show contents.") |
d478e69d | 1881 | (invalid "x" custom-invalid "\ |
167eefc5 | 1882 | INVALID, the displayed value cannot be set.") |
d478e69d | 1883 | (modified "*" custom-modified "\ |
167eefc5 | 1884 | EDITED, shown value does not take effect until you set or save it." "\ |
1833b7b3 | 1885 | something in this group has been edited but not set.") |
d478e69d | 1886 | (set "+" custom-set "\ |
167eefc5 | 1887 | SET for current session only." "\ |
1833b7b3 | 1888 | something in this group has been set but not saved.") |
d478e69d | 1889 | (changed ":" custom-changed "\ |
167eefc5 | 1890 | CHANGED outside Customize; operating on it here may be unreliable." "\ |
25ac13b5 | 1891 | something in this group has been changed outside customize.") |
d478e69d | 1892 | (saved "!" custom-saved "\ |
167eefc5 | 1893 | SAVED and set." "\ |
5dd0cad0 | 1894 | something in this group has been set and saved.") |
d820f1fb CY |
1895 | (themed "o" custom-themed "\ |
1896 | THEMED." "\ | |
1897 | visible group members are all at standard values.") | |
d478e69d | 1898 | (rogue "@" custom-rogue "\ |
f63d5a0e | 1899 | NO CUSTOMIZATION DATA; not intended to be customized." "\ |
25ac13b5 | 1900 | something in this group is not prepared for customization.") |
2dfa4c57 | 1901 | (standard " " nil "\ |
167eefc5 | 1902 | STANDARD." "\ |
50137744 | 1903 | visible group members are all at standard values.")) |
d543e20b | 1904 | "Alist of customize option states. |
d3d4df42 | 1905 | Each entry is of the form (STATE MAGIC FACE ITEM-DESC [ GROUP-DESC ]), where |
d543e20b PA |
1906 | |
1907 | STATE is one of the following symbols: | |
1908 | ||
1909 | `nil' | |
1910 | For internal use, should never occur. | |
1911 | `unknown' | |
1912 | For internal use, should never occur. | |
1913 | `hidden' | |
d3d4df42 | 1914 | This item is not being displayed. |
d543e20b PA |
1915 | `invalid' |
1916 | This item is modified, but has an invalid form. | |
1917 | `modified' | |
1918 | This item is modified, and has a valid form. | |
1919 | `set' | |
1920 | This item has been set but not saved. | |
1921 | `changed' | |
167eefc5 | 1922 | The current value of this item has been changed outside Customize. |
d543e20b PA |
1923 | `saved' |
1924 | This item is marked for saving. | |
1925 | `rogue' | |
1926 | This item has no customization information. | |
25ac13b5 | 1927 | `standard' |
5dd0cad0 | 1928 | This item is unchanged from the standard setting. |
d543e20b PA |
1929 | |
1930 | MAGIC is a string used to present that state. | |
1931 | ||
1932 | FACE is a face used to present the state. | |
1933 | ||
25ac13b5 PA |
1934 | ITEM-DESC is a string describing the state for options. |
1935 | ||
1936 | GROUP-DESC is a string describing the state for groups. If this is | |
1937 | left out, ITEM-DESC will be used. | |
1938 | ||
9097aeb7 PA |
1939 | The string %c in either description will be replaced with the |
1940 | category of the item. These are `group'. `option', and `face'. | |
1941 | ||
25ac13b5 | 1942 | The list should be sorted most significant first.") |
d543e20b PA |
1943 | |
1944 | (defcustom custom-magic-show 'long | |
3acab5ef | 1945 | "If non-nil, show textual description of the state. |
b62c92bb | 1946 | If `long', show a full-line description, not just one word." |
d543e20b | 1947 | :type '(choice (const :tag "no" nil) |
c992338c AS |
1948 | (const long) |
1949 | (other :tag "short" short)) | |
6aaedd12 | 1950 | :group 'custom-buffer) |
d543e20b | 1951 | |
9097aeb7 | 1952 | (defcustom custom-magic-show-hidden '(option face) |
b62c92bb RS |
1953 | "Control whether the State button is shown for hidden items. |
1954 | The value should be a list with the custom categories where the State | |
9097aeb7 PA |
1955 | button should be visible. Possible categories are `group', `option', |
1956 | and `face'." | |
1957 | :type '(set (const group) (const option) (const face)) | |
6aaedd12 | 1958 | :group 'custom-buffer) |
3acab5ef | 1959 | |
25ac13b5 | 1960 | (defcustom custom-magic-show-button nil |
b62c92bb | 1961 | "Show a \"magic\" button indicating the state of each customization option." |
d543e20b | 1962 | :type 'boolean |
6aaedd12 | 1963 | :group 'custom-buffer) |
d543e20b PA |
1964 | |
1965 | (define-widget 'custom-magic 'default | |
1966 | "Show and manipulate state for a customization option." | |
1967 | :format "%v" | |
86bd10bc | 1968 | :action 'widget-parent-action |
6d528fc5 | 1969 | :notify 'ignore |
d543e20b PA |
1970 | :value-get 'ignore |
1971 | :value-create 'custom-magic-value-create | |
1972 | :value-delete 'widget-children-value-delete) | |
1973 | ||
86bd10bc PA |
1974 | (defun widget-magic-mouse-down-action (widget &optional event) |
1975 | ;; Non-nil unless hidden. | |
d3d4df42 | 1976 | (not (eq (widget-get (widget-get (widget-get widget :parent) :parent) |
86bd10bc PA |
1977 | :custom-state) |
1978 | 'hidden))) | |
1979 | ||
d543e20b | 1980 | (defun custom-magic-value-create (widget) |
2365594b | 1981 | "Create compact status report for WIDGET." |
d543e20b PA |
1982 | (let* ((parent (widget-get widget :parent)) |
1983 | (state (widget-get parent :custom-state)) | |
3acab5ef | 1984 | (hidden (eq state 'hidden)) |
25ac13b5 | 1985 | (entry (assq state custom-magic-alist)) |
d543e20b PA |
1986 | (magic (nth 1 entry)) |
1987 | (face (nth 2 entry)) | |
9097aeb7 PA |
1988 | (category (widget-get parent :custom-category)) |
1989 | (text (or (and (eq category 'group) | |
25ac13b5 PA |
1990 | (nth 4 entry)) |
1991 | (nth 3 entry))) | |
f985c5f7 | 1992 | (form (widget-get parent :custom-form)) |
d543e20b | 1993 | children) |
9097aeb7 | 1994 | (while (string-match "\\`\\(.*\\)%c\\(.*\\)\\'" text) |
d3d4df42 | 1995 | (setq text (concat (match-string 1 text) |
9097aeb7 PA |
1996 | (symbol-name category) |
1997 | (match-string 2 text)))) | |
3acab5ef | 1998 | (when (and custom-magic-show |
9097aeb7 PA |
1999 | (or (not hidden) |
2000 | (memq category custom-magic-show-hidden))) | |
25ac13b5 | 2001 | (insert " ") |
26c7b3ef RS |
2002 | (when (and (eq category 'group) |
2003 | (not (and (eq custom-buffer-style 'links) | |
2004 | (> (widget-get parent :custom-level) 1)))) | |
944c91b6 PA |
2005 | (insert-char ?\ (* custom-buffer-indent |
2006 | (widget-get parent :custom-level)))) | |
d3d4df42 DL |
2007 | (push (widget-create-child-and-convert |
2008 | widget 'choice-item | |
d5c42d02 | 2009 | :help-echo "Change the state of this item." |
3acab5ef | 2010 | :format (if hidden "%t" "%[%t%]") |
25ac13b5 PA |
2011 | :button-prefix 'widget-push-button-prefix |
2012 | :button-suffix 'widget-push-button-suffix | |
86bd10bc PA |
2013 | :mouse-down-action 'widget-magic-mouse-down-action |
2014 | :tag "State") | |
d543e20b PA |
2015 | children) |
2016 | (insert ": ") | |
b62c92bb RS |
2017 | (let ((start (point))) |
2018 | (if (eq custom-magic-show 'long) | |
2019 | (insert text) | |
2020 | (insert (symbol-name state))) | |
f985c5f7 PA |
2021 | (cond ((eq form 'lisp) |
2022 | (insert " (lisp)")) | |
2023 | ((eq form 'mismatch) | |
2024 | (insert " (mismatch)"))) | |
d478e69d | 2025 | (put-text-property start (point) 'face 'custom-state)) |
d543e20b | 2026 | (insert "\n")) |
26c7b3ef RS |
2027 | (when (and (eq category 'group) |
2028 | (not (and (eq custom-buffer-style 'links) | |
2029 | (> (widget-get parent :custom-level) 1)))) | |
944c91b6 PA |
2030 | (insert-char ?\ (* custom-buffer-indent |
2031 | (widget-get parent :custom-level)))) | |
d543e20b PA |
2032 | (when custom-magic-show-button |
2033 | (when custom-magic-show | |
2034 | (let ((indent (widget-get parent :indent))) | |
2035 | (when indent | |
2036 | (insert-char ? indent)))) | |
d3d4df42 DL |
2037 | (push (widget-create-child-and-convert |
2038 | widget 'choice-item | |
86bd10bc PA |
2039 | :mouse-down-action 'widget-magic-mouse-down-action |
2040 | :button-face face | |
3acab5ef PA |
2041 | :button-prefix "" |
2042 | :button-suffix "" | |
86bd10bc | 2043 | :help-echo "Change the state." |
3acab5ef | 2044 | :format (if hidden "%t" "%[%t%]") |
f985c5f7 | 2045 | :tag (if (memq form '(lisp mismatch)) |
86bd10bc PA |
2046 | (concat "(" magic ")") |
2047 | (concat "[" magic "]"))) | |
d543e20b PA |
2048 | children) |
2049 | (insert " ")) | |
2050 | (widget-put widget :children children))) | |
2051 | ||
2052 | (defun custom-magic-reset (widget) | |
2053 | "Redraw the :custom-magic property of WIDGET." | |
2054 | (let ((magic (widget-get widget :custom-magic))) | |
2055 | (widget-value-set magic (widget-value magic)))) | |
2056 | ||
d543e20b PA |
2057 | ;;; The `custom' Widget. |
2058 | ||
d478e69d | 2059 | (defface custom-button |
9e2a2647 | 2060 | '((((type x w32 ns) (class color)) ; Like default modeline |
1a578e9b AC |
2061 | (:box (:line-width 2 :style released-button) |
2062 | :background "lightgrey" :foreground "black")) | |
d3d4df42 DL |
2063 | (t |
2064 | nil)) | |
87911bdb | 2065 | "Face for custom buffer buttons if `custom-raised-buttons' is non-nil." |
d3d4df42 DL |
2066 | :version "21.1" |
2067 | :group 'custom-faces) | |
d478e69d MB |
2068 | ;; backward-compatibility alias |
2069 | (put 'custom-button-face 'face-alias 'custom-button) | |
d3d4df42 | 2070 | |
85a5eb0e | 2071 | (defface custom-button-mouse |
9e2a2647 | 2072 | '((((type x w32 ns) (class color)) |
85a5eb0e CY |
2073 | (:box (:line-width 2 :style released-button) |
2074 | :background "grey90" :foreground "black")) | |
2075 | (t | |
2076 | nil)) | |
2077 | "Mouse face for custom buffer buttons if `custom-raised-buttons' is non-nil." | |
2078 | :version "22.1" | |
2079 | :group 'custom-faces) | |
2080 | ||
87911bdb | 2081 | (defface custom-button-unraised |
192e44fc | 2082 | '((t :inherit underline)) |
87911bdb CY |
2083 | "Face for custom buffer buttons if `custom-raised-buttons' is nil." |
2084 | :version "22.1" | |
2085 | :group 'custom-faces) | |
2086 | ||
2087 | (setq custom-button | |
2088 | (if custom-raised-buttons 'custom-button 'custom-button-unraised)) | |
2089 | ||
85a5eb0e CY |
2090 | (setq custom-button-mouse |
2091 | (if custom-raised-buttons 'custom-button-mouse 'highlight)) | |
2092 | ||
d478e69d | 2093 | (defface custom-button-pressed |
9e2a2647 | 2094 | '((((type x w32 ns) (class color)) |
1a578e9b AC |
2095 | (:box (:line-width 2 :style pressed-button) |
2096 | :background "lightgrey" :foreground "black")) | |
d3d4df42 DL |
2097 | (t |
2098 | (:inverse-video t))) | |
87911bdb | 2099 | "Face for pressed custom buttons if `custom-raised-buttons' is non-nil." |
d3d4df42 | 2100 | :version "21.1" |
b62c92bb | 2101 | :group 'custom-faces) |
d478e69d MB |
2102 | ;; backward-compatibility alias |
2103 | (put 'custom-button-pressed-face 'face-alias 'custom-button-pressed) | |
b62c92bb | 2104 | |
87911bdb CY |
2105 | (defface custom-button-pressed-unraised |
2106 | '((default :inherit custom-button-unraised) | |
2107 | (((class color) (background light)) :foreground "magenta4") | |
2108 | (((class color) (background dark)) :foreground "violet")) | |
2109 | "Face for pressed custom buttons if `custom-raised-buttons' is nil." | |
2110 | :version "22.1" | |
2111 | :group 'custom-faces) | |
2112 | ||
2113 | (setq custom-button-pressed | |
2114 | (if custom-raised-buttons | |
2115 | 'custom-button-pressed | |
2116 | 'custom-button-pressed-unraised)) | |
2117 | ||
dbc1f997 | 2118 | (defface custom-documentation '((t nil)) |
b62c92bb RS |
2119 | "Face used for documentation strings in customization buffers." |
2120 | :group 'custom-faces) | |
d478e69d MB |
2121 | ;; backward-compatibility alias |
2122 | (put 'custom-documentation-face 'face-alias 'custom-documentation) | |
2123 | ||
2124 | (defface custom-state '((((class color) | |
2125 | (background dark)) | |
2126 | (:foreground "lime green")) | |
2127 | (((class color) | |
2128 | (background light)) | |
2129 | (:foreground "dark green")) | |
2130 | (t nil)) | |
b62c92bb RS |
2131 | "Face used for State descriptions in the customize buffer." |
2132 | :group 'custom-faces) | |
d478e69d MB |
2133 | ;; backward-compatibility alias |
2134 | (put 'custom-state-face 'face-alias 'custom-state) | |
b62c92bb | 2135 | |
73e60f53 | 2136 | (defface custom-link |
192e44fc JL |
2137 | '((t :inherit link)) |
2138 | "Face for links in customization buffers." | |
2139 | :version "22.1" | |
2140 | :group 'custom-faces) | |
73e60f53 | 2141 | |
d543e20b PA |
2142 | (define-widget 'custom 'default |
2143 | "Customize a user option." | |
944c91b6 | 2144 | :format "%v" |
d543e20b | 2145 | :convert-widget 'custom-convert-widget |
d543e20b | 2146 | :notify 'custom-notify |
944c91b6 | 2147 | :custom-prefix "" |
d543e20b PA |
2148 | :custom-level 1 |
2149 | :custom-state 'hidden | |
2150 | :documentation-property 'widget-subclass-responsibility | |
2151 | :value-create 'widget-subclass-responsibility | |
2152 | :value-delete 'widget-children-value-delete | |
86bd10bc PA |
2153 | :value-get 'widget-value-value-get |
2154 | :validate 'widget-children-validate | |
d543e20b PA |
2155 | :match (lambda (widget value) (symbolp value))) |
2156 | ||
2157 | (defun custom-convert-widget (widget) | |
2365594b | 2158 | "Initialize :value and :tag from :args in WIDGET." |
d543e20b | 2159 | (let ((args (widget-get widget :args))) |
d3d4df42 | 2160 | (when args |
d543e20b PA |
2161 | (widget-put widget :value (widget-apply widget |
2162 | :value-to-internal (car args))) | |
2163 | (widget-put widget :tag (custom-unlispify-tag-name (car args))) | |
2164 | (widget-put widget :args nil))) | |
2165 | widget) | |
2166 | ||
d543e20b PA |
2167 | (defun custom-notify (widget &rest args) |
2168 | "Keep track of changes." | |
0a3a0b56 PA |
2169 | (let ((state (widget-get widget :custom-state))) |
2170 | (unless (eq state 'modified) | |
2171 | (unless (memq state '(nil unknown hidden)) | |
2172 | (widget-put widget :custom-state 'modified)) | |
2173 | (custom-magic-reset widget) | |
2174 | (apply 'widget-default-notify widget args)))) | |
d543e20b PA |
2175 | |
2176 | (defun custom-redraw (widget) | |
2177 | "Redraw WIDGET with current settings." | |
6d528fc5 PA |
2178 | (let ((line (count-lines (point-min) (point))) |
2179 | (column (current-column)) | |
2180 | (pos (point)) | |
d543e20b PA |
2181 | (from (marker-position (widget-get widget :from))) |
2182 | (to (marker-position (widget-get widget :to)))) | |
2183 | (save-excursion | |
2184 | (widget-value-set widget (widget-value widget)) | |
2185 | (custom-redraw-magic widget)) | |
2186 | (when (and (>= pos from) (<= pos to)) | |
6d528fc5 | 2187 | (condition-case nil |
d3d4df42 | 2188 | (progn |
86bd10bc PA |
2189 | (if (> column 0) |
2190 | (goto-line line) | |
2191 | (goto-line (1+ line))) | |
6d528fc5 PA |
2192 | (move-to-column column)) |
2193 | (error nil))))) | |
d543e20b PA |
2194 | |
2195 | (defun custom-redraw-magic (widget) | |
2196 | "Redraw WIDGET state with current settings." | |
d3d4df42 | 2197 | (while widget |
d543e20b | 2198 | (let ((magic (widget-get widget :custom-magic))) |
d3d4df42 | 2199 | (cond (magic |
944c91b6 PA |
2200 | (widget-value-set magic (widget-value magic)) |
2201 | (when (setq widget (widget-get widget :group)) | |
2202 | (custom-group-state-update widget))) | |
2203 | (t | |
2204 | (setq widget nil))))) | |
d543e20b PA |
2205 | (widget-setup)) |
2206 | ||
2207 | (defun custom-show (widget value) | |
2208 | "Non-nil if WIDGET should be shown with VALUE by default." | |
2209 | (let ((show (widget-get widget :custom-show))) | |
2210 | (cond ((null show) | |
2211 | nil) | |
2212 | ((eq t show) | |
2213 | t) | |
2214 | (t | |
2215 | (funcall show widget value))))) | |
2216 | ||
d543e20b PA |
2217 | (defun custom-load-widget (widget) |
2218 | "Load all dependencies for WIDGET." | |
2219 | (custom-load-symbol (widget-value widget))) | |
2220 | ||
c953515e | 2221 | (defun custom-unloaded-symbol-p (symbol) |
3127aa13 | 2222 | "Return non-nil if the dependencies of SYMBOL have not yet been loaded." |
c953515e PA |
2223 | (let ((found nil) |
2224 | (loads (get symbol 'custom-loads)) | |
2225 | load) | |
2226 | (while loads | |
2227 | (setq load (car loads) | |
2228 | loads (cdr loads)) | |
2229 | (cond ((symbolp load) | |
2230 | (unless (featurep load) | |
2231 | (setq found t))) | |
2232 | ((assoc load load-history)) | |
2233 | ((assoc (locate-library load) load-history) | |
2234 | (message nil)) | |
2235 | (t | |
2236 | (setq found t)))) | |
2237 | found)) | |
2238 | ||
2239 | (defun custom-unloaded-widget-p (widget) | |
3127aa13 | 2240 | "Return non-nil if the dependencies of WIDGET have not yet been loaded." |
c953515e PA |
2241 | (custom-unloaded-symbol-p (widget-value widget))) |
2242 | ||
6d528fc5 PA |
2243 | (defun custom-toggle-hide (widget) |
2244 | "Toggle visibility of WIDGET." | |
c953515e | 2245 | (custom-load-widget widget) |
6d528fc5 PA |
2246 | (let ((state (widget-get widget :custom-state))) |
2247 | (cond ((memq state '(invalid modified)) | |
2248 | (error "There are unset changes")) | |
2249 | ((eq state 'hidden) | |
2250 | (widget-put widget :custom-state 'unknown)) | |
d3d4df42 | 2251 | (t |
3acab5ef | 2252 | (widget-put widget :documentation-shown nil) |
6d528fc5 | 2253 | (widget-put widget :custom-state 'hidden))) |
8697863a PA |
2254 | (custom-redraw widget) |
2255 | (widget-setup))) | |
6d528fc5 | 2256 | |
3acab5ef | 2257 | (defun custom-toggle-parent (widget &rest ignore) |
b62c92bb | 2258 | "Toggle visibility of parent of WIDGET." |
3acab5ef PA |
2259 | (custom-toggle-hide (widget-get widget :parent))) |
2260 | ||
944c91b6 PA |
2261 | (defun custom-add-see-also (widget &optional prefix) |
2262 | "Add `See also ...' to WIDGET if there are any links. | |
2263 | Insert PREFIX first if non-nil." | |
2264 | (let* ((symbol (widget-get widget :value)) | |
2265 | (links (get symbol 'custom-links)) | |
2266 | (many (> (length links) 2)) | |
2267 | (buttons (widget-get widget :buttons)) | |
2268 | (indent (widget-get widget :indent))) | |
2269 | (when links | |
2270 | (when indent | |
2271 | (insert-char ?\ indent)) | |
2272 | (when prefix | |
2273 | (insert prefix)) | |
2274 | (insert "See also ") | |
2275 | (while links | |
83dc149d EZ |
2276 | (push (widget-create-child-and-convert |
2277 | widget (car links) | |
2278 | :button-face 'custom-link | |
e1ec62a5 CY |
2279 | :mouse-face 'highlight |
2280 | :pressed-face 'highlight) | |
944c91b6 PA |
2281 | buttons) |
2282 | (setq links (cdr links)) | |
2283 | (cond ((null links) | |
2284 | (insert ".\n")) | |
2285 | ((null (cdr links)) | |
2286 | (if many | |
2287 | (insert ", and ") | |
2288 | (insert " and "))) | |
d3d4df42 | 2289 | (t |
944c91b6 PA |
2290 | (insert ", ")))) |
2291 | (widget-put widget :buttons buttons)))) | |
2292 | ||
f1201e3a RS |
2293 | (defun custom-add-parent-links (widget &optional initial-string |
2294 | doc-initial-string) | |
cd6c0940 | 2295 | "Add \"Parent groups: ...\" to WIDGET if the group has parents. |
08adfdbb | 2296 | The value is non-nil if any parents were found. |
cd6c0940 | 2297 | If INITIAL-STRING is non-nil, use that rather than \"Parent groups:\"." |
944c91b6 PA |
2298 | (let ((name (widget-value widget)) |
2299 | (type (widget-type widget)) | |
2300 | (buttons (widget-get widget :buttons)) | |
d377bee9 | 2301 | (start (point)) |
ac00d71c | 2302 | (parents nil)) |
f1201e3a | 2303 | (insert (or initial-string "Groups:")) |
944c91b6 | 2304 | (mapatoms (lambda (symbol) |
08adfdbb LT |
2305 | (when (member (list name type) (get symbol 'custom-group)) |
2306 | (insert " ") | |
2307 | (push (widget-create-child-and-convert | |
2308 | widget 'custom-group-link | |
2309 | :tag (custom-unlispify-tag-name symbol) | |
2310 | symbol) | |
2311 | buttons) | |
2312 | (setq parents (cons symbol parents))))) | |
8e4d1662 | 2313 | (and (null (get name 'custom-links)) ;No links of its own. |
ac00d71c | 2314 | (= (length parents) 1) ;A single parent. |
3f30c272 JL |
2315 | (let* ((links (delq nil (mapcar (lambda (w) |
2316 | (unless (eq (widget-type w) | |
2317 | 'custom-group-link) | |
2318 | w)) | |
2319 | (get (car parents) 'custom-links)))) | |
cfa921fd | 2320 | (many (> (length links) 2))) |
ac00d71c | 2321 | (when links |
8ed10e73 RS |
2322 | (let ((pt (point)) |
2323 | (left-margin (+ left-margin 2))) | |
76564e7c RS |
2324 | (insert "\n" (or doc-initial-string "Group documentation:") " ") |
2325 | (while links | |
2326 | (push (widget-create-child-and-convert | |
2327 | widget (car links) | |
2328 | :button-face 'custom-link | |
2329 | :mouse-face 'highlight | |
2330 | :pressed-face 'highlight) | |
2331 | buttons) | |
2332 | (setq links (cdr links)) | |
2333 | (cond ((null links) | |
2334 | (insert ".\n")) | |
2335 | ((null (cdr links)) | |
2336 | (if many | |
2337 | (insert ", and ") | |
2338 | (insert " and "))) | |
2339 | (t | |
8ed10e73 RS |
2340 | (insert ", ")))) |
2341 | (fill-region-as-paragraph pt (point)) | |
2342 | (delete-to-left-margin (1+ pt) (+ pt 2)))))) | |
ac00d71c PA |
2343 | (if parents |
2344 | (insert "\n") | |
d377bee9 | 2345 | (delete-region start (point))) |
ac00d71c PA |
2346 | (widget-put widget :buttons buttons) |
2347 | parents)) | |
944c91b6 | 2348 | |
d3d4df42 DL |
2349 | ;;; The `custom-comment' Widget. |
2350 | ||
2351 | ;; like the editable field | |
ee5137b3 JPW |
2352 | (defface custom-comment '((((type tty)) |
2353 | :background "yellow3" | |
2354 | :foreground "black") | |
2355 | (((class grayscale color) | |
d478e69d | 2356 | (background light)) |
ee5137b3 | 2357 | :background "gray85") |
d478e69d MB |
2358 | (((class grayscale color) |
2359 | (background dark)) | |
ee5137b3 | 2360 | :background "dim gray") |
d478e69d | 2361 | (t |
ee5137b3 | 2362 | :slant italic)) |
d3d4df42 DL |
2363 | "Face used for comments on variables or faces" |
2364 | :version "21.1" | |
2365 | :group 'custom-faces) | |
d478e69d MB |
2366 | ;; backward-compatibility alias |
2367 | (put 'custom-comment-face 'face-alias 'custom-comment) | |
d3d4df42 DL |
2368 | |
2369 | ;; like font-lock-comment-face | |
d478e69d | 2370 | (defface custom-comment-tag |
d3d4df42 DL |
2371 | '((((class color) (background dark)) (:foreground "gray80")) |
2372 | (((class color) (background light)) (:foreground "blue4")) | |
2373 | (((class grayscale) (background light)) | |
b5555381 | 2374 | (:foreground "DimGray" :weight bold :slant italic)) |
d3d4df42 | 2375 | (((class grayscale) (background dark)) |
b5555381 RS |
2376 | (:foreground "LightGray" :weight bold :slant italic)) |
2377 | (t (:weight bold))) | |
d3d4df42 DL |
2378 | "Face used for variables or faces comment tags" |
2379 | :group 'custom-faces) | |
d478e69d MB |
2380 | ;; backward-compatibility alias |
2381 | (put 'custom-comment-tag-face 'face-alias 'custom-comment-tag) | |
d3d4df42 DL |
2382 | |
2383 | (define-widget 'custom-comment 'string | |
164cfaeb | 2384 | "User comment." |
d3d4df42 | 2385 | :tag "Comment" |
164cfaeb | 2386 | :help-echo "Edit a comment here." |
d3d4df42 DL |
2387 | :sample-face 'custom-comment-tag-face |
2388 | :value-face 'custom-comment-face | |
164cfaeb DL |
2389 | :shown nil |
2390 | :create 'custom-comment-create) | |
d3d4df42 DL |
2391 | |
2392 | (defun custom-comment-create (widget) | |
164cfaeb | 2393 | (let* ((null-comment (equal "" (widget-value widget)))) |
6171a945 DL |
2394 | (if (or (widget-get (widget-get widget :parent) :comment-shown) |
2395 | (not null-comment)) | |
2396 | (widget-default-create widget) | |
2397 | ;; `widget-default-delete' expects markers in these slots -- | |
2398 | ;; maybe it shouldn't. | |
2399 | (widget-put widget :from (point-marker)) | |
2400 | (widget-put widget :to (point-marker))))) | |
164cfaeb DL |
2401 | |
2402 | (defun custom-comment-hide (widget) | |
2403 | (widget-put (widget-get widget :parent) :comment-shown nil)) | |
d3d4df42 DL |
2404 | |
2405 | ;; Those functions are for the menu. WIDGET is NOT the comment widget. It's | |
2406 | ;; the global custom one | |
2407 | (defun custom-comment-show (widget) | |
164cfaeb DL |
2408 | (widget-put widget :comment-shown t) |
2409 | (custom-redraw widget) | |
2410 | (widget-setup)) | |
d3d4df42 DL |
2411 | |
2412 | (defun custom-comment-invisible-p (widget) | |
164cfaeb DL |
2413 | (let ((val (widget-value (widget-get widget :comment-widget)))) |
2414 | (and (equal "" val) | |
2415 | (not (widget-get widget :comment-shown))))) | |
d3d4df42 | 2416 | |
d543e20b PA |
2417 | ;;; The `custom-variable' Widget. |
2418 | ||
2365594b DL |
2419 | ;; When this was underlined blue, users confused it with a |
2420 | ;; Mosaic-style hyperlink... | |
d478e69d | 2421 | (defface custom-variable-tag |
16b20ed9 GM |
2422 | `((((class color) |
2423 | (background dark)) | |
9db1942d | 2424 | (:foreground "light blue" :weight bold)) |
ea81d57e DN |
2425 | (((min-colors 88) (class color) |
2426 | (background light)) | |
9db1942d | 2427 | (:foreground "blue1" :weight bold)) |
16b20ed9 GM |
2428 | (((class color) |
2429 | (background light)) | |
9db1942d | 2430 | (:foreground "blue" :weight bold)) |
b5555381 | 2431 | (t (:weight bold))) |
d543e20b | 2432 | "Face used for unpushable variable tags." |
bd042c03 | 2433 | :group 'custom-faces) |
d478e69d MB |
2434 | ;; backward-compatibility alias |
2435 | (put 'custom-variable-tag-face 'face-alias 'custom-variable-tag) | |
d543e20b | 2436 | |
d478e69d | 2437 | (defface custom-variable-button '((t (:underline t :weight bold))) |
d543e20b | 2438 | "Face used for pushable variable tags." |
bd042c03 | 2439 | :group 'custom-faces) |
d478e69d MB |
2440 | ;; backward-compatibility alias |
2441 | (put 'custom-variable-button-face 'face-alias 'custom-variable-button) | |
d543e20b | 2442 | |
d64478da KH |
2443 | (defcustom custom-variable-default-form 'edit |
2444 | "Default form of displaying variable values." | |
2445 | :type '(choice (const edit) | |
2446 | (const lisp)) | |
cd32a7ba DN |
2447 | :group 'custom-buffer |
2448 | :version "20.3") | |
d64478da | 2449 | |
a075569a LT |
2450 | (defun custom-variable-documentation (variable) |
2451 | "Return documentation of VARIABLE for use in Custom buffer. | |
2452 | Normally just return the docstring. But if VARIABLE automatically | |
2453 | becomes buffer local when set, append a message to that effect." | |
2454 | (if (and (local-variable-if-set-p variable) | |
2455 | (or (not (local-variable-p variable)) | |
2456 | (with-temp-buffer | |
2457 | (local-variable-if-set-p variable)))) | |
2458 | (concat (documentation-property variable 'variable-documentation) | |
2459 | "\n | |
2460 | This variable automatically becomes buffer-local when set outside Custom. | |
2461 | However, setting it through Custom sets the default value.") | |
2462 | (documentation-property variable 'variable-documentation))) | |
2463 | ||
d543e20b PA |
2464 | (define-widget 'custom-variable 'custom |
2465 | "Customize variable." | |
944c91b6 | 2466 | :format "%v" |
d543e20b | 2467 | :help-echo "Set or reset this variable." |
a075569a | 2468 | :documentation-property #'custom-variable-documentation |
9097aeb7 | 2469 | :custom-category 'option |
d543e20b PA |
2470 | :custom-state nil |
2471 | :custom-menu 'custom-variable-menu-create | |
d64478da | 2472 | :custom-form nil ; defaults to value of `custom-variable-default-form' |
d543e20b PA |
2473 | :value-create 'custom-variable-value-create |
2474 | :action 'custom-variable-action | |
2475 | :custom-set 'custom-variable-set | |
5ae87ed4 | 2476 | :custom-mark-to-save 'custom-variable-mark-to-save |
d543e20b PA |
2477 | :custom-reset-current 'custom-redraw |
2478 | :custom-reset-saved 'custom-variable-reset-saved | |
4f985043 | 2479 | :custom-reset-standard 'custom-variable-reset-standard |
5ae87ed4 MR |
2480 | :custom-mark-to-reset-standard 'custom-variable-mark-to-reset-standard |
2481 | :custom-standard-value 'custom-variable-standard-value | |
2482 | :custom-state-set-and-redraw 'custom-variable-state-set-and-redraw) | |
d543e20b | 2483 | |
bd042c03 PA |
2484 | (defun custom-variable-type (symbol) |
2485 | "Return a widget suitable for editing the value of SYMBOL. | |
d3d4df42 | 2486 | If SYMBOL has a `custom-type' property, use that. |
f0fc8583 RS |
2487 | Otherwise, try matching SYMBOL against `custom-guess-name-alist' and |
2488 | try matching its doc string against `custom-guess-doc-alist'." | |
bd042c03 | 2489 | (let* ((type (or (get symbol 'custom-type) |
25ac13b5 | 2490 | (and (not (get symbol 'standard-value)) |
bd042c03 PA |
2491 | (custom-guess-type symbol)) |
2492 | 'sexp)) | |
2493 | (options (get symbol 'custom-options)) | |
2494 | (tmp (if (listp type) | |
46fa5a83 | 2495 | (copy-sequence type) |
bd042c03 PA |
2496 | (list type)))) |
2497 | (when options | |
2498 | (widget-put tmp :options options)) | |
2499 | tmp)) | |
2500 | ||
d543e20b | 2501 | (defun custom-variable-value-create (widget) |
164cfaeb | 2502 | "Here is where you edit the variable's value." |
d543e20b | 2503 | (custom-load-widget widget) |
d64478da KH |
2504 | (unless (widget-get widget :custom-form) |
2505 | (widget-put widget :custom-form custom-variable-default-form)) | |
d543e20b PA |
2506 | (let* ((buttons (widget-get widget :buttons)) |
2507 | (children (widget-get widget :children)) | |
2508 | (form (widget-get widget :custom-form)) | |
2509 | (state (widget-get widget :custom-state)) | |
2510 | (symbol (widget-get widget :value)) | |
d543e20b | 2511 | (tag (widget-get widget :tag)) |
bd042c03 | 2512 | (type (custom-variable-type symbol)) |
d543e20b | 2513 | (conv (widget-convert type)) |
6d528fc5 | 2514 | (get (or (get symbol 'custom-get) 'default-value)) |
944c91b6 PA |
2515 | (prefix (widget-get widget :custom-prefix)) |
2516 | (last (widget-get widget :custom-last)) | |
d543e20b | 2517 | (value (if (default-boundp symbol) |
6d528fc5 | 2518 | (funcall get symbol) |
d543e20b | 2519 | (widget-get conv :value)))) |
164cfaeb | 2520 | ;; If the widget is new, the child determines whether it is hidden. |
d543e20b PA |
2521 | (cond (state) |
2522 | ((custom-show type value) | |
2523 | (setq state 'unknown)) | |
2524 | (t | |
2525 | (setq state 'hidden))) | |
2526 | ;; If we don't know the state, see if we need to edit it in lisp form. | |
2527 | (when (eq state 'unknown) | |
2528 | (unless (widget-apply conv :match value) | |
2529 | ;; (widget-apply (widget-convert type) :match value) | |
f985c5f7 | 2530 | (setq form 'mismatch))) |
d543e20b | 2531 | ;; Now we can create the child widget. |
944c91b6 | 2532 | (cond ((eq custom-buffer-style 'tree) |
da5ec617 | 2533 | (insert prefix (if last " `--- " " |--- ")) |
944c91b6 | 2534 | (push (widget-create-child-and-convert |
c953515e | 2535 | widget 'custom-browse-variable-tag) |
944c91b6 PA |
2536 | buttons) |
2537 | (insert " " tag "\n") | |
2538 | (widget-put widget :buttons buttons)) | |
2539 | ((eq state 'hidden) | |
d543e20b | 2540 | ;; Indicate hidden value. |
d3d4df42 | 2541 | (push (widget-create-child-and-convert |
d543e20b | 2542 | widget 'item |
3acab5ef | 2543 | :format "%{%t%}: " |
b62c92bb | 2544 | :sample-face 'custom-variable-tag-face |
d543e20b PA |
2545 | :tag tag |
2546 | :parent widget) | |
3acab5ef | 2547 | buttons) |
d3d4df42 | 2548 | (push (widget-create-child-and-convert |
3acab5ef | 2549 | widget 'visibility |
8697863a | 2550 | :help-echo "Show the value of this option." |
7f663295 | 2551 | :off "Show Value" |
3acab5ef PA |
2552 | :action 'custom-toggle-parent |
2553 | nil) | |
2554 | buttons)) | |
f985c5f7 | 2555 | ((memq form '(lisp mismatch)) |
d543e20b PA |
2556 | ;; In lisp mode edit the saved value when possible. |
2557 | (let* ((value (cond ((get symbol 'saved-value) | |
2558 | (car (get symbol 'saved-value))) | |
25ac13b5 PA |
2559 | ((get symbol 'standard-value) |
2560 | (car (get symbol 'standard-value))) | |
d543e20b | 2561 | ((default-boundp symbol) |
6d528fc5 | 2562 | (custom-quote (funcall get symbol))) |
d543e20b PA |
2563 | (t |
2564 | (custom-quote (widget-get conv :value)))))) | |
3acab5ef | 2565 | (insert (symbol-name symbol) ": ") |
d3d4df42 | 2566 | (push (widget-create-child-and-convert |
944c91b6 PA |
2567 | widget 'visibility |
2568 | :help-echo "Hide the value of this option." | |
7f663295 RS |
2569 | :on "Hide Value" |
2570 | :off "Show Value" | |
944c91b6 PA |
2571 | :action 'custom-toggle-parent |
2572 | t) | |
2573 | buttons) | |
3acab5ef | 2574 | (insert " ") |
d3d4df42 DL |
2575 | (push (widget-create-child-and-convert |
2576 | widget 'sexp | |
d543e20b | 2577 | :button-face 'custom-variable-button-face |
3acab5ef | 2578 | :format "%v" |
d543e20b PA |
2579 | :tag (symbol-name symbol) |
2580 | :parent widget | |
2581 | :value value) | |
2582 | children))) | |
2583 | (t | |
2584 | ;; Edit mode. | |
3acab5ef PA |
2585 | (let* ((format (widget-get type :format)) |
2586 | tag-format value-format) | |
2587 | (unless (string-match ":" format) | |
896a6a5d | 2588 | (error "Bad format")) |
3acab5ef PA |
2589 | (setq tag-format (substring format 0 (match-end 0))) |
2590 | (setq value-format (substring format (match-end 0))) | |
2591 | (push (widget-create-child-and-convert | |
d3d4df42 | 2592 | widget 'item |
3acab5ef PA |
2593 | :format tag-format |
2594 | :action 'custom-tag-action | |
8697863a | 2595 | :help-echo "Change value of this option." |
3acab5ef PA |
2596 | :mouse-down-action 'custom-tag-mouse-down-action |
2597 | :button-face 'custom-variable-button-face | |
b62c92bb | 2598 | :sample-face 'custom-variable-tag-face |
3acab5ef PA |
2599 | tag) |
2600 | buttons) | |
2601 | (insert " ") | |
d3d4df42 | 2602 | (push (widget-create-child-and-convert |
164cfaeb DL |
2603 | widget 'visibility |
2604 | :help-echo "Hide the value of this option." | |
7f663295 RS |
2605 | :on "Hide Value" |
2606 | :off "Show Value" | |
164cfaeb DL |
2607 | :action 'custom-toggle-parent |
2608 | t) | |
2609 | buttons) | |
3acab5ef | 2610 | (push (widget-create-child-and-convert |
d3d4df42 | 2611 | widget type |
3acab5ef PA |
2612 | :format value-format |
2613 | :value value) | |
2614 | children)))) | |
944c91b6 | 2615 | (unless (eq custom-buffer-style 'tree) |
944c91b6 PA |
2616 | (unless (eq (preceding-char) ?\n) |
2617 | (widget-insert "\n")) | |
944c91b6 PA |
2618 | ;; Create the magic button. |
2619 | (let ((magic (widget-create-child-and-convert | |
2620 | widget 'custom-magic nil))) | |
2621 | (widget-put widget :custom-magic magic) | |
2622 | (push magic buttons)) | |
944c91b6 | 2623 | (widget-put widget :buttons buttons) |
944c91b6 | 2624 | ;; Insert documentation. |
9db1942d | 2625 | (widget-put widget :documentation-indent 3) |
12bafdaa CY |
2626 | (widget-add-documentation-string-button |
2627 | widget :visibility-widget 'custom-visibility) | |
d3d4df42 DL |
2628 | |
2629 | ;; The comment field | |
2630 | (unless (eq state 'hidden) | |
2631 | (let* ((comment (get symbol 'variable-comment)) | |
2632 | (comment-widget | |
2633 | (widget-create-child-and-convert | |
2634 | widget 'custom-comment | |
2635 | :parent widget | |
2636 | :value (or comment "")))) | |
2637 | (widget-put widget :comment-widget comment-widget) | |
2638 | ;; Don't push it !!! Custom assumes that the first child is the | |
2639 | ;; value one. | |
2640 | (setq children (append children (list comment-widget))))) | |
2641 | ;; Update the rest of the properties properties. | |
2642 | (widget-put widget :custom-form form) | |
2643 | (widget-put widget :children children) | |
2644 | ;; Now update the state. | |
2645 | (if (eq state 'hidden) | |
2646 | (widget-put widget :custom-state state) | |
2647 | (custom-variable-state-set widget)) | |
944c91b6 PA |
2648 | ;; See also. |
2649 | (unless (eq state 'hidden) | |
2650 | (when (eq (widget-get widget :custom-level) 1) | |
2651 | (custom-add-parent-links widget)) | |
2652 | (custom-add-see-also widget))))) | |
d543e20b | 2653 | |
3acab5ef PA |
2654 | (defun custom-tag-action (widget &rest args) |
2655 | "Pass :action to first child of WIDGET's parent." | |
2656 | (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children)) | |
2657 | :action args)) | |
2658 | ||
2659 | (defun custom-tag-mouse-down-action (widget &rest args) | |
2660 | "Pass :mouse-down-action to first child of WIDGET's parent." | |
2661 | (apply 'widget-apply (car (widget-get (widget-get widget :parent) :children)) | |
2662 | :mouse-down-action args)) | |
2663 | ||
d543e20b PA |
2664 | (defun custom-variable-state-set (widget) |
2665 | "Set the state of WIDGET." | |
2666 | (let* ((symbol (widget-value widget)) | |
6d528fc5 | 2667 | (get (or (get symbol 'custom-get) 'default-value)) |
d543e20b | 2668 | (value (if (default-boundp symbol) |
6d528fc5 | 2669 | (funcall get symbol) |
d543e20b | 2670 | (widget-get widget :value))) |
d3d4df42 | 2671 | (comment (get symbol 'variable-comment)) |
d543e20b | 2672 | tmp |
d3d4df42 DL |
2673 | temp |
2674 | (state (cond ((progn (setq tmp (get symbol 'customized-value)) | |
2675 | (setq temp | |
2676 | (get symbol 'customized-variable-comment)) | |
2677 | (or tmp temp)) | |
d543e20b | 2678 | (if (condition-case nil |
d3d4df42 DL |
2679 | (and (equal value (eval (car tmp))) |
2680 | (equal comment temp)) | |
d543e20b PA |
2681 | (error nil)) |
2682 | 'set | |
2683 | 'changed)) | |
25c6d447 | 2684 | ((progn (setq tmp (get symbol 'theme-value)) |
d3d4df42 DL |
2685 | (setq temp (get symbol 'saved-variable-comment)) |
2686 | (or tmp temp)) | |
d543e20b | 2687 | (if (condition-case nil |
25c6d447 CY |
2688 | (and (equal comment temp) |
2689 | (equal value | |
d358aa10 CY |
2690 | (eval |
2691 | (car (custom-variable-theme-value | |
2692 | symbol))))) | |
d543e20b | 2693 | (error nil)) |
d820f1fb | 2694 | (cond |
d358aa10 | 2695 | ((eq (caar tmp) 'user) 'saved) |
e0a0d9fe SM |
2696 | ((eq (caar tmp) 'changed) |
2697 | (if (condition-case nil | |
2698 | (and (null comment) | |
2699 | (equal value | |
2700 | (eval | |
2701 | (car (get symbol 'standard-value))))) | |
2702 | (error nil)) | |
2703 | ;; The value was originally set outside | |
2704 | ;; custom, but it was set to the standard | |
2705 | ;; value (probably an autoloaded defcustom). | |
2706 | 'standard | |
2707 | 'changed)) | |
d820f1fb | 2708 | (t 'themed)) |
d543e20b | 2709 | 'changed)) |
25ac13b5 | 2710 | ((setq tmp (get symbol 'standard-value)) |
d543e20b | 2711 | (if (condition-case nil |
d3d4df42 DL |
2712 | (and (equal value (eval (car tmp))) |
2713 | (equal comment nil)) | |
d543e20b | 2714 | (error nil)) |
25ac13b5 | 2715 | 'standard |
d543e20b PA |
2716 | 'changed)) |
2717 | (t 'rogue)))) | |
2718 | (widget-put widget :custom-state state))) | |
2719 | ||
4f985043 RS |
2720 | (defun custom-variable-standard-value (widget) |
2721 | (get (widget-value widget) 'standard-value)) | |
2722 | ||
d3d4df42 | 2723 | (defvar custom-variable-menu |
70482877 | 2724 | `(("Set for Current Session" custom-variable-set |
0c731046 | 2725 | (lambda (widget) |
eaa99205 | 2726 | (eq (widget-get widget :custom-state) 'modified))) |
9b5007e7 GM |
2727 | ;; Note that in all the backquoted code in this file, we test |
2728 | ;; init-file-user rather than user-init-file. This is in case | |
2729 | ;; cus-edit is loaded by something in site-start.el, because | |
2730 | ;; user-init-file is not set at that stage. | |
2731 | ;; http://lists.gnu.org/archive/html/emacs-devel/2007-10/msg00310.html | |
2732 | ,@(when (or custom-file init-file-user) | |
70482877 | 2733 | '(("Save for Future Sessions" custom-variable-save |
eaa99205 CY |
2734 | (lambda (widget) |
2735 | (memq (widget-get widget :custom-state) | |
2736 | '(modified set changed rogue)))))) | |
70482877 | 2737 | ("Undo Edits" custom-redraw |
6d528fc5 PA |
2738 | (lambda (widget) |
2739 | (and (default-boundp (widget-value widget)) | |
86bd10bc | 2740 | (memq (widget-get widget :custom-state) '(modified changed))))) |
70482877 | 2741 | ("Reset to Saved" custom-variable-reset-saved |
6d528fc5 | 2742 | (lambda (widget) |
d3d4df42 DL |
2743 | (and (or (get (widget-value widget) 'saved-value) |
2744 | (get (widget-value widget) 'saved-variable-comment)) | |
6d528fc5 PA |
2745 | (memq (widget-get widget :custom-state) |
2746 | '(modified set changed rogue))))) | |
9b5007e7 | 2747 | ,@(when (or custom-file init-file-user) |
70482877 | 2748 | '(("Erase Customization" custom-variable-reset-standard |
73e60f53 CY |
2749 | (lambda (widget) |
2750 | (and (get (widget-value widget) 'standard-value) | |
2751 | (memq (widget-get widget :custom-state) | |
2752 | '(modified set changed saved rogue))))))) | |
70482877 LT |
2753 | ("Set to Backup Value" custom-variable-reset-backup |
2754 | (lambda (widget) | |
2755 | (get (widget-value widget) 'backup-value))) | |
2756 | ("---" ignore ignore) | |
2757 | ("Add Comment" custom-comment-show custom-comment-invisible-p) | |
eaa99205 | 2758 | ("---" ignore ignore) |
70482877 | 2759 | ("Show Current Value" custom-variable-edit |
73e60f53 | 2760 | (lambda (widget) |
eaa99205 | 2761 | (eq (widget-get widget :custom-form) 'lisp))) |
70482877 | 2762 | ("Show Saved Lisp Expression" custom-variable-edit-lisp |
eaa99205 CY |
2763 | (lambda (widget) |
2764 | (eq (widget-get widget :custom-form) 'edit)))) | |
d543e20b | 2765 | "Alist of actions for the `custom-variable' widget. |
6d528fc5 PA |
2766 | Each entry has the form (NAME ACTION FILTER) where NAME is the name of |
2767 | the menu entry, ACTION is the function to call on the widget when the | |
2768 | menu is selected, and FILTER is a predicate which takes a `custom-variable' | |
2769 | widget as an argument, and returns non-nil if ACTION is valid on that | |
19d63704 | 2770 | widget. If FILTER is nil, ACTION is always valid.") |
d543e20b PA |
2771 | |
2772 | (defun custom-variable-action (widget &optional event) | |
2773 | "Show the menu for `custom-variable' WIDGET. | |
2774 | Optional EVENT is the location for the menu." | |
2775 | (if (eq (widget-get widget :custom-state) 'hidden) | |
6d528fc5 | 2776 | (custom-toggle-hide widget) |
86bd10bc PA |
2777 | (unless (eq (widget-get widget :custom-state) 'modified) |
2778 | (custom-variable-state-set widget)) | |
2779 | (custom-redraw-magic widget) | |
d543e20b | 2780 | (let* ((completion-ignore-case t) |
25ac13b5 PA |
2781 | (answer (widget-choose (concat "Operation on " |
2782 | (custom-unlispify-tag-name | |
2783 | (widget-get widget :value))) | |
6d528fc5 PA |
2784 | (custom-menu-filter custom-variable-menu |
2785 | widget) | |
d543e20b PA |
2786 | event))) |
2787 | (if answer | |
2788 | (funcall answer widget))))) | |
2789 | ||
2790 | (defun custom-variable-edit (widget) | |
2791 | "Edit value of WIDGET." | |
2792 | (widget-put widget :custom-state 'unknown) | |
2793 | (widget-put widget :custom-form 'edit) | |
2794 | (custom-redraw widget)) | |
2795 | ||
2796 | (defun custom-variable-edit-lisp (widget) | |
2365594b | 2797 | "Edit the Lisp representation of the value of WIDGET." |
d543e20b PA |
2798 | (widget-put widget :custom-state 'unknown) |
2799 | (widget-put widget :custom-form 'lisp) | |
2800 | (custom-redraw widget)) | |
2801 | ||
2802 | (defun custom-variable-set (widget) | |
2803 | "Set the current value for the variable being edited by WIDGET." | |
6d528fc5 PA |
2804 | (let* ((form (widget-get widget :custom-form)) |
2805 | (state (widget-get widget :custom-state)) | |
2806 | (child (car (widget-get widget :children))) | |
2807 | (symbol (widget-value widget)) | |
2808 | (set (or (get symbol 'custom-set) 'set-default)) | |
d3d4df42 DL |
2809 | (comment-widget (widget-get widget :comment-widget)) |
2810 | (comment (widget-value comment-widget)) | |
2811 | val) | |
d543e20b | 2812 | (cond ((eq state 'hidden) |
896a6a5d | 2813 | (error "Cannot set hidden variable")) |
d543e20b PA |
2814 | ((setq val (widget-apply child :validate)) |
2815 | (goto-char (widget-get val :from)) | |
2816 | (error "%s" (widget-get val :error))) | |
f985c5f7 | 2817 | ((memq form '(lisp mismatch)) |
d3d4df42 DL |
2818 | (when (equal comment "") |
2819 | (setq comment nil) | |
2820 | ;; Make the comment invisible by hand if it's empty | |
164cfaeb | 2821 | (custom-comment-hide comment-widget)) |
bde4f354 | 2822 | (custom-variable-backup-value widget) |
25c6d447 | 2823 | (custom-push-theme 'theme-value symbol 'user |
c5d290fb | 2824 | 'set (custom-quote (widget-value child))) |
6d528fc5 | 2825 | (funcall set symbol (eval (setq val (widget-value child)))) |
d3d4df42 DL |
2826 | (put symbol 'customized-value (list val)) |
2827 | (put symbol 'variable-comment comment) | |
2828 | (put symbol 'customized-variable-comment comment)) | |
d543e20b | 2829 | (t |
d3d4df42 DL |
2830 | (when (equal comment "") |
2831 | (setq comment nil) | |
2832 | ;; Make the comment invisible by hand if it's empty | |
164cfaeb | 2833 | (custom-comment-hide comment-widget)) |
bde4f354 | 2834 | (custom-variable-backup-value widget) |
25c6d447 | 2835 | (custom-push-theme 'theme-value symbol 'user |
c5d290fb | 2836 | 'set (custom-quote (widget-value child))) |
6d528fc5 | 2837 | (funcall set symbol (setq val (widget-value child))) |
d3d4df42 DL |
2838 | (put symbol 'customized-value (list (custom-quote val))) |
2839 | (put symbol 'variable-comment comment) | |
2840 | (put symbol 'customized-variable-comment comment))) | |
d543e20b PA |
2841 | (custom-variable-state-set widget) |
2842 | (custom-redraw-magic widget))) | |
2843 | ||
5ae87ed4 MR |
2844 | (defun custom-variable-mark-to-save (widget) |
2845 | "Set value and mark for saving the variable edited by WIDGET." | |
6d528fc5 PA |
2846 | (let* ((form (widget-get widget :custom-form)) |
2847 | (state (widget-get widget :custom-state)) | |
2848 | (child (car (widget-get widget :children))) | |
2849 | (symbol (widget-value widget)) | |
2850 | (set (or (get symbol 'custom-set) 'set-default)) | |
d3d4df42 DL |
2851 | (comment-widget (widget-get widget :comment-widget)) |
2852 | (comment (widget-value comment-widget)) | |
6d528fc5 | 2853 | val) |
d543e20b | 2854 | (cond ((eq state 'hidden) |
896a6a5d | 2855 | (error "Cannot set hidden variable")) |
d543e20b PA |
2856 | ((setq val (widget-apply child :validate)) |
2857 | (goto-char (widget-get val :from)) | |
6b292312 | 2858 | (error "Saving %s: %s" symbol (widget-get val :error))) |
f985c5f7 | 2859 | ((memq form '(lisp mismatch)) |
d3d4df42 DL |
2860 | (when (equal comment "") |
2861 | (setq comment nil) | |
2862 | ;; Make the comment invisible by hand if it's empty | |
164cfaeb | 2863 | (custom-comment-hide comment-widget)) |
d543e20b | 2864 | (put symbol 'saved-value (list (widget-value child))) |
c942535f | 2865 | (custom-push-theme 'theme-value symbol 'user |
c5d290fb | 2866 | 'set (custom-quote (widget-value child))) |
d3d4df42 DL |
2867 | (funcall set symbol (eval (widget-value child))) |
2868 | (put symbol 'variable-comment comment) | |
2869 | (put symbol 'saved-variable-comment comment)) | |
d543e20b | 2870 | (t |
d3d4df42 DL |
2871 | (when (equal comment "") |
2872 | (setq comment nil) | |
2873 | ;; Make the comment invisible by hand if it's empty | |
164cfaeb | 2874 | (custom-comment-hide comment-widget)) |
d3d4df42 DL |
2875 | (put symbol 'saved-value |
2876 | (list (custom-quote (widget-value child)))) | |
c942535f | 2877 | (custom-push-theme 'theme-value symbol 'user |
c5d290fb | 2878 | 'set (custom-quote (widget-value child))) |
d3d4df42 DL |
2879 | (funcall set symbol (widget-value child)) |
2880 | (put symbol 'variable-comment comment) | |
2881 | (put symbol 'saved-variable-comment comment))) | |
d543e20b | 2882 | (put symbol 'customized-value nil) |
5ae87ed4 MR |
2883 | (put symbol 'customized-variable-comment nil))) |
2884 | ||
2885 | (defsubst custom-variable-state-set-and-redraw (widget) | |
2886 | "Set state of variable widget WIDGET and redraw with current settings." | |
2887 | (custom-variable-state-set widget) | |
2888 | (custom-redraw-magic widget)) | |
2889 | ||
2890 | (defun custom-variable-save (widget) | |
2891 | "Save value of variable edited by widget WIDGET." | |
2892 | (custom-variable-mark-to-save widget) | |
2893 | (custom-save-all) | |
2894 | (custom-variable-state-set-and-redraw widget)) | |
d543e20b PA |
2895 | |
2896 | (defun custom-variable-reset-saved (widget) | |
bde4f354 | 2897 | "Restore the saved value for the variable being edited by WIDGET. |
67177975 | 2898 | This also updates the buffer to show that value. |
bde4f354 RS |
2899 | The value that was current before this operation |
2900 | becomes the backup value, so you can get it again." | |
6d528fc5 | 2901 | (let* ((symbol (widget-value widget)) |
d3d4df42 | 2902 | (set (or (get symbol 'custom-set) 'set-default)) |
d3d4df42 DL |
2903 | (value (get symbol 'saved-value)) |
2904 | (comment (get symbol 'saved-variable-comment))) | |
2905 | (cond ((or value comment) | |
2906 | (put symbol 'variable-comment comment) | |
bde4f354 | 2907 | (custom-variable-backup-value widget) |
d358aa10 | 2908 | (custom-push-theme 'theme-value symbol 'user 'set (car-safe value)) |
d3d4df42 DL |
2909 | (condition-case nil |
2910 | (funcall set symbol (eval (car value))) | |
2911 | (error nil))) | |
2912 | (t | |
2913 | (error "No saved value for %s" symbol))) | |
d543e20b | 2914 | (put symbol 'customized-value nil) |
d3d4df42 | 2915 | (put symbol 'customized-variable-comment nil) |
d543e20b | 2916 | (widget-put widget :custom-state 'unknown) |
d3d4df42 | 2917 | ;; This call will possibly make the comment invisible |
d543e20b PA |
2918 | (custom-redraw widget))) |
2919 | ||
5ae87ed4 MR |
2920 | (defun custom-variable-mark-to-reset-standard (widget) |
2921 | "Mark to restore standard setting for the variable edited by widget WIDGET. | |
2922 | If `custom-reset-standard-variables-list' is nil, save, reset and | |
2923 | redraw the widget immediately." | |
d358aa10 | 2924 | (let* ((symbol (widget-value widget))) |
25ac13b5 | 2925 | (if (get symbol 'standard-value) |
25c6d447 | 2926 | (custom-variable-backup-value widget) |
5dd0cad0 | 2927 | (error "No standard setting known for %S" symbol)) |
164cfaeb | 2928 | (put symbol 'variable-comment nil) |
d543e20b | 2929 | (put symbol 'customized-value nil) |
d3d4df42 | 2930 | (put symbol 'customized-variable-comment nil) |
d358aa10 | 2931 | (custom-push-theme 'theme-value symbol 'user 'reset) |
25c6d447 | 2932 | (custom-theme-recalc-variable symbol) |
5ae87ed4 MR |
2933 | (if (and custom-reset-standard-variables-list |
2934 | (or (get symbol 'saved-value) (get symbol 'saved-variable-comment))) | |
2935 | (progn | |
2936 | (put symbol 'saved-value nil) | |
2937 | (put symbol 'saved-variable-comment nil) | |
2938 | ;; Append this to `custom-reset-standard-variables-list' to | |
2939 | ;; have `custom-reset-standard-save-and-update' save setting | |
2940 | ;; to the file, update the widget's state, and redraw it. | |
2941 | (setq custom-reset-standard-variables-list | |
2942 | (cons widget custom-reset-standard-variables-list))) | |
2943 | (when (or (get symbol 'saved-value) (get symbol 'saved-variable-comment)) | |
2944 | (put symbol 'saved-value nil) | |
2945 | (put symbol 'saved-variable-comment nil) | |
2946 | (custom-save-all)) | |
2947 | (widget-put widget :custom-state 'unknown) | |
2948 | ;; This call will possibly make the comment invisible | |
2949 | (custom-redraw widget)))) | |
2950 | ||
2951 | (defun custom-variable-reset-standard (widget) | |
2952 | "Restore standard setting for the variable edited by WIDGET. | |
2953 | This operation eliminates any saved setting for the variable, | |
2954 | restoring it to the state of a variable that has never been customized. | |
2955 | The value that was current before this operation | |
2956 | becomes the backup value, so you can get it again." | |
2957 | (let (custom-reset-standard-variables-list) | |
2958 | (custom-variable-mark-to-reset-standard widget))) | |
d543e20b | 2959 | |
bde4f354 RS |
2960 | (defun custom-variable-backup-value (widget) |
2961 | "Back up the current value for WIDGET's variable. | |
2962 | The backup value is kept in the car of the `backup-value' property." | |
2963 | (let* ((symbol (widget-value widget)) | |
2964 | (get (or (get symbol 'custom-get) 'default-value)) | |
2965 | (type (custom-variable-type symbol)) | |
2966 | (conv (widget-convert type)) | |
2967 | (value (if (default-boundp symbol) | |
2968 | (funcall get symbol) | |
2969 | (widget-get conv :value)))) | |
2970 | (put symbol 'backup-value (list value)))) | |
2971 | ||
2972 | (defun custom-variable-reset-backup (widget) | |
2973 | "Restore the backup value for the variable being edited by WIDGET. | |
2974 | The value that was current before this operation | |
2975 | becomes the backup value, so you can use this operation repeatedly | |
2976 | to switch between two values." | |
2977 | (let* ((symbol (widget-value widget)) | |
2978 | (set (or (get symbol 'custom-set) 'set-default)) | |
2979 | (value (get symbol 'backup-value)) | |
2980 | (comment-widget (widget-get widget :comment-widget)) | |
2981 | (comment (widget-value comment-widget))) | |
2982 | (if value | |
2983 | (progn | |
2984 | (custom-variable-backup-value widget) | |
25c6d447 | 2985 | (custom-push-theme 'theme-value symbol 'user 'set value) |
bde4f354 RS |
2986 | (condition-case nil |
2987 | (funcall set symbol (car value)) | |
2988 | (error nil))) | |
2989 | (error "No backup value for %s" symbol)) | |
2990 | (put symbol 'customized-value (list (car value))) | |
2991 | (put symbol 'variable-comment comment) | |
2992 | (put symbol 'customized-variable-comment comment) | |
2993 | (custom-variable-state-set widget) | |
2994 | ;; This call will possibly make the comment invisible | |
2995 | (custom-redraw widget))) | |
2996 | ||
12bafdaa CY |
2997 | ;;; The `custom-visibility' Widget |
2998 | ||
2999 | (define-widget 'custom-visibility 'visibility | |
3000 | "Show or hide a documentation string." | |
3001 | :button-face 'custom-visibility | |
3002 | :pressed-face 'custom-visibility | |
3003 | :mouse-face 'highlight | |
3004 | :pressed-face 'highlight) | |
3005 | ||
3006 | (defface custom-visibility | |
3007 | '((t :height 0.8 :inherit link)) | |
3008 | "Face for the `custom-visibility' widget." | |
3009 | :version "23.1" | |
3010 | :group 'custom-faces) | |
3011 | ||
d543e20b PA |
3012 | ;;; The `custom-face-edit' Widget. |
3013 | ||
3014 | (define-widget 'custom-face-edit 'checklist | |
3015 | "Edit face attributes." | |
3016 | :format "%t: %v" | |
3017 | :tag "Attributes" | |
2dfa4c57 | 3018 | :extra-offset 13 |
d3d4df42 | 3019 | :button-args '(:help-echo "Control whether this attribute has any effect.") |
d75fa08f RS |
3020 | :value-to-internal 'custom-face-edit-fix-value |
3021 | :match (lambda (widget value) | |
ee1f522d | 3022 | (widget-checklist-match widget |
d75fa08f | 3023 | (custom-face-edit-fix-value widget value))) |
3ea051cb | 3024 | :convert-widget 'custom-face-edit-convert-widget |
d543e20b | 3025 | :args (mapcar (lambda (att) |
d3d4df42 | 3026 | (list 'group |
d543e20b PA |
3027 | :inline t |
3028 | :sibling-args (widget-get (nth 1 att) :sibling-args) | |
d3d4df42 | 3029 | (list 'const :format "" :value (nth 0 att)) |
d543e20b PA |
3030 | (nth 1 att))) |
3031 | custom-face-attributes)) | |
3032 | ||
d75fa08f | 3033 | (defun custom-face-edit-fix-value (widget value) |
0bbe869a AS |
3034 | "Ignoring WIDGET, convert :bold and :italic in VALUE to new form. |
3035 | Also change :reverse-video to :inverse-video." | |
4f985043 RS |
3036 | (if (listp value) |
3037 | (let (result) | |
3038 | (while value | |
3039 | (let ((key (car value)) | |
3040 | (val (car (cdr value)))) | |
3041 | (cond ((eq key :italic) | |
3042 | (push :slant result) | |
3043 | (push (if val 'italic 'normal) result)) | |
3044 | ((eq key :bold) | |
3045 | (push :weight result) | |
3046 | (push (if val 'bold 'normal) result)) | |
0bbe869a AS |
3047 | ((eq key :reverse-video) |
3048 | (push :inverse-video result) | |
3049 | (push val result)) | |
ee1f522d | 3050 | (t |
4f985043 RS |
3051 | (push key result) |
3052 | (push val result)))) | |
3053 | (setq value (cdr (cdr value)))) | |
3054 | (setq result (nreverse result)) | |
3055 | result) | |
3056 | value)) | |
d75fa08f | 3057 | |
3ea051cb MB |
3058 | (defun custom-face-edit-convert-widget (widget) |
3059 | "Convert :args as widget types in WIDGET." | |
3060 | (widget-put | |
3061 | widget | |
3062 | :args (mapcar (lambda (arg) | |
3063 | (widget-convert arg | |
3064 | :deactivate 'custom-face-edit-deactivate | |
3065 | :activate 'custom-face-edit-activate | |
3066 | :delete 'custom-face-edit-delete)) | |
3067 | (widget-get widget :args))) | |
3068 | widget) | |
3069 | ||
3070 | (defun custom-face-edit-deactivate (widget) | |
3071 | "Make face widget WIDGET inactive for user modifications." | |
3072 | (unless (widget-get widget :inactive) | |
3073 | (let ((tag (custom-face-edit-attribute-tag widget)) | |
3074 | (from (copy-marker (widget-get widget :from))) | |
3ea051cb MB |
3075 | (value (widget-value widget)) |
3076 | (inhibit-read-only t) | |
3077 | (inhibit-modification-hooks t)) | |
3078 | (save-excursion | |
3079 | (goto-char from) | |
3080 | (widget-default-delete widget) | |
3081 | (insert tag ": *\n") | |
3082 | (widget-put widget :inactive | |
3083 | (cons value (cons from (- (point) from)))))))) | |
3084 | ||
3085 | (defun custom-face-edit-activate (widget) | |
47fdaab8 | 3086 | "Make face widget WIDGET active for user modifications." |
3ea051cb MB |
3087 | (let ((inactive (widget-get widget :inactive)) |
3088 | (inhibit-read-only t) | |
3089 | (inhibit-modification-hooks t)) | |
3090 | (when (consp inactive) | |
3091 | (save-excursion | |
3092 | (goto-char (car (cdr inactive))) | |
3093 | (delete-region (point) (+ (point) (cdr (cdr inactive)))) | |
3094 | (widget-put widget :inactive nil) | |
3095 | (widget-apply widget :create) | |
3096 | (widget-value-set widget (car inactive)) | |
3097 | (widget-setup))))) | |
3098 | ||
3099 | (defun custom-face-edit-delete (widget) | |
3127aa13 | 3100 | "Remove WIDGET from the buffer." |
3ea051cb MB |
3101 | (let ((inactive (widget-get widget :inactive)) |
3102 | (inhibit-read-only t) | |
3103 | (inhibit-modification-hooks t)) | |
3104 | (if (not inactive) | |
3105 | ;; Widget is alive, we don't have to do anything special | |
3106 | (widget-default-delete widget) | |
3107 | ;; WIDGET is already deleted because we did so to inactivate it; | |
3108 | ;; now just get rid of the label we put in its place. | |
3109 | (delete-region (car (cdr inactive)) | |
3110 | (+ (car (cdr inactive)) (cdr (cdr inactive)))) | |
3111 | (widget-put widget :inactive nil)))) | |
ee1f522d | 3112 | |
3ea051cb MB |
3113 | |
3114 | (defun custom-face-edit-attribute-tag (widget) | |
3115 | "Returns the first :tag property in WIDGET or one of its children." | |
3116 | (let ((tag (widget-get widget :tag))) | |
3117 | (or (and (not (equal tag "")) tag) | |
3118 | (let ((children (widget-get widget :children))) | |
3119 | (while (and (null tag) children) | |
3120 | (setq tag (custom-face-edit-attribute-tag (pop children)))) | |
3121 | tag)))) | |
3122 | ||
d543e20b PA |
3123 | ;;; The `custom-display' Widget. |
3124 | ||
3125 | (define-widget 'custom-display 'menu-choice | |
3126 | "Select a display type." | |
3127 | :tag "Display" | |
3128 | :value t | |
3129 | :help-echo "Specify frames where the face attributes should be used." | |
3130 | :args '((const :tag "all" t) | |
b9afd6dd | 3131 | (const :tag "defaults" default) |
d543e20b PA |
3132 | (checklist |
3133 | :offset 0 | |
3134 | :extra-offset 9 | |
3135 | :args ((group :sibling-args (:help-echo "\ | |
3136 | Only match the specified window systems.") | |
3137 | (const :format "Type: " | |
3138 | type) | |
3139 | (checklist :inline t | |
3140 | :offset 0 | |
3141 | (const :format "X " | |
3142 | :sibling-args (:help-echo "\ | |
3143 | The X11 Window System.") | |
3144 | x) | |
3145 | (const :format "PM " | |
3146 | :sibling-args (:help-echo "\ | |
3147 | OS/2 Presentation Manager.") | |
3148 | pm) | |
b97aca27 | 3149 | (const :format "W32 " |
d543e20b | 3150 | :sibling-args (:help-echo "\ |
b97aca27 GV |
3151 | Windows NT/9X.") |
3152 | w32) | |
edfda783 AR |
3153 | (const :format "NS " |
3154 | :sibling-args (:help-echo "\ | |
3155 | GNUstep or Macintosh OS Cocoa interface.") | |
3156 | ns) | |
d543e20b PA |
3157 | (const :format "DOS " |
3158 | :sibling-args (:help-echo "\ | |
3159 | Plain MS-DOS.") | |
3160 | pc) | |
3161 | (const :format "TTY%n" | |
3162 | :sibling-args (:help-echo "\ | |
3163 | Plain text terminals.") | |
3164 | tty))) | |
3165 | (group :sibling-args (:help-echo "\ | |
3166 | Only match the frames with the specified color support.") | |
3167 | (const :format "Class: " | |
3168 | class) | |
3169 | (checklist :inline t | |
3170 | :offset 0 | |
3171 | (const :format "Color " | |
3172 | :sibling-args (:help-echo "\ | |
3173 | Match color frames.") | |
3174 | color) | |
3175 | (const :format "Grayscale " | |
3176 | :sibling-args (:help-echo "\ | |
3177 | Match grayscale frames.") | |
3178 | grayscale) | |
3179 | (const :format "Monochrome%n" | |
3180 | :sibling-args (:help-echo "\ | |
3181 | Match frames with no color support.") | |
3182 | mono))) | |
3183 | (group :sibling-args (:help-echo "\ | |
c4d9734c JL |
3184 | The minimum number of colors the frame should support.") |
3185 | (const :format "" min-colors) | |
3186 | (integer :tag "Minimum number of colors" )) | |
3187 | (group :sibling-args (:help-echo "\ | |
d543e20b PA |
3188 | Only match frames with the specified intensity.") |
3189 | (const :format "\ | |
3190 | Background brightness: " | |
3191 | background) | |
3192 | (checklist :inline t | |
3193 | :offset 0 | |
3194 | (const :format "Light " | |
3195 | :sibling-args (:help-echo "\ | |
3196 | Match frames with light backgrounds.") | |
3197 | light) | |
3198 | (const :format "Dark\n" | |
3199 | :sibling-args (:help-echo "\ | |
3200 | Match frames with dark backgrounds.") | |
2b32d1a7 MB |
3201 | dark))) |
3202 | (group :sibling-args (:help-echo "\ | |
3203 | Only match frames that support the specified face attributes.") | |
3204 | (const :format "Supports attributes:" supports) | |
4abe16b5 | 3205 | (custom-face-edit :inline t :format "%n%v")))))) |
d543e20b PA |
3206 | |
3207 | ;;; The `custom-face' Widget. | |
3208 | ||
d478e69d | 3209 | (defface custom-face-tag |
01b38d61 | 3210 | `((t :inherit custom-variable-tag)) |
d543e20b | 3211 | "Face used for face tags." |
bd042c03 | 3212 | :group 'custom-faces) |
d478e69d MB |
3213 | ;; backward-compatibility alias |
3214 | (put 'custom-face-tag-face 'face-alias 'custom-face-tag) | |
d543e20b | 3215 | |
d64478da KH |
3216 | (defcustom custom-face-default-form 'selected |
3217 | "Default form of displaying face definition." | |
3218 | :type '(choice (const all) | |
3219 | (const selected) | |
3220 | (const lisp)) | |
cd32a7ba DN |
3221 | :group 'custom-buffer |
3222 | :version "20.3") | |
d64478da | 3223 | |
d543e20b PA |
3224 | (define-widget 'custom-face 'custom |
3225 | "Customize face." | |
d543e20b PA |
3226 | :sample-face 'custom-face-tag-face |
3227 | :help-echo "Set or reset this face." | |
23c0fb21 | 3228 | :documentation-property #'face-doc-string |
d543e20b PA |
3229 | :value-create 'custom-face-value-create |
3230 | :action 'custom-face-action | |
9097aeb7 | 3231 | :custom-category 'face |
d64478da | 3232 | :custom-form nil ; defaults to value of `custom-face-default-form' |
d543e20b | 3233 | :custom-set 'custom-face-set |
5ae87ed4 | 3234 | :custom-mark-to-save 'custom-face-mark-to-save |
d543e20b PA |
3235 | :custom-reset-current 'custom-redraw |
3236 | :custom-reset-saved 'custom-face-reset-saved | |
25ac13b5 | 3237 | :custom-reset-standard 'custom-face-reset-standard |
5ae87ed4 | 3238 | :custom-mark-to-reset-standard 'custom-face-mark-to-reset-standard |
4f985043 | 3239 | :custom-standard-value 'custom-face-standard-value |
5ae87ed4 | 3240 | :custom-state-set-and-redraw 'custom-face-state-set-and-redraw |
d543e20b PA |
3241 | :custom-menu 'custom-face-menu-create) |
3242 | ||
d3d4df42 | 3243 | (define-widget 'custom-face-all 'editable-list |
d543e20b PA |
3244 | "An editable list of display specifications and attributes." |
3245 | :entry-format "%i %d %v" | |
3246 | :insert-button-args '(:help-echo "Insert new display specification here.") | |
3247 | :append-button-args '(:help-echo "Append new display specification here.") | |
3248 | :delete-button-args '(:help-echo "Delete this display specification.") | |
3249 | :args '((group :format "%v" custom-display custom-face-edit))) | |
3250 | ||
3251 | (defconst custom-face-all (widget-convert 'custom-face-all) | |
3252 | "Converted version of the `custom-face-all' widget.") | |
3253 | ||
3254 | (define-widget 'custom-display-unselected 'item | |
3255 | "A display specification that doesn't match the selected display." | |
3256 | :match 'custom-display-unselected-match) | |
3257 | ||
3258 | (defun custom-display-unselected-match (widget value) | |
3259 | "Non-nil if VALUE is an unselected display specification." | |
86bd10bc | 3260 | (not (face-spec-set-match-display value (selected-frame)))) |
d543e20b | 3261 | |
d3d4df42 | 3262 | (define-widget 'custom-face-selected 'group |
d543e20b | 3263 | "Edit the attributes of the selected display in a face specification." |
2dfa4c57 RS |
3264 | :args '((choice :inline t |
3265 | (group :tag "With Defaults" :inline t | |
3266 | (group (const :tag "" default) | |
3267 | (custom-face-edit :tag " Default\n Attributes")) | |
3268 | (repeat :format "" | |
3269 | :inline t | |
3270 | (group custom-display-unselected sexp)) | |
3271 | (group (sexp :format "") | |
3272 | (custom-face-edit :tag " Overriding\n Attributes")) | |
3273 | (repeat :format "" | |
3274 | :inline t | |
3275 | sexp)) | |
3276 | (group :tag "No Defaults" :inline t | |
3277 | (repeat :format "" | |
3278 | :inline t | |
3279 | (group custom-display-unselected sexp)) | |
3280 | (group (sexp :format "") | |
3281 | (custom-face-edit :tag "\n Attributes")) | |
3282 | (repeat :format "" | |
3283 | :inline t | |
3284 | sexp))))) | |
3285 | ||
3286 | ||
d543e20b PA |
3287 | |
3288 | (defconst custom-face-selected (widget-convert 'custom-face-selected) | |
3289 | "Converted version of the `custom-face-selected' widget.") | |
3290 | ||
3ea051cb | 3291 | (defun custom-filter-face-spec (spec filter-index &optional default-filter) |
f5b50baa MB |
3292 | "Return a canonicalized version of SPEC using. |
3293 | FILTER-INDEX is the index in the entry for each attribute in | |
3294 | `custom-face-attributes' at which the appropriate filter function can be | |
3295 | found, and DEFAULT-FILTER is the filter to apply for attributes that | |
3296 | don't specify one." | |
3297 | (mapcar (lambda (entry) | |
3298 | ;; Filter a single face-spec entry | |
3299 | (let ((tests (car entry)) | |
3300 | (unfiltered-attrs | |
3301 | ;; Handle both old- and new-style attribute syntax | |
3302 | (if (listp (car (cdr entry))) | |
3303 | (car (cdr entry)) | |
3304 | (cdr entry))) | |
3305 | (filtered-attrs nil)) | |
3306 | ;; Filter each face attribute | |
3307 | (while unfiltered-attrs | |
3308 | (let* ((attr (pop unfiltered-attrs)) | |
3309 | (pre-filtered-value (pop unfiltered-attrs)) | |
3310 | (filter | |
3311 | (or (nth filter-index (assq attr custom-face-attributes)) | |
3312 | default-filter)) | |
3313 | (filtered-value | |
3314 | (if filter | |
3315 | (funcall filter pre-filtered-value) | |
3316 | pre-filtered-value))) | |
3317 | (push filtered-value filtered-attrs) | |
3318 | (push attr filtered-attrs))) | |
3319 | ;; | |
3320 | (list tests filtered-attrs))) | |
3321 | spec)) | |
3322 | ||
3323 | (defun custom-pre-filter-face-spec (spec) | |
3324 | "Return SPEC changed as necessary for editing by the face customization widget. | |
3325 | SPEC must be a full face spec." | |
3ea051cb | 3326 | (custom-filter-face-spec spec 2)) |
f5b50baa MB |
3327 | |
3328 | (defun custom-post-filter-face-spec (spec) | |
3329 | "Return the customized SPEC in a form suitable for setting the face." | |
3ea051cb | 3330 | (custom-filter-face-spec spec 3)) |
f5b50baa | 3331 | |
d543e20b | 3332 | (defun custom-face-value-create (widget) |
944c91b6 PA |
3333 | "Create a list of the display specifications for WIDGET." |
3334 | (let ((buttons (widget-get widget :buttons)) | |
d3d4df42 | 3335 | children |
944c91b6 PA |
3336 | (symbol (widget-get widget :value)) |
3337 | (tag (widget-get widget :tag)) | |
3338 | (state (widget-get widget :custom-state)) | |
3339 | (begin (point)) | |
3340 | (is-last (widget-get widget :custom-last)) | |
3341 | (prefix (widget-get widget :custom-prefix))) | |
3342 | (unless tag | |
3343 | (setq tag (prin1-to-string symbol))) | |
3344 | (cond ((eq custom-buffer-style 'tree) | |
da5ec617 | 3345 | (insert prefix (if is-last " `--- " " |--- ")) |
944c91b6 | 3346 | (push (widget-create-child-and-convert |
c953515e | 3347 | widget 'custom-browse-face-tag) |
944c91b6 PA |
3348 | buttons) |
3349 | (insert " " tag "\n") | |
3350 | (widget-put widget :buttons buttons)) | |
3351 | (t | |
3352 | ;; Create tag. | |
3353 | (insert tag) | |
c069a9d3 | 3354 | (widget-specify-sample widget begin (point)) |
944c91b6 PA |
3355 | (if (eq custom-buffer-style 'face) |
3356 | (insert " ") | |
a62ebc52 MB |
3357 | (if (string-match "face\\'" tag) |
3358 | (insert ":") | |
3359 | (insert " face: "))) | |
944c91b6 | 3360 | ;; Sample. |
944c91b6 PA |
3361 | (push (widget-create-child-and-convert widget 'item |
3362 | :format "(%{%t%})" | |
3363 | :sample-face symbol | |
3364 | :tag "sample") | |
3365 | buttons) | |
3366 | ;; Visibility. | |
3367 | (insert " ") | |
d3d4df42 | 3368 | (push (widget-create-child-and-convert |
944c91b6 PA |
3369 | widget 'visibility |
3370 | :help-echo "Hide or show this face." | |
7f663295 RS |
3371 | :on "Hide Face" |
3372 | :off "Show Face" | |
944c91b6 PA |
3373 | :action 'custom-toggle-parent |
3374 | (not (eq state 'hidden))) | |
3375 | buttons) | |
3376 | ;; Magic. | |
3377 | (insert "\n") | |
3378 | (let ((magic (widget-create-child-and-convert | |
3379 | widget 'custom-magic nil))) | |
3380 | (widget-put widget :custom-magic magic) | |
3381 | (push magic buttons)) | |
3382 | ;; Update buttons. | |
3383 | (widget-put widget :buttons buttons) | |
3384 | ;; Insert documentation. | |
5ae87ed4 | 3385 | (widget-put widget :documentation-indent 3) |
12bafdaa CY |
3386 | (widget-add-documentation-string-button |
3387 | widget :visibility-widget 'custom-visibility) | |
3388 | ||
d3d4df42 DL |
3389 | ;; The comment field |
3390 | (unless (eq state 'hidden) | |
3391 | (let* ((comment (get symbol 'face-comment)) | |
3392 | (comment-widget | |
3393 | (widget-create-child-and-convert | |
3394 | widget 'custom-comment | |
3395 | :parent widget | |
3396 | :value (or comment "")))) | |
3397 | (widget-put widget :comment-widget comment-widget) | |
3398 | (push comment-widget children))) | |
944c91b6 PA |
3399 | ;; See also. |
3400 | (unless (eq state 'hidden) | |
3401 | (when (eq (widget-get widget :custom-level) 1) | |
3402 | (custom-add-parent-links widget)) | |
3403 | (custom-add-see-also widget)) | |
3404 | ;; Editor. | |
3405 | (unless (eq (preceding-char) ?\n) | |
3406 | (insert "\n")) | |
3407 | (unless (eq state 'hidden) | |
3408 | (message "Creating face editor...") | |
3409 | (custom-load-widget widget) | |
d64478da KH |
3410 | (unless (widget-get widget :custom-form) |
3411 | (widget-put widget :custom-form custom-face-default-form)) | |
944c91b6 | 3412 | (let* ((symbol (widget-value widget)) |
61763509 PA |
3413 | (spec (or (get symbol 'customized-face) |
3414 | (get symbol 'saved-face) | |
944c91b6 PA |
3415 | (get symbol 'face-defface-spec) |
3416 | ;; Attempt to construct it. | |
d3d4df42 | 3417 | (list (list t (custom-face-attributes-get |
944c91b6 PA |
3418 | symbol (selected-frame)))))) |
3419 | (form (widget-get widget :custom-form)) | |
3420 | (indent (widget-get widget :indent)) | |
fa0b3d46 RS |
3421 | edit) |
3422 | ;; If the user has changed this face in some other way, | |
3423 | ;; edit it as the user has specified it. | |
3424 | (if (not (face-spec-match-p symbol spec (selected-frame))) | |
3425 | (setq spec (list (list t (face-attr-construct symbol (selected-frame)))))) | |
f5b50baa | 3426 | (setq spec (custom-pre-filter-face-spec spec)) |
fa0b3d46 | 3427 | (setq edit (widget-create-child-and-convert |
944c91b6 PA |
3428 | widget |
3429 | (cond ((and (eq form 'selected) | |
d3d4df42 | 3430 | (widget-apply custom-face-selected |
944c91b6 PA |
3431 | :match spec)) |
3432 | (when indent (insert-char ?\ indent)) | |
3433 | 'custom-face-selected) | |
3434 | ((and (not (eq form 'lisp)) | |
3435 | (widget-apply custom-face-all | |
3436 | :match spec)) | |
3437 | 'custom-face-all) | |
d3d4df42 | 3438 | (t |
944c91b6 PA |
3439 | (when indent (insert-char ?\ indent)) |
3440 | 'sexp)) | |
fa0b3d46 | 3441 | :value spec)) |
944c91b6 | 3442 | (custom-face-state-set widget) |
d3d4df42 DL |
3443 | (push edit children) |
3444 | (widget-put widget :children children)) | |
944c91b6 | 3445 | (message "Creating face editor...done")))))) |
d543e20b | 3446 | |
d3d4df42 | 3447 | (defvar custom-face-menu |
70482877 | 3448 | `(("Set for Current Session" custom-face-set) |
9b5007e7 | 3449 | ,@(when (or custom-file init-file-user) |
633bb8a9 | 3450 | '(("Save for Future Sessions" custom-face-save))) |
70482877 LT |
3451 | ("Undo Edits" custom-redraw |
3452 | (lambda (widget) | |
3453 | (memq (widget-get widget :custom-state) '(modified changed)))) | |
3454 | ("Reset to Saved" custom-face-reset-saved | |
0c731046 CY |
3455 | (lambda (widget) |
3456 | (or (get (widget-value widget) 'saved-face) | |
3457 | (get (widget-value widget) 'saved-face-comment)))) | |
9b5007e7 | 3458 | ,@(when (or custom-file init-file-user) |
70482877 | 3459 | '(("Erase Customization" custom-face-reset-standard |
73e60f53 CY |
3460 | (lambda (widget) |
3461 | (get (widget-value widget) 'face-defface-spec))))) | |
eaa99205 | 3462 | ("---" ignore ignore) |
70482877 LT |
3463 | ("Add Comment" custom-comment-show custom-comment-invisible-p) |
3464 | ("---" ignore ignore) | |
3465 | ("For Current Display" custom-face-edit-selected | |
eaa99205 CY |
3466 | (lambda (widget) |
3467 | (not (eq (widget-get widget :custom-form) 'selected)))) | |
70482877 LT |
3468 | ("For All Kinds of Displays" custom-face-edit-all |
3469 | (lambda (widget) | |
3470 | (not (eq (widget-get widget :custom-form) 'all)))) | |
3471 | ("Show Lisp Expression" custom-face-edit-lisp | |
eaa99205 CY |
3472 | (lambda (widget) |
3473 | (not (eq (widget-get widget :custom-form) 'lisp))))) | |
d543e20b | 3474 | "Alist of actions for the `custom-face' widget. |
6d528fc5 PA |
3475 | Each entry has the form (NAME ACTION FILTER) where NAME is the name of |
3476 | the menu entry, ACTION is the function to call on the widget when the | |
3477 | menu is selected, and FILTER is a predicate which takes a `custom-face' | |
3478 | widget as an argument, and returns non-nil if ACTION is valid on that | |
19d63704 | 3479 | widget. If FILTER is nil, ACTION is always valid.") |
d543e20b PA |
3480 | |
3481 | (defun custom-face-edit-selected (widget) | |
3482 | "Edit selected attributes of the value of WIDGET." | |
3483 | (widget-put widget :custom-state 'unknown) | |
3484 | (widget-put widget :custom-form 'selected) | |
3485 | (custom-redraw widget)) | |
3486 | ||
3487 | (defun custom-face-edit-all (widget) | |
3488 | "Edit all attributes of the value of WIDGET." | |
3489 | (widget-put widget :custom-state 'unknown) | |
3490 | (widget-put widget :custom-form 'all) | |
3491 | (custom-redraw widget)) | |
3492 | ||
3493 | (defun custom-face-edit-lisp (widget) | |
2365594b | 3494 | "Edit the Lisp representation of the value of WIDGET." |
d543e20b PA |
3495 | (widget-put widget :custom-state 'unknown) |
3496 | (widget-put widget :custom-form 'lisp) | |
3497 | (custom-redraw widget)) | |
3498 | ||
3499 | (defun custom-face-state-set (widget) | |
3500 | "Set the state of WIDGET." | |
d3d4df42 DL |
3501 | (let* ((symbol (widget-value widget)) |
3502 | (comment (get symbol 'face-comment)) | |
a4992f73 RS |
3503 | tmp temp |
3504 | (state | |
3505 | (cond ((progn | |
3506 | (setq tmp (get symbol 'customized-face)) | |
3507 | (setq temp (get symbol 'customized-face-comment)) | |
3508 | (or tmp temp)) | |
3509 | (if (equal temp comment) | |
3510 | 'set | |
3511 | 'changed)) | |
3512 | ((progn | |
3513 | (setq tmp (get symbol 'saved-face)) | |
3514 | (setq temp (get symbol 'saved-face-comment)) | |
3515 | (or tmp temp)) | |
3516 | (if (equal temp comment) | |
70128967 CY |
3517 | (cond |
3518 | ((eq 'user (caar (get symbol 'theme-face))) | |
3519 | 'saved) | |
d358aa10 | 3520 | ((eq 'changed (caar (get symbol 'theme-face))) |
70128967 CY |
3521 | 'changed) |
3522 | (t 'themed)) | |
a4992f73 RS |
3523 | 'changed)) |
3524 | ((get symbol 'face-defface-spec) | |
3525 | (if (equal comment nil) | |
3526 | 'standard | |
3527 | 'changed)) | |
3528 | (t | |
3529 | 'rogue)))) | |
3530 | ;; If the user called set-face-attribute to change the default | |
3531 | ;; for new frames, this face is "set outside of Customize". | |
3532 | (if (and (not (eq state 'rogue)) | |
3533 | (get symbol 'face-modified)) | |
3534 | (setq state 'changed)) | |
3535 | (widget-put widget :custom-state state))) | |
d543e20b PA |
3536 | |
3537 | (defun custom-face-action (widget &optional event) | |
3538 | "Show the menu for `custom-face' WIDGET. | |
3539 | Optional EVENT is the location for the menu." | |
3540 | (if (eq (widget-get widget :custom-state) 'hidden) | |
6d528fc5 | 3541 | (custom-toggle-hide widget) |
d543e20b PA |
3542 | (let* ((completion-ignore-case t) |
3543 | (symbol (widget-get widget :value)) | |
25ac13b5 PA |
3544 | (answer (widget-choose (concat "Operation on " |
3545 | (custom-unlispify-tag-name symbol)) | |
6d528fc5 PA |
3546 | (custom-menu-filter custom-face-menu |
3547 | widget) | |
3548 | event))) | |
d543e20b PA |
3549 | (if answer |
3550 | (funcall answer widget))))) | |
3551 | ||
3552 | (defun custom-face-set (widget) | |
3553 | "Make the face attributes in WIDGET take effect." | |
3554 | (let* ((symbol (widget-value widget)) | |
3555 | (child (car (widget-get widget :children))) | |
f5b50baa | 3556 | (value (custom-post-filter-face-spec (widget-value child))) |
d3d4df42 DL |
3557 | (comment-widget (widget-get widget :comment-widget)) |
3558 | (comment (widget-value comment-widget))) | |
3559 | (when (equal comment "") | |
3560 | (setq comment nil) | |
3561 | ;; Make the comment invisible by hand if it's empty | |
164cfaeb | 3562 | (custom-comment-hide comment-widget)) |
d543e20b | 3563 | (put symbol 'customized-face value) |
e02577b7 | 3564 | (custom-push-theme 'theme-face symbol 'user 'set value) |
f5b50baa | 3565 | (if (face-spec-choose value) |
d50e9d5b | 3566 | (face-spec-set symbol value t) |
f5b50baa MB |
3567 | ;; face-set-spec ignores empty attribute lists, so just give it |
3568 | ;; something harmless instead. | |
d50e9d5b | 3569 | (face-spec-set symbol '((t :foreground unspecified)) t)) |
d3d4df42 DL |
3570 | (put symbol 'customized-face-comment comment) |
3571 | (put symbol 'face-comment comment) | |
d543e20b PA |
3572 | (custom-face-state-set widget) |
3573 | (custom-redraw-magic widget))) | |
3574 | ||
5ae87ed4 MR |
3575 | (defun custom-face-mark-to-save (widget) |
3576 | "Mark for saving the face edited by WIDGET." | |
d543e20b PA |
3577 | (let* ((symbol (widget-value widget)) |
3578 | (child (car (widget-get widget :children))) | |
e475612a | 3579 | (value (custom-post-filter-face-spec (widget-value child))) |
d3d4df42 DL |
3580 | (comment-widget (widget-get widget :comment-widget)) |
3581 | (comment (widget-value comment-widget))) | |
3582 | (when (equal comment "") | |
3583 | (setq comment nil) | |
3584 | ;; Make the comment invisible by hand if it's empty | |
164cfaeb | 3585 | (custom-comment-hide comment-widget)) |
b76747af | 3586 | (custom-push-theme 'theme-face symbol 'user 'set value) |
e475612a | 3587 | (if (face-spec-choose value) |
d50e9d5b | 3588 | (face-spec-set symbol value t) |
e475612a MB |
3589 | ;; face-set-spec ignores empty attribute lists, so just give it |
3590 | ;; something harmless instead. | |
d50e9d5b | 3591 | (face-spec-set symbol '((t :foreground unspecified)) t)) |
4f985043 RS |
3592 | (unless (eq (widget-get widget :custom-state) 'standard) |
3593 | (put symbol 'saved-face value)) | |
d543e20b | 3594 | (put symbol 'customized-face nil) |
d3d4df42 DL |
3595 | (put symbol 'face-comment comment) |
3596 | (put symbol 'customized-face-comment nil) | |
5ae87ed4 MR |
3597 | (put symbol 'saved-face-comment comment))) |
3598 | ||
3599 | (defsubst custom-face-state-set-and-redraw (widget) | |
3600 | "Set state of face widget WIDGET and redraw with current settings." | |
3601 | (custom-face-state-set widget) | |
3602 | (custom-redraw-magic widget)) | |
3603 | ||
3604 | (defun custom-face-save (widget) | |
3605 | "Save the face edited by WIDGET." | |
3606 | (custom-face-mark-to-save widget) | |
3607 | (custom-save-all) | |
3608 | (custom-face-state-set-and-redraw widget)) | |
d543e20b | 3609 | |
633bb8a9 LT |
3610 | ;; For backward compatibility. |
3611 | (define-obsolete-function-alias 'custom-face-save-command 'custom-face-save | |
3612 | "22.1") | |
3613 | ||
d543e20b PA |
3614 | (defun custom-face-reset-saved (widget) |
3615 | "Restore WIDGET to the face's default attributes." | |
3616 | (let* ((symbol (widget-value widget)) | |
3617 | (child (car (widget-get widget :children))) | |
d3d4df42 DL |
3618 | (value (get symbol 'saved-face)) |
3619 | (comment (get symbol 'saved-face-comment)) | |
3620 | (comment-widget (widget-get widget :comment-widget))) | |
3621 | (unless (or value comment) | |
d543e20b PA |
3622 | (error "No saved value for this face")) |
3623 | (put symbol 'customized-face nil) | |
d3d4df42 | 3624 | (put symbol 'customized-face-comment nil) |
25c6d447 | 3625 | (custom-push-theme 'theme-face symbol 'user 'set value) |
d50e9d5b | 3626 | (face-spec-set symbol value t) |
d3d4df42 | 3627 | (put symbol 'face-comment comment) |
d543e20b | 3628 | (widget-value-set child value) |
d3d4df42 DL |
3629 | ;; This call manages the comment visibility |
3630 | (widget-value-set comment-widget (or comment "")) | |
d543e20b PA |
3631 | (custom-face-state-set widget) |
3632 | (custom-redraw-magic widget))) | |
3633 | ||
4f985043 RS |
3634 | (defun custom-face-standard-value (widget) |
3635 | (get (widget-value widget) 'face-defface-spec)) | |
3636 | ||
5ae87ed4 MR |
3637 | (defun custom-face-mark-to-reset-standard (widget) |
3638 | "Restore widget WIDGET to the face's standard attribute values. | |
3639 | If `custom-reset-standard-faces-list' is nil, save, reset and | |
3640 | redraw the widget immediately." | |
d543e20b PA |
3641 | (let* ((symbol (widget-value widget)) |
3642 | (child (car (widget-get widget :children))) | |
d3d4df42 DL |
3643 | (value (get symbol 'face-defface-spec)) |
3644 | (comment-widget (widget-get widget :comment-widget))) | |
d543e20b | 3645 | (unless value |
5dd0cad0 | 3646 | (error "No standard setting for this face")) |
d543e20b | 3647 | (put symbol 'customized-face nil) |
d3d4df42 | 3648 | (put symbol 'customized-face-comment nil) |
d358aa10 | 3649 | (custom-push-theme 'theme-face symbol 'user 'reset) |
d50e9d5b | 3650 | (face-spec-set symbol value t) |
25c6d447 | 3651 | (custom-theme-recalc-face symbol) |
5ae87ed4 MR |
3652 | (if (and custom-reset-standard-faces-list |
3653 | (or (get symbol 'saved-face) (get symbol 'saved-face-comment))) | |
3654 | ;; Do this later. | |
3655 | (progn | |
3656 | (put symbol 'saved-face nil) | |
3657 | (put symbol 'saved-face-comment nil) | |
3658 | ;; Append this to `custom-reset-standard-faces-list' and have | |
3659 | ;; `custom-reset-standard-save-and-update' save setting to the | |
3660 | ;; file, update the widget's state, and redraw it. | |
3661 | (setq custom-reset-standard-faces-list | |
3662 | (cons widget custom-reset-standard-faces-list))) | |
3663 | (when (or (get symbol 'saved-face) (get symbol 'saved-face-comment)) | |
3664 | (put symbol 'saved-face nil) | |
3665 | (put symbol 'saved-face-comment nil) | |
3666 | (custom-save-all)) | |
3667 | (put symbol 'face-comment nil) | |
3668 | (widget-value-set child | |
3669 | (custom-pre-filter-face-spec | |
3670 | (list (list t (custom-face-attributes-get | |
3671 | symbol nil))))) | |
3672 | ;; This call manages the comment visibility | |
3673 | (widget-value-set comment-widget "") | |
3674 | (custom-face-state-set widget) | |
3675 | (custom-redraw-magic widget)))) | |
3676 | ||
3677 | (defun custom-face-reset-standard (widget) | |
3678 | "Restore WIDGET to the face's standard attribute values. | |
3679 | This operation eliminates any saved attributes for the face, | |
3680 | restoring it to the state of a face that has never been customized." | |
3681 | (let (custom-reset-standard-faces-list) | |
3682 | (custom-face-mark-to-reset-standard widget))) | |
d543e20b PA |
3683 | |
3684 | ;;; The `face' Widget. | |
3685 | ||
1833b7b3 RS |
3686 | (defvar widget-face-prompt-value-history nil |
3687 | "History of input to `widget-face-prompt-value'.") | |
3688 | ||
0e739597 DP |
3689 | (define-widget 'face 'symbol |
3690 | "A Lisp face name (with sample)." | |
49698bb7 | 3691 | :format "%{%t%}: (%{sample%}) %v" |
0e739597 DP |
3692 | :tag "Face" |
3693 | :value 'default | |
3694 | :sample-face-get 'widget-face-sample-face-get | |
3695 | :notify 'widget-face-notify | |
3696 | :match (lambda (widget value) (facep value)) | |
1833b7b3 RS |
3697 | :complete-function (lambda () |
3698 | (interactive) | |
3699 | (lisp-complete-symbol 'facep)) | |
1833b7b3 RS |
3700 | :prompt-match 'facep |
3701 | :prompt-history 'widget-face-prompt-value-history | |
1833b7b3 RS |
3702 | :validate (lambda (widget) |
3703 | (unless (facep (widget-value widget)) | |
0e739597 DP |
3704 | (widget-put widget |
3705 | :error (format "Invalid face: %S" | |
3706 | (widget-value widget))) | |
3707 | widget))) | |
3708 | ||
3709 | (defun widget-face-sample-face-get (widget) | |
3710 | (let ((value (widget-value widget))) | |
3711 | (if (facep value) | |
3712 | value | |
3713 | 'default))) | |
3714 | ||
3715 | (defun widget-face-notify (widget child &optional event) | |
3716 | "Update the sample, and notify the parent." | |
3717 | (overlay-put (widget-get widget :sample-overlay) | |
3718 | 'face (widget-apply widget :sample-face-get)) | |
3719 | (widget-default-notify widget child event)) | |
1833b7b3 | 3720 | |
d543e20b PA |
3721 | |
3722 | ;;; The `hook' Widget. | |
3723 | ||
3724 | (define-widget 'hook 'list | |
c8c9333c | 3725 | "An Emacs Lisp hook." |
f985c5f7 | 3726 | :value-to-internal (lambda (widget value) |
5aa3f181 | 3727 | (if (and value (symbolp value)) |
f985c5f7 PA |
3728 | (list value) |
3729 | value)) | |
3730 | :match (lambda (widget value) | |
3731 | (or (symbolp value) | |
4743fc91 | 3732 | (widget-group-match widget value))) |
2365594b DL |
3733 | ;; Avoid adding undefined functions to the hook, especially for |
3734 | ;; things like `find-file-hook' or even more basic ones, to avoid | |
3735 | ;; chaos. | |
3736 | :set (lambda (symbol value) | |
d4881668 SM |
3737 | (dolist (elt value) |
3738 | (if (fboundp elt) | |
3739 | (add-hook symbol elt)))) | |
d543e20b PA |
3740 | :convert-widget 'custom-hook-convert-widget |
3741 | :tag "Hook") | |
3742 | ||
3743 | (defun custom-hook-convert-widget (widget) | |
3c708e98 | 3744 | ;; Handle `:options'. |
d543e20b | 3745 | (let* ((options (widget-get widget :options)) |
d3d4df42 | 3746 | (other `(editable-list :inline t |
d543e20b PA |
3747 | :entry-format "%i %d%v" |
3748 | (function :format " %v"))) | |
3749 | (args (if options | |
3750 | (list `(checklist :inline t | |
3751 | ,@(mapcar (lambda (entry) | |
3752 | `(function-item ,entry)) | |
3753 | options)) | |
3754 | other) | |
3755 | (list other)))) | |
3756 | (widget-put widget :args args) | |
3757 | widget)) | |
3758 | ||
944c91b6 PA |
3759 | ;;; The `custom-group-link' Widget. |
3760 | ||
3761 | (define-widget 'custom-group-link 'link | |
3762 | "Show parent in other window when activated." | |
192e44fc JL |
3763 | :button-face 'custom-link |
3764 | :mouse-face 'highlight | |
e1ec62a5 | 3765 | :pressed-face 'highlight |
b62c92bb | 3766 | :help-echo "Create customization buffer for this group." |
f3093f77 CY |
3767 | :keymap custom-mode-link-map |
3768 | :follow-link 'mouse-face | |
944c91b6 PA |
3769 | :action 'custom-group-link-action) |
3770 | ||
3771 | (defun custom-group-link-action (widget &rest ignore) | |
3772 | (customize-group (widget-value widget))) | |
3773 | ||
d543e20b PA |
3774 | ;;; The `custom-group' Widget. |
3775 | ||
b62c92bb | 3776 | (defcustom custom-group-tag-faces nil |
d543e20b | 3777 | ;; In XEmacs, this ought to play games with font size. |
d3d4df42 | 3778 | ;; Fixme: make it do so in Emacs. |
d543e20b PA |
3779 | "Face used for group tags. |
3780 | The first member is used for level 1 groups, the second for level 2, | |
d478e69d | 3781 | and so forth. The remaining group tags are shown with `custom-group-tag'." |
d543e20b | 3782 | :type '(repeat face) |
bd042c03 | 3783 | :group 'custom-faces) |
d543e20b | 3784 | |
d478e69d | 3785 | (defface custom-group-tag-1 |
16b20ed9 GM |
3786 | `((((class color) |
3787 | (background dark)) | |
b5555381 | 3788 | (:foreground "pink" :weight bold :height 1.2 :inherit variable-pitch)) |
ea81d57e DN |
3789 | (((min-colors 88) (class color) |
3790 | (background light)) | |
3791 | (:foreground "red1" :weight bold :height 1.2 :inherit variable-pitch)) | |
16b20ed9 GM |
3792 | (((class color) |
3793 | (background light)) | |
b5555381 RS |
3794 | (:foreground "red" :weight bold :height 1.2 :inherit variable-pitch)) |
3795 | (t (:weight bold))) | |
16b20ed9 GM |
3796 | "Face used for group tags." |
3797 | :group 'custom-faces) | |
d478e69d MB |
3798 | ;; backward-compatibility alias |
3799 | (put 'custom-group-tag-face-1 'face-alias 'custom-group-tag-1) | |
16b20ed9 | 3800 | |
d478e69d | 3801 | (defface custom-group-tag |
16b20ed9 GM |
3802 | `((((class color) |
3803 | (background dark)) | |
9db1942d | 3804 | (:foreground "light blue" :weight bold :height 1.2 :inherit variable-pitch)) |
ea81d57e DN |
3805 | (((min-colors 88) (class color) |
3806 | (background light)) | |
9db1942d | 3807 | (:foreground "blue1" :weight bold :height 1.2 :inherit variable-pitch)) |
16b20ed9 GM |
3808 | (((class color) |
3809 | (background light)) | |
9db1942d | 3810 | (:foreground "blue" :weight bold :height 1.2 :inherit variable-pitch)) |
b5555381 | 3811 | (t (:weight bold))) |
d543e20b | 3812 | "Face used for low level group tags." |
bd042c03 | 3813 | :group 'custom-faces) |
d478e69d MB |
3814 | ;; backward-compatibility alias |
3815 | (put 'custom-group-tag-face 'face-alias 'custom-group-tag) | |
d543e20b PA |
3816 | |
3817 | (define-widget 'custom-group 'custom | |
3818 | "Customize group." | |
944c91b6 | 3819 | :format "%v" |
d543e20b PA |
3820 | :sample-face-get 'custom-group-sample-face-get |
3821 | :documentation-property 'group-documentation | |
3822 | :help-echo "Set or reset all members of this group." | |
3823 | :value-create 'custom-group-value-create | |
3824 | :action 'custom-group-action | |
9097aeb7 | 3825 | :custom-category 'group |
d543e20b | 3826 | :custom-set 'custom-group-set |
5ae87ed4 | 3827 | :custom-mark-to-save 'custom-group-mark-to-save |
d543e20b PA |
3828 | :custom-reset-current 'custom-group-reset-current |
3829 | :custom-reset-saved 'custom-group-reset-saved | |
25ac13b5 | 3830 | :custom-reset-standard 'custom-group-reset-standard |
5ae87ed4 MR |
3831 | :custom-mark-to-reset-standard 'custom-group-mark-to-reset-standard |
3832 | :custom-state-set-and-redraw 'custom-group-state-set-and-redraw | |
d543e20b PA |
3833 | :custom-menu 'custom-group-menu-create) |
3834 | ||
3835 | (defun custom-group-sample-face-get (widget) | |
3836 | ;; Use :sample-face. | |
3837 | (or (nth (1- (widget-get widget :custom-level)) custom-group-tag-faces) | |
d478e69d | 3838 | 'custom-group-tag)) |
d543e20b | 3839 | |
8691cfa7 RS |
3840 | (define-widget 'custom-group-visibility 'visibility |
3841 | "An indicator and manipulator for hidden group contents." | |
3842 | :create 'custom-group-visibility-create) | |
3843 | ||
3844 | (defun custom-group-visibility-create (widget) | |
3845 | (let ((visible (widget-value widget))) | |
3846 | (if visible | |
3847 | (insert "--------"))) | |
3848 | (widget-default-create widget)) | |
3849 | ||
4ee1cf9f PA |
3850 | (defun custom-group-members (symbol groups-only) |
3851 | "Return SYMBOL's custom group members. | |
3852 | If GROUPS-ONLY non-nil, return only those members that are groups." | |
3853 | (if (not groups-only) | |
3854 | (get symbol 'custom-group) | |
3855 | (let (members) | |
3856 | (dolist (entry (get symbol 'custom-group)) | |
3857 | (when (eq (nth 1 entry) 'custom-group) | |
3858 | (push entry members))) | |
3859 | (nreverse members)))) | |
3860 | ||
d543e20b | 3861 | (defun custom-group-value-create (widget) |
944c91b6 | 3862 | "Insert a customize group for WIDGET in the current buffer." |
2de2cb02 | 3863 | (unless (eq (widget-get widget :custom-state) 'hidden) |
2ee398c4 | 3864 | (custom-load-widget widget)) |
4ee1cf9f PA |
3865 | (let* ((state (widget-get widget :custom-state)) |
3866 | (level (widget-get widget :custom-level)) | |
f985c5f7 | 3867 | ;; (indent (widget-get widget :indent)) |
4ee1cf9f PA |
3868 | (prefix (widget-get widget :custom-prefix)) |
3869 | (buttons (widget-get widget :buttons)) | |
3870 | (tag (widget-get widget :tag)) | |
3871 | (symbol (widget-value widget)) | |
3872 | (members (custom-group-members symbol | |
3873 | (and (eq custom-buffer-style 'tree) | |
3874 | custom-browse-only-groups)))) | |
944c91b6 | 3875 | (cond ((and (eq custom-buffer-style 'tree) |
c953515e | 3876 | (eq state 'hidden) |
4ee1cf9f | 3877 | (or members (custom-unloaded-widget-p widget))) |
c953515e | 3878 | (custom-browse-insert-prefix prefix) |
944c91b6 | 3879 | (push (widget-create-child-and-convert |
d3d4df42 | 3880 | widget 'custom-browse-visibility |
da5ec617 | 3881 | ;; :tag-glyph "plus" |
df816618 | 3882 | :tag "+") |
944c91b6 PA |
3883 | buttons) |
3884 | (insert "-- ") | |
da5ec617 | 3885 | ;; (widget-glyph-insert nil "-- " "horizontal") |
944c91b6 | 3886 | (push (widget-create-child-and-convert |
c953515e | 3887 | widget 'custom-browse-group-tag) |
944c91b6 PA |
3888 | buttons) |
3889 | (insert " " tag "\n") | |
3890 | (widget-put widget :buttons buttons)) | |
3891 | ((and (eq custom-buffer-style 'tree) | |
4ee1cf9f | 3892 | (zerop (length members))) |
c953515e | 3893 | (custom-browse-insert-prefix prefix) |
da5ec617 PA |
3894 | (insert "[ ]-- ") |
3895 | ;; (widget-glyph-insert nil "[ ]" "empty") | |
3896 | ;; (widget-glyph-insert nil "-- " "horizontal") | |
d3d4df42 | 3897 | (push (widget-create-child-and-convert |
c953515e | 3898 | widget 'custom-browse-group-tag) |
944c91b6 PA |
3899 | buttons) |
3900 | (insert " " tag "\n") | |
3901 | (widget-put widget :buttons buttons)) | |
3902 | ((eq custom-buffer-style 'tree) | |
c953515e | 3903 | (custom-browse-insert-prefix prefix) |
4ee1cf9f | 3904 | (if (zerop (length members)) |
d3d4df42 | 3905 | (progn |
c953515e | 3906 | (custom-browse-insert-prefix prefix) |
da5ec617 PA |
3907 | (insert "[ ]-- ") |
3908 | ;; (widget-glyph-insert nil "[ ]" "empty") | |
3909 | ;; (widget-glyph-insert nil "-- " "horizontal") | |
d3d4df42 | 3910 | (push (widget-create-child-and-convert |
c953515e | 3911 | widget 'custom-browse-group-tag) |
944c91b6 PA |
3912 | buttons) |
3913 | (insert " " tag "\n") | |
3914 | (widget-put widget :buttons buttons)) | |
d3d4df42 DL |
3915 | (push (widget-create-child-and-convert |
3916 | widget 'custom-browse-visibility | |
da5ec617 PA |
3917 | ;; :tag-glyph "minus" |
3918 | :tag "-") | |
944c91b6 | 3919 | buttons) |
da5ec617 PA |
3920 | (insert "-\\ ") |
3921 | ;; (widget-glyph-insert nil "-\\ " "top") | |
d3d4df42 | 3922 | (push (widget-create-child-and-convert |
c953515e | 3923 | widget 'custom-browse-group-tag) |
944c91b6 PA |
3924 | buttons) |
3925 | (insert " " tag "\n") | |
3926 | (widget-put widget :buttons buttons) | |
3927 | (message "Creating group...") | |
4ee1cf9f | 3928 | (let* ((members (custom-sort-items members |
da5ec617 PA |
3929 | custom-browse-sort-alphabetically |
3930 | custom-browse-order-groups)) | |
944c91b6 PA |
3931 | (prefixes (widget-get widget :custom-prefixes)) |
3932 | (custom-prefix-list (custom-prefix-add symbol prefixes)) | |
944c91b6 PA |
3933 | (extra-prefix (if (widget-get widget :custom-last) |
3934 | " " | |
3935 | " | ")) | |
3936 | (prefix (concat prefix extra-prefix)) | |
3937 | children entry) | |
3938 | (while members | |
3939 | (setq entry (car members) | |
3940 | members (cdr members)) | |
4ee1cf9f PA |
3941 | (push (widget-create-child-and-convert |
3942 | widget (nth 1 entry) | |
3943 | :group widget | |
3944 | :tag (custom-unlispify-tag-name (nth 0 entry)) | |
3945 | :custom-prefixes custom-prefix-list | |
3946 | :custom-level (1+ level) | |
3947 | :custom-last (null members) | |
3948 | :value (nth 0 entry) | |
3949 | :custom-prefix prefix) | |
3950 | children)) | |
944c91b6 PA |
3951 | (widget-put widget :children (reverse children))) |
3952 | (message "Creating group...done"))) | |
3953 | ;; Nested style. | |
3954 | ((eq state 'hidden) | |
3955 | ;; Create level indicator. | |
944c91b6 | 3956 | ;; Create tag. |
944c91b6 PA |
3957 | (if (eq custom-buffer-style 'links) |
3958 | (push (widget-create-child-and-convert | |
d3d4df42 | 3959 | widget 'custom-group-link |
9db1942d | 3960 | :tag tag |
944c91b6 PA |
3961 | symbol) |
3962 | buttons) | |
9db1942d CY |
3963 | (insert-char ?\ (* custom-buffer-indent (1- level))) |
3964 | (insert "-- ") | |
d3d4df42 | 3965 | (push (widget-create-child-and-convert |
98d5aafe | 3966 | widget 'custom-group-visibility |
944c91b6 PA |
3967 | :help-echo "Show members of this group." |
3968 | :action 'custom-toggle-parent | |
3969 | (not (eq state 'hidden))) | |
3970 | buttons)) | |
9db1942d | 3971 | (insert " : ") |
944c91b6 PA |
3972 | ;; Create magic button. |
3973 | (let ((magic (widget-create-child-and-convert | |
3974 | widget 'custom-magic nil))) | |
3975 | (widget-put widget :custom-magic magic) | |
3976 | (push magic buttons)) | |
3977 | ;; Update buttons. | |
3978 | (widget-put widget :buttons buttons) | |
3979 | ;; Insert documentation. | |
26c7b3ef RS |
3980 | (if (and (eq custom-buffer-style 'links) (> level 1)) |
3981 | (widget-put widget :documentation-indent 0)) | |
12bafdaa CY |
3982 | (widget-add-documentation-string-button |
3983 | widget :visibility-widget 'custom-visibility)) | |
3984 | ||
944c91b6 PA |
3985 | ;; Nested style. |
3986 | (t ;Visible. | |
d377bee9 RS |
3987 | ;; Add parent groups references above the group. |
3988 | (if t ;;; This should test that the buffer | |
3989 | ;;; was made to display a group. | |
3990 | (when (eq level 1) | |
cd6c0940 | 3991 | (if (custom-add-parent-links widget |
f1201e3a RS |
3992 | "Parent groups:" |
3993 | "Parent group documentation:") | |
d377bee9 | 3994 | (insert "\n")))) |
944c91b6 PA |
3995 | ;; Create level indicator. |
3996 | (insert-char ?\ (* custom-buffer-indent (1- level))) | |
3997 | (insert "/- ") | |
3998 | ;; Create tag. | |
3999 | (let ((start (point))) | |
9db1942d | 4000 | (insert tag " group: ") |
944c91b6 | 4001 | (widget-specify-sample widget start (point))) |
9db1942d | 4002 | (insert (widget-docstring widget)) |
944c91b6 PA |
4003 | ;; Create visibility indicator. |
4004 | (unless (eq custom-buffer-style 'links) | |
4005 | (insert "--------") | |
d3d4df42 | 4006 | (push (widget-create-child-and-convert |
944c91b6 PA |
4007 | widget 'visibility |
4008 | :help-echo "Hide members of this group." | |
4009 | :action 'custom-toggle-parent | |
4010 | (not (eq state 'hidden))) | |
4011 | buttons) | |
4012 | (insert " ")) | |
4013 | ;; Create more dashes. | |
4014 | ;; Use 76 instead of 75 to compensate for the temporary "<" | |
d3d4df42 | 4015 | ;; added by `widget-insert'. |
944c91b6 PA |
4016 | (insert-char ?- (- 76 (current-column) |
4017 | (* custom-buffer-indent level))) | |
4018 | (insert "\\\n") | |
4019 | ;; Create magic button. | |
4020 | (let ((magic (widget-create-child-and-convert | |
d3d4df42 | 4021 | widget 'custom-magic |
944c91b6 PA |
4022 | :indent 0 |
4023 | nil))) | |
4024 | (widget-put widget :custom-magic magic) | |
4025 | (push magic buttons)) | |
4026 | ;; Update buttons. | |
4027 | (widget-put widget :buttons buttons) | |
4028 | ;; Insert documentation. | |
12bafdaa CY |
4029 | (widget-add-documentation-string-button |
4030 | widget :visibility-widget 'custom-visibility) | |
4031 | ||
d377bee9 RS |
4032 | ;; Parent groups. |
4033 | (if nil ;;; This should test that the buffer | |
4034 | ;;; was not made to display a group. | |
4035 | (when (eq level 1) | |
4036 | (insert-char ?\ custom-buffer-indent) | |
4037 | (custom-add-parent-links widget))) | |
d3d4df42 | 4038 | (custom-add-see-also widget |
944c91b6 PA |
4039 | (make-string (* custom-buffer-indent level) |
4040 | ?\ )) | |
4041 | ;; Members. | |
4042 | (message "Creating group...") | |
4ee1cf9f | 4043 | (let* ((members (custom-sort-items members |
da5ec617 PA |
4044 | custom-buffer-sort-alphabetically |
4045 | custom-buffer-order-groups)) | |
944c91b6 PA |
4046 | (prefixes (widget-get widget :custom-prefixes)) |
4047 | (custom-prefix-list (custom-prefix-add symbol prefixes)) | |
4048 | (length (length members)) | |
4049 | (count 0) | |
4050 | (children (mapcar (lambda (entry) | |
4051 | (widget-insert "\n") | |
4052 | (message "\ | |
4053 | Creating group members... %2d%%" | |
4054 | (/ (* 100.0 count) length)) | |
4055 | (setq count (1+ count)) | |
4056 | (prog1 | |
4057 | (widget-create-child-and-convert | |
4058 | widget (nth 1 entry) | |
4059 | :group widget | |
4060 | :tag (custom-unlispify-tag-name | |
4061 | (nth 0 entry)) | |
4062 | :custom-prefixes custom-prefix-list | |
4063 | :custom-level (1+ level) | |
4064 | :value (nth 0 entry)) | |
4065 | (unless (eq (preceding-char) ?\n) | |
4066 | (widget-insert "\n")))) | |
4067 | members))) | |
4068 | (message "Creating group magic...") | |
fadbdfea | 4069 | (mapc 'custom-magic-reset children) |
944c91b6 PA |
4070 | (message "Creating group state...") |
4071 | (widget-put widget :children children) | |
4072 | (custom-group-state-update widget) | |
4073 | (message "Creating group... done")) | |
4074 | ;; End line | |
4075 | (insert "\n") | |
4076 | (insert-char ?\ (* custom-buffer-indent (1- level))) | |
4077 | (insert "\\- " (widget-get widget :tag) " group end ") | |
4078 | (insert-char ?- (- 75 (current-column) (* custom-buffer-indent level))) | |
4079 | (insert "/\n"))))) | |
d543e20b | 4080 | |
d3d4df42 | 4081 | (defvar custom-group-menu |
70482877 | 4082 | `(("Set for Current Session" custom-group-set |
eaa99205 CY |
4083 | (lambda (widget) |
4084 | (eq (widget-get widget :custom-state) 'modified))) | |
9b5007e7 | 4085 | ,@(when (or custom-file init-file-user) |
70482877 | 4086 | '(("Save for Future Sessions" custom-group-save |
eaa99205 CY |
4087 | (lambda (widget) |
4088 | (memq (widget-get widget :custom-state) '(modified set)))))) | |
70482877 | 4089 | ("Undo Edits" custom-group-reset-current |
6d528fc5 | 4090 | (lambda (widget) |
86bd10bc | 4091 | (memq (widget-get widget :custom-state) '(modified)))) |
70482877 | 4092 | ("Reset to Saved" custom-group-reset-saved |
6d528fc5 | 4093 | (lambda (widget) |
86bd10bc | 4094 | (memq (widget-get widget :custom-state) '(modified set)))) |
9b5007e7 | 4095 | ,@(when (or custom-file init-file-user) |
70482877 | 4096 | '(("Erase Customization" custom-group-reset-standard |
73e60f53 | 4097 | (lambda (widget) |
eaa99205 | 4098 | (memq (widget-get widget :custom-state) '(modified set saved))))))) |
d543e20b | 4099 | "Alist of actions for the `custom-group' widget. |
6d528fc5 PA |
4100 | Each entry has the form (NAME ACTION FILTER) where NAME is the name of |
4101 | the menu entry, ACTION is the function to call on the widget when the | |
4102 | menu is selected, and FILTER is a predicate which takes a `custom-group' | |
4103 | widget as an argument, and returns non-nil if ACTION is valid on that | |
d3d4df42 | 4104 | widget. If FILTER is nil, ACTION is always valid.") |
d543e20b PA |
4105 | |
4106 | (defun custom-group-action (widget &optional event) | |
4107 | "Show the menu for `custom-group' WIDGET. | |
4108 | Optional EVENT is the location for the menu." | |
4109 | (if (eq (widget-get widget :custom-state) 'hidden) | |
6d528fc5 | 4110 | (custom-toggle-hide widget) |
d543e20b | 4111 | (let* ((completion-ignore-case t) |
25ac13b5 PA |
4112 | (answer (widget-choose (concat "Operation on " |
4113 | (custom-unlispify-tag-name | |
4114 | (widget-get widget :value))) | |
6d528fc5 PA |
4115 | (custom-menu-filter custom-group-menu |
4116 | widget) | |
d543e20b PA |
4117 | event))) |
4118 | (if answer | |
4119 | (funcall answer widget))))) | |
4120 | ||
4121 | (defun custom-group-set (widget) | |
4122 | "Set changes in all modified group members." | |
9db1942d CY |
4123 | (dolist (child (widget-get widget :children)) |
4124 | (when (eq (widget-get child :custom-state) 'modified) | |
4125 | (widget-apply child :custom-set)))) | |
d543e20b | 4126 | |
5ae87ed4 MR |
4127 | (defun custom-group-mark-to-save (widget) |
4128 | "Mark all modified group members for saving." | |
ed8c9cf1 | 4129 | (dolist (child (widget-get widget :children)) |
9db1942d | 4130 | (when (memq (widget-get child :custom-state) '(modified set)) |
5ae87ed4 MR |
4131 | (widget-apply child :custom-mark-to-save)))) |
4132 | ||
4133 | (defsubst custom-group-state-set-and-redraw (widget) | |
4134 | "Set state of group widget WIDGET and redraw with current settings." | |
4135 | (dolist (child (widget-get widget :children)) | |
4136 | (when (memq (widget-get child :custom-state) '(modified set)) | |
4137 | (widget-apply child :custom-state-set-and-redraw)))) | |
4138 | ||
4139 | (defun custom-group-save (widget) | |
4140 | "Save all modified group members." | |
4141 | (custom-group-mark-to-save widget) | |
4142 | (custom-save-all) | |
4143 | (custom-group-state-set-and-redraw widget)) | |
d543e20b PA |
4144 | |
4145 | (defun custom-group-reset-current (widget) | |
4146 | "Reset all modified group members." | |
9db1942d CY |
4147 | (dolist (child (widget-get widget :children)) |
4148 | (when (eq (widget-get child :custom-state) 'modified) | |
4149 | (widget-apply child :custom-reset-current)))) | |
d543e20b PA |
4150 | |
4151 | (defun custom-group-reset-saved (widget) | |
4152 | "Reset all modified or set group members." | |
9db1942d CY |
4153 | (dolist (child (widget-get widget :children)) |
4154 | (when (memq (widget-get child :custom-state) '(modified set)) | |
4155 | (widget-apply child :custom-reset-saved)))) | |
d543e20b | 4156 | |
25ac13b5 | 4157 | (defun custom-group-reset-standard (widget) |
d543e20b | 4158 | "Reset all modified, set, or saved group members." |
5ae87ed4 MR |
4159 | (let ((custom-reset-standard-variables-list '(t)) |
4160 | (custom-reset-standard-faces-list '(t))) | |
4161 | (custom-group-mark-to-reset-standard widget) | |
4162 | (custom-reset-standard-save-and-update))) | |
4163 | ||
4164 | (defun custom-group-mark-to-reset-standard (widget) | |
4165 | "Mark to reset all modified, set, or saved group members." | |
9db1942d CY |
4166 | (dolist (child (widget-get widget :children)) |
4167 | (when (memq (widget-get child :custom-state) | |
4168 | '(modified set saved)) | |
5ae87ed4 | 4169 | (widget-apply child :custom-mark-to-reset-standard)))) |
d543e20b PA |
4170 | |
4171 | (defun custom-group-state-update (widget) | |
4172 | "Update magic." | |
4173 | (unless (eq (widget-get widget :custom-state) 'hidden) | |
4174 | (let* ((children (widget-get widget :children)) | |
4175 | (states (mapcar (lambda (child) | |
4176 | (widget-get child :custom-state)) | |
4177 | children)) | |
25ac13b5 PA |
4178 | (magics custom-magic-alist) |
4179 | (found 'standard)) | |
d543e20b PA |
4180 | (while magics |
4181 | (let ((magic (car (car magics)))) | |
4182 | (if (and (not (eq magic 'hidden)) | |
4183 | (memq magic states)) | |
4184 | (setq found magic | |
4185 | magics nil) | |
4186 | (setq magics (cdr magics))))) | |
4187 | (widget-put widget :custom-state found))) | |
4188 | (custom-magic-reset widget)) | |
f8d869d1 RS |
4189 | \f |
4190 | ;;; Reading and writing the custom file. | |
d543e20b | 4191 | |
a1a4fa22 | 4192 | ;;;###autoload |
1e4ed6df | 4193 | (defcustom custom-file nil |
d543e20b | 4194 | "File used for storing customization information. |
1e4ed6df | 4195 | The default is nil, which means to use your init file |
09b73f49 RS |
4196 | as specified by `user-init-file'. If the value is not nil, |
4197 | it should be an absolute file name. | |
4198 | ||
5aa971e3 LT |
4199 | You can set this option through Custom, if you carefully read the |
4200 | last paragraph below. However, usually it is simpler to write | |
4201 | something like the following in your init file: | |
4202 | ||
4203 | \(setq custom-file \"~/.emacs-custom.el\") | |
4204 | \(load custom-file) | |
4205 | ||
4206 | Note that both lines are necessary: the first line tells Custom to | |
4207 | save all customizations in this file, but does not load it. | |
4208 | ||
4209 | When you change this variable outside Custom, look in the | |
4210 | previous custom file \(usually your init file) for the | |
4211 | forms `(custom-set-variables ...)' and `(custom-set-faces ...)', | |
4212 | and copy them (whichever ones you find) to the new custom file. | |
4213 | This will preserve your existing customizations. | |
4214 | ||
4215 | If you save this option using Custom, Custom will write all | |
4216 | currently saved customizations, including the new one for this | |
4217 | option itself, into the file you specify, overwriting any | |
4218 | `custom-set-variables' and `custom-set-faces' forms already | |
4219 | present in that file. It will not delete any customizations from | |
4220 | the old custom file. You should do that manually if that is what you | |
4221 | want. You also have to put something like `\(load \"CUSTOM-FILE\") | |
4222 | in your init file, where CUSTOM-FILE is the actual name of the | |
4223 | file. Otherwise, Emacs will not load the file when it starts up, | |
4224 | and hence will not set `custom-file' to that file either." | |
4225 | :type '(choice (const :tag "Your Emacs init file" nil) | |
4226 | (file :format "%t:%v%d" | |
4227 | :doc | |
4228 | "Please read entire docstring below before setting \ | |
4229 | this through Custom. | |
4230 | Click om \"More\" \(or position point there and press RETURN) | |
4231 | if only the first line of the docstring is shown.")) | |
d543e20b PA |
4232 | :group 'customize) |
4233 | ||
176eb8cb KH |
4234 | (defun custom-file () |
4235 | "Return the file name for saving customizations." | |
541044b0 RS |
4236 | (file-chase-links |
4237 | (or custom-file | |
4238 | (let ((user-init-file user-init-file) | |
4239 | (default-init-file | |
4240 | (if (eq system-type 'ms-dos) "~/_emacs" "~/.emacs"))) | |
4241 | (when (null user-init-file) | |
4242 | (if (or (file-exists-p default-init-file) | |
4243 | (and (eq system-type 'windows-nt) | |
4244 | (file-exists-p "~/_emacs"))) | |
4245 | ;; Started with -q, i.e. the file containing | |
4246 | ;; Custom settings hasn't been read. Saving | |
4247 | ;; settings there would overwrite other settings. | |
4248 | (error "Saving settings from \"emacs -q\" would overwrite existing customizations")) | |
4249 | (setq user-init-file default-init-file)) | |
4250 | user-init-file)))) | |
176eb8cb | 4251 | |
b581d2ea GM |
4252 | ;; If recentf-mode is non-nil, this is defined. |
4253 | (declare-function recentf-expand-file-name "recentf" (name)) | |
4254 | ||
f8d869d1 RS |
4255 | ;;;###autoload |
4256 | (defun custom-save-all () | |
4257 | "Save all customizations in `custom-file'." | |
e29e9065 RS |
4258 | (when (and (null custom-file) init-file-had-error) |
4259 | (error "Cannot save customizations; init file was not fully loaded")) | |
f8d869d1 | 4260 | (let* ((filename (custom-file)) |
c34a8a87 EZ |
4261 | (recentf-exclude |
4262 | (if recentf-mode | |
4263 | (cons (concat "\\`" | |
4264 | (regexp-quote | |
4265 | (recentf-expand-file-name (custom-file))) | |
4266 | "\\'") | |
4267 | recentf-exclude))) | |
f8d869d1 | 4268 | (old-buffer (find-buffer-visiting filename))) |
9e2f5050 RS |
4269 | (with-current-buffer (let ((find-file-visit-truename t)) |
4270 | (or old-buffer (find-file-noselect filename))) | |
31b7fa51 CY |
4271 | (unless (eq major-mode 'emacs-lisp-mode) |
4272 | (emacs-lisp-mode)) | |
f8d869d1 RS |
4273 | (let ((inhibit-read-only t)) |
4274 | (custom-save-variables) | |
4275 | (custom-save-faces)) | |
4276 | (let ((file-precious-flag t)) | |
4277 | (save-buffer)) | |
4278 | (unless old-buffer | |
4279 | (kill-buffer (current-buffer)))))) | |
16ecd4c5 RS |
4280 | |
4281 | ;;;###autoload | |
4282 | (defun customize-save-customized () | |
4283 | "Save all user options which have been set in this session." | |
4284 | (interactive) | |
4285 | (mapatoms (lambda (symbol) | |
4286 | (let ((face (get symbol 'customized-face)) | |
4287 | (value (get symbol 'customized-value)) | |
4288 | (face-comment (get symbol 'customized-face-comment)) | |
4289 | (variable-comment | |
4290 | (get symbol 'customized-variable-comment))) | |
4291 | (when face | |
4292 | (put symbol 'saved-face face) | |
4293 | (custom-push-theme 'theme-face symbol 'user 'set value) | |
4294 | (put symbol 'customized-face nil)) | |
4295 | (when value | |
4296 | (put symbol 'saved-value value) | |
4297 | (custom-push-theme 'theme-value symbol 'user 'set value) | |
4298 | (put symbol 'customized-value nil)) | |
4299 | (when variable-comment | |
4300 | (put symbol 'saved-variable-comment variable-comment) | |
4301 | (put symbol 'customized-variable-comment nil)) | |
4302 | (when face-comment | |
4303 | (put symbol 'saved-face-comment face-comment) | |
4304 | (put symbol 'customized-face-comment nil))))) | |
4305 | ;; We really should update all custom buffers here. | |
4306 | (custom-save-all)) | |
f8d869d1 RS |
4307 | \f |
4308 | ;; Editing the custom file contents in a buffer. | |
4309 | ||
d543e20b | 4310 | (defun custom-save-delete (symbol) |
f8d869d1 | 4311 | "Delete all calls to SYMBOL from the contents of the current buffer. |
a34511a1 | 4312 | Leave point at the old location of the first such call, |
f8d869d1 RS |
4313 | or (if there were none) at the end of the buffer. |
4314 | ||
4315 | This function does not save the buffer." | |
d543e20b | 4316 | (goto-char (point-min)) |
cbe8bb8e KH |
4317 | ;; Skip all whitespace and comments. |
4318 | (while (forward-comment 1)) | |
4319 | (or (eobp) | |
4320 | (save-excursion (forward-sexp (buffer-size)))) ; Test for scan errors. | |
a34511a1 RS |
4321 | (let (first) |
4322 | (catch 'found | |
4323 | (while t ;; We exit this loop only via throw. | |
4324 | ;; Skip all whitespace and comments. | |
4325 | (while (forward-comment 1)) | |
4326 | (let ((start (point)) | |
4327 | (sexp (condition-case nil | |
4328 | (read (current-buffer)) | |
4329 | (end-of-file (throw 'found nil))))) | |
4330 | (when (and (listp sexp) | |
4331 | (eq (car sexp) symbol)) | |
4332 | (delete-region start (point)) | |
4333 | (unless first | |
4334 | (setq first (point))))))) | |
4335 | (if first | |
4336 | (goto-char first) | |
189638d5 GM |
4337 | ;; Move in front of local variables, otherwise long Custom |
4338 | ;; entries would make them ineffective. | |
4339 | (let ((pos (point-max)) | |
4340 | (case-fold-search t)) | |
4341 | (save-excursion | |
4342 | (goto-char (point-max)) | |
4343 | (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) | |
4344 | 'move) | |
4345 | (when (search-forward "Local Variables:" nil t) | |
4346 | (setq pos (line-beginning-position)))) | |
4347 | (goto-char pos))))) | |
d543e20b PA |
4348 | |
4349 | (defun custom-save-variables () | |
4350 | "Save all customized variables in `custom-file'." | |
4351 | (save-excursion | |
4352 | (custom-save-delete 'custom-set-variables) | |
d151422c MR |
4353 | (let ((standard-output (current-buffer)) |
4354 | (saved-list (make-list 1 0)) | |
4355 | sort-fold-case) | |
4356 | ;; First create a sorted list of saved variables. | |
4357 | (mapatoms | |
4358 | (lambda (symbol) | |
d358aa10 | 4359 | (if (and (get symbol 'saved-value) |
2d656942 CY |
4360 | ;; ignore theme values |
4361 | (or (null (get symbol 'theme-value)) | |
4362 | (eq 'user (caar (get symbol 'theme-value))))) | |
d151422c MR |
4363 | (nconc saved-list (list symbol))))) |
4364 | (setq saved-list (sort (cdr saved-list) 'string<)) | |
d543e20b PA |
4365 | (unless (bolp) |
4366 | (princ "\n")) | |
aec2bb63 | 4367 | (princ "(custom-set-variables |
99b398e0 RS |
4368 | ;; custom-set-variables was added by Custom. |
4369 | ;; If you edit it by hand, you could mess it up, so be careful. | |
4370 | ;; Your init file should contain only one such instance. | |
4371 | ;; If there is more than one, they won't work right.\n") | |
d9f67134 SM |
4372 | (dolist (symbol saved-list) |
4373 | (let ((spec (car-safe (get symbol 'theme-value))) | |
4374 | (value (get symbol 'saved-value)) | |
4375 | (requests (get symbol 'custom-requests)) | |
adcc7a37 RS |
4376 | (now (and (not (custom-variable-p symbol)) |
4377 | (or (boundp symbol) | |
4378 | (eq (get symbol 'force-value) | |
4379 | 'rogue)))) | |
40627755 | 4380 | (comment (get symbol 'saved-variable-comment))) |
c8c9333c | 4381 | ;; Check REQUESTS for validity. |
d9f67134 SM |
4382 | (dolist (request requests) |
4383 | (when (and (symbolp request) (not (featurep request))) | |
4384 | (message "Unknown requested feature: %s" request) | |
4385 | (setq requests (delq request requests)))) | |
adcc7a37 | 4386 | ;; Is there anything customized about this variable? |
d358aa10 | 4387 | (when (or (and spec (eq (car spec) 'user)) |
d9f67134 SM |
4388 | comment |
4389 | (and (null spec) (get symbol 'saved-value))) | |
adcc7a37 RS |
4390 | ;; Output an element for this variable. |
4391 | ;; It has the form (SYMBOL VALUE-FORM NOW REQUESTS COMMENT). | |
4392 | ;; SYMBOL is the variable name. | |
4393 | ;; VALUE-FORM is an expression to return the customized value. | |
4394 | ;; NOW if non-nil means always set the variable immediately | |
4395 | ;; when the customizations are reloaded. This is used | |
4396 | ;; for rogue variables | |
4397 | ;; REQUESTS is a list of packages to load before setting the | |
4398 | ;; variable. Each element of it will be passed to `require'. | |
4399 | ;; COMMENT is whatever comment the user has specified | |
4400 | ;; with the customize facility. | |
d9f67134 SM |
4401 | (unless (bolp) |
4402 | (princ "\n")) | |
4403 | (princ " '(") | |
4404 | (prin1 symbol) | |
4405 | (princ " ") | |
4406 | (prin1 (car value)) | |
4407 | (when (or now requests comment) | |
4408 | (princ " ") | |
4409 | (prin1 now) | |
4410 | (when (or requests comment) | |
4411 | (princ " ") | |
4412 | (prin1 requests) | |
4413 | (when comment | |
4414 | (princ " ") | |
4415 | (prin1 comment)))) | |
4416 | (princ ")")))) | |
a34511a1 RS |
4417 | (if (bolp) |
4418 | (princ " ")) | |
d543e20b PA |
4419 | (princ ")") |
4420 | (unless (looking-at "\n") | |
4421 | (princ "\n"))))) | |
4422 | ||
4423 | (defun custom-save-faces () | |
4424 | "Save all customized faces in `custom-file'." | |
4425 | (save-excursion | |
c942535f | 4426 | (custom-save-delete 'custom-reset-faces) |
d543e20b | 4427 | (custom-save-delete 'custom-set-faces) |
d151422c MR |
4428 | (let ((standard-output (current-buffer)) |
4429 | (saved-list (make-list 1 0)) | |
4430 | sort-fold-case) | |
4431 | ;; First create a sorted list of saved faces. | |
4432 | (mapatoms | |
4433 | (lambda (symbol) | |
d358aa10 CY |
4434 | (if (and (get symbol 'saved-face) |
4435 | (eq 'user (car (car-safe (get symbol 'theme-face))))) | |
d151422c MR |
4436 | (nconc saved-list (list symbol))))) |
4437 | (setq saved-list (sort (cdr saved-list) 'string<)) | |
4438 | ;; The default face must be first, since it affects the others. | |
4439 | (if (memq 'default saved-list) | |
4440 | (setq saved-list (cons 'default (delq 'default saved-list)))) | |
d543e20b PA |
4441 | (unless (bolp) |
4442 | (princ "\n")) | |
aec2bb63 | 4443 | (princ "(custom-set-faces |
99b398e0 RS |
4444 | ;; custom-set-faces was added by Custom. |
4445 | ;; If you edit it by hand, you could mess it up, so be careful. | |
4446 | ;; Your init file should contain only one such instance. | |
4447 | ;; If there is more than one, they won't work right.\n") | |
d9f67134 SM |
4448 | (dolist (symbol saved-list) |
4449 | (let ((spec (car-safe (get symbol 'theme-face))) | |
4450 | (value (get symbol 'saved-face)) | |
4451 | (now (not (or (get symbol 'face-defface-spec) | |
4452 | (and (not (custom-facep symbol)) | |
4453 | (not (get symbol 'force-face)))))) | |
4454 | (comment (get symbol 'saved-face-comment))) | |
d358aa10 | 4455 | (when (or (and spec (eq (nth 0 spec) 'user)) |
d9f67134 SM |
4456 | comment |
4457 | (and (null spec) (get symbol 'saved-face))) | |
4458 | ;; Don't print default face here. | |
4459 | (unless (bolp) | |
4460 | (princ "\n")) | |
4461 | (princ " '(") | |
4462 | (prin1 symbol) | |
4463 | (princ " ") | |
4464 | (prin1 value) | |
4465 | (when (or now comment) | |
4466 | (princ " ") | |
4467 | (prin1 now) | |
4468 | (when comment | |
4469 | (princ " ") | |
4470 | (prin1 comment))) | |
4471 | (princ ")")))) | |
a34511a1 RS |
4472 | (if (bolp) |
4473 | (princ " ")) | |
d543e20b PA |
4474 | (princ ")") |
4475 | (unless (looking-at "\n") | |
08b4ae6c | 4476 | (princ "\n"))))) |
f8d869d1 | 4477 | \f |
d543e20b PA |
4478 | ;;; The Customize Menu. |
4479 | ||
bd042c03 PA |
4480 | ;;; Menu support |
4481 | ||
25ac13b5 PA |
4482 | (defcustom custom-menu-nesting 2 |
4483 | "Maximum nesting in custom menus." | |
4484 | :type 'integer | |
6aaedd12 | 4485 | :group 'custom-menu) |
d543e20b PA |
4486 | |
4487 | (defun custom-face-menu-create (widget symbol) | |
4488 | "Ignoring WIDGET, create a menu entry for customization face SYMBOL." | |
4489 | (vector (custom-unlispify-menu-entry symbol) | |
86bd10bc | 4490 | `(customize-face ',symbol) |
d543e20b PA |
4491 | t)) |
4492 | ||
4493 | (defun custom-variable-menu-create (widget symbol) | |
4494 | "Ignoring WIDGET, create a menu entry for customization variable SYMBOL." | |
4495 | (let ((type (get symbol 'custom-type))) | |
4496 | (unless (listp type) | |
4497 | (setq type (list type))) | |
4498 | (if (and type (widget-get type :custom-menu)) | |
4499 | (widget-apply type :custom-menu symbol) | |
4500 | (vector (custom-unlispify-menu-entry symbol) | |
86bd10bc | 4501 | `(customize-variable ',symbol) |
d543e20b PA |
4502 | t)))) |
4503 | ||
bd042c03 | 4504 | ;; Add checkboxes to boolean variable entries. |
d543e20b PA |
4505 | (widget-put (get 'boolean 'widget-type) |
4506 | :custom-menu (lambda (widget symbol) | |
4507 | (vector (custom-unlispify-menu-entry symbol) | |
86bd10bc | 4508 | `(customize-variable ',symbol) |
d543e20b PA |
4509 | ':style 'toggle |
4510 | ':selected symbol))) | |
4511 | ||
d04a3972 DL |
4512 | (defun custom-group-menu-create (widget symbol) |
4513 | "Ignoring WIDGET, create a menu entry for customization group SYMBOL." | |
4514 | `( ,(custom-unlispify-menu-entry symbol t) | |
4515 | :filter (lambda (&rest junk) | |
809f0c35 | 4516 | (let* ((menu (custom-menu-create ',symbol))) |
3b2f3d30 | 4517 | (if (consp menu) (cdr menu) menu))))) |
d543e20b | 4518 | |
bd042c03 PA |
4519 | ;;;###autoload |
4520 | (defun custom-menu-create (symbol) | |
d543e20b | 4521 | "Create menu for customization group SYMBOL. |
d543e20b | 4522 | The menu is in a format applicable to `easy-menu-define'." |
809f0c35 RS |
4523 | (let* ((deactivate-mark nil) |
4524 | (item (vector (custom-unlispify-menu-entry symbol) | |
86bd10bc | 4525 | `(customize-group ',symbol) |
bd042c03 PA |
4526 | t))) |
4527 | (if (and (or (not (boundp 'custom-menu-nesting)) | |
4528 | (>= custom-menu-nesting 0)) | |
2de2cb02 MR |
4529 | (progn |
4530 | (custom-load-symbol symbol) | |
4531 | (< (length (get symbol 'custom-group)) widget-menu-max-size))) | |
d543e20b | 4532 | (let ((custom-prefix-list (custom-prefix-add symbol |
25ac13b5 | 4533 | custom-prefix-list)) |
da5ec617 PA |
4534 | (members (custom-sort-items (get symbol 'custom-group) |
4535 | custom-menu-sort-alphabetically | |
4536 | custom-menu-order-groups))) | |
d543e20b PA |
4537 | `(,(custom-unlispify-menu-entry symbol t) |
4538 | ,item | |
4539 | "--" | |
4540 | ,@(mapcar (lambda (entry) | |
4541 | (widget-apply (if (listp (nth 1 entry)) | |
4542 | (nth 1 entry) | |
4543 | (list (nth 1 entry))) | |
4544 | :custom-menu (nth 0 entry))) | |
25ac13b5 | 4545 | members))) |
d543e20b PA |
4546 | item))) |
4547 | ||
4548 | ;;;###autoload | |
bd042c03 PA |
4549 | (defun customize-menu-create (symbol &optional name) |
4550 | "Return a customize menu for customization group SYMBOL. | |
d3d4df42 | 4551 | If optional NAME is given, use that as the name of the menu. |
bd042c03 PA |
4552 | Otherwise the menu will be named `Customize'. |
4553 | The format is suitable for use with `easy-menu-define'." | |
4554 | (unless name | |
4555 | (setq name "Customize")) | |
d04a3972 DL |
4556 | `(,name |
4557 | :filter (lambda (&rest junk) | |
3b2f3d30 SM |
4558 | (let ((menu (custom-menu-create ',symbol))) |
4559 | (if (consp menu) (cdr menu) menu))))) | |
d543e20b | 4560 | |
9db1942d CY |
4561 | ;;; Toolbar and menubar support |
4562 | ||
4563 | (easy-menu-define | |
34cf517c | 4564 | Custom-mode-menu (list custom-mode-map custom-field-keymap) |
9db1942d CY |
4565 | "Menu used in customization buffers." |
4566 | (nconc (list "Custom" | |
4567 | (customize-menu-create 'customize)) | |
4568 | (mapcar (lambda (arg) | |
4569 | (let ((tag (nth 0 arg)) | |
4570 | (command (nth 1 arg)) | |
4571 | (active (nth 2 arg)) | |
4572 | (help (nth 3 arg))) | |
4573 | (vector tag command :active (eval active) :help help))) | |
4574 | custom-commands))) | |
4575 | ||
4576 | (defvar tool-bar-map) | |
2614ccc3 MR |
4577 | |
4578 | ;;; `custom-tool-bar-map' used to be set up here. This will fail to | |
4579 | ;;; DTRT when `display-graphic-p' returns nil during compilation. Hence | |
6aec3b9d | 4580 | ;;; we set this up lazily in `Custom-mode'. |
2614ccc3 MR |
4581 | (defvar custom-tool-bar-map nil |
4582 | "Keymap for toolbar in Custom mode.") | |
9db1942d | 4583 | |
bd042c03 PA |
4584 | ;;; The Custom Mode. |
4585 | ||
adcc7a37 | 4586 | (defun Custom-no-edit (pos &optional event) |
7eb944cf RS |
4587 | "Invoke button at POS, or refuse to allow editing of Custom buffer." |
4588 | (interactive "@d") | |
a8da2abd | 4589 | (error "You can't edit this part of the Custom buffer")) |
0ce026b1 | 4590 | |
adcc7a37 | 4591 | (defun Custom-newline (pos &optional event) |
19f0515a RS |
4592 | "Invoke button at POS, or refuse to allow editing of Custom buffer." |
4593 | (interactive "@d") | |
4594 | (let ((button (get-char-property pos 'button))) | |
4595 | (if button | |
4596 | (widget-apply-action button event) | |
4597 | (error "You can't edit this part of the Custom buffer")))) | |
4598 | ||
b62c92bb RS |
4599 | (defun Custom-goto-parent () |
4600 | "Go to the parent group listed at the top of this buffer. | |
4601 | If several parents are listed, go to the first of them." | |
4602 | (interactive) | |
4603 | (save-excursion | |
4604 | (goto-char (point-min)) | |
d84fcc30 | 4605 | (if (search-forward "\nParent groups: " nil t) |
b62c92bb RS |
4606 | (let* ((button (get-char-property (point) 'button)) |
4607 | (parent (downcase (widget-get button :tag)))) | |
4608 | (customize-group parent))))) | |
4609 | ||
6aec3b9d | 4610 | (defcustom Custom-mode-hook nil |
d3d4df42 | 4611 | "Hook called when entering Custom mode." |
bd042c03 | 4612 | :type 'hook |
6aec3b9d | 4613 | :group 'custom-buffer) |
bd042c03 | 4614 | |
b62c92bb RS |
4615 | (defun custom-state-buffer-message (widget) |
4616 | (if (eq (widget-get (widget-get widget :parent) :custom-state) 'modified) | |
4617 | (message "To install your edits, invoke [State] and choose the Set operation"))) | |
8691cfa7 | 4618 | |
6aec3b9d | 4619 | (define-derived-mode Custom-mode nil "Custom" |
bd042c03 PA |
4620 | "Major mode for editing customization buffers. |
4621 | ||
4622 | The following commands are available: | |
4623 | ||
192e44fc JL |
4624 | \\<widget-keymap>\ |
4625 | Move to next button, link or editable field. \\[widget-forward] | |
61e80285 | 4626 | Move to previous button, link or editable field. \\[advertised-widget-backward] |
192e44fc | 4627 | \\<custom-field-keymap>\ |
4ee1cf9f PA |
4628 | Complete content of editable text field. \\[widget-complete] |
4629 | \\<custom-mode-map>\ | |
9ca66103 | 4630 | Invoke button under the mouse pointer. \\[widget-button-click] |
192e44fc | 4631 | Invoke button under point. \\[widget-button-press] |
107736a2 RS |
4632 | Set all options from current text. \\[Custom-set] |
4633 | Make values in current text permanent. \\[Custom-save] | |
192e44fc JL |
4634 | Make text match actual option values. \\[Custom-reset-current] |
4635 | Reset options to permanent settings. \\[Custom-reset-saved] | |
107736a2 RS |
4636 | Erase customizations; set options |
4637 | and buffer text to the standard values. \\[Custom-reset-standard] | |
bd042c03 | 4638 | |
6aec3b9d | 4639 | Entry to this mode calls the value of `Custom-mode-hook' |
bd042c03 | 4640 | if that value is non-nil." |
bd042c03 | 4641 | (use-local-map custom-mode-map) |
ab678382 | 4642 | (easy-menu-add Custom-mode-menu) |
2614ccc3 MR |
4643 | (when (display-graphic-p) |
4644 | (set (make-local-variable 'tool-bar-map) | |
4645 | (or custom-tool-bar-map | |
4646 | ;; Set up `custom-tool-bar-map'. | |
4647 | (let ((map (make-sparse-keymap))) | |
4648 | (mapc | |
4649 | (lambda (arg) | |
4650 | (tool-bar-local-item-from-menu | |
4651 | (nth 1 arg) (nth 4 arg) map custom-mode-map)) | |
4652 | custom-commands) | |
4653 | (setq custom-tool-bar-map map))))) | |
bd042c03 | 4654 | (make-local-variable 'custom-options) |
9b7826f4 | 4655 | (make-local-variable 'custom-local-buffer) |
b62c92bb | 4656 | (make-local-variable 'widget-documentation-face) |
d478e69d | 4657 | (setq widget-documentation-face 'custom-documentation) |
3aec85bf | 4658 | (make-local-variable 'widget-button-face) |
87911bdb | 4659 | (setq widget-button-face custom-button) |
d1a3873f | 4660 | (setq show-trailing-whitespace nil) |
b0c4ae71 CY |
4661 | |
4662 | ;; We need this because of the "More" button on docstrings. | |
4663 | ;; Otherwise clicking on "More" can push point offscreen, which | |
4664 | ;; causes the window to recenter on point, which pushes the | |
4665 | ;; newly-revealed docstring offscreen; which is annoying. -- cyd. | |
4666 | (set (make-local-variable 'widget-button-click-moves-point) t) | |
4667 | ||
87911bdb | 4668 | (set (make-local-variable 'widget-button-pressed-face) custom-button-pressed) |
85a5eb0e | 4669 | (set (make-local-variable 'widget-mouse-face) custom-button-mouse) |
87911bdb | 4670 | |
d3d4df42 DL |
4671 | ;; When possible, use relief for buttons, not bracketing. This test |
4672 | ;; may not be optimal. | |
4673 | (when custom-raised-buttons | |
4674 | (set (make-local-variable 'widget-push-button-prefix) "") | |
4675 | (set (make-local-variable 'widget-push-button-suffix) "") | |
4676 | (set (make-local-variable 'widget-link-prefix) "") | |
4677 | (set (make-local-variable 'widget-link-suffix) "")) | |
d1a3873f | 4678 | (add-hook 'widget-edit-functions 'custom-state-buffer-message nil t)) |
d543e20b | 4679 | |
6aec3b9d JL |
4680 | (put 'Custom-mode 'mode-class 'special) |
4681 | ||
4682 | ;; backward-compatibility | |
4683 | (defun custom-mode () | |
4684 | "Non-interactive variant of `Custom-mode'." | |
4685 | (Custom-mode)) | |
82c02591 | 4686 | (make-obsolete 'custom-mode 'Custom-mode "23.1") |
7f352f86 | 4687 | (put 'custom-mode 'mode-class 'special) |
82c02591 | 4688 | (define-obsolete-variable-alias 'custom-mode-hook 'Custom-mode-hook "23.1") |
7f352f86 | 4689 | |
81711dba EZ |
4690 | (dolist (regexp |
4691 | '("^No user option defaults have been changed since Emacs " | |
4692 | "^Invalid face:? " | |
4693 | "^No \\(?:customized\\|rogue\\|saved\\) user options" | |
4694 | "^No customizable items matching " | |
4695 | "^There are unset changes" | |
4696 | "^Cannot set hidden variable" | |
4697 | "^No \\(?:saved\\|backup\\) value for " | |
4698 | "^No standard setting known for " | |
4699 | "^No standard setting for this face" | |
4700 | "^Saving settings from \"emacs -q\" would overwrite existing customizations")) | |
4701 | (add-to-list 'debug-ignored-errors regexp)) | |
2365594b | 4702 | |
d543e20b PA |
4703 | ;;; The End. |
4704 | ||
4705 | (provide 'cus-edit) | |
4706 | ||
f7105ede | 4707 | ;; arch-tag: 64533aa4-1b1a-48c3-8812-f9dc718e8a6f |
d3d4df42 | 4708 | ;;; cus-edit.el ends here |