annotate lisp/cus-theme.el @ 111016:fedd4f6fa7e5

Move built-in theme directory to etc/. * custom.el: Custom themes no longer use load-path. (custom-theme-load-path): New option. Change built-in theme directory to etc/. (custom-enabled-themes): Add custom-theme-load-path dependency. (custom-theme--load-path): New function. (load-theme, custom-available-themes): Use it. * cus-theme.el (describe-theme-1): Use custom-theme--load-path. (customize-themes): Link to custom-theme-load-path variable.
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 16 Oct 2010 14:27:08 -0400
parents 5ffdb52c377c
children 9506df1b7b65
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; cus-theme.el -- custom theme creation user interface
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2 ;;
68651
3bd95f4f2941 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 68161
diff changeset
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
4 ;; 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;;
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: Alex Schroeder <alex@gnu.org>
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Maintainer: FSF
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: help, faces
110015
280c8ae2476d Add "Package:" file headers to denote built-in packages.
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
9 ;; Package: emacs
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
15 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
16 ;; (at your option) any later version.
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Code:
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 (require 'widget)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 (require 'cus-edit)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (eval-when-compile
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (require 'wid-edit))
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33
67950
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
34 (defvar custom-new-theme-mode-map
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
35 (let ((map (make-keymap)))
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
36 (set-keymap-parent map widget-keymap)
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
37 (suppress-keymap map)
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
38 (define-key map "\C-x\C-s" 'custom-theme-write)
67950
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
39 (define-key map "n" 'widget-forward)
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
40 (define-key map "p" 'widget-backward)
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
41 map)
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
42 "Keymap for `custom-new-theme-mode'.")
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
43
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
44 (define-derived-mode custom-new-theme-mode nil "Cus-Theme"
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
45 "Major mode for editing Custom themes.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
46 Do not call this mode function yourself. It is meant for internal use."
67950
87b213a028b3 * cus-theme.el (custom-new-theme-mode-map): New variable.
Chong Yidong <cyd@stupidchicken.com>
parents: 67949
diff changeset
47 (use-local-map custom-new-theme-mode-map)
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
48 (custom--initialize-widget-variables)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
49 (set (make-local-variable 'revert-buffer-function) 'custom-theme-revert))
63928
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
50 (put 'custom-new-theme-mode 'mode-class 'special)
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
51
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
52 (defvar custom-theme-name nil)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
53 (defvar custom-theme-variables nil)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
54 (defvar custom-theme-faces nil)
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
55 (defvar custom-theme-description nil)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
56 (defvar custom-theme-insert-variable-marker nil)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
57 (defvar custom-theme-insert-face-marker nil)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
58
110955
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
59 (defvar custom-theme--listed-faces '(default cursor fixed-pitch
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
60 variable-pitch escape-glyph minibuffer-prompt highlight region
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
61 shadow secondary-selection trailing-whitespace
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
62 font-lock-builtin-face font-lock-comment-delimiter-face
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
63 font-lock-comment-face font-lock-constant-face
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
64 font-lock-doc-face font-lock-function-name-face
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
65 font-lock-keyword-face font-lock-negation-char-face
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
66 font-lock-preprocessor-face font-lock-regexp-grouping-backslash
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
67 font-lock-regexp-grouping-construct font-lock-string-face
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
68 font-lock-type-face font-lock-variable-name-face
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
69 font-lock-warning-face button link link-visited fringe
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
70 header-line tooltip mode-line mode-line-buffer-id
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
71 mode-line-emphasis mode-line-highlight mode-line-inactive
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
72 isearch isearch-fail lazy-highlight match next-error
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
73 query-replace)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
74 "Faces listed by default in the *Custom Theme* buffer.")
63928
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
75
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
76 (defvar custom-theme--save-name)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
77
50203
3803afb52e4f (custom-theme-create): Add autoload cookie.
John Paul Wallington <jpw@pobox.com>
parents: 49588
diff changeset
78 ;;;###autoload
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
79 (defun customize-create-theme (&optional theme buffer)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
80 "Create or edit a custom theme.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
81 THEME, if non-nil, should be an existing theme to edit.
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
82 BUFFER, if non-nil, should be a buffer to use; the default is
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
83 named *Custom Theme*."
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (interactive)
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
85 (switch-to-buffer (get-buffer-create (or buffer "*Custom Theme*")))
63928
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
86 (let ((inhibit-read-only t))
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
87 (erase-buffer)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
88 (dolist (ov (overlays-in (point-min) (point-max)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
89 (delete-overlay ov)))
63928
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
90 (custom-new-theme-mode)
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (make-local-variable 'custom-theme-name)
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
92 (set (make-local-variable 'custom-theme--save-name) theme)
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
93 (set (make-local-variable 'custom-theme-faces) nil)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
94 (set (make-local-variable 'custom-theme-variables) nil)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
95 (set (make-local-variable 'custom-theme-description) "")
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
96 (make-local-variable 'custom-theme-insert-face-marker)
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
97 (make-local-variable 'custom-theme-insert-variable-marker)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
98 (make-local-variable 'custom-theme--listed-faces)
63928
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
99
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
100 (widget-create 'push-button
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
101 :tag " Visit Theme "
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
102 :help-echo "Insert the settings of a pre-defined theme."
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
103 :action (lambda (widget &optional event)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
104 (call-interactively 'custom-theme-visit-theme)))
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
105 (widget-insert " ")
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
106 (widget-create 'push-button
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
107 :tag " Merge Theme "
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
108 :help-echo "Merge in the settings of a pre-defined theme."
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
109 :action (lambda (widget &optional event)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
110 (call-interactively 'custom-theme-merge-theme)))
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
111 (widget-insert " ")
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
112 (widget-create 'push-button :notify 'revert-buffer " Revert ")
63928
e559c2c766bc (custom-new-theme-mode): New function.
Luc Teirlinck <teirllm@auburn.edu>
parents: 61603
diff changeset
113
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
114 (widget-insert "\n\nTheme name : ")
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (setq custom-theme-name
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
116 (widget-create 'editable-field
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
117 :value (if theme (symbol-name theme) "")))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
118 (widget-insert "Description: ")
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (setq custom-theme-description
49588
37645a051842 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48952
diff changeset
120 (widget-create 'text
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 :value (format-time-string "Created %Y-%m-%d.")))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
122 (widget-insert " ")
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
123 (widget-create 'push-button
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
124 :notify (function custom-theme-write)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
125 " Save Theme ")
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
126
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
127 (let (vars values faces face-specs)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
128
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
129 ;; Load the theme settings.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
130 (when theme
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
131 (load-theme theme t)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
132 (dolist (setting (get theme 'theme-settings))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
133 (if (eq (car setting) 'theme-value)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
134 (progn (push (nth 1 setting) vars)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
135 (push (nth 3 setting) values))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
136 (push (nth 1 setting) faces)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
137 (push (nth 3 setting) face-specs))))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
138
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
139 ;; If THEME is non-nil, insert all of that theme's faces.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
140 ;; Otherwise, insert those in `custom-theme--listed-faces'.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
141 (widget-insert "\n\n Theme faces:\n ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
142 (if theme
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
143 (while faces
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
144 (custom-theme-add-face-1 (pop faces) (pop face-specs)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
145 (dolist (face custom-theme--listed-faces)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
146 (custom-theme-add-face-1 face nil)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
147 (setq custom-theme-insert-face-marker (point-marker))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
148 (widget-insert " ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
149 (widget-create 'push-button
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
150 :tag "Insert Additional Face"
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
151 :help-echo "Add another face to this theme."
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
152 :follow-link 'mouse-face
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
153 :button-face 'custom-link
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
154 :mouse-face 'highlight
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
155 :pressed-face 'highlight
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
156 :action (lambda (widget &optional event)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
157 (call-interactively 'custom-theme-add-face)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
158
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
159 ;; If THEME is non-nil, insert all of that theme's variables.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
160 (widget-insert "\n\n Theme variables:\n ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
161 (if theme
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
162 (while vars
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
163 (custom-theme-add-var-1 (pop vars) (pop values))))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
164 (setq custom-theme-insert-variable-marker (point-marker))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
165 (widget-insert " ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
166 (widget-create 'push-button
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
167 :tag "Insert Variable"
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
168 :help-echo "Add another variable to this theme."
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
169 :follow-link 'mouse-face
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
170 :button-face 'custom-link
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
171 :mouse-face 'highlight
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
172 :pressed-face 'highlight
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
173 :action (lambda (widget &optional event)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
174 (call-interactively 'custom-theme-add-variable)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
175 (widget-insert ?\n)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
176 (widget-setup)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
177 (goto-char (point-min))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
178 (message "")))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
179
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
180 (defun custom-theme-revert (ignore-auto noconfirm)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
181 (when (or noconfirm (y-or-n-p "Discard current changes? "))
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
182 (customize-create-theme custom-theme--save-name (current-buffer))))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
183
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
184 ;;; Theme variables
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
185
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
186 (defun custom-theme-add-variable (var value)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
187 "Add a widget for VAR (a symbol) to the *New Custom Theme* buffer.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
188 VALUE should be a value to which to set the widget; when called
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
189 interactively, this defaults to the current value of VAR."
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
190 (interactive
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
191 (let ((v (read-variable "Variable name: ")))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
192 (list v (symbol-value v))))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
193 (let ((var-and-widget (assq var custom-theme-faces)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
194 (cond ((null var-and-widget)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
195 ;; If VAR is not yet in the buffer, add it.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
196 (save-excursion
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
197 (goto-char custom-theme-insert-variable-marker)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
198 (custom-theme-add-var-1 var value)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
199 (move-marker custom-theme-insert-variable-marker (point))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
200 (widget-setup)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
201 ;; Otherwise, alter that var widget.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
202 (t
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
203 (let ((widget (cdr var-and-widget)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
204 (widget-put widget :shown-value (list value))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
205 (custom-redraw widget))))))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
206
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
207 (defun custom-theme-add-var-1 (symbol val)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
208 (widget-insert " ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
209 (push (cons symbol
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
210 (widget-create 'custom-variable
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
211 :tag (custom-unlispify-tag-name symbol)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
212 :value symbol
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
213 :shown-value (list val)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
214 :notify 'ignore
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
215 :custom-level 0
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
216 :custom-state 'hidden
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
217 :inhibit-magic t))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
218 custom-theme-variables)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
219 (widget-insert " "))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
220
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
221 ;;; Theme faces
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
222
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
223 (defun custom-theme-add-face (face &optional spec)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
224 "Add a widget for FACE (a symbol) to the *New Custom Theme* buffer.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
225 SPEC, if non-nil, should be a face spec to which to set the widget."
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
226 (interactive (list (read-face-name "Face name" nil nil) nil))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
227 (unless (or (facep face) spec)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
228 (error "`%s' has no face definition" face))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
229 (let ((face-and-widget (assq face custom-theme-faces)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
230 (cond ((null face-and-widget)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
231 ;; If FACE is not yet in the buffer, add it.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
232 (save-excursion
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
233 (goto-char custom-theme-insert-face-marker)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
234 (custom-theme-add-face-1 face spec)
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
235 (move-marker custom-theme-insert-face-marker (point))
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
236 (widget-setup)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
237 ;; Otherwise, if SPEC is supplied, alter that face widget.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
238 (spec
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
239 (let ((widget (cdr face-and-widget)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
240 (widget-put widget :shown-value spec)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
241 (custom-redraw widget)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
242 ((called-interactively-p 'interactive)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
243 (error "`%s' is already present" face)))))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
244
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
245 (defun custom-theme-add-face-1 (symbol spec)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
246 (widget-insert " ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
247 (push (cons symbol
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
248 (widget-create 'custom-face
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
249 :tag (custom-unlispify-tag-name symbol)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
250 :documentation-shown t
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
251 :value symbol
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
252 :custom-state 'hidden
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
253 :display-style 'concise
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
254 :shown-value spec
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
255 :inhibit-magic t
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
256 :sample-indent 34))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
257 custom-theme-faces)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
258 (widget-insert " "))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
259
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
260 ;;; Reading and writing
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
261
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
262 (defun custom-theme-visit-theme (theme)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
263 "Load the custom theme THEME's settings into the current buffer."
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
264 (interactive
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
265 (list
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
266 (intern (completing-read "Find custom theme: "
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
267 (mapcar 'symbol-name
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
268 (custom-available-themes))))))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
269 (unless (custom-theme-name-valid-p theme)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
270 (error "No valid theme named `%s'" theme))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
271 (cond ((not (eq major-mode 'custom-new-theme-mode))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
272 (customize-create-theme theme))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
273 ((y-or-n-p "Discard current changes? ")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
274 (setq custom-theme--save-name theme)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
275 (custom-theme-revert nil t))))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
276
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
277 (defun custom-theme-merge-theme (theme)
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
278 "Merge the custom theme THEME's settings into the current buffer."
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
279 (interactive
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
280 (list
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
281 (intern (completing-read "Merge custom theme: "
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
282 (mapcar 'symbol-name
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
283 (custom-available-themes))))))
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
284 (unless (eq theme 'user)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
285 (unless (custom-theme-name-valid-p theme)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
286 (error "Invalid theme name `%s'" theme))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
287 (load-theme theme t))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
288 (let ((settings (reverse (get theme 'theme-settings))))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
289 (dolist (setting settings)
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
290 (funcall (if (eq (car setting) 'theme-value)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
291 'custom-theme-add-variable
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
292 'custom-theme-add-face)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
293 (nth 1 setting)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
294 (nth 3 setting))))
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
295 theme)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
296
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (defun custom-theme-write (&rest ignore)
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
298 "Write the current custom theme to its theme file."
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
299 (interactive)
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
300 (let* ((name (widget-value custom-theme-name))
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
301 (doc (widget-value custom-theme-description))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
302 (vars custom-theme-variables)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
303 (faces custom-theme-faces)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
304 filename)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
305 (when (string-equal name "")
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
306 (setq name (read-from-minibuffer "Theme name: " (user-login-name)))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
307 (widget-value-set custom-theme-name name))
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
308 (unless (custom-theme-name-valid-p (intern name))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
309 (error "Custom themes cannot be named `%s'" name))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
310
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
311 (setq filename (expand-file-name (concat name "-theme.el")
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
312 custom-theme-directory))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
313 (and (file-exists-p filename)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
314 (not (y-or-n-p (format "File %s exists. Overwrite? " filename)))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
315 (error "Aborted"))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
316
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
317 (with-temp-buffer
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
318 (emacs-lisp-mode)
111016
fedd4f6fa7e5 Move built-in theme directory to etc/.
Chong Yidong <cyd@stupidchicken.com>
parents: 111013
diff changeset
319 (unless (file-directory-p custom-theme-directory)
67982
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
320 (make-directory (file-name-as-directory custom-theme-directory) t))
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
321 (setq buffer-file-name filename)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
322 (erase-buffer)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
323 (insert "(deftheme " name)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
324 (if doc (insert "\n \"" doc "\""))
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
325 (insert ")\n")
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
326 (custom-theme-write-variables name vars)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
327 (custom-theme-write-faces name faces)
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
328 (insert "\n(provide-theme '" name ")\n")
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
329 (save-buffer))
a711a44049e2 * cus-theme.el: Rewrite the Custom New Theme Mode interface.
Chong Yidong <cyd@stupidchicken.com>
parents: 67961
diff changeset
330 (dolist (var vars)
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
331 (when (widget-get (cdr var) :children)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
332 (widget-put (cdr var) :custom-state 'saved)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
333 (custom-redraw-magic (cdr var))))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
334 (dolist (face custom-theme-faces)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
335 (when (widget-get (cdr face) :children)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
336 (widget-put (cdr face) :custom-state 'saved)
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
337 (custom-redraw-magic (cdr face))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
338 (message "Theme written to %s" filename)))
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (defun custom-theme-write-variables (theme vars)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 "Write a `custom-theme-set-variables' command for THEME.
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 It includes all variables in list VARS."
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (when vars
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (let ((standard-output (current-buffer)))
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (princ "\n(custom-theme-set-variables\n")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (princ " '")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (princ theme)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (princ "\n")
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
349 (dolist (spec vars)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
350 (let* ((symbol (car spec))
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
351 (widget (cdr spec))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
352 (child (car-safe (widget-get widget :children)))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
353 (value (if child
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
354 (widget-value child)
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
355 ;; Child is null if the widget is closed (hidden).
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
356 (car (widget-get widget :shown-value)))))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
357 (when (boundp symbol)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
358 (unless (bolp)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
359 (princ "\n"))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
360 (princ " '(")
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
361 (prin1 symbol)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
362 (princ " ")
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
363 (prin1 (custom-quote value))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
364 (princ ")"))))
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (if (bolp)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (princ " "))
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (princ ")")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (unless (looking-at "\n")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (princ "\n")))))
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (defun custom-theme-write-faces (theme faces)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 "Write a `custom-theme-set-faces' command for THEME.
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 It includes all faces in list FACES."
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (when faces
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (let ((standard-output (current-buffer)))
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (princ "\n(custom-theme-set-faces\n")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (princ " '")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (princ theme)
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (princ "\n")
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
380 (dolist (spec faces)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
381 (let* ((symbol (car spec))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
382 (widget (cdr spec))
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
383 (value
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
384 (if (car-safe (widget-get widget :children))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
385 (custom-face-widget-to-spec widget)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
386 ;; Child is null if the widget is closed (hidden).
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
387 (widget-get widget :shown-value))))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
388 (when (and (facep symbol) value)
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
389 (princ (if (bolp) " '(" "\n '("))
110896
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
390 (prin1 symbol)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
391 (princ " ")
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
392 (prin1 value)
0d6d71f9b91a Interface improvements to cus-theme.el.
Chong Yidong <cyd@stupidchicken.com>
parents: 110015
diff changeset
393 (princ ")"))))
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
394 (if (bolp) (princ " "))
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (princ ")")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (unless (looking-at "\n")
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (princ "\n")))))
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
399
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
400 ;;; Describing Custom themes.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
401
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
402 ;;;###autoload
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
403 (defun describe-theme (theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
404 "Display a description of the Custom theme THEME (a symbol)."
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
405 (interactive
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
406 (list
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
407 (intern (completing-read "Describe custom theme: "
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
408 (mapcar 'symbol-name
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
409 (custom-available-themes))))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
410 (unless (custom-theme-name-valid-p theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
411 (error "Invalid theme name `%s'" theme))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
412 (help-setup-xref (list 'describe-theme theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
413 (called-interactively-p 'interactive))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
414 (with-help-window (help-buffer)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
415 (with-current-buffer standard-output
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
416 (describe-theme-1 theme))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
417
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
418 (defun describe-theme-1 (theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
419 (prin1 theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
420 (princ " is a custom theme")
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
421 (let ((fn (locate-file (concat (symbol-name theme) "-theme.el")
111016
fedd4f6fa7e5 Move built-in theme directory to etc/.
Chong Yidong <cyd@stupidchicken.com>
parents: 111013
diff changeset
422 (custom-theme--load-path)
110955
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
423 '("" "c")))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
424 doc)
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
425 (when fn
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
426 (princ " in `")
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
427 (help-insert-xref-button (file-name-nondirectory fn)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
428 'help-theme-def fn)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
429 (princ "'"))
110955
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
430 (princ ".\n")
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
431 (if (not (memq theme custom-known-themes))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
432 (progn
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
433 (princ "It is not loaded.")
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
434 ;; Attempt to grab the theme documentation
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
435 (when fn
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
436 (with-temp-buffer
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
437 (insert-file-contents fn)
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
438 (let ((sexp (let ((read-circle nil))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
439 (condition-case nil
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
440 (read (current-buffer))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
441 (end-of-file nil)))))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
442 (and sexp (listp sexp)
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
443 (eq (car sexp) 'deftheme)
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
444 (setq doc (nth 2 sexp)))))))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
445 (if (custom-theme-enabled-p theme)
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
446 (princ "It is loaded and enabled.")
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
447 (princ "It is loaded but disabled."))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
448 (setq doc (get theme 'theme-documentation)))
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
449
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
450 (princ "\n\nDocumentation:\n")
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
451 (princ (if (stringp doc)
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
452 doc
c84f553cca36 Add some default custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110938
diff changeset
453 "No documentation available.")))
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
454 (princ "\n\nYou can ")
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
455 (help-insert-xref-button "customize" 'help-theme-edit theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
456 (princ " this theme."))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
457
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
458
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
459 ;;; Theme chooser
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
460
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
461 (defvar custom--listed-themes)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
462
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
463 (defcustom custom-theme-allow-multiple-selections nil
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
464 "Whether to allow multi-selections in the *Custom Themes* buffer."
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
465 :type 'boolean
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
466 :group 'custom-buffer)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
467
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
468 (defvar custom-theme-choose-mode-map
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
469 (let ((map (make-keymap)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
470 (set-keymap-parent map widget-keymap)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
471 (suppress-keymap map)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
472 (define-key map "\C-x\C-s" 'custom-theme-save)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
473 (define-key map "n" 'widget-forward)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
474 (define-key map "p" 'widget-backward)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
475 (define-key map "?" 'custom-describe-theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
476 map)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
477 "Keymap for `custom-theme-choose-mode'.")
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
478
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
479 (define-derived-mode custom-theme-choose-mode nil "Cus-Theme"
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
480 "Major mode for selecting Custom themes.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
481 Do not call this mode function yourself. It is meant for internal use."
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
482 (use-local-map custom-theme-choose-mode-map)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
483 (custom--initialize-widget-variables)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
484 (set (make-local-variable 'revert-buffer-function)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
485 (lambda (ignore-auto noconfirm)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
486 (when (or noconfirm (y-or-n-p "Discard current choices? "))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
487 (customize-themes (current-buffer))))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
488 (put 'custom-theme-choose-mode 'mode-class 'special)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
489
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
490 ;;;###autoload
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
491 (defun customize-themes (&optional buffer)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
492 "Display a selectable list of Custom themes.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
493 When called from Lisp, BUFFER should be the buffer to use; if
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
494 omitted, a buffer named *Custom Themes* is used."
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
495 (interactive)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
496 (pop-to-buffer (get-buffer-create (or buffer "*Custom Themes*")))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
497 (let ((inhibit-read-only t))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
498 (erase-buffer))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
499 (custom-theme-choose-mode)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
500 (set (make-local-variable 'custom--listed-themes) nil)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
501 (make-local-variable 'custom-theme-allow-multiple-selections)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
502 (and (null custom-theme-allow-multiple-selections)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
503 (> (length custom-enabled-themes) 1)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
504 (setq custom-theme-allow-multiple-selections t))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
505
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
506 (widget-insert
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
507 (substitute-command-keys
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
508 "Type RET or click to enable/disable listed custom themes.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
509 Type \\[custom-describe-theme] to describe the theme at point.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
510 Theme files are named *-theme.el in `"))
111016
fedd4f6fa7e5 Move built-in theme directory to etc/.
Chong Yidong <cyd@stupidchicken.com>
parents: 111013
diff changeset
511 (widget-create 'link :value "custom-theme-load-path"
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
512 :button-face 'custom-link
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
513 :mouse-face 'highlight
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
514 :pressed-face 'highlight
111016
fedd4f6fa7e5 Move built-in theme directory to etc/.
Chong Yidong <cyd@stupidchicken.com>
parents: 111013
diff changeset
515 :help-echo "Describe `custom-theme-load-path'."
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
516 :keymap custom-mode-link-map
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
517 :follow-link 'mouse-face
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
518 :action (lambda (widget &rest ignore)
111016
fedd4f6fa7e5 Move built-in theme directory to etc/.
Chong Yidong <cyd@stupidchicken.com>
parents: 111013
diff changeset
519 (describe-variable 'custom-theme-load-path)))
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
520 (widget-insert "'.\n\n")
111013
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
521
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
522 ;; If the user has made customizations, display a warning and
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
523 ;; provide buttons to disable or convert them.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
524 (let ((user-settings (get 'user 'theme-settings)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
525 (unless (or (null user-settings)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
526 (and (null (cdr user-settings))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
527 (eq (caar user-settings) 'theme-value)
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
528 (eq (cadr (car user-settings)) 'custom-enabled-themes)))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
529 (widget-insert "Note: Your custom settings take precedence over theme settings.\n\n")
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
530 ;; FIXME: Provide some way to painlessly disable or migrate
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
531 ;; these settings.
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
532 ))
5ffdb52c377c Bugfixes for `customize-create-theme'.
Chong Yidong <cyd@stupidchicken.com>
parents: 110955
diff changeset
533
110938
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
534 (widget-create 'push-button
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
535 :tag " Save Theme Settings "
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
536 :help-echo "Save the selected themes for future sessions."
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
537 :action 'custom-theme-save)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
538 (widget-insert ?\n)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
539 (widget-create 'checkbox
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
540 :value custom-theme-allow-multiple-selections
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
541 :action 'custom-theme-selections-toggle)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
542 (widget-insert (propertize " Allow more than one theme at a time"
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
543 'face '(variable-pitch (:height 0.9))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
544
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
545 (widget-insert "\n\nAvailable Custom Themes:\n")
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
546 (let (widget)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
547 (dolist (theme (custom-available-themes))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
548 (setq widget (widget-create 'checkbox
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
549 :value (custom-theme-enabled-p theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
550 :theme-name theme
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
551 :action 'custom-theme-checkbox-toggle))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
552 (push (cons theme widget) custom--listed-themes)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
553 (widget-create-child-and-convert widget 'push-button
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
554 :button-face-get 'ignore
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
555 :mouse-face-get 'ignore
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
556 :value (format " %s" theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
557 :action 'widget-parent-action)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
558 (widget-insert ?\n)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
559 (goto-char (point-min))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
560 (widget-setup))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
561
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
562 (defun custom-theme-checkbox-toggle (widget &optional event)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
563 (let ((this-theme (widget-get widget :theme-name)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
564 (if (widget-value widget)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
565 ;; Disable the theme.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
566 (disable-theme this-theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
567 ;; Enable the theme.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
568 (unless custom-theme-allow-multiple-selections
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
569 ;; If only one theme is allowed, disable all other themes and
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
570 ;; uncheck their boxes.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
571 (dolist (theme custom-enabled-themes)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
572 (and (not (eq theme this-theme))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
573 (assq theme custom--listed-themes)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
574 (disable-theme theme)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
575 (dolist (theme custom--listed-themes)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
576 (unless (eq (car theme) this-theme)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
577 (widget-value-set (cdr theme) nil)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
578 (widget-apply (cdr theme) :notify (cdr theme) event))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
579 (load-theme this-theme)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
580 ;; Mark `custom-enabled-themes' as "set for current session".
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
581 (put 'custom-enabled-themes 'customized-value
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
582 (list (custom-quote custom-enabled-themes)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
583 ;; Check/uncheck the widget.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
584 (widget-toggle-action widget event))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
585
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
586 (defun custom-describe-theme ()
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
587 "Describe the Custom theme on the current line."
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
588 (interactive)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
589 (let ((widget (widget-at (line-beginning-position))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
590 (and widget
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
591 (describe-theme (widget-get widget :theme-name)))))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
592
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
593 (defun custom-theme-save (&rest ignore)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
594 (interactive)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
595 (customize-save-variable 'custom-enabled-themes custom-enabled-themes)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
596 (message "Custom themes saved for future sessions."))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
597
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
598 (defun custom-theme-selections-toggle (widget &optional event)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
599 (when (widget-value widget)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
600 ;; Deactivate multiple-selections.
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
601 (if (> (length (delq nil (mapcar (lambda (x) (widget-value (cdr x)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
602 custom--listed-themes)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
603 1)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
604 (error "More than one theme is currently selected")))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
605 (widget-toggle-action widget event)
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
606 (setq custom-theme-allow-multiple-selections (widget-value widget)))
17bbe431e616 New interface for choosing Custom themes.
Chong Yidong <cyd@stupidchicken.com>
parents: 110896
diff changeset
607
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79721
diff changeset
608 ;; arch-tag: cd6919bc-63af-410e-bae2-b6702e762344
48952
ac7ebc63415a New file.
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 ;;; cus-theme.el ends here