Mercurial > emacs
comparison lisp/cus-edit.el @ 17415:30a567b89fb6
Sync with 1.84.
author | Per Abrahamsen <abraham@dina.kvl.dk> |
---|---|
date | Sat, 12 Apr 1997 17:51:31 +0000 |
parents | 1effe507ea85 |
children | ddce9ecc6f6a |
comparison
equal
deleted
inserted
replaced
17414:f967f12c8ec8 | 17415:30a567b89fb6 |
---|---|
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.71 | 7 ;; Version: 1.84 |
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." |
200 "Customization of the Customization support." | 204 "Customization of the Customization support." |
201 :link '(custom-manual "(custom)Top") | 205 :link '(custom-manual "(custom)Top") |
202 :link '(url-link :tag "Development Page" | 206 :link '(url-link :tag "Development Page" |
203 "http://www.dina.kvl.dk/~abraham/custom/") | 207 "http://www.dina.kvl.dk/~abraham/custom/") |
204 :prefix "custom-" | 208 :prefix "custom-" |
205 :group 'help | 209 :group 'help) |
210 | |
211 (defgroup custom-faces nil | |
212 "Faces used by customize." | |
213 :group 'customize | |
206 :group 'faces) | 214 :group 'faces) |
215 | |
216 (defgroup abbrev-mode nil | |
217 "Word abbreviations mode." | |
218 :group 'abbrev) | |
219 | |
220 (defgroup alloc nil | |
221 "Storage allocation and gc for GNU Emacs Lisp interpreter." | |
222 :tag "Storage Allocation" | |
223 :group 'internal) | |
224 | |
225 (defgroup undo nil | |
226 "Undoing changes in buffers." | |
227 :group 'editing) | |
228 | |
229 (defgroup modeline nil | |
230 "Content of the modeline." | |
231 :group 'environment) | |
232 | |
233 (defgroup fill nil | |
234 "Indenting and filling text." | |
235 :group 'editing) | |
236 | |
237 (defgroup editing-basics nil | |
238 "Most basic editing facilities." | |
239 :group 'editing) | |
240 | |
241 (defgroup display nil | |
242 "How characters are displayed in buffers." | |
243 :group 'environment) | |
244 | |
245 (defgroup execute nil | |
246 "Executing external commands." | |
247 :group 'processes) | |
248 | |
249 (defgroup installation nil | |
250 "The Emacs installation." | |
251 :group 'environment) | |
252 | |
253 (defgroup dired nil | |
254 "Directory editing." | |
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 minibuffer nil | |
266 "Controling the behaviour of the minibuffer." | |
267 :group 'environment) | |
268 | |
269 (defgroup keyboard nil | |
270 "Input from the keyboard." | |
271 :group 'environment) | |
272 | |
273 (defgroup mouse nil | |
274 "Input from the mouse." | |
275 :group 'environment) | |
276 | |
277 (defgroup menu nil | |
278 "Input from the menus." | |
279 :group 'environment) | |
280 | |
281 (defgroup auto-save nil | |
282 "Preventing accidential loss of data." | |
283 :group 'data) | |
284 | |
285 (defgroup processes-basics nil | |
286 "Basic stuff dealing with processes." | |
287 :group 'processes) | |
288 | |
289 (defgroup windows nil | |
290 "Windows within a frame." | |
291 :group 'processes) | |
207 | 292 |
208 ;;; Utilities. | 293 ;;; Utilities. |
209 | 294 |
210 (defun custom-quote (sexp) | 295 (defun custom-quote (sexp) |
211 "Quote SEXP iff it is not self quoting." | 296 "Quote SEXP iff it is not self quoting." |
233 (while (string-match "\\\\|" regexp start) | 318 (while (string-match "\\\\|" regexp start) |
234 (setq all (cons (substring regexp start (match-beginning 0)) all) | 319 (setq all (cons (substring regexp start (match-beginning 0)) all) |
235 start (match-end 0))) | 320 start (match-end 0))) |
236 (nreverse (cons (substring regexp start) all))) | 321 (nreverse (cons (substring regexp start) all))) |
237 regexp)) | 322 regexp)) |
323 | |
324 (defun custom-variable-prompt () | |
325 ;; Code stolen from `help.el'. | |
326 "Prompt for a variable, defaulting to the variable at point. | |
327 Return a list suitable for use in `interactive'." | |
328 (let ((v (variable-at-point)) | |
329 (enable-recursive-minibuffers t) | |
330 val) | |
331 (setq val (completing-read | |
332 (if v | |
333 (format "Customize variable (default %s): " v) | |
334 "Customize variable: ") | |
335 obarray 'boundp t)) | |
336 (list (if (equal val "") | |
337 v (intern val))))) | |
338 | |
339 ;;; Unlispify. | |
238 | 340 |
239 (defvar custom-prefix-list nil | 341 (defvar custom-prefix-list nil |
240 "List of prefixes that should be ignored by `custom-unlispify'") | 342 "List of prefixes that should be ignored by `custom-unlispify'") |
241 | 343 |
242 (defcustom custom-unlispify-menu-entries t | 344 (defcustom custom-unlispify-menu-entries t |
256 (save-excursion | 358 (save-excursion |
257 (set-buffer (get-buffer-create " *Custom-Work*")) | 359 (set-buffer (get-buffer-create " *Custom-Work*")) |
258 (erase-buffer) | 360 (erase-buffer) |
259 (princ symbol (current-buffer)) | 361 (princ symbol (current-buffer)) |
260 (goto-char (point-min)) | 362 (goto-char (point-min)) |
363 (when (and (eq (get symbol 'custom-type) 'boolean) | |
364 (re-search-forward "-p\\'" nil t)) | |
365 (replace-match "" t t) | |
366 (goto-char (point-min))) | |
261 (let ((prefixes custom-prefix-list) | 367 (let ((prefixes custom-prefix-list) |
262 prefix) | 368 prefix) |
263 (while prefixes | 369 (while prefixes |
264 (setq prefix (car prefixes)) | 370 (setq prefix (car prefixes)) |
265 (if (search-forward prefix (+ (point) (length prefix)) t) | 371 (if (search-forward prefix (+ (point) (length prefix)) t) |
288 ;; Addd SYMBOL to list of ignored PREFIXES. | 394 ;; Addd SYMBOL to list of ignored PREFIXES. |
289 (cons (or (get symbol 'custom-prefix) | 395 (cons (or (get symbol 'custom-prefix) |
290 (concat (symbol-name symbol) "-")) | 396 (concat (symbol-name symbol) "-")) |
291 prefixes)) | 397 prefixes)) |
292 | 398 |
293 ;;; The Custom Mode. | 399 ;;; Guess. |
400 | |
401 (defcustom custom-guess-name-alist | |
402 '(("-p\\'" boolean) | |
403 ("-hook\\'" hook) | |
404 ("-face\\'" face) | |
405 ("-file\\'" file) | |
406 ("-function\\'" function) | |
407 ("-functions\\'" (repeat function)) | |
408 ("-list\\'" (repeat sexp)) | |
409 ("-alist\\'" (repeat (cons sexp sexp)))) | |
410 "Alist of (MATCH TYPE). | |
411 | |
412 MATCH should be a regexp matching the name of a symbol, and TYPE should | |
413 be a widget suitable for editing the value of that symbol. The TYPE | |
414 of the first entry where MATCH matches the name of the symbol will be | |
415 used. | |
416 | |
417 This is used for guessing the type of variables not declared with | |
418 customize." | |
419 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type"))) | |
420 :group 'customize) | |
421 | |
422 (defcustom custom-guess-doc-alist | |
423 '(("\\`\\*?Non-nil " boolean)) | |
424 "Alist of (MATCH TYPE). | |
425 | |
426 MATCH should be a regexp matching a documentation string, and TYPE | |
427 should be a widget suitable for editing the value of a variable with | |
428 that documentation string. The TYPE of the first entry where MATCH | |
429 matches the name of the symbol will be used. | |
430 | |
431 This is used for guessing the type of variables not declared with | |
432 customize." | |
433 :type '(repeat (group (regexp :tag "Match") (sexp :tag "Type"))) | |
434 :group 'customize) | |
435 | |
436 (defun custom-guess-type (symbol) | |
437 "Guess a widget suitable for editing the value of SYMBOL. | |
438 This is done by matching SYMBOL with `custom-guess-name-alist' and | |
439 if that fails, the doc string with `custom-guess-doc-alist'." | |
440 (let ((name (symbol-name symbol)) | |
441 (names custom-guess-name-alist) | |
442 current found) | |
443 (while names | |
444 (setq current (car names) | |
445 names (cdr names)) | |
446 (when (string-match (nth 0 current) name) | |
447 (setq found (nth 1 current) | |
448 names nil))) | |
449 (unless found | |
450 (let ((doc (documentation-property symbol 'variable-documentation)) | |
451 (docs custom-guess-doc-alist)) | |
452 (when doc | |
453 (while docs | |
454 (setq current (car docs) | |
455 docs (cdr docs)) | |
456 (when (string-match (nth 0 current) doc) | |
457 (setq found (nth 1 current) | |
458 docs nil)))))) | |
459 found)) | |
460 | |
461 ;;; Custom Mode Commands. | |
294 | 462 |
295 (defvar custom-options nil | 463 (defvar custom-options nil |
296 "Customization widgets in the current buffer.") | 464 "Customization widgets in the current buffer.") |
297 | |
298 (defvar custom-mode-map nil | |
299 "Keymap for `custom-mode'.") | |
300 | |
301 (unless custom-mode-map | |
302 (setq custom-mode-map (make-sparse-keymap)) | |
303 (set-keymap-parent custom-mode-map widget-keymap) | |
304 (define-key custom-mode-map "q" 'bury-buffer)) | |
305 | |
306 (easy-menu-define custom-mode-menu | |
307 custom-mode-map | |
308 "Menu used in customization buffers." | |
309 '("Custom" | |
310 ["Set" custom-set t] | |
311 ["Save" custom-save t] | |
312 ["Reset to Current" custom-reset-current t] | |
313 ["Reset to Saved" custom-reset-saved t] | |
314 ["Reset to Factory Settings" custom-reset-factory t] | |
315 ["Info" (Info-goto-node "(custom)The Customization Buffer") t])) | |
316 | |
317 (defcustom custom-mode-hook nil | |
318 "Hook called when entering custom-mode." | |
319 :type 'hook | |
320 :group 'customize) | |
321 | |
322 (defun custom-mode () | |
323 "Major mode for editing customization buffers. | |
324 | |
325 The following commands are available: | |
326 | |
327 \\[widget-forward] Move to next button or editable field. | |
328 \\[widget-backward] Move to previous button or editable field. | |
329 \\[widget-button-click] Activate button under the mouse pointer. | |
330 \\[widget-button-press] Activate button under point. | |
331 \\[custom-set] Set all modifications. | |
332 \\[custom-save] Make all modifications default. | |
333 \\[custom-reset-current] Reset all modified options. | |
334 \\[custom-reset-saved] Reset all modified or set options. | |
335 \\[custom-reset-factory] Reset all options. | |
336 | |
337 Entry to this mode calls the value of `custom-mode-hook' | |
338 if that value is non-nil." | |
339 (kill-all-local-variables) | |
340 (setq major-mode 'custom-mode | |
341 mode-name "Custom") | |
342 (use-local-map custom-mode-map) | |
343 (easy-menu-add custom-mode-menu) | |
344 (make-local-variable 'custom-options) | |
345 (run-hooks 'custom-mode-hook)) | |
346 | |
347 ;;; Custom Mode Commands. | |
348 | 465 |
349 (defun custom-set () | 466 (defun custom-set () |
350 "Set changes in all modified options." | 467 "Set changes in all modified options." |
351 (interactive) | 468 (interactive) |
352 (let ((children custom-options)) | 469 (let ((children custom-options)) |
428 (custom-buffer-create (list (list symbol 'custom-group)))) | 545 (custom-buffer-create (list (list symbol 'custom-group)))) |
429 | 546 |
430 ;;;###autoload | 547 ;;;###autoload |
431 (defun customize-variable (symbol) | 548 (defun customize-variable (symbol) |
432 "Customize SYMBOL, which must be a variable." | 549 "Customize SYMBOL, which must be a variable." |
433 (interactive | 550 (interactive (custom-variable-prompt)) |
434 ;; Code stolen from `help.el'. | |
435 (let ((v (variable-at-point)) | |
436 (enable-recursive-minibuffers t) | |
437 val) | |
438 (setq val (completing-read | |
439 (if v | |
440 (format "Customize variable (default %s): " v) | |
441 "Customize variable: ") | |
442 obarray 'boundp t)) | |
443 (list (if (equal val "") | |
444 v (intern val))))) | |
445 (custom-buffer-create (list (list symbol 'custom-variable)))) | 551 (custom-buffer-create (list (list symbol 'custom-variable)))) |
552 | |
553 ;;;###autoload | |
554 (defun customize-variable-other-window (symbol) | |
555 "Customize SYMBOL, which must be a variable. | |
556 Show the buffer in another window, but don't select it." | |
557 (interactive (custom-variable-prompt)) | |
558 (custom-buffer-create-other-window (list (list symbol 'custom-variable)))) | |
446 | 559 |
447 ;;;###autoload | 560 ;;;###autoload |
448 (defun customize-face (&optional symbol) | 561 (defun customize-face (&optional symbol) |
449 "Customize SYMBOL, which should be a face name or nil. | 562 "Customize SYMBOL, which should be a face name or nil. |
450 If SYMBOL is nil, customize all faces." | 563 If SYMBOL is nil, customize all faces." |
453 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol)))) | 566 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol)))) |
454 (let ((found nil)) | 567 (let ((found nil)) |
455 (message "Looking for faces...") | 568 (message "Looking for faces...") |
456 (mapcar (lambda (symbol) | 569 (mapcar (lambda (symbol) |
457 (setq found (cons (list symbol 'custom-face) found))) | 570 (setq found (cons (list symbol 'custom-face) found))) |
458 (face-list)) | 571 (nreverse (mapcar 'intern |
572 (sort (mapcar 'symbol-name (face-list)) | |
573 'string<)))) | |
574 | |
459 (custom-buffer-create found)) | 575 (custom-buffer-create found)) |
460 (if (stringp symbol) | 576 (if (stringp symbol) |
461 (setq symbol (intern symbol))) | 577 (setq symbol (intern symbol))) |
462 (unless (symbolp symbol) | 578 (unless (symbolp symbol) |
463 (error "Should be a symbol %S" symbol)) | 579 (error "Should be a symbol %S" symbol)) |
464 (custom-buffer-create (list (list symbol 'custom-face))))) | 580 (custom-buffer-create (list (list symbol 'custom-face))))) |
581 | |
582 ;;;###autoload | |
583 (defun customize-face-other-window (&optional symbol) | |
584 "Show customization buffer for FACE in other window." | |
585 (interactive (list (completing-read "Customize face: " | |
586 obarray 'custom-facep))) | |
587 (if (or (null symbol) (and (stringp symbol) (zerop (length symbol)))) | |
588 () | |
589 (if (stringp symbol) | |
590 (setq symbol (intern symbol))) | |
591 (unless (symbolp symbol) | |
592 (error "Should be a symbol %S" symbol)) | |
593 (custom-buffer-create-other-window (list (list symbol 'custom-face))))) | |
465 | 594 |
466 ;;;###autoload | 595 ;;;###autoload |
467 (defun customize-customized () | 596 (defun customize-customized () |
468 "Customize all already customized user options." | 597 "Customize all already customized user options." |
469 (interactive) | 598 (interactive) |
509 (defun custom-buffer-create (options) | 638 (defun custom-buffer-create (options) |
510 "Create a buffer containing OPTIONS. | 639 "Create a buffer containing OPTIONS. |
511 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where | 640 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where |
512 SYMBOL is a customization option, and WIDGET is a widget for editing | 641 SYMBOL is a customization option, and WIDGET is a widget for editing |
513 that option." | 642 that option." |
514 (message "Creating customization buffer...") | |
515 (kill-buffer (get-buffer-create "*Customization*")) | 643 (kill-buffer (get-buffer-create "*Customization*")) |
516 (switch-to-buffer (get-buffer-create "*Customization*")) | 644 (switch-to-buffer (get-buffer-create "*Customization*")) |
645 (custom-buffer-create-internal options)) | |
646 | |
647 (defun custom-buffer-create-other-window (options) | |
648 "Create a buffer containing OPTIONS. | |
649 OPTIONS should be an alist of the form ((SYMBOL WIDGET)...), where | |
650 SYMBOL is a customization option, and WIDGET is a widget for editing | |
651 that option." | |
652 (kill-buffer (get-buffer-create "*Customization*")) | |
653 (let ((window (selected-window))) | |
654 (switch-to-buffer-other-window (get-buffer-create "*Customization*")) | |
655 (custom-buffer-create-internal options) | |
656 (select-window window))) | |
657 | |
658 | |
659 (defun custom-buffer-create-internal (options) | |
660 (message "Creating customization buffer...") | |
517 (custom-mode) | 661 (custom-mode) |
518 (widget-insert "This is a customization buffer. | 662 (widget-insert "This is a customization buffer. |
519 Push RET or click mouse-2 on the word ") | 663 Push RET or click mouse-2 on the word ") |
520 ;; (put-text-property 1 2 'start-open nil) | 664 ;; (put-text-property 1 2 'start-open nil) |
521 (widget-create 'info-link | 665 (widget-create 'info-link |
751 (editable-list :inline t | 895 (editable-list :inline t |
752 (group symbol | 896 (group symbol |
753 (string :tag "Magic") | 897 (string :tag "Magic") |
754 face | 898 face |
755 (string :tag "Description")))) | 899 (string :tag "Description")))) |
756 :group 'customize) | 900 :group 'customize |
901 :group 'custom-faces) | |
757 | 902 |
758 (defcustom custom-magic-show 'long | 903 (defcustom custom-magic-show 'long |
759 "Show long description of the state of each customization option." | 904 "Show long description of the state of each customization option." |
760 :type '(choice (const :tag "no" nil) | 905 :type '(choice (const :tag "no" nil) |
761 (const short) | 906 (const short) |
954 ((eq t show) | 1099 ((eq t show) |
955 t) | 1100 t) |
956 (t | 1101 (t |
957 (funcall show widget value))))) | 1102 (funcall show widget value))))) |
958 | 1103 |
1104 (defvar custom-load-recursion nil | |
1105 "Hack to avoid recursive dependencies.") | |
1106 | |
959 (defun custom-load-symbol (symbol) | 1107 (defun custom-load-symbol (symbol) |
960 "Load all dependencies for SYMBOL." | 1108 "Load all dependencies for SYMBOL." |
961 (let ((loads (get symbol 'custom-loads)) | 1109 (unless custom-load-recursion |
962 load) | 1110 (let ((custom-load-recursion t) |
963 (while loads | 1111 (loads (get symbol 'custom-loads)) |
964 (setq load (car loads) | 1112 load) |
965 loads (cdr loads)) | 1113 (while loads |
966 (cond ((symbolp load) | 1114 (setq load (car loads) |
967 (condition-case nil | 1115 loads (cdr loads)) |
968 (require load) | 1116 (cond ((symbolp load) |
969 (error nil))) | 1117 (condition-case nil |
970 ((assoc load load-history)) | 1118 (require load) |
971 (t | 1119 (error nil))) |
972 (condition-case nil | 1120 ((assoc load load-history)) |
973 (load-library load) | 1121 (t |
974 (error nil))))))) | 1122 (condition-case nil |
1123 (load-library load) | |
1124 (error nil)))))))) | |
975 | 1125 |
976 (defun custom-load-widget (widget) | 1126 (defun custom-load-widget (widget) |
977 "Load all dependencies for WIDGET." | 1127 "Load all dependencies for WIDGET." |
978 (custom-load-symbol (widget-value widget))) | 1128 (custom-load-symbol (widget-value widget))) |
979 | 1129 |
980 ;;; The `custom-variable' Widget. | 1130 ;;; The `custom-variable' Widget. |
981 | 1131 |
982 (defface custom-variable-sample-face '((t (:underline t))) | 1132 (defface custom-variable-sample-face '((t (:underline t))) |
983 "Face used for unpushable variable tags." | 1133 "Face used for unpushable variable tags." |
984 :group 'customize) | 1134 :group 'custom-faces) |
985 | 1135 |
986 (defface custom-variable-button-face '((t (:underline t :bold t))) | 1136 (defface custom-variable-button-face '((t (:underline t :bold t))) |
987 "Face used for pushable variable tags." | 1137 "Face used for pushable variable tags." |
988 :group 'customize) | 1138 :group 'custom-faces) |
989 | 1139 |
990 (define-widget 'custom-variable 'custom | 1140 (define-widget 'custom-variable 'custom |
991 "Customize variable." | 1141 "Customize variable." |
992 :format "%l%v%m%h%a" | 1142 :format "%l%v%m%h%a" |
993 :help-echo "Set or reset this variable." | 1143 :help-echo "Set or reset this variable." |
1001 :custom-save 'custom-variable-save | 1151 :custom-save 'custom-variable-save |
1002 :custom-reset-current 'custom-redraw | 1152 :custom-reset-current 'custom-redraw |
1003 :custom-reset-saved 'custom-variable-reset-saved | 1153 :custom-reset-saved 'custom-variable-reset-saved |
1004 :custom-reset-factory 'custom-variable-reset-factory) | 1154 :custom-reset-factory 'custom-variable-reset-factory) |
1005 | 1155 |
1156 (defun custom-variable-type (symbol) | |
1157 "Return a widget suitable for editing the value of SYMBOL. | |
1158 If SYMBOL has a `custom-type' property, use that. | |
1159 Otherwise, look up symbol in `custom-guess-type-alist'." | |
1160 (let* ((type (or (get symbol 'custom-type) | |
1161 (and (not (get symbol 'factory-value)) | |
1162 (custom-guess-type symbol)) | |
1163 'sexp)) | |
1164 (options (get symbol 'custom-options)) | |
1165 (tmp (if (listp type) | |
1166 (copy-list type) | |
1167 (list type)))) | |
1168 (when options | |
1169 (widget-put tmp :options options)) | |
1170 tmp)) | |
1171 | |
1006 (defun custom-variable-value-create (widget) | 1172 (defun custom-variable-value-create (widget) |
1007 "Here is where you edit the variables value." | 1173 "Here is where you edit the variables value." |
1008 (custom-load-widget widget) | 1174 (custom-load-widget widget) |
1009 (let* ((buttons (widget-get widget :buttons)) | 1175 (let* ((buttons (widget-get widget :buttons)) |
1010 (children (widget-get widget :children)) | 1176 (children (widget-get widget :children)) |
1011 (form (widget-get widget :custom-form)) | 1177 (form (widget-get widget :custom-form)) |
1012 (state (widget-get widget :custom-state)) | 1178 (state (widget-get widget :custom-state)) |
1013 (symbol (widget-get widget :value)) | 1179 (symbol (widget-get widget :value)) |
1014 (options (get symbol 'custom-options)) | |
1015 (child-type (or (get symbol 'custom-type) 'sexp)) | |
1016 (tag (widget-get widget :tag)) | 1180 (tag (widget-get widget :tag)) |
1017 (type (let ((tmp (if (listp child-type) | 1181 (type (custom-variable-type symbol)) |
1018 (copy-list child-type) | |
1019 (list child-type)))) | |
1020 (when options | |
1021 (widget-put tmp :options options)) | |
1022 tmp)) | |
1023 (conv (widget-convert type)) | 1182 (conv (widget-convert type)) |
1024 (value (if (default-boundp symbol) | 1183 (value (if (default-boundp symbol) |
1025 (default-value symbol) | 1184 (default-value symbol) |
1026 (widget-get conv :value)))) | 1185 (widget-get conv :value)))) |
1027 ;; If the widget is new, the child determine whether it is hidden. | 1186 ;; If the widget is new, the child determine whether it is hidden. |
1160 (error "Cannot set hidden variable.")) | 1319 (error "Cannot set hidden variable.")) |
1161 ((setq val (widget-apply child :validate)) | 1320 ((setq val (widget-apply child :validate)) |
1162 (goto-char (widget-get val :from)) | 1321 (goto-char (widget-get val :from)) |
1163 (error "%s" (widget-get val :error))) | 1322 (error "%s" (widget-get val :error))) |
1164 ((eq form 'lisp) | 1323 ((eq form 'lisp) |
1165 (set symbol (eval (setq val (widget-value child)))) | 1324 (set-default symbol (eval (setq val (widget-value child)))) |
1166 (put symbol 'customized-value (list val))) | 1325 (put symbol 'customized-value (list val))) |
1167 (t | 1326 (t |
1168 (set symbol (setq val (widget-value child))) | 1327 (set-default symbol (setq val (widget-value child))) |
1169 (put symbol 'customized-value (list (custom-quote val))))) | 1328 (put symbol 'customized-value (list (custom-quote val))))) |
1170 (custom-variable-state-set widget) | 1329 (custom-variable-state-set widget) |
1171 (custom-redraw-magic widget))) | 1330 (custom-redraw-magic widget))) |
1172 | 1331 |
1173 (defun custom-variable-save (widget) | 1332 (defun custom-variable-save (widget) |
1182 ((setq val (widget-apply child :validate)) | 1341 ((setq val (widget-apply child :validate)) |
1183 (goto-char (widget-get val :from)) | 1342 (goto-char (widget-get val :from)) |
1184 (error "%s" (widget-get val :error))) | 1343 (error "%s" (widget-get val :error))) |
1185 ((eq form 'lisp) | 1344 ((eq form 'lisp) |
1186 (put symbol 'saved-value (list (widget-value child))) | 1345 (put symbol 'saved-value (list (widget-value child))) |
1187 (set symbol (eval (widget-value child)))) | 1346 (set-default symbol (eval (widget-value child)))) |
1188 (t | 1347 (t |
1189 (put symbol | 1348 (put symbol |
1190 'saved-value (list (custom-quote (widget-value | 1349 'saved-value (list (custom-quote (widget-value |
1191 child)))) | 1350 child)))) |
1192 (set symbol (widget-value child)))) | 1351 (set-default symbol (widget-value child)))) |
1193 (put symbol 'customized-value nil) | 1352 (put symbol 'customized-value nil) |
1194 (custom-save-all) | 1353 (custom-save-all) |
1195 (custom-variable-state-set widget) | 1354 (custom-variable-state-set widget) |
1196 (custom-redraw-magic widget))) | 1355 (custom-redraw-magic widget))) |
1197 | 1356 |
1198 (defun custom-variable-reset-saved (widget) | 1357 (defun custom-variable-reset-saved (widget) |
1199 "Restore the saved value for the variable being edited by WIDGET." | 1358 "Restore the saved value for the variable being edited by WIDGET." |
1200 (let ((symbol (widget-value widget))) | 1359 (let ((symbol (widget-value widget))) |
1201 (if (get symbol 'saved-value) | 1360 (if (get symbol 'saved-value) |
1202 (condition-case nil | 1361 (condition-case nil |
1203 (set symbol (eval (car (get symbol 'saved-value)))) | 1362 (set-default symbol (eval (car (get symbol 'saved-value)))) |
1204 (error nil)) | 1363 (error nil)) |
1205 (error "No saved value for %s" symbol)) | 1364 (error "No saved value for %s" symbol)) |
1206 (put symbol 'customized-value nil) | 1365 (put symbol 'customized-value nil) |
1207 (widget-put widget :custom-state 'unknown) | 1366 (widget-put widget :custom-state 'unknown) |
1208 (custom-redraw widget))) | 1367 (custom-redraw widget))) |
1209 | 1368 |
1210 (defun custom-variable-reset-factory (widget) | 1369 (defun custom-variable-reset-factory (widget) |
1211 "Restore the factory setting for the variable being edited by WIDGET." | 1370 "Restore the factory setting for the variable being edited by WIDGET." |
1212 (let ((symbol (widget-value widget))) | 1371 (let ((symbol (widget-value widget))) |
1213 (if (get symbol 'factory-value) | 1372 (if (get symbol 'factory-value) |
1214 (set symbol (eval (car (get symbol 'factory-value)))) | 1373 (set-default symbol (eval (car (get symbol 'factory-value)))) |
1215 (error "No factory default for %S" symbol)) | 1374 (error "No factory default for %S" symbol)) |
1216 (put symbol 'customized-value nil) | 1375 (put symbol 'customized-value nil) |
1217 (when (get symbol 'saved-value) | 1376 (when (get symbol 'saved-value) |
1218 (put symbol 'saved-value nil) | 1377 (put symbol 'saved-value nil) |
1219 (custom-save-all)) | 1378 (custom-save-all)) |
1309 | 1468 |
1310 ;;; The `custom-face' Widget. | 1469 ;;; The `custom-face' Widget. |
1311 | 1470 |
1312 (defface custom-face-tag-face '((t (:underline t))) | 1471 (defface custom-face-tag-face '((t (:underline t))) |
1313 "Face used for face tags." | 1472 "Face used for face tags." |
1314 :group 'customize) | 1473 :group 'custom-faces) |
1315 | 1474 |
1316 (define-widget 'custom-face 'custom | 1475 (define-widget 'custom-face 'custom |
1317 "Customize face." | 1476 "Customize face." |
1318 :format "%l%{%t%}: %s%m%h%a%v" | 1477 :format "%l%{%t%}: %s%m%h%a%v" |
1319 :format-handler 'custom-face-format-handler | 1478 :format-handler 'custom-face-format-handler |
1611 "Face used for group tags. | 1770 "Face used for group tags. |
1612 The first member is used for level 1 groups, the second for level 2, | 1771 The first member is used for level 1 groups, the second for level 2, |
1613 and so forth. The remaining group tags are shown with | 1772 and so forth. The remaining group tags are shown with |
1614 `custom-group-tag-face'." | 1773 `custom-group-tag-face'." |
1615 :type '(repeat face) | 1774 :type '(repeat face) |
1616 :group 'customize) | 1775 :group 'custom-faces) |
1617 | 1776 |
1618 (defface custom-group-tag-face-1 '((((class color) | 1777 (defface custom-group-tag-face-1 '((((class color) |
1619 (background dark)) | 1778 (background dark)) |
1620 (:foreground "pink" :underline t)) | 1779 (:foreground "pink" :underline t)) |
1621 (((class color) | 1780 (((class color) |
1630 (((class color) | 1789 (((class color) |
1631 (background light)) | 1790 (background light)) |
1632 (:foreground "blue" :underline t)) | 1791 (:foreground "blue" :underline t)) |
1633 (t (:underline t))) | 1792 (t (:underline t))) |
1634 "Face used for low level group tags." | 1793 "Face used for low level group tags." |
1635 :group 'customize) | 1794 :group 'custom-faces) |
1636 | 1795 |
1637 (define-widget 'custom-group 'custom | 1796 (define-widget 'custom-group 'custom |
1638 "Customize group." | 1797 "Customize group." |
1639 :format "%l%{%t%}:%L\n%m%h%a%v" | 1798 :format "%l%{%t%}:%L\n%m%h%a%v" |
1640 :sample-face-get 'custom-group-sample-face-get | 1799 :sample-face-get 'custom-group-sample-face-get |
1833 (custom-save-delete 'custom-set-faces) | 1992 (custom-save-delete 'custom-set-faces) |
1834 (let ((standard-output (current-buffer))) | 1993 (let ((standard-output (current-buffer))) |
1835 (unless (bolp) | 1994 (unless (bolp) |
1836 (princ "\n")) | 1995 (princ "\n")) |
1837 (princ "(custom-set-faces") | 1996 (princ "(custom-set-faces") |
1997 (let ((value (get 'default 'saved-face))) | |
1998 ;; The default face must be first, since it affects the others. | |
1999 (when value | |
2000 (princ "\n '(default ") | |
2001 (prin1 value) | |
2002 (if (or (get 'default 'factory-face) | |
2003 (and (not (custom-facep 'default)) | |
2004 (not (get 'default 'force-face)))) | |
2005 (princ ")") | |
2006 (princ " t)")))) | |
1838 (mapatoms (lambda (symbol) | 2007 (mapatoms (lambda (symbol) |
1839 (let ((value (get symbol 'saved-face))) | 2008 (let ((value (get symbol 'saved-face))) |
1840 (when value | 2009 (when (and (not (eq symbol 'default)) |
2010 ;; Don't print default face here. | |
2011 value) | |
1841 (princ "\n '(") | 2012 (princ "\n '(") |
1842 (princ symbol) | 2013 (princ symbol) |
1843 (princ " ") | 2014 (princ " ") |
1844 (prin1 value) | 2015 (prin1 value) |
1845 (if (or (get symbol 'factory-face) | 2016 (if (or (get symbol 'factory-face) |
1860 (set-buffer (find-file-noselect custom-file)) | 2031 (set-buffer (find-file-noselect custom-file)) |
1861 (save-buffer))) | 2032 (save-buffer))) |
1862 | 2033 |
1863 ;;; The Customize Menu. | 2034 ;;; The Customize Menu. |
1864 | 2035 |
1865 (defcustom custom-menu-nesting 2 | 2036 ;;; Menu support |
1866 "Maximum nesting in custom menus." | 2037 |
1867 :type 'integer | 2038 (unless (string-match "XEmacs" emacs-version) |
1868 :group 'customize) | 2039 (defconst custom-help-menu '("Customize" |
2040 ["Update menu..." custom-menu-update t] | |
2041 ["Group..." customize t] | |
2042 ["Variable..." customize-variable t] | |
2043 ["Face..." customize-face t] | |
2044 ["Saved..." customize-customized t] | |
2045 ["Apropos..." customize-apropos t]) | |
2046 ;; This menu should be identical to the one defined in `menu-bar.el'. | |
2047 "Customize menu") | |
2048 | |
2049 (defun custom-menu-reset () | |
2050 "Reset customize menu." | |
2051 (remove-hook 'custom-define-hook 'custom-menu-reset) | |
2052 (define-key global-map [menu-bar help-menu customize-menu] | |
2053 (cons (car custom-help-menu) | |
2054 (easy-menu-create-keymaps (car custom-help-menu) | |
2055 (cdr custom-help-menu))))) | |
2056 | |
2057 (defun custom-menu-update (event) | |
2058 "Update customize menu." | |
2059 (interactive "e") | |
2060 (add-hook 'custom-define-hook 'custom-menu-reset) | |
2061 (let* ((emacs (widget-apply '(custom-group) :custom-menu 'emacs)) | |
2062 (menu `(,(car custom-help-menu) | |
2063 ,emacs | |
2064 ,@(cdr (cdr custom-help-menu))))) | |
2065 (let ((map (easy-menu-create-keymaps (car menu) (cdr menu)))) | |
2066 (define-key global-map [menu-bar help-menu customize-menu] | |
2067 (cons (car menu) map))))) | |
2068 | |
2069 (defcustom custom-menu-nesting 2 | |
2070 "Maximum nesting in custom menus." | |
2071 :type 'integer | |
2072 :group 'customize)) | |
1869 | 2073 |
1870 (defun custom-face-menu-create (widget symbol) | 2074 (defun custom-face-menu-create (widget symbol) |
1871 "Ignoring WIDGET, create a menu entry for customization face SYMBOL." | 2075 "Ignoring WIDGET, create a menu entry for customization face SYMBOL." |
1872 (vector (custom-unlispify-menu-entry symbol) | 2076 (vector (custom-unlispify-menu-entry symbol) |
1873 `(custom-buffer-create '((,symbol custom-face))) | 2077 `(custom-buffer-create '((,symbol custom-face))) |
1882 (widget-apply type :custom-menu symbol) | 2086 (widget-apply type :custom-menu symbol) |
1883 (vector (custom-unlispify-menu-entry symbol) | 2087 (vector (custom-unlispify-menu-entry symbol) |
1884 `(custom-buffer-create '((,symbol custom-variable))) | 2088 `(custom-buffer-create '((,symbol custom-variable))) |
1885 t)))) | 2089 t)))) |
1886 | 2090 |
2091 ;; Add checkboxes to boolean variable entries. | |
1887 (widget-put (get 'boolean 'widget-type) | 2092 (widget-put (get 'boolean 'widget-type) |
1888 :custom-menu (lambda (widget symbol) | 2093 :custom-menu (lambda (widget symbol) |
1889 (vector (custom-unlispify-menu-entry symbol) | 2094 (vector (custom-unlispify-menu-entry symbol) |
1890 `(custom-buffer-create | 2095 `(custom-buffer-create |
1891 '((,symbol custom-variable))) | 2096 '((,symbol custom-variable))) |
1904 "Ignoring WIDGET, create a menu entry for customization group SYMBOL." | 2109 "Ignoring WIDGET, create a menu entry for customization group SYMBOL." |
1905 ;; Limit the nesting. | 2110 ;; Limit the nesting. |
1906 (let ((custom-menu-nesting (1- custom-menu-nesting))) | 2111 (let ((custom-menu-nesting (1- custom-menu-nesting))) |
1907 (custom-menu-create symbol)))) | 2112 (custom-menu-create symbol)))) |
1908 | 2113 |
1909 (defun custom-menu-create (symbol &optional name) | 2114 ;;;###autoload |
2115 (defun custom-menu-create (symbol) | |
1910 "Create menu for customization group SYMBOL. | 2116 "Create menu for customization group SYMBOL. |
1911 If optional NAME is given, use that as the name of the menu. | |
1912 Otherwise make up a name from SYMBOL. | |
1913 The menu is in a format applicable to `easy-menu-define'." | 2117 The menu is in a format applicable to `easy-menu-define'." |
1914 (unless name | 2118 (let* ((item (vector (custom-unlispify-menu-entry symbol) |
1915 (setq name (custom-unlispify-menu-entry symbol))) | 2119 `(custom-buffer-create '((,symbol custom-group))) |
1916 (let ((item (vector name | 2120 t))) |
1917 `(custom-buffer-create '((,symbol custom-group))) | 2121 (if (and (or (not (boundp 'custom-menu-nesting)) |
1918 t))) | 2122 (>= custom-menu-nesting 0)) |
1919 (if (and (>= custom-menu-nesting 0) | |
1920 (< (length (get symbol 'custom-group)) widget-menu-max-size)) | 2123 (< (length (get symbol 'custom-group)) widget-menu-max-size)) |
1921 (let ((custom-prefix-list (custom-prefix-add symbol | 2124 (let ((custom-prefix-list (custom-prefix-add symbol |
1922 custom-prefix-list))) | 2125 custom-prefix-list))) |
1923 (custom-load-symbol symbol) | 2126 (custom-load-symbol symbol) |
1924 `(,(custom-unlispify-menu-entry symbol t) | 2127 `(,(custom-unlispify-menu-entry symbol t) |
1931 :custom-menu (nth 0 entry))) | 2134 :custom-menu (nth 0 entry))) |
1932 (get symbol 'custom-group)))) | 2135 (get symbol 'custom-group)))) |
1933 item))) | 2136 item))) |
1934 | 2137 |
1935 ;;;###autoload | 2138 ;;;###autoload |
1936 (defun custom-menu-update (event) | 2139 (defun customize-menu-create (symbol &optional name) |
1937 "Update customize menu." | 2140 "Return a customize menu for customization group SYMBOL. |
1938 (interactive "e") | 2141 If optional NAME is given, use that as the name of the menu. |
1939 (add-hook 'custom-define-hook 'custom-menu-reset) | 2142 Otherwise the menu will be named `Customize'. |
1940 (let* ((emacs (widget-apply '(custom-group) :custom-menu 'emacs)) | 2143 The format is suitable for use with `easy-menu-define'." |
1941 (menu `(,(car custom-help-menu) | 2144 (unless name |
1942 ,emacs | 2145 (setq name "Customize")) |
1943 ,@(cdr (cdr custom-help-menu))))) | 2146 (if (string-match "XEmacs" emacs-version) |
1944 (let ((map (easy-menu-create-keymaps (car menu) (cdr menu)))) | 2147 ;; We can delay it under XEmacs. |
1945 (define-key global-map [menu-bar help-menu customize-menu] | 2148 `(,name |
1946 (cons (car menu) map))))) | 2149 :filter (lambda (&rest junk) |
1947 | 2150 (cdr (custom-menu-create ',symbol)))) |
1948 ;;; Dependencies. | 2151 ;; But we must create it now under Emacs. |
1949 | 2152 (cons name (cdr (custom-menu-create symbol))))) |
1950 ;;;###autoload | 2153 |
1951 (defun custom-make-dependencies () | 2154 ;;; The Custom Mode. |
1952 "Batch function to extract custom dependencies from .el files. | 2155 |
1953 Usage: emacs -batch *.el -f custom-make-dependencies > deps.el" | 2156 (defvar custom-mode-map nil |
1954 (let ((buffers (buffer-list))) | 2157 "Keymap for `custom-mode'.") |
1955 (while buffers | 2158 |
1956 (set-buffer (car buffers)) | 2159 (unless custom-mode-map |
1957 (setq buffers (cdr buffers)) | 2160 (setq custom-mode-map (make-sparse-keymap)) |
1958 (let ((file (buffer-file-name))) | 2161 (set-keymap-parent custom-mode-map widget-keymap) |
1959 (when (and file (string-match "\\`\\(.*\\)\\.el\\'" file)) | 2162 (define-key custom-mode-map "q" 'bury-buffer)) |
1960 (goto-char (point-min)) | 2163 |
1961 (condition-case nil | 2164 (easy-menu-define custom-mode-customize-menu |
1962 (let ((name (file-name-nondirectory (match-string 1 file)))) | 2165 custom-mode-map |
1963 (while t | 2166 "Menu used in customization buffers." |
1964 (let ((expr (read (current-buffer)))) | 2167 (customize-menu-create 'customize)) |
1965 (when (and (listp expr) | 2168 |
1966 (memq (car expr) '(defcustom defface defgroup))) | 2169 (easy-menu-define custom-mode-menu |
1967 (eval expr) | 2170 custom-mode-map |
1968 (put (nth 1 expr) 'custom-where name))))) | 2171 "Menu used in customization buffers." |
1969 (error nil)))))) | 2172 `("Custom" |
1970 (mapatoms (lambda (symbol) | 2173 ["Set" custom-set t] |
1971 (let ((members (get symbol 'custom-group)) | 2174 ["Save" custom-save t] |
1972 item where found) | 2175 ["Reset to Current" custom-reset-current t] |
1973 (when members | 2176 ["Reset to Saved" custom-reset-saved t] |
1974 (princ "(put '") | 2177 ["Reset to Factory Settings" custom-reset-factory t] |
1975 (princ symbol) | 2178 ["Info" (Info-goto-node "(custom)The Customization Buffer") t])) |
1976 (princ " 'custom-loads '(") | 2179 |
1977 (while members | 2180 (defcustom custom-mode-hook nil |
1978 (setq item (car (car members)) | 2181 "Hook called when entering custom-mode." |
1979 members (cdr members) | 2182 :type 'hook |
1980 where (get item 'custom-where)) | 2183 :group 'customize) |
1981 (unless (or (null where) | 2184 |
1982 (member where found)) | 2185 (defun custom-mode () |
1983 (when found | 2186 "Major mode for editing customization buffers. |
1984 (princ " ")) | 2187 |
1985 (prin1 where) | 2188 The following commands are available: |
1986 (push where found))) | 2189 |
1987 (princ "))\n")))))) | 2190 Move to next button or editable field. \\[widget-forward] |
2191 Move to previous button or editable field. \\[widget-backward] | |
2192 Activate button under the mouse pointer. \\[widget-button-click] | |
2193 Activate button under point. \\[widget-button-press] | |
2194 Set all modifications. \\[custom-set] | |
2195 Make all modifications default. \\[custom-save] | |
2196 Reset all modified options. \\[custom-reset-current] | |
2197 Reset all modified or set options. \\[custom-reset-saved] | |
2198 Reset all options. \\[custom-reset-factory] | |
2199 | |
2200 Entry to this mode calls the value of `custom-mode-hook' | |
2201 if that value is non-nil." | |
2202 (kill-all-local-variables) | |
2203 (setq major-mode 'custom-mode | |
2204 mode-name "Custom") | |
2205 (use-local-map custom-mode-map) | |
2206 (easy-menu-add custom-mode-customize-menu) | |
2207 (easy-menu-add custom-mode-menu) | |
2208 (make-local-variable 'custom-options) | |
2209 (run-hooks 'custom-mode-hook)) | |
1988 | 2210 |
1989 ;;; The End. | 2211 ;;; The End. |
1990 | 2212 |
1991 (provide 'cus-edit) | 2213 (provide 'cus-edit) |
1992 | 2214 |