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