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