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