annotate lisp/custom.el @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children de805c49cfc1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; custom.el -- Tools for declaring and initializing options.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
6 ;; Maintainer: Hrvoje Niksic <hniksic@xemacs.org>
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: help, faces, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8 ;; Version: 1.9960-x
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; X-URL: http://www.dina.kvl.dk/~abraham/custom/
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; XEmacs is free software; you can redistribute it and/or modify
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; XEmacs is distributed in the hope that it will be useful,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; GNU General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; along with XEmacs; see the file COPYING. If not, write to the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; This file only contain the code needed to declare and initialize
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;; user options. The code to customize options is autoloaded from
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
34 ;; `cus-edit.el'.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;; The code implementing face declarations is in `cus-face.el'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
40 (eval-when-compile
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
41 (load "cl-macs"))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
42
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
43 (if (not (fboundp 'defun*))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
44 (autoload 'defun* "cl-macs"))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
45
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 (require 'widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 (defvar custom-define-hook nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 ;; Customize information for this option is in `cus-edit.el'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 "Hook called after defining each customize option.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 ;;; The `defcustom' Macro.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 (defun custom-initialize-default (symbol value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 "Initialize SYMBOL with VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 This will do nothing if symbol already has a default binding.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 Otherwise, if symbol has a `saved-value' property, it will evaluate
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 the car of that and used as the default binding for symbol.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 Otherwise, VALUE will be evaluated and used as the default binding for
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 symbol."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (unless (default-boundp symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 ;; Use the saved value if it exists, otherwise the standard setting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 (set-default symbol (if (get symbol 'saved-value)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
64 (eval (car (get symbol 'saved-value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
65 (eval value)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 (defun custom-initialize-set (symbol value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 "Initialize SYMBOL with VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 Like `custom-initialize-default', but use the function specified by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 `:set' to initialize SYMBOL."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (unless (default-boundp symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (funcall (or (get symbol 'custom-set) 'set-default)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
73 symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
74 (if (get symbol 'saved-value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
75 (eval (car (get symbol 'saved-value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
76 (eval value)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (defun custom-initialize-reset (symbol value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 "Initialize SYMBOL with VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 Like `custom-initialize-set', but use the function specified by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 `:get' to reinitialize SYMBOL if it is already bound."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (funcall (or (get symbol 'custom-set) 'set-default)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
83 symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
84 (cond ((default-boundp symbol)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
85 (funcall (or (get symbol 'custom-get) 'default-value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
86 symbol))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
87 ((get symbol 'saved-value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
88 (eval (car (get symbol 'saved-value))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
89 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
90 (eval value)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (defun custom-initialize-changed (symbol value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 "Initialize SYMBOL with VALUE.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
94 Like `custom-initialize-reset', but only use the `:set' function if the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 not using the standard setting. Otherwise, use the `set-default'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (cond ((default-boundp symbol)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
97 (funcall (or (get symbol 'custom-set) 'set-default)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
98 symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
99 (funcall (or (get symbol 'custom-get) 'default-value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
100 symbol)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
101 ((get symbol 'saved-value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
102 (funcall (or (get symbol 'custom-set) 'set-default)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
103 symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
104 (eval (car (get symbol 'saved-value)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
105 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
106 (set-default symbol (eval value)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 (defun custom-declare-variable (symbol value doc &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 "Like `defcustom', but SYMBOL and VALUE are evaluated as normal arguments."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ;; Remember the standard setting.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (put symbol 'standard-value (list value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 ;; Maybe this option was rogue in an earlier version. It no longer is.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
113 (when (eq (get symbol 'force-value) 'rogue)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
114 ;; It no longer is.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (put symbol 'force-value nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 (when doc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 (put symbol 'variable-documentation doc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 (let ((initialize 'custom-initialize-reset)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
119 (requests nil))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
120 (while args
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (let ((arg (car args)))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
122 (setq args (cdr args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
123 (check-argument-type 'keywordp arg)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
124 (let ((keyword arg)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
125 (value (car args)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
126 (unless args
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
127 (signal 'error (list "Keyword is missing an argument" keyword)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
128 (setq args (cdr args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
129 (cond ((eq keyword :initialize)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
130 (setq initialize value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
131 ((eq keyword :set)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
132 (put symbol 'custom-set value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
133 ((eq keyword :get)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
134 (put symbol 'custom-get value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
135 ((eq keyword :require)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
136 (setq requests (cons value requests)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
137 ((eq keyword :type)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
138 (put symbol 'custom-type value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
139 ((eq keyword :options)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
140 (if (get symbol 'custom-options)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
141 ;; Slow safe code to avoid duplicates.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
142 (mapc (lambda (option)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
143 (custom-add-option symbol option))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
144 value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
145 ;; Fast code for the common case.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
146 (put symbol 'custom-options (copy-sequence value))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
147 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
148 (custom-handle-keyword symbol keyword value
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
149 'custom-variable))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (put symbol 'custom-requests requests)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 ;; Do the actual initialization.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (funcall initialize symbol value))
217
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents: 209
diff changeset
153 ;; #### This is a rough equivalent of LOADHIST_ATTACH. However,
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents: 209
diff changeset
154 ;; LOADHIST_ATTACH also checks for `initialized'.
d44af0c54775 Import from CVS: tag r20-4b7
cvs
parents: 209
diff changeset
155 (push symbol current-load-list)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 (run-hooks 'custom-define-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (defmacro defcustom (symbol value doc &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 "Declare SYMBOL as a customizable variable that defaults to VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 DOC is the variable documentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 Neither SYMBOL nor VALUE needs to be quoted.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 If SYMBOL is not already bound, initialize it to VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 The remaining arguments should have the form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
167 [KEYWORD VALUE]...
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 The following KEYWORD's are defined:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
171 :type VALUE should be a widget type for editing the symbols value.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
172 The default is `sexp'.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 :options VALUE should be a list of valid members of the widget type.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
174 :group VALUE should be a customization group.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 Add SYMBOL to that group.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 :initialize VALUE should be a function used to initialize the
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
177 variable. It takes two arguments, the symbol and value
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
178 given in the `defcustom' call. The default is
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
179 `custom-initialize-set'
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
180 :set VALUE should be a function to set the value of the symbol.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
181 It takes two arguments, the symbol to set and the value to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
182 give it. The default is `set-default'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
183 :get VALUE should be a function to extract the value of symbol.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
184 The function takes one argument, a symbol, and should return
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
185 the current value for that symbol. The default is
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
186 `default-value'.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 :require VALUE should be a feature symbol. Each feature will be
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
188 required after initialization, of the the user have saved this
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
189 option.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 Read the section about customization in the Emacs Lisp manual for more
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 `(custom-declare-variable (quote ,symbol) (quote ,value) ,doc ,@args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 ;;; The `defface' Macro.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 (defmacro defface (face spec doc &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 "Declare FACE as a customizable face that defaults to SPEC.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 FACE does not need to be quoted.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 Third argument DOC is the face documentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 If FACE has been set with `custom-set-face', set the face attributes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 as specified by that function, otherwise set the face attributes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 according to SPEC.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 The remaining arguments should have the form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 [KEYWORD VALUE]...
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 The following KEYWORDs are defined:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 :group VALUE should be a customization group.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 Add FACE to that group.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 SPEC should be an alist of the form ((DISPLAY ATTS)...).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 ATTS is a list of face attributes and their values. The possible
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219 attributes are defined in the variable `custom-face-attributes'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 The ATTS of the first entry in SPEC where the DISPLAY matches the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 frame should take effect in that frame. DISPLAY can either be the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 symbol t, which will match all frames, or an alist of the form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 \((REQ ITEM...)...)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 For the DISPLAY to match a FRAME, the REQ property of the frame must
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 match one of the ITEM. The following REQ are defined:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 `type' (the value of `window-system')
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
230 Should be one of `x', `mswindows', or `tty'.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 `class' (the frame's color support)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 Should be one of `color', `grayscale', or `mono'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 `background' (what color is used for the background text)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 Should be one of `light' or `dark'.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 Read the section about customization in the Emacs Lisp manual for more
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 `(custom-declare-face (quote ,face) ,spec ,doc ,@args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 ;;; The `defgroup' Macro.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (defun custom-declare-group (symbol members doc &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 "Like `defgroup', but SYMBOL is evaluated as a normal argument."
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
246 (while members
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (apply 'custom-add-to-group symbol (car members))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 (pop members))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (put symbol 'custom-group (nconc members (get symbol 'custom-group)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (when doc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 (put symbol 'group-documentation doc))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (while args
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 (let ((arg (car args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (setq args (cdr args))
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 223
diff changeset
255 (check-argument-type 'keywordp arg)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 (let ((keyword arg)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
257 (value (car args)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
258 (unless args
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
259 (signal 'error (list "Keyword is missing an argument" keyword)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
260 (setq args (cdr args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
261 (cond ((eq keyword :prefix)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
262 (put symbol 'custom-prefix value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
263 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
264 (custom-handle-keyword symbol keyword value
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
265 'custom-group))))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 (run-hooks 'custom-define-hook)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 (defmacro defgroup (symbol members doc &rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 "Declare SYMBOL as a customization group containing MEMBERS.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 SYMBOL does not need to be quoted.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 Third arg DOC is the group documentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 MEMBERS should be an alist of the form ((NAME WIDGET)...) where NAME
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 is a symbol and WIDGET is a widget for editing that symbol. Useful
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 widgets are `custom-variable' for editing variables, `custom-face' for
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 edit faces, and `custom-group' for editing groups.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 The remaining arguments should have the form
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
282 [KEYWORD VALUE]...
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 The following KEYWORD's are defined:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 :group VALUE should be a customization group.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 Add SYMBOL to that group.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 Read the section about customization in the Emacs Lisp manual for more
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 information."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 `(custom-declare-group (quote ,symbol) ,members ,doc ,@args))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
293 (defvar custom-group-hash-table (make-hash-table :size 300 :test 'eq)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 "Hash-table of non-empty groups.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 (defun custom-add-to-group (group option widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 "To existing GROUP add a new OPTION of type WIDGET.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 If there already is an entry for that option, overwrite it."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 (let* ((members (get group 'custom-group))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
300 (old (assq option members)))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 (if old
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
302 (setcar (cdr old) widget)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 (put group 'custom-group (nconc members (list (list option widget))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 (puthash group t custom-group-hash-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 ;;; Properties.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 (defun custom-handle-all-keywords (symbol args type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 "For customization option SYMBOL, handle keyword arguments ARGS.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 Third argument TYPE is the custom option type."
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
311 (while args
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 (let ((arg (car args)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (setq args (cdr args))
227
0e522484dd2a Import from CVS: tag r20-5b12
cvs
parents: 223
diff changeset
314 (check-argument-type 'keywordp arg)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (let ((keyword arg)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
316 (value (car args)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
317 (unless args
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
318 (signal 'error (list "Keyword is missing an argument" keyword)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
319 (setq args (cdr args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
320 (custom-handle-keyword symbol keyword value type)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 (defun custom-handle-keyword (symbol keyword value type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 "For customization option SYMBOL, handle KEYWORD with VALUE.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 Fourth argument TYPE is the custom option type."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 (cond ((eq keyword :group)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
326 (custom-add-to-group value symbol type))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
327 ((eq keyword :version)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
328 (custom-add-version symbol value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
329 ((eq keyword :link)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
330 (custom-add-link symbol value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
331 ((eq keyword :load)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
332 (custom-add-load symbol value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
333 ((eq keyword :tag)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
334 (put symbol 'custom-tag value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
335 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
336 (signal 'error (list "Unknown keyword" keyword)))))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 (defun custom-add-option (symbol option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 "To the variable SYMBOL add OPTION.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 If SYMBOL is a hook variable, OPTION should be a hook member.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 For other types variables, the effect is undefined."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343 (let ((options (get symbol 'custom-options)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 (unless (member option options)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 (put symbol 'custom-options (cons option options)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 (defun custom-add-link (symbol widget)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 "To the custom option SYMBOL add the link WIDGET."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 (let ((links (get symbol 'custom-links)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 (unless (member widget links)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (put symbol 'custom-links (cons widget links)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
353 (defun custom-add-version (symbol version)
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
354 "To the custom option SYMBOL add the version VERSION."
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
355 (put symbol 'custom-version version))
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
356
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (defun custom-add-load (symbol load)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358 "To the custom option SYMBOL add the dependency LOAD.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 LOAD should be either a library file name, or a feature name."
223
2c611d1463a6 Import from CVS: tag r20-4b10
cvs
parents: 217
diff changeset
360 (puthash symbol t custom-group-hash-table)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 (let ((loads (get symbol 'custom-loads)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 (unless (member load loads)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
363 (put symbol 'custom-loads (cons load loads)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
365 ;;; deftheme macro
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
366
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
367 (defvar custom-known-themes '(user standard)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
368 "Themes that have been defthemed.")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
369
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
370 ;; #### add strings for group
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
371 ;; #### during bootstrap we cannot use cl-macs stuff
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
372 (defun* custom-define-theme (theme feature &optional doc
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
373 &key short-description immediate variable-reset-string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
374 variable-set-string face-set-string face-reset-string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
375 &allow-other-keys)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
376 (push theme custom-known-themes)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
377 (put theme 'theme-feature feature)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
378 (put theme 'theme-documentation doc)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
379 (if immediate (put theme 'theme-immediate immediate))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
380 (if variable-reset-string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
381 (put theme 'theme-variable-reset-string variable-reset-string ))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
382 (if variable-set-string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
383 (put theme 'theme-variable-set-string variable-set-string ))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
384 (if face-reset-string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
385 (put theme 'theme-face-reset-string face-reset-string ))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
386 (if face-set-string
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
387 (put theme 'theme-face-set-string face-set-string ))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
388 (if short-description
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
389 (put theme 'theme-short-description short-description )))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
390
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
391 (defun custom-make-theme-feature (theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
392 (intern (concat (symbol-name theme) "-theme")))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
393
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
394 (defmacro deftheme (theme &rest body)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
395 "(deftheme THEME &optional DOC &key KEYWORDS)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
396
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
397 Define a theme labeled by SYMBOL THEME. The optional argument DOC is a
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
398 doc string describing the the theme. It is optionally followed by the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
399 following keyboard arguments
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
400
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
401 :short-description DESC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
402 DESC is a short (one line) description of the theme. If not given DOC
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
403 is used.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
404 :immediate FLAG
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
405 If FLAG is non-nil variables set in this theme are bound
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
406 immediately when loading the theme.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
407 :variable-set-string VARIABLE_-SET-STRING
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
408 A string used by the UI to indicate that the value takes it
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
409 setting from this theme. It is passed to FORMAT with the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
410 name of the theme a additional argument.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
411 If not given, a generic description is used.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
412 :variable-reset-string VARIABLE-RESET-STRING
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
413 As above but used in the case the variable has been forced to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
414 the value in this theme.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
415 :face-set-string FACE-SET-STRING
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
416 :face-reset-string FACE-RESET-STRING
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
417 As above but for faces."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
418 (let ((feature (custom-make-theme-feature theme)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
419 `(custom-define-theme (quote ,theme) (quote ,feature) ,@body)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
420
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
421 (defsubst custom-theme-p (theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
422 "Non-nil when THEME has been defined."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
423 (memq theme custom-known-themes))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
424
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
425 (defsubst custom-check-theme (theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
426 "Check whether THEME is valid and signal an error if NOT"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
427 (unless (custom-theme-p theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
428 (error "Unknown theme `%s'" theme)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
429
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
430
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
431 ; #### do we need to deftheme 'user and/or 'standard here to make the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
432 ; code in cus-edit cleaner?.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
433
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 ;;; Initializing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
435
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
436 (defun custom-push-theme (prop symbol theme mode value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
437 (let ((old (get symbol prop)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
438 (if (eq (car-safe (car-safe old)) theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
439 (setq old (cdr old)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
440 (put symbol prop (cons (list theme mode value) old))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
441
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442 (defun custom-set-variables (&rest args)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
443 "Initialize variables according to user preferences.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
444 The settings are registered as theme `user'.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
445 The arguments should be a list where each entry has the form:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
446
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
447 (SYMBOL VALUE [NOW [REQUEST [COMMENT]]])
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
448
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
449 The unevaluated VALUE is stored as the saved value for SYMBOL.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
450 If NOW is present and non-nil, VALUE is also evaluated and bound as
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
451 the default value for the SYMBOL.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
452 REQUEST is a list of features we must 'require for SYMBOL.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
453 COMMENT is a comment string about SYMBOL."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
454 (apply 'custom-theme-set-variables 'user args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
455
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
456 (defun custom-theme-set-variables (theme &rest args)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
457 "Initialize variables according to settings specified by args.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
458 Records the settings as belonging to THEME.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
459
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
460 See `custom-set-variables' for a description of the arguments ARGS."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
461 (custom-check-theme theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
462 (let ((immediate (get theme 'theme-immediate)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
463 (while args * etc/custom/example-themes/example-theme.el:
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
464 (let ((entry (car args)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
465 (if (listp entry)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
466 (let* ((symbol (nth 0 entry))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
467 (value (nth 1 entry))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
468 (now (nth 2 entry))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
469 (requests (nth 3 entry))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
470 (comment (nth 4 entry))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
471 (set (or (get symbol 'custom-set) 'set-default)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
472 (put symbol 'saved-value (list value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
473 (custom-push-theme 'theme-value symbol theme 'set value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
474 (put symbol 'saved-variable-comment comment)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
475 (cond ((or now immediate)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
476 ;; Rogue variable, set it now.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
477 (put symbol 'force-value (if now 'rogue 'immediate))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
478 (funcall set symbol (eval value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
479 ((default-boundp symbol)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
480 ;; Something already set this, overwrite it.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
481 (funcall set symbol (eval value))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
482 (and (or now (default-boundp symbol))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
483 (put symbol 'variable-comment comment))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
484 (when requests
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
485 (put symbol 'custom-requests requests)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
486 (mapc 'require requests))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
487 (setq args (cdr args)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
488 ;; Old format, a plist of SYMBOL VALUE pairs.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
489 (message "Warning: old format `custom-set-variables'")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
490 (ding)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
491 (sit-for 2)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
492 (let ((symbol (nth 0 args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
493 (value (nth 1 args)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
494 (put symbol 'saved-value (list value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
495 (custom-push-theme 'theme-value symbol theme 'set value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
496 (setq args (cdr (cdr args))))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
497
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
498 (defvar custom-loaded-themes nil
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
499 "Themes in the order they are loaded.")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
500
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
501 (defun custom-theme-loaded-p (theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
502 "Return non-nil when THEME has been loaded."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
503 (memq theme custom-loaded-themes))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
504
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
505 (defun provide-theme (theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
506 "Indicate that this file provides THEME."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
507 (custom-check-theme theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
508 (provide (get theme 'theme-feature))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
509 (push theme custom-loaded-themes))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
510
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
511 (defun require-theme (theme &optional soft)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
512 "Try to load a theme by requiring its feature."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
513 ;; Note we do no check for validity of the theme here.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
514 ;; This allows to pull in themes by a file-name convention
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
515 (require (get theme 'theme-feature (custom-make-theme-feature theme))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
516
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
517 (defun custom-do-theme-reset (theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
518 ; #### untested! slow!
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
519 (let (spec-list)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
520 (mapatoms (lambda (symbol)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
521 (setq spec-list (get symbol 'theme-value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
522 (when spec-list
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
523 (setq spec-list (delete-if (lambda (elt)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
524 (eq (car elt) theme))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
525 spec-list))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
526 (put symbol 'theme-value spec-list)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
527 (custom-theme-reset-internal symbol 'user))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
528 (setq spec-list (get symbol 'theme-face))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
529 (when spec-list
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
530 (setq spec-list (delete-if (lambda (elt)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
531 (eq (car elt) theme))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
532 spec-list))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
533 (put symbol 'theme-face spec-list)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
534 (custom-theme-reset-internal-face symbol 'user))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
535
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
536 (defun custom-theme-load-themes (by-theme &rest body)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
537 "Load the themes specified by BODY and record them as required by
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
538 theme BY-THEME. BODY is a secuence of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
539 - a SYMBOL
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
540 require the theme SYMBOL
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
541 - a list (reset THEME)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
542 Undo all the settings made by THEME.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
543 - a list (hidden THEME)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
544 require the THEME but hide it from the user."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
545 (custom-check-theme by-theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
546 (dolist (theme body)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
547 (cond ((and (consp theme) (eq (car theme) 'reset))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
548 (custom-do-theme-reset (cadr theme)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
549 ((and (consp theme) (eq (car theme) 'hidden))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
550 (require-theme (cadr theme))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
551 (unless (custom-theme-loaded-p (cadr theme))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
552 (put (cadr theme) 'theme-hidden t)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
553 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
554 (require-theme theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
555 (remprop theme 'theme-hidden)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
556 (push theme (get by-theme 'theme-loads-themes))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
557
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
558 (defun custom-load-themes (&rest body)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
559 "Load themes for the USER theme as specified by BODY.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
560
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
561 BODY is as with custom-theme-load-themes."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
562 (apply #'custom-theme-load-themes 'user body))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
563
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
564
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
565
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
566
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
567 (defsubst copy-upto-last (elt list)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
568 "Copy all the elements of the list upto the last occurence of elt"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
569 ;; Is it faster to do more work in C than to do less in elisp?
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
570 (nreverse (cdr (member elt (reverse list)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
571
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
572 (defun custom-theme-value (theme theme-spec-list)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
573 "Determine the value for THEME defined by THEME-SPEC-LIST.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
574 Returns (list value) if found. Nil otherwise."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
575 ;; Note we do _NOT_ signal an error if the theme is unknown
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
576 ;; it might have gone away without the user knowing.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
577 (let ((theme-or-lower (memq theme (cons 'user custom-loaded-themes)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
578 value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
579 (mapc #'(lambda (theme-spec)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
580 (when (member (car theme-spec) theme-or-lower)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
581 (setq value (cdr theme-spec))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
582 ;; We need to continue because if theme =A and we found
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
583 ;; B then if the load order is B A C B
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
584 ;; we actually want the value in C.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
585 (setq theme-or-lower (copy-upto-last (car theme-spec)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
586 theme-or-lower))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
587 ;; We could should circuit if this is now nil.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
588 ))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
589 theme-spec-list)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
590 (if value
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
591 (if (eq (car value) 'set)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
592 (list (cadr value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
593 ;; Yet another reset spec. car value = reset
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
594 (custom-theme-value (cadr value) theme-spec-list)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
595
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
596
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
597 (defun custom-theme-variable-value (variable theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
598 "Return (list value) value of VARIABLE in THEME if the THEME modifies the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
599 VARIABLE. Nil otherwise."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
600 (custom-theme-value theme (get variable 'theme-value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
601
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
602 (defun custom-theme-reset-internal (symbol to-theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
603 (let ((value (custom-theme-variable-value symbol to-theme))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
604 was-in-theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
605 (setq was-in-theme value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
606 (setq value (or value (get symbol 'standard-value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
607 (when value
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
608 (put symbol 'saved-value was-in-theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
609 (if (or (get 'force-value symbol) (default-boundp symbol))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
610 (funcall (get symbol 'custom-set 'set-default) symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
611 (eval (car value)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
612 value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
613
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
614
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
615 (defun custom-theme-reset-variables (theme &rest args)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
616 "Reset the value of the variables to values previously defined.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
617 Assosiate this setting with THEME.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
618
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
619 ARGS is a list of lists of the form
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
620
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
621 (variable to-theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
622
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
623 This means reset variable to its value in to-theme."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
624 (custom-check-theme theme)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
625 (mapc #'(lambda (arg)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
626 (apply #'custom-theme-reset-internal arg)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
627 (custom-push-theme 'theme-value (car arg) theme 'reset (cadr arg)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
628 args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
629
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
630 (defun custom-reset-variables (&rest args)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
631 "Reset the value of the variables to values previously defined.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
632 Assosiate this setting with the `user' theme.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
633
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
634 The ARGS are as in `custom-theme-reset-variables'."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
635 (apply #'custom-theme-reset-variables 'user args))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 380
diff changeset
636
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
637
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
638 ;;; The End.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
639
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
640 (provide 'custom)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
641
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
642 ;; custom.el ends here