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