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