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