diff options
Diffstat (limited to 'lisp/custom.el')
-rw-r--r-- | lisp/custom.el | 91 |
1 files changed, 68 insertions, 23 deletions
diff --git a/lisp/custom.el b/lisp/custom.el index 968b28f7a89..bbbe70c5ea8 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -67,8 +67,10 @@ symbol." (defun custom-initialize-set (symbol exp) "Initialize SYMBOL based on EXP. -If the symbol doesn't have a default binding already, -then set it using its `:set' function (or `set-default' if it has none). +If the symbol doesn't have a default binding already, then set it +using its `:set' function (or `set-default-toplevel-value' if it +has none). + The value is either the value in the symbol's `saved-value' property, if any, or the value of EXP." (condition-case nil @@ -81,11 +83,27 @@ if any, or the value of EXP." (defun custom-initialize-reset (symbol exp) "Initialize SYMBOL based on EXP. -Set the symbol, using its `:set' function (or `set-default' if it has none). +Set the symbol, using its `:set' function (or `set-default-toplevel-value' +if it has none). + The value is either the symbol's current value (as obtained using the `:get' function), if any, or the value in the symbol's `saved-value' property if any, or (last of all) the value of EXP." + ;; If this value has been set with `setopt' (for instance in + ;; ~/.emacs), we didn't necessarily know the type of the user option + ;; then. So check now, and issue a warning if it's wrong. + (let ((value (get symbol 'custom-check-value))) + (when value + (let ((type (get symbol 'custom-type))) + (when (and type + (boundp symbol) + (eq (car value) (symbol-value symbol)) + ;; Check that the type is correct. + (not (widget-apply (widget-convert type) + :match (car value)))) + (warn "Value `%S' for `%s' does not match type %s" + value symbol type))))) (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value) symbol (condition-case nil @@ -100,7 +118,7 @@ or (last of all) the value of EXP." "Initialize SYMBOL with EXP. Like `custom-initialize-reset', but only use the `:set' function if not using the standard setting. -For the standard setting, use `set-default'." +For the standard setting, use `set-default-toplevel-value'." (condition-case nil (let ((def (default-toplevel-value symbol))) (funcall (or (get symbol 'custom-set) #'set-default-toplevel-value) @@ -114,7 +132,7 @@ For the standard setting, use `set-default'." symbol (eval (car (get symbol 'saved-value))))) (t - (set-default symbol (eval exp))))))) + (set-default-toplevel-value symbol (eval exp))))))) (defvar custom-delayed-init-variables nil "List of variables whose initialization is pending until startup. @@ -262,11 +280,11 @@ The following keywords are meaningful: when using the Customize user interface. It takes two arguments, the symbol to set and the value to give it. The function should not modify its value argument destructively. The default choice - of function is `set-default'. + of function is `set-default-toplevel-value'. :get VALUE should be a function to extract the value of symbol. The function takes one argument, a symbol, and should return the current value for that symbol. The default choice of function - is `default-value'. + is `default-toplevel-value'. :require VALUE should be a feature symbol. If you save a value for this option, then when your init file loads the value, @@ -364,7 +382,8 @@ call that function directly. See Info node `(elisp) Customization' in the Emacs Lisp manual for more information." - (declare (doc-string 3) (debug (name body))) + (declare (doc-string 3) (debug (name body)) + (indent defun)) ;; It is better not to use backquote in this file, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. @@ -447,7 +466,7 @@ In the ATTS property list, possible attributes are `:family', See Info node `(elisp) Faces' in the Emacs Lisp manual for more information." - (declare (doc-string 3)) + (declare (doc-string 3) (indent defun)) ;; It is better not to use backquote in this file, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. @@ -515,7 +534,7 @@ non-nil. See Info node `(elisp) Customization' in the Emacs Lisp manual for more information." - (declare (doc-string 3)) + (declare (doc-string 3) (indent defun)) ;; It is better not to use backquote in this file, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. @@ -716,7 +735,7 @@ this sets the local binding in that buffer instead." (if custom-local-buffer (with-current-buffer custom-local-buffer (set variable value)) - (set-default variable value))) + (set-default-toplevel-value variable value))) (defun custom-set-minor-mode (variable value) ":set function for minor mode variables. @@ -1135,29 +1154,24 @@ list, in which A occurs before B if B was defined with a ;; (provide-theme 'THEME) -;; The IGNORED arguments to deftheme come from the XEmacs theme code, where -;; they were used to supply keyword-value pairs like `:immediate', -;; `:variable-reset-string', etc. We don't use any of these, so ignore them. - -(defmacro deftheme (theme &optional doc &rest _ignored) +(defmacro deftheme (theme &optional doc) "Declare THEME to be a Custom theme. The optional argument DOC is a doc string describing the theme. Any theme `foo' should be defined in a file called `foo-theme.el'; see `custom-make-theme-feature' for more information." (declare (doc-string 2) - (advertised-calling-convention (theme &optional doc) "22.1")) + (indent 1)) (let ((feature (custom-make-theme-feature theme))) ;; It is better not to use backquote in this file, ;; because that makes a bootstrapping problem ;; if you need to recompile all the Lisp files using interpreted code. (list 'custom-declare-theme (list 'quote theme) (list 'quote feature) doc))) -(defun custom-declare-theme (theme feature &optional doc &rest _ignored) +(defun custom-declare-theme (theme feature &optional doc) "Like `deftheme', but THEME is evaluated as a normal argument. FEATURE is the feature this theme provides. Normally, this is a symbol created from THEME by `custom-make-theme-feature'." - (declare (advertised-calling-convention (theme feature &optional doc) "22.1")) (unless (custom-theme-name-valid-p theme) (error "Custom theme cannot be named %S" theme)) (unless (memq theme custom-known-themes) @@ -1335,6 +1349,13 @@ Return t if THEME was successfully loaded, nil otherwise." t)))) (t (error "Unable to load theme `%s'" theme)))) + (when-let ((obs (get theme 'byte-obsolete-info))) + (display-warning 'initialization + (format "The `%s' theme is obsolete%s" + theme + (if (nth 2 obs) + (format " since Emacs %s" (nth 2 obs)) + "")))) ;; Optimization: if the theme changes the `default' face, put that ;; entry first. This avoids some `frame-set-background-mode' rigmarole ;; by assigning the new background immediately. @@ -1419,6 +1440,22 @@ are not directories are omitted from the expansion." ;;; Enabling and disabling loaded themes. +(defcustom enable-theme-functions nil + "Abnormal hook that is run after a theme has been enabled. +The functions in the hook are called with one parameter -- the + name of the theme that's been enabled (as a symbol)." + :type 'hook + :group 'customize + :version "29.1") + +(defcustom disable-theme-functions nil + "Abnormal hook that is run after a theme has been disabled. +The functions in the hook are called with one parameter -- the + name of the theme that's been disabled (as a symbol)." + :type 'hook + :group 'customize + :version "29.1") + (defun enable-theme (theme) "Reenable all variable and face settings defined by THEME. THEME should be either `user', or a theme loaded via `load-theme'. @@ -1427,7 +1464,9 @@ After this function completes, THEME will have the highest precedence (after `user') among enabled themes. Note that any already-enabled themes remain enabled after this -function runs. To disable other themes, use `disable-theme'." +function runs. To disable other themes, use `disable-theme'. + +After THEME has been enabled, runs `enable-theme-functions'." (interactive (list (intern (completing-read "Enable custom theme: " @@ -1475,7 +1514,9 @@ function runs. To disable other themes, use `disable-theme'." (setq custom-enabled-themes (cons theme (remq theme custom-enabled-themes))) ;; Give the `user' theme the highest priority. - (enable-theme 'user))) + (enable-theme 'user)) + ;; Allow callers to react to the enabling. + (run-hook-with-args 'enable-theme-functions theme)) (defcustom custom-enabled-themes nil "List of enabled Custom Themes, highest precedence first. @@ -1520,7 +1561,9 @@ Setting this variable through Customize calls `enable-theme' or (defun disable-theme (theme) "Disable all variable and face settings defined by THEME. -See `custom-enabled-themes' for a list of enabled themes." +See `custom-enabled-themes' for a list of enabled themes. + +After THEME has been disabled, runs `disable-theme-functions'." (interactive (list (intern (completing-read "Disable custom theme: " @@ -1564,7 +1607,9 @@ See `custom-enabled-themes' for a list of enabled themes." "unspecified-fg" "black")) (face-set-after-frame-default frame)) (setq custom-enabled-themes - (delq theme custom-enabled-themes)))) + (delq theme custom-enabled-themes)) + ;; Allow callers to react to the disabling. + (run-hook-with-args 'disable-theme-functions theme))) ;; Only used if window-system not null. (declare-function x-get-resource "frame.c" |