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