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