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