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