Mercurial > hg > xemacs-beta
comparison lisp/custom/cus-edit.el @ 120:cca96a509cfe r20-1b12
Import from CVS: tag r20-1b12
author | cvs |
---|---|
date | Mon, 13 Aug 2007 09:25:29 +0200 |
parents | 7d55a9ba150c |
children | 9b50b4588a93 |
comparison
equal
deleted
inserted
replaced
119:d101af7320b8 | 120:cca96a509cfe |
---|---|
2 ;; | 2 ;; |
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc. |
4 ;; | 4 ;; |
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> | 5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk> |
6 ;; Keywords: help, faces | 6 ;; Keywords: help, faces |
7 ;; Version: 1.69 | 7 ;; Version: 1.74 |
8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ | 8 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/ |
9 | 9 |
10 ;;; Commentary: | 10 ;;; Commentary: |
11 ;; | 11 ;; |
12 ;; See `custom.el'. | 12 ;; See `custom.el'. |
19 | 19 |
20 (define-widget-keywords :custom-prefixes :custom-menu :custom-show | 20 (define-widget-keywords :custom-prefixes :custom-menu :custom-show |
21 :custom-magic :custom-state :custom-level :custom-form | 21 :custom-magic :custom-state :custom-level :custom-form |
22 :custom-set :custom-save :custom-reset-current :custom-reset-saved | 22 :custom-set :custom-save :custom-reset-current :custom-reset-saved |
23 :custom-reset-factory) | 23 :custom-reset-factory) |
24 | |
25 (put 'custom-define-hook 'custom-type 'hook) | |
26 (put 'custom-define-hook 'factory-value '(nil)) | |
27 (custom-add-to-group 'customize 'custom-define-hook 'custom-variable) | |
24 | 28 |
25 ;;; Customization Groups. | 29 ;;; Customization Groups. |
26 | 30 |
27 (defgroup emacs nil | 31 (defgroup emacs nil |
28 "Customization of the One True Editor." | 32 "Customization of the One True Editor." |
256 (save-excursion | 260 (save-excursion |
257 (set-buffer (get-buffer-create " *Custom-Work*")) | 261 (set-buffer (get-buffer-create " *Custom-Work*")) |
258 (erase-buffer) | 262 (erase-buffer) |
259 (princ symbol (current-buffer)) | 263 (princ symbol (current-buffer)) |
260 (goto-char (point-min)) | 264 (goto-char (point-min)) |
265 (when (and (eq (get symbol 'custom-type) 'boolean) | |
266 (re-search-forward "-p\\'" nil t)) | |
267 (replace-match "" t t) | |
268 (goto-char (point-min))) | |
261 (let ((prefixes custom-prefix-list) | 269 (let ((prefixes custom-prefix-list) |
262 prefix) | 270 prefix) |
263 (while prefixes | 271 (while prefixes |
264 (setq prefix (car prefixes)) | 272 (setq prefix (car prefixes)) |
265 (if (search-forward prefix (+ (point) (length prefix)) t) | 273 (if (search-forward prefix (+ (point) (length prefix)) t) |
287 (defun custom-prefix-add (symbol prefixes) | 295 (defun custom-prefix-add (symbol prefixes) |
288 ;; Addd SYMBOL to list of ignored PREFIXES. | 296 ;; Addd SYMBOL to list of ignored PREFIXES. |
289 (cons (or (get symbol 'custom-prefix) | 297 (cons (or (get symbol 'custom-prefix) |
290 (concat (symbol-name symbol) "-")) | 298 (concat (symbol-name symbol) "-")) |
291 prefixes)) | 299 prefixes)) |
300 | |
301 (defcustom custom-guess-type-alist | |
302 '(("-p\\'" boolean) | |
303 ("-hook\\'" hook) | |
304 ("-face\\'" face) | |
305 ("-file\\'" file) | |
306 ("-function\\'" function) | |
307 ("-functions\\'" (repeat function)) | |
308 ("-list\\'" (repeat sexp)) | |
309 ("-alist\\'" (repeat (cons sexp sexp)))) | |
310 "Alist of (MATCH TYPE). | |
311 | |
312 MATCH should be a regexp matching the name of a symbol, and TYPE should | |
313 be a widget suitable for editing the value of that symbol. The TYPE | |
314 of the first entry where MATCH matches the name of the symbol will be | |
315 used. | |
316 | |
317 This is used for guessing the type of variables not declared with | |
318 customize." | |
319 :type '(repeat (group regexp sexp)) | |
320 :group 'customize) | |
321 | |
322 (defun custom-guess-type (symbol) | |
323 "Guess a widget suitable for editing the value of SYMBOL. | |
324 This is done by matching SYMBOL with `custom-guess-type-alist'." | |
325 (let ((name (symbol-name symbol)) | |
326 (alist custom-guess-type-alist) | |
327 current found) | |
328 (while alist | |
329 (setq current (car alist) | |
330 alist (cdr alist)) | |
331 (when (string-match (nth 0 current) name) | |
332 (setq found (nth 1 current) | |
333 alist nil))) | |
334 found)) | |
292 | 335 |
293 ;;; The Custom Mode. | 336 ;;; The Custom Mode. |
294 | 337 |
295 (defvar custom-options nil | 338 (defvar custom-options nil |
296 "Customization widgets in the current buffer.") | 339 "Customization widgets in the current buffer.") |
454 (let ((found nil)) | 497 (let ((found nil)) |
455 (message "Looking for faces...") | 498 (message "Looking for faces...") |
456 (mapcar (lambda (symbol) | 499 (mapcar (lambda (symbol) |
457 (setq found (cons (list symbol 'custom-face) found))) | 500 (setq found (cons (list symbol 'custom-face) found))) |
458 (face-list)) | 501 (face-list)) |
459 (message "Creating customization buffer...") | |
460 (custom-buffer-create found)) | 502 (custom-buffer-create found)) |
461 (if (stringp symbol) | 503 (if (stringp symbol) |
462 (setq symbol (intern symbol))) | 504 (setq symbol (intern symbol))) |
463 (unless (symbolp symbol) | 505 (unless (symbolp symbol) |
464 (error "Should be a symbol %S" symbol)) | 506 (error "Should be a symbol %S" symbol)) |
510 (defun custom-buffer-create (options) | 552 (defun custom-buffer-create (options) |
511 "Create a buffer containing OPTIONS. | 553 "Create a buffer containing OPTIONS. |
512 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where | 554 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where |
513 SYMBOL is a customization option, and WIDGET is a widget for editing | 555 SYMBOL is a customization option, and WIDGET is a widget for editing |
514 that option." | 556 that option." |
557 (message "Creating customization buffer...") | |
515 (kill-buffer (get-buffer-create "*Customization*")) | 558 (kill-buffer (get-buffer-create "*Customization*")) |
516 (switch-to-buffer (get-buffer-create "*Customization*")) | 559 (switch-to-buffer (get-buffer-create "*Customization*")) |
517 (custom-mode) | 560 (custom-mode) |
518 (widget-insert "This is a customization buffer. | 561 (widget-insert "This is a customization buffer. |
519 Push RET or click mouse-2 on the word ") | 562 Push RET or click mouse-2 on the word ") |
522 :tag "help" | 565 :tag "help" |
523 :help-echo "Read the online help." | 566 :help-echo "Read the online help." |
524 "(custom)The Customization Buffer") | 567 "(custom)The Customization Buffer") |
525 (widget-insert " for more information.\n\n") | 568 (widget-insert " for more information.\n\n") |
526 (setq custom-options | 569 (setq custom-options |
527 (mapcar (lambda (entry) | 570 (if (= (length options) 1) |
528 (prog1 | 571 (mapcar (lambda (entry) |
529 (if (> (length options) 1) | 572 (widget-create (nth 1 entry) |
530 (widget-create (nth 1 entry) | 573 :custom-state 'unknown |
574 :tag (custom-unlispify-tag-name | |
575 (nth 0 entry)) | |
576 :value (nth 0 entry))) | |
577 options) | |
578 (let ((count 0) | |
579 (length (length options))) | |
580 (mapcar (lambda (entry) | |
581 (prog2 | |
582 (message "Creating customization items %2d%%..." | |
583 (/ (* 100.0 count) length)) | |
584 (widget-create (nth 1 entry) | |
531 :tag (custom-unlispify-tag-name | 585 :tag (custom-unlispify-tag-name |
532 (nth 0 entry)) | 586 (nth 0 entry)) |
533 :value (nth 0 entry)) | 587 :value (nth 0 entry)) |
534 ;; If there is only one entry, don't hide it! | 588 (setq count (1+ count)) |
535 (widget-create (nth 1 entry) | 589 (unless (eq (preceding-char) ?\n) |
536 :custom-state 'unknown | 590 (widget-insert "\n")) |
537 :tag (custom-unlispify-tag-name | 591 (widget-insert "\n"))) |
538 (nth 0 entry)) | 592 options)))) |
539 :value (nth 0 entry))) | 593 (unless (eq (preceding-char) ?\n) |
540 (unless (eq (preceding-char) ?\n) | 594 (widget-insert "\n")) |
541 (widget-insert "\n")) | 595 (widget-insert "\n") |
542 (widget-insert "\n"))) | 596 (message "Creating customization magic...") |
543 options)) | |
544 (mapcar 'custom-magic-reset custom-options) | 597 (mapcar 'custom-magic-reset custom-options) |
598 (message "Creating customization buttons...") | |
545 (widget-create 'push-button | 599 (widget-create 'push-button |
546 :tag "Set" | 600 :tag "Set" |
547 :help-echo "Set all modifications for this session." | 601 :help-echo "Set all modifications for this session." |
548 :action (lambda (widget &optional event) | 602 :action (lambda (widget &optional event) |
549 (custom-set))) | 603 (custom-set))) |
575 (next-command-event)) | 629 (next-command-event)) |
576 ;; Emacs | 630 ;; Emacs |
577 (when (memq 'down (event-modifiers event)) | 631 (when (memq 'down (event-modifiers event)) |
578 (read-event))))) | 632 (read-event))))) |
579 (widget-insert "\n") | 633 (widget-insert "\n") |
634 (message "Creating customization setup...") | |
580 (widget-setup) | 635 (widget-setup) |
581 (goto-char (point-min))) | 636 (goto-char (point-min)) |
637 (message "Creating customization buffer...done")) | |
582 | 638 |
583 ;;; Modification of Basic Widgets. | 639 ;;; Modification of Basic Widgets. |
584 ;; | 640 ;; |
585 ;; We add extra properties to the basic widgets needed here. This is | 641 ;; We add extra properties to the basic widgets needed here. This is |
586 ;; fine, as long as we are careful to stay within out own namespace. | 642 ;; fine, as long as we are careful to stay within out own namespace. |
988 :custom-save 'custom-variable-save | 1044 :custom-save 'custom-variable-save |
989 :custom-reset-current 'custom-redraw | 1045 :custom-reset-current 'custom-redraw |
990 :custom-reset-saved 'custom-variable-reset-saved | 1046 :custom-reset-saved 'custom-variable-reset-saved |
991 :custom-reset-factory 'custom-variable-reset-factory) | 1047 :custom-reset-factory 'custom-variable-reset-factory) |
992 | 1048 |
1049 (defun custom-variable-type (symbol) | |
1050 "Return a widget suitable for editing the value of SYMBOL. | |
1051 If SYMBOL has a `custom-type' property, use that. | |
1052 Otherwise, look up symbol in `custom-guess-type-alist'." | |
1053 (let* ((type (or (get symbol 'custom-type) | |
1054 (custom-guess-type symbol) | |
1055 'sexp)) | |
1056 (options (get symbol 'custom-options)) | |
1057 (tmp (if (listp type) | |
1058 (copy-list type) | |
1059 (list type)))) | |
1060 (when options | |
1061 (widget-put tmp :options options)) | |
1062 tmp)) | |
1063 | |
993 (defun custom-variable-value-create (widget) | 1064 (defun custom-variable-value-create (widget) |
994 "Here is where you edit the variables value." | 1065 "Here is where you edit the variables value." |
995 (custom-load-widget widget) | 1066 (custom-load-widget widget) |
996 (let* ((buttons (widget-get widget :buttons)) | 1067 (let* ((buttons (widget-get widget :buttons)) |
997 (children (widget-get widget :children)) | 1068 (children (widget-get widget :children)) |
998 (form (widget-get widget :custom-form)) | 1069 (form (widget-get widget :custom-form)) |
999 (state (widget-get widget :custom-state)) | 1070 (state (widget-get widget :custom-state)) |
1000 (symbol (widget-get widget :value)) | 1071 (symbol (widget-get widget :value)) |
1001 (options (get symbol 'custom-options)) | |
1002 (child-type (or (get symbol 'custom-type) 'sexp)) | |
1003 (tag (widget-get widget :tag)) | 1072 (tag (widget-get widget :tag)) |
1004 (type (let ((tmp (if (listp child-type) | 1073 (type (custom-variable-type symbol)) |
1005 (copy-list child-type) | |
1006 (list child-type)))) | |
1007 (when options | |
1008 (widget-put tmp :options options)) | |
1009 tmp)) | |
1010 (conv (widget-convert type)) | 1074 (conv (widget-convert type)) |
1011 (value (if (default-boundp symbol) | 1075 (value (if (default-boundp symbol) |
1012 (default-value symbol) | 1076 (default-value symbol) |
1013 (widget-get conv :value)))) | 1077 (widget-get conv :value)))) |
1014 ;; If the widget is new, the child determine whether it is hidden. | 1078 ;; If the widget is new, the child determine whether it is hidden. |
1308 :help-echo "Set or reset this face." | 1372 :help-echo "Set or reset this face." |
1309 :documentation-property '(lambda (face) | 1373 :documentation-property '(lambda (face) |
1310 (face-doc-string face)) | 1374 (face-doc-string face)) |
1311 :value-create 'custom-face-value-create | 1375 :value-create 'custom-face-value-create |
1312 :action 'custom-face-action | 1376 :action 'custom-face-action |
1377 :custom-form 'selected | |
1313 :custom-set 'custom-face-set | 1378 :custom-set 'custom-face-set |
1314 :custom-save 'custom-face-save | 1379 :custom-save 'custom-face-save |
1315 :custom-reset-current 'custom-redraw | 1380 :custom-reset-current 'custom-redraw |
1316 :custom-reset-saved 'custom-face-reset-saved | 1381 :custom-reset-saved 'custom-face-reset-saved |
1317 :custom-reset-factory 'custom-face-reset-factory | 1382 :custom-reset-factory 'custom-face-reset-factory |
1335 (custom-format-handler widget escape))) | 1400 (custom-format-handler widget escape))) |
1336 (when child | 1401 (when child |
1337 (widget-put widget | 1402 (widget-put widget |
1338 :buttons (cons child (widget-get widget :buttons)))))) | 1403 :buttons (cons child (widget-get widget :buttons)))))) |
1339 | 1404 |
1405 (define-widget 'custom-face-all 'editable-list | |
1406 "An editable list of display specifications and attributes." | |
1407 :entry-format "%i %d %v" | |
1408 :insert-button-args '(:help-echo "Insert new display specification here.") | |
1409 :append-button-args '(:help-echo "Append new display specification here.") | |
1410 :delete-button-args '(:help-echo "Delete this display specification.") | |
1411 :args '((group :format "%v" custom-display custom-face-edit))) | |
1412 | |
1413 (defconst custom-face-all (widget-convert 'custom-face-all) | |
1414 "Converted version of the `custom-face-all' widget.") | |
1415 | |
1416 (define-widget 'custom-display-unselected 'item | |
1417 "A display specification that doesn't match the selected display." | |
1418 :match 'custom-display-unselected-match) | |
1419 | |
1420 (defun custom-display-unselected-match (widget value) | |
1421 "Non-nil if VALUE is an unselected display specification." | |
1422 (and (listp value) | |
1423 (eq (length value) 2) | |
1424 (not (custom-display-match-frame value (selected-frame))))) | |
1425 | |
1426 (define-widget 'custom-face-selected 'group | |
1427 "Edit the attributes of the selected display in a face specification." | |
1428 :args '((repeat :format "" | |
1429 :inline t | |
1430 (group custom-display-unselected sexp)) | |
1431 (group (sexp :format "") custom-face-edit) | |
1432 (repeat :format "" | |
1433 :inline t | |
1434 sexp))) | |
1435 | |
1436 (defconst custom-face-selected (widget-convert 'custom-face-selected) | |
1437 "Converted version of the `custom-face-selected' widget.") | |
1438 | |
1340 (defun custom-face-value-create (widget) | 1439 (defun custom-face-value-create (widget) |
1341 ;; Create a list of the display specifications. | 1440 ;; Create a list of the display specifications. |
1342 (unless (eq (preceding-char) ?\n) | 1441 (unless (eq (preceding-char) ?\n) |
1343 (insert "\n")) | 1442 (insert "\n")) |
1344 (when (not (eq (widget-get widget :custom-state) 'hidden)) | 1443 (when (not (eq (widget-get widget :custom-state) 'hidden)) |
1444 (message "Creating face editor...") | |
1345 (custom-load-widget widget) | 1445 (custom-load-widget widget) |
1346 (let* ((symbol (widget-value widget)) | 1446 (let* ((symbol (widget-value widget)) |
1447 (spec (or (get symbol 'saved-face) | |
1448 (get symbol 'factory-face) | |
1449 ;; Attempt to construct it. | |
1450 (list (list t (custom-face-attributes-get | |
1451 symbol (selected-frame)))))) | |
1452 (form (widget-get widget :custom-form)) | |
1453 (indent (widget-get widget :indent)) | |
1347 (edit (widget-create-child-and-convert | 1454 (edit (widget-create-child-and-convert |
1348 widget 'editable-list | 1455 widget |
1349 :entry-format "%i %d %v" | 1456 (cond ((and (eq form 'selected) |
1350 :value (or (get symbol 'saved-face) | 1457 (widget-apply custom-face-selected :match spec)) |
1351 (get symbol 'factory-face) | 1458 (when indent (insert-char ?\ indent)) |
1352 ;; Attempt to construct it. | 1459 'custom-face-selected) |
1353 (list (list t (custom-face-attributes-get | 1460 ((and (not (eq form 'lisp)) |
1354 symbol (selected-frame))))) | 1461 (widget-apply custom-face-all :match spec)) |
1355 :insert-button-args '(:help-echo "\ | 1462 'custom-face-all) |
1356 Insert new display specification here.") | 1463 (t |
1357 :append-button-args '(:help-echo "\ | 1464 (when indent (insert-char ?\ indent)) |
1358 Append new display specification here.") | 1465 'sexp)) |
1359 :delete-button-args '(:help-echo "\ | 1466 :value spec))) |
1360 Delete this display specification.") | |
1361 '(group :format "%v" | |
1362 custom-display custom-face-edit)))) | |
1363 (custom-face-state-set widget) | 1467 (custom-face-state-set widget) |
1364 (widget-put widget :children (list edit))))) | 1468 (widget-put widget :children (list edit))) |
1469 (message "Creating face editor...done"))) | |
1365 | 1470 |
1366 (defvar custom-face-menu | 1471 (defvar custom-face-menu |
1367 '(("Set" . custom-face-set) | 1472 '(("Edit Selected" . custom-face-edit-selected) |
1473 ("Edit All" . custom-face-edit-all) | |
1474 ("Edit Lisp" . custom-face-edit-lisp) | |
1475 ("Set" . custom-face-set) | |
1368 ("Save" . custom-face-save) | 1476 ("Save" . custom-face-save) |
1369 ("Reset to Saved" . custom-face-reset-saved) | 1477 ("Reset to Saved" . custom-face-reset-saved) |
1370 ("Reset to Factory Setting" . custom-face-reset-factory)) | 1478 ("Reset to Factory Setting" . custom-face-reset-factory)) |
1371 "Alist of actions for the `custom-face' widget. | 1479 "Alist of actions for the `custom-face' widget. |
1372 The key is a string containing the name of the action, the value is a | 1480 The key is a string containing the name of the action, the value is a |
1373 lisp function taking the widget as an element which will be called | 1481 lisp function taking the widget as an element which will be called |
1374 when the action is chosen.") | 1482 when the action is chosen.") |
1483 | |
1484 (defun custom-face-edit-selected (widget) | |
1485 "Edit selected attributes of the value of WIDGET." | |
1486 (widget-put widget :custom-state 'unknown) | |
1487 (widget-put widget :custom-form 'selected) | |
1488 (custom-redraw widget)) | |
1489 | |
1490 (defun custom-face-edit-all (widget) | |
1491 "Edit all attributes of the value of WIDGET." | |
1492 (widget-put widget :custom-state 'unknown) | |
1493 (widget-put widget :custom-form 'all) | |
1494 (custom-redraw widget)) | |
1495 | |
1496 (defun custom-face-edit-lisp (widget) | |
1497 "Edit the lisp representation of the value of WIDGET." | |
1498 (widget-put widget :custom-state 'unknown) | |
1499 (widget-put widget :custom-form 'lisp) | |
1500 (custom-redraw widget)) | |
1375 | 1501 |
1376 (defun custom-face-state-set (widget) | 1502 (defun custom-face-state-set (widget) |
1377 "Set the state of WIDGET." | 1503 "Set the state of WIDGET." |
1378 (let ((symbol (widget-value widget))) | 1504 (let ((symbol (widget-value widget))) |
1379 (widget-put widget :custom-state (cond ((get symbol 'customized-face) | 1505 (widget-put widget :custom-state (cond ((get symbol 'customized-face) |
1580 'custom-group-tag-face)) | 1706 'custom-group-tag-face)) |
1581 | 1707 |
1582 (defun custom-group-value-create (widget) | 1708 (defun custom-group-value-create (widget) |
1583 (let ((state (widget-get widget :custom-state))) | 1709 (let ((state (widget-get widget :custom-state))) |
1584 (unless (eq state 'hidden) | 1710 (unless (eq state 'hidden) |
1711 (message "Creating group...") | |
1585 (custom-load-widget widget) | 1712 (custom-load-widget widget) |
1586 (let* ((level (widget-get widget :custom-level)) | 1713 (let* ((level (widget-get widget :custom-level)) |
1587 (symbol (widget-value widget)) | 1714 (symbol (widget-value widget)) |
1588 (members (get symbol 'custom-group)) | 1715 (members (get symbol 'custom-group)) |
1589 (prefixes (widget-get widget :custom-prefixes)) | 1716 (prefixes (widget-get widget :custom-prefixes)) |
1590 (custom-prefix-list (custom-prefix-add symbol prefixes)) | 1717 (custom-prefix-list (custom-prefix-add symbol prefixes)) |
1718 (length (length members)) | |
1719 (count 0) | |
1591 (children (mapcar (lambda (entry) | 1720 (children (mapcar (lambda (entry) |
1592 (widget-insert "\n") | 1721 (widget-insert "\n") |
1722 (message "Creating group members... %2d%%" | |
1723 (/ (* 100.0 count) length)) | |
1724 (setq count (1+ count)) | |
1593 (prog1 | 1725 (prog1 |
1594 (widget-create-child-and-convert | 1726 (widget-create-child-and-convert |
1595 widget (nth 1 entry) | 1727 widget (nth 1 entry) |
1596 :group widget | 1728 :group widget |
1597 :tag (custom-unlispify-tag-name | 1729 :tag (custom-unlispify-tag-name |
1600 :custom-level (1+ level) | 1732 :custom-level (1+ level) |
1601 :value (nth 0 entry)) | 1733 :value (nth 0 entry)) |
1602 (unless (eq (preceding-char) ?\n) | 1734 (unless (eq (preceding-char) ?\n) |
1603 (widget-insert "\n")))) | 1735 (widget-insert "\n")))) |
1604 members))) | 1736 members))) |
1737 (message "Creating group magic...") | |
1605 (mapcar 'custom-magic-reset children) | 1738 (mapcar 'custom-magic-reset children) |
1739 (message "Creating group state...") | |
1606 (widget-put widget :children children) | 1740 (widget-put widget :children children) |
1607 (custom-group-state-update widget))))) | 1741 (custom-group-state-update widget) |
1742 (message "Creating group... done"))))) | |
1608 | 1743 |
1609 (defvar custom-group-menu | 1744 (defvar custom-group-menu |
1610 '(("Set" . custom-group-set) | 1745 '(("Set" . custom-group-set) |
1611 ("Save" . custom-group-save) | 1746 ("Save" . custom-group-save) |
1612 ("Reset to Current" . custom-group-reset-current) | 1747 ("Reset to Current" . custom-group-reset-current) |
1738 (and (not (boundp symbol)) | 1873 (and (not (boundp symbol)) |
1739 (not (get symbol 'force-value)))) | 1874 (not (get symbol 'force-value)))) |
1740 (princ ")") | 1875 (princ ")") |
1741 (princ " t)")))))) | 1876 (princ " t)")))))) |
1742 (princ ")") | 1877 (princ ")") |
1743 (unless (eolp) | 1878 (unless (looking-at "\n") |
1744 (princ "\n"))))) | 1879 (princ "\n"))))) |
1745 | 1880 |
1746 (defun custom-save-faces () | 1881 (defun custom-save-faces () |
1747 "Save all customized faces in `custom-file'." | 1882 "Save all customized faces in `custom-file'." |
1748 (save-excursion | 1883 (save-excursion |
1749 (custom-save-delete 'custom-set-faces) | 1884 (custom-save-delete 'custom-set-faces) |
1750 (let ((standard-output (current-buffer))) | 1885 (let ((standard-output (current-buffer))) |
1751 (unless (bolp) | 1886 (unless (bolp) |
1752 (princ "\n")) | 1887 (princ "\n")) |
1753 (princ "(custom-set-faces") | 1888 (princ "(custom-set-faces") |
1889 (let ((value (get 'default 'saved-face))) | |
1890 ;; The default face must be first, since it affects the others. | |
1891 (when value | |
1892 (princ "\n '(default ") | |
1893 (prin1 value) | |
1894 (if (or (get 'default 'factory-face) | |
1895 (and (not (custom-facep 'default)) | |
1896 (not (get 'default 'force-face)))) | |
1897 (princ ")") | |
1898 (princ " t)")))) | |
1754 (mapatoms (lambda (symbol) | 1899 (mapatoms (lambda (symbol) |
1755 (let ((value (get symbol 'saved-face))) | 1900 (let ((value (get symbol 'saved-face))) |
1756 (when value | 1901 (when (and (not (eq symbol 'default)) |
1902 ;; Don't print default face here. | |
1903 value) | |
1757 (princ "\n '(") | 1904 (princ "\n '(") |
1758 (princ symbol) | 1905 (princ symbol) |
1759 (princ " ") | 1906 (princ " ") |
1760 (prin1 value) | 1907 (prin1 value) |
1761 (if (or (get symbol 'factory-face) | 1908 (if (or (get symbol 'factory-face) |
1762 (and (not (custom-facep symbol)) | 1909 (and (not (custom-facep symbol)) |
1763 (not (get symbol 'force-face)))) | 1910 (not (get symbol 'force-face)))) |
1764 (princ ")") | 1911 (princ ")") |
1765 (princ " t)")))))) | 1912 (princ " t)")))))) |
1766 (princ ")") | 1913 (princ ")") |
1767 (unless (eolp) | 1914 (unless (looking-at "\n") |
1768 (princ "\n"))))) | 1915 (princ "\n"))))) |
1769 | 1916 |
1770 ;;;###autoload | 1917 ;;;###autoload |
1771 (defun custom-save-all () | 1918 (defun custom-save-all () |
1772 "Save all customizations in `custom-file'." | 1919 "Save all customizations in `custom-file'." |
1776 (set-buffer (find-file-noselect custom-file)) | 1923 (set-buffer (find-file-noselect custom-file)) |
1777 (save-buffer))) | 1924 (save-buffer))) |
1778 | 1925 |
1779 ;;; The Customize Menu. | 1926 ;;; The Customize Menu. |
1780 | 1927 |
1781 (defcustom custom-menu-nesting 2 | 1928 ;;; Menu support |
1782 "Maximum nesting in custom menus." | 1929 |
1783 :type 'integer | 1930 (unless (string-match "XEmacs" emacs-version) |
1784 :group 'customize) | 1931 (defconst custom-help-menu '("Customize" |
1932 ["Update menu..." custom-menu-update t] | |
1933 ["Group..." customize t] | |
1934 ["Variable..." customize-variable t] | |
1935 ["Face..." customize-face t] | |
1936 ["Saved..." customize-customized t] | |
1937 ["Apropos..." customize-apropos t]) | |
1938 ;; This menu should be identical to the one defined in `menu-bar.el'. | |
1939 "Customize menu") | |
1940 | |
1941 (defun custom-menu-reset () | |
1942 "Reset customize menu." | |
1943 (remove-hook 'custom-define-hook 'custom-menu-reset) | |
1944 (define-key global-map [menu-bar help-menu customize-menu] | |
1945 (cons (car custom-help-menu) | |
1946 (easy-menu-create-keymaps (car custom-help-menu) | |
1947 (cdr custom-help-menu))))) | |
1948 | |
1949 (defun custom-menu-update (event) | |
1950 "Update customize menu." | |
1951 (interactive "e") | |
1952 (add-hook 'custom-define-hook 'custom-menu-reset) | |
1953 (let* ((emacs (widget-apply '(custom-group) :custom-menu 'emacs)) | |
1954 (menu `(,(car custom-help-menu) | |
1955 ,emacs | |
1956 ,@(cdr (cdr custom-help-menu))))) | |
1957 (let ((map (easy-menu-create-keymaps (car menu) (cdr menu)))) | |
1958 (define-key global-map [menu-bar help-menu customize-menu] | |
1959 (cons (car menu) map))))) | |
1960 | |
1961 (defcustom custom-menu-nesting 2 | |
1962 "Maximum nesting in custom menus." | |
1963 :type 'integer | |
1964 :group 'customize)) | |
1785 | 1965 |
1786 (defun custom-face-menu-create (widget symbol) | 1966 (defun custom-face-menu-create (widget symbol) |
1787 "Ignoring WIDGET, create a menu entry for customization face SYMBOL." | 1967 "Ignoring WIDGET, create a menu entry for customization face SYMBOL." |
1788 (vector (custom-unlispify-menu-entry symbol) | 1968 (vector (custom-unlispify-menu-entry symbol) |
1789 `(custom-buffer-create '((,symbol custom-face))) | 1969 `(custom-buffer-create '((,symbol custom-face))) |
1798 (widget-apply type :custom-menu symbol) | 1978 (widget-apply type :custom-menu symbol) |
1799 (vector (custom-unlispify-menu-entry symbol) | 1979 (vector (custom-unlispify-menu-entry symbol) |
1800 `(custom-buffer-create '((,symbol custom-variable))) | 1980 `(custom-buffer-create '((,symbol custom-variable))) |
1801 t)))) | 1981 t)))) |
1802 | 1982 |
1983 ;; Add checkboxes to boolean variable entries. | |
1803 (widget-put (get 'boolean 'widget-type) | 1984 (widget-put (get 'boolean 'widget-type) |
1804 :custom-menu (lambda (widget symbol) | 1985 :custom-menu (lambda (widget symbol) |
1805 (vector (custom-unlispify-menu-entry symbol) | 1986 (vector (custom-unlispify-menu-entry symbol) |
1806 `(custom-buffer-create | 1987 `(custom-buffer-create |
1807 '((,symbol custom-variable))) | 1988 '((,symbol custom-variable))) |
1820 "Ignoring WIDGET, create a menu entry for customization group SYMBOL." | 2001 "Ignoring WIDGET, create a menu entry for customization group SYMBOL." |
1821 ;; Limit the nesting. | 2002 ;; Limit the nesting. |
1822 (let ((custom-menu-nesting (1- custom-menu-nesting))) | 2003 (let ((custom-menu-nesting (1- custom-menu-nesting))) |
1823 (custom-menu-create symbol)))) | 2004 (custom-menu-create symbol)))) |
1824 | 2005 |
2006 ;;;###autoload | |
1825 (defun custom-menu-create (symbol &optional name) | 2007 (defun custom-menu-create (symbol &optional name) |
1826 "Create menu for customization group SYMBOL. | 2008 "Create menu for customization group SYMBOL. |
1827 If optional NAME is given, use that as the name of the menu. | 2009 If optional NAME is given, use that as the name of the menu. |
1828 Otherwise make up a name from SYMBOL. | 2010 Otherwise make up a name from SYMBOL. |
1829 The menu is in a format applicable to `easy-menu-define'." | 2011 The menu is in a format applicable to `easy-menu-define'." |
1830 (unless name | 2012 (unless name |
1831 (setq name (custom-unlispify-menu-entry symbol))) | 2013 (setq name (custom-unlispify-menu-entry symbol))) |
1832 (let ((item (vector name | 2014 (let ((item (vector name |
1833 `(custom-buffer-create '((,symbol custom-group))) | 2015 `(custom-buffer-create '((,symbol custom-group))) |
1834 t))) | 2016 t))) |
1835 (if (and (>= custom-menu-nesting 0) | 2017 (if (and (or (not (boundp 'custom-menu-nesting)) |
2018 (>= custom-menu-nesting 0)) | |
1836 (< (length (get symbol 'custom-group)) widget-menu-max-size)) | 2019 (< (length (get symbol 'custom-group)) widget-menu-max-size)) |
1837 (let ((custom-prefix-list (custom-prefix-add symbol | 2020 (let ((custom-prefix-list (custom-prefix-add symbol |
1838 custom-prefix-list))) | 2021 custom-prefix-list))) |
1839 (custom-load-symbol symbol) | 2022 (custom-load-symbol symbol) |
1840 `(,(custom-unlispify-menu-entry symbol t) | 2023 `(,(custom-unlispify-menu-entry symbol t) |
1845 (nth 1 entry) | 2028 (nth 1 entry) |
1846 (list (nth 1 entry))) | 2029 (list (nth 1 entry))) |
1847 :custom-menu (nth 0 entry))) | 2030 :custom-menu (nth 0 entry))) |
1848 (get symbol 'custom-group)))) | 2031 (get symbol 'custom-group)))) |
1849 item))) | 2032 item))) |
1850 | |
1851 ;;;###autoload | |
1852 (defun custom-menu-update (event) | |
1853 "Update customize menu." | |
1854 (interactive "e") | |
1855 (add-hook 'custom-define-hook 'custom-menu-reset) | |
1856 (let* ((emacs (widget-apply '(custom-group) :custom-menu 'emacs)) | |
1857 (menu `(,(car custom-help-menu) | |
1858 ,emacs | |
1859 ,@(cdr (cdr custom-help-menu))))) | |
1860 (let ((map (easy-menu-create-keymaps (car menu) (cdr menu)))) | |
1861 (define-key global-map [menu-bar help-menu customize-menu] | |
1862 (cons (car menu) map))))) | |
1863 | 2033 |
1864 ;;; Dependencies. | 2034 ;;; Dependencies. |
1865 | 2035 |
1866 ;;;###autoload | 2036 ;;;###autoload |
1867 (defun custom-make-dependencies () | 2037 (defun custom-make-dependencies () |