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