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