aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2010-10-11 00:49:59 -0400
committerChong Yidong2010-10-11 00:49:59 -0400
commit05d22d02175330f9a9899d5daa431b1fdaf28470 (patch)
treeb1cf3b77165eb9c54e028b44eb96466ab6210c6f
parentdf187c6252439abcc958bbeb507344d6781b46e7 (diff)
downloademacs-05d22d02175330f9a9899d5daa431b1fdaf28470.tar.gz
emacs-05d22d02175330f9a9899d5daa431b1fdaf28470.zip
More cleanups and minor fixes for Customize.
* cus-edit.el (custom-face-edit-fix-value): Use custom-fix-face-spec. * custom.el (custom-push-theme): Cleanup (use cond). (disable-theme): Recompute the saved-face property. (custom-theme-recalc-face): Follow face alias before setting prop. * custom.el (custom-fix-face-spec): New function; code moved from custom-face-edit-fix-value. (custom-push-theme): Use it when checking if a face has been changed outside customize. (custom-available-themes): New function. (load-theme): Use it. * image.el (image-checkbox-checked, image-checkbox-unchecked): New variables, containing checkbox images. * startup.el (fancy-startup-tail): * wid-edit.el (checkbox): Use them.
-rw-r--r--lisp/ChangeLog22
-rw-r--r--lisp/cus-edit.el22
-rw-r--r--lisp/custom.el166
-rw-r--r--lisp/image.el15
-rw-r--r--lisp/startup.el32
-rw-r--r--lisp/wid-edit.el14
6 files changed, 167 insertions, 104 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index c2f222d4d9b..a4a9ab216a9 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,25 @@
12010-10-11 Chong Yidong <cyd@stupidchicken.com>
2
3 * custom.el (custom-fix-face-spec): New function; code moved from
4 custom-face-edit-fix-value.
5 (custom-push-theme): Use it when checking if a face has been
6 changed outside customize.
7 (custom-available-themes): New function.
8 (load-theme): Use it.
9
10 * cus-edit.el (custom-face-edit-fix-value): Use
11 custom-fix-face-spec.
12
13 * custom.el (custom-push-theme): Cleanup (use cond).
14 (disable-theme): Recompute the saved-face property.
15 (custom-theme-recalc-face): Follow face alias before setting prop.
16
17 * image.el (image-checkbox-checked, image-checkbox-unchecked): New
18 variables, containing checkbox images.
19
20 * startup.el (fancy-startup-tail):
21 * wid-edit.el (checkbox): Use them.
22
12010-10-10 Dan Nicolaescu <dann@ics.uci.edu> 232010-10-10 Dan Nicolaescu <dann@ics.uci.edu>
2 24
3 * shell.el (shell-mode-map): 25 * shell.el (shell-mode-map):
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 8a9775b0ebf..1b69d0c59b2 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -3102,27 +3102,7 @@ face attributes (as specified by a `default' defface entry)."
3102(defun custom-face-edit-fix-value (widget value) 3102(defun custom-face-edit-fix-value (widget value)
3103 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form. 3103 "Ignoring WIDGET, convert :bold and :italic in VALUE to new form.
3104Also change :reverse-video to :inverse-video." 3104Also change :reverse-video to :inverse-video."
3105 (if (listp value) 3105 (custom-fix-face-spec value))
3106 (let (result)
3107 (while value
3108 (let ((key (car value))
3109 (val (car (cdr value))))
3110 (cond ((eq key :italic)
3111 (push :slant result)
3112 (push (if val 'italic 'normal) result))
3113 ((eq key :bold)
3114 (push :weight result)
3115 (push (if val 'bold 'normal) result))
3116 ((eq key :reverse-video)
3117 (push :inverse-video result)
3118 (push val result))
3119 (t
3120 (push key result)
3121 (push val result))))
3122 (setq value (cdr (cdr value))))
3123 (setq result (nreverse result))
3124 result)
3125 value))
3126 3106
3127(defun custom-face-edit-convert-widget (widget) 3107(defun custom-face-edit-convert-widget (widget)
3128 "Convert :args as widget types in WIDGET." 3108 "Convert :args as widget types in WIDGET."
diff --git a/lisp/custom.el b/lisp/custom.el
index d6ecc6dfbd5..681b55f9178 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -819,48 +819,80 @@ See `custom-known-themes' for a list of known themes."
819 (setting (assq theme old)) ; '(theme value) 819 (setting (assq theme old)) ; '(theme value)
820 (theme-settings ; '(prop symbol theme value) 820 (theme-settings ; '(prop symbol theme value)
821 (get theme 'theme-settings))) 821 (get theme 'theme-settings)))
822 (if (eq mode 'reset) 822 (cond
823 ;; Remove a setting. 823 ;; Remove a setting:
824 (when setting 824 ((eq mode 'reset)
825 (let (res) 825 (when setting
826 (dolist (theme-setting theme-settings) 826 (let (res)
827 (if (and (eq (car theme-setting) prop) 827 (dolist (theme-setting theme-settings)
828 (eq (cadr theme-setting) symbol)) 828 (if (and (eq (car theme-setting) prop)
829 (setq res theme-setting))) 829 (eq (cadr theme-setting) symbol))
830 (put theme 'theme-settings (delq res theme-settings))) 830 (setq res theme-setting)))
831 (put symbol prop (delq setting old))) 831 (put theme 'theme-settings (delq res theme-settings)))
832 (if setting 832 (put symbol prop (delq setting old))))
833 ;; Alter an existing setting. 833 ;; Alter an existing setting:
834 (let (res) 834 (setting
835 (dolist (theme-setting theme-settings) 835 (let (res)
836 (if (and (eq (car theme-setting) prop) 836 (dolist (theme-setting theme-settings)
837 (eq (cadr theme-setting) symbol)) 837 (if (and (eq (car theme-setting) prop)
838 (setq res theme-setting))) 838 (eq (cadr theme-setting) symbol))
839 (put theme 'theme-settings 839 (setq res theme-setting)))
840 (cons (list prop symbol theme value) 840 (put theme 'theme-settings
841 (delq res theme-settings))) 841 (cons (list prop symbol theme value)
842 (setcar (cdr setting) value)) 842 (delq res theme-settings)))
843 ;; Add a new setting. 843 (setcar (cdr setting) value)))
844 ;; Add a new setting:
845 (t
846 (unless old
844 ;; If the user changed the value outside of Customize, we 847 ;; If the user changed the value outside of Customize, we
845 ;; first save the current value to a fake theme, `changed'. 848 ;; first save the current value to a fake theme, `changed'.
846 ;; This ensures that the user-set value comes back if the 849 ;; This ensures that the user-set value comes back if the
847 ;; theme is later disabled. 850 ;; theme is later disabled.
848 (if (null old) 851 (cond ((and (eq prop 'theme-value)
849 (if (and (eq prop 'theme-value) 852 (boundp symbol))
850 (boundp symbol)) 853 (let ((sv (get symbol 'standard-value)))
851 (let ((sv (get symbol 'standard-value))) 854 (unless (and sv
852 (unless (and sv 855 (equal (eval (car sv)) (symbol-value symbol)))
853 (equal (eval (car sv)) (symbol-value symbol))) 856 (setq old (list (list 'changed (symbol-value symbol)))))))
854 (setq old (list (list 'changed (symbol-value symbol)))))) 857 ((and (facep symbol)
855 (if (and (facep symbol) 858 (not (face-attr-match-p
856 (not (face-spec-match-p symbol (get symbol 'face-defface-spec)))) 859 symbol
857 (setq old (list (list 'changed (list 860 (custom-fix-face-spec
858 (append '(t) (custom-face-attributes-get symbol nil))))))))) 861 (face-spec-choose
859 (put symbol prop (cons (list theme value) old)) 862 (get symbol 'face-defface-spec))))))
860 (put theme 'theme-settings 863 (setq old `((changed
861 (cons (list prop symbol theme value) 864 (,(append '(t) (custom-face-attributes-get
862 theme-settings)))))) 865 symbol nil)))))))))
863 866 (put symbol prop (cons (list theme value) old))
867 (put theme 'theme-settings
868 (cons (list prop symbol theme value) theme-settings))))))
869
870(defun custom-fix-face-spec (spec)
871 "Convert face SPEC, replacing obsolete :bold and :italic attributes.
872Also change :reverse-video to :inverse-video."
873 (when (listp spec)
874 (if (or (memq :bold spec)
875 (memq :italic spec)
876 (memq :inverse-video spec))
877 (let (result)
878 (while spec
879 (let ((key (car spec))
880 (val (car (cdr spec))))
881 (cond ((eq key :italic)
882 (push :slant result)
883 (push (if val 'italic 'normal) result))
884 ((eq key :bold)
885 (push :weight result)
886 (push (if val 'bold 'normal) result))
887 ((eq key :reverse-video)
888 (push :inverse-video result)
889 (push val result))
890 (t
891 (push key result)
892 (push val result))))
893 (setq spec (cddr spec)))
894 (nreverse result))
895 spec)))
864 896
865(defun custom-set-variables (&rest args) 897(defun custom-set-variables (&rest args)
866 "Install user customizations of variable values specified in ARGS. 898 "Install user customizations of variable values specified in ARGS.
@@ -895,7 +927,7 @@ COMMENT is a comment string about SYMBOL.
895EXP itself is saved unevaluated as SYMBOL property `saved-value' and 927EXP itself is saved unevaluated as SYMBOL property `saved-value' and
896in SYMBOL's list property `theme-value' \(using `custom-push-theme')." 928in SYMBOL's list property `theme-value' \(using `custom-push-theme')."
897 (custom-check-theme theme) 929 (custom-check-theme theme)
898 930
899 ;; Process all the needed autoloads before anything else, so that the 931 ;; Process all the needed autoloads before anything else, so that the
900 ;; subsequent code has all the info it needs (e.g. which var corresponds 932 ;; subsequent code has all the info it needs (e.g. which var corresponds
901 ;; to a minor mode), regardless of the ordering of the variables. 933 ;; to a minor mode), regardless of the ordering of the variables.
@@ -1062,7 +1094,10 @@ property `theme-feature' (which is usually a symbol created by
1062This also enables the theme; use `disable-theme' to disable it." 1094This also enables the theme; use `disable-theme' to disable it."
1063 ;; Note we do no check for validity of the theme here. 1095 ;; Note we do no check for validity of the theme here.
1064 ;; This allows to pull in themes by a file-name convention 1096 ;; This allows to pull in themes by a file-name convention
1065 (interactive "SCustom theme name: ") 1097 (interactive
1098 (list
1099 (intern (completing-read "Load custom theme: "
1100 (mapcar 'symbol-name (custom-available-themes))))))
1066 ;; If reloading, clear out the old theme settings. 1101 ;; If reloading, clear out the old theme settings.
1067 (when (custom-theme-p theme) 1102 (when (custom-theme-p theme)
1068 (disable-theme theme) 1103 (disable-theme theme)
@@ -1073,6 +1108,21 @@ This also enables the theme; use `disable-theme' to disable it."
1073 (cons custom-theme-directory load-path) 1108 (cons custom-theme-directory load-path)
1074 load-path))) 1109 load-path)))
1075 (load (symbol-name (custom-make-theme-feature theme))))) 1110 (load (symbol-name (custom-make-theme-feature theme)))))
1111
1112(defun custom-available-themes ()
1113 (let* ((load-path (if (file-directory-p custom-theme-directory)
1114 (cons custom-theme-directory load-path)
1115 load-path))
1116 sym themes)
1117 (dolist (dir load-path)
1118 (dolist (file (file-expand-wildcards
1119 (expand-file-name "*-theme.el" dir) t))
1120 (setq file (file-name-nondirectory file))
1121 (and (string-match "\\`\\(.+\\)-theme.el\\'" file)
1122 (setq sym (intern (match-string 1 file)))
1123 (not (memq sym '(cus user changed color)))
1124 (push sym themes))))
1125 (delete-dups themes)))
1076 1126
1077;;; Enabling and disabling loaded themes. 1127;;; Enabling and disabling loaded themes.
1078 1128
@@ -1085,7 +1135,10 @@ If it is already enabled, just give it highest precedence (after `user').
1085 1135
1086If THEME does not specify any theme settings, this tries to load 1136If THEME does not specify any theme settings, this tries to load
1087the theme from its theme file, by calling `load-theme'." 1137the theme from its theme file, by calling `load-theme'."
1088 (interactive "SEnable Custom theme: ") 1138 (interactive (list (intern
1139 (completing-read
1140 "Enable custom theme: "
1141 obarray (lambda (sym) (get sym 'theme-settings))))))
1089 (if (not (custom-theme-p theme)) 1142 (if (not (custom-theme-p theme))
1090 (load-theme theme) 1143 (load-theme theme)
1091 ;; This could use a bit of optimization -- cyd 1144 ;; This could use a bit of optimization -- cyd
@@ -1143,21 +1196,28 @@ and always takes precedence over other Custom Themes."
1143See `custom-enabled-themes' for a list of enabled themes." 1196See `custom-enabled-themes' for a list of enabled themes."
1144 (interactive (list (intern 1197 (interactive (list (intern
1145 (completing-read 1198 (completing-read
1146 "Disable Custom theme: " 1199 "Disable custom theme: "
1147 (mapcar 'symbol-name custom-enabled-themes) 1200 (mapcar 'symbol-name custom-enabled-themes)
1148 nil t)))) 1201 nil t))))
1149 (when (custom-theme-enabled-p theme) 1202 (when (custom-theme-enabled-p theme)
1150 (let ((settings (get theme 'theme-settings))) 1203 (let ((settings (get theme 'theme-settings)))
1151 (dolist (s settings) 1204 (dolist (s settings)
1152 (let* ((prop (car s)) 1205 (let* ((prop (car s))
1153 (symbol (cadr s)) 1206 (symbol (cadr s))
1154 (spec-list (get symbol prop))) 1207 (val (assq-delete-all theme (get symbol prop))))
1155 (put symbol prop (assq-delete-all theme spec-list)) 1208 (put symbol prop val)
1156 (if (eq prop 'theme-value) 1209 (cond
1157 (custom-theme-recalc-variable symbol) 1210 ((eq prop 'theme-value)
1211 (custom-theme-recalc-variable symbol))
1212 ((eq prop 'theme-face)
1213 ;; If the face spec specified by this theme is in the
1214 ;; saved-face property, reset that property.
1215 (when (equal (nth 3 s) (get symbol 'saved-face))
1216 (put symbol 'saved-face
1217 (and val (cadr (car val)))))
1158 (custom-theme-recalc-face symbol))))) 1218 (custom-theme-recalc-face symbol)))))
1159 (setq custom-enabled-themes 1219 (setq custom-enabled-themes
1160 (delq theme custom-enabled-themes)))) 1220 (delq theme custom-enabled-themes)))))
1161 1221
1162(defun custom-variable-theme-value (variable) 1222(defun custom-variable-theme-value (variable)
1163 "Return (list VALUE) indicating the custom theme value of VARIABLE. 1223 "Return (list VALUE) indicating the custom theme value of VARIABLE.
@@ -1183,10 +1243,10 @@ This function returns nil if no custom theme specifies a value for VARIABLE."
1183 1243
1184(defun custom-theme-recalc-face (face) 1244(defun custom-theme-recalc-face (face)
1185 "Set FACE according to currently enabled custom themes." 1245 "Set FACE according to currently enabled custom themes."
1186 (if (facep face) 1246 (if (get face 'face-alias)
1187 (face-spec-set face 1247 (setq face (get face 'face-alias)))
1188 (get (or (get face 'face-alias) face) 1248 (face-spec-set face (get face 'face-override-spec)))
1189 'face-override-spec)))) 1249
1190 1250
1191;;; XEmacs compability functions 1251;;; XEmacs compability functions
1192 1252
diff --git a/lisp/image.el b/lisp/image.el
index 2ca2971b4aa..8dd88f627a1 100644
--- a/lisp/image.el
+++ b/lisp/image.el
@@ -721,7 +721,20 @@ shall be displayed."
721 (cons (concat "\\." extension "\\'") 'imagemagick) 721 (cons (concat "\\." extension "\\'") 'imagemagick)
722 image-type-file-name-regexps))))) 722 image-type-file-name-regexps)))))
723 723
724 724
725;;; Inline stock images
726
727(defvar image-checkbox-checked
728 (create-image "\300\300\141\143\067\076\034\030"
729 'xbm t :width 8 :height 8 :background "grey75"
730 :foreground "black" :relief -2 :ascent 'center)
731 "Image of a checked checkbox.")
732
733(defvar image-checkbox-unchecked
734 (create-image (make-string 8 0)
735 'xbm t :width 8 :height 8 :background "grey75"
736 :foreground "black" :relief -2 :ascent 'center)
737 "Image of an unchecked checkbox.")
725 738
726(provide 'image) 739(provide 'image)
727 740
diff --git a/lisp/startup.el b/lisp/startup.el
index c029eff54cf..aa791f2a04a 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1563,23 +1563,21 @@ a face or button specification."
1563 (kill-buffer "*GNU Emacs*"))) 1563 (kill-buffer "*GNU Emacs*")))
1564 " ") 1564 " ")
1565 (when (or user-init-file custom-file) 1565 (when (or user-init-file custom-file)
1566 (let ((checked (create-image "\300\300\141\143\067\076\034\030" 1566 (insert-button
1567 'xbm t :width 8 :height 8 :background "grey75" 1567 " "
1568 :foreground "black" :relief -2 :ascent 'center)) 1568 :on-glyph image-checkbox-checked
1569 (unchecked (create-image (make-string 8 0) 1569 :off-glyph image-checkbox-unchecked
1570 'xbm t :width 8 :height 8 :background "grey75" 1570 'checked nil 'display image-checkbox-unchecked 'follow-link t
1571 :foreground "black" :relief -2 :ascent 'center))) 1571 'action (lambda (button)
1572 (insert-button 1572 (if (overlay-get button 'checked)
1573 " " :on-glyph checked :off-glyph unchecked 'checked nil 1573 (progn (overlay-put button 'checked nil)
1574 'display unchecked 'follow-link t 1574 (overlay-put button 'display
1575 'action (lambda (button) 1575 (overlay-get button :off-glyph))
1576 (if (overlay-get button 'checked) 1576 (setq startup-screen-inhibit-startup-screen nil))
1577 (progn (overlay-put button 'checked nil) 1577 (overlay-put button 'checked t)
1578 (overlay-put button 'display (overlay-get button :off-glyph)) 1578 (overlay-put button 'display
1579 (setq startup-screen-inhibit-startup-screen nil)) 1579 (overlay-get button :on-glyph))
1580 (overlay-put button 'checked t) 1580 (setq startup-screen-inhibit-startup-screen t))))
1581 (overlay-put button 'display (overlay-get button :on-glyph))
1582 (setq startup-screen-inhibit-startup-screen t)))))
1583 (fancy-splash-insert :face '(variable-pitch (:height 0.9)) 1581 (fancy-splash-insert :face '(variable-pitch (:height 0.9))
1584 " Never show it again."))))) 1582 " Never show it again.")))))
1585 1583
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index a6dca41bc28..3b9a0372de5 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -2195,19 +2195,9 @@ when he invoked the menu."
2195 ;; We could probably do the same job as the images using single 2195 ;; We could probably do the same job as the images using single
2196 ;; space characters in a boxed face with a stretch specification to 2196 ;; space characters in a boxed face with a stretch specification to
2197 ;; make them square. 2197 ;; make them square.
2198 :on-glyph '(create-image "\300\300\141\143\067\076\034\030" 2198 :on-glyph image-checkbox-checked
2199 'xbm t :width 8 :height 8
2200 :background "grey75" ; like default mode line
2201 :foreground "black"
2202 :relief -2
2203 :ascent 'center)
2204 :off "[ ]" 2199 :off "[ ]"
2205 :off-glyph '(create-image (make-string 8 0) 2200 :off-glyph image-checkbox-unchecked
2206 'xbm t :width 8 :height 8
2207 :background "grey75"
2208 :foreground "black"
2209 :relief -2
2210 :ascent 'center)
2211 :help-echo "Toggle this item." 2201 :help-echo "Toggle this item."
2212 :action 'widget-checkbox-action) 2202 :action 'widget-checkbox-action)
2213 2203