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