aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBasil L. Contovounesios2018-05-31 18:37:02 +0100
committerStefan Monnier2018-07-13 11:28:16 -0400
commitb16f08015f69ecb1e665411533e6f8b64ccb847e (patch)
tree8742ee0308de48c6088fde821cec5e4469fe36f3
parentfeb6863e64a94466af867d63c1e8fef4cc5e84fc (diff)
downloademacs-b16f08015f69ecb1e665411533e6f8b64ccb847e.tar.gz
emacs-b16f08015f69ecb1e665411533e6f8b64ccb847e.zip
Minor custom.el simplifications
* lisp/custom.el (custom-quote): Duplicate macroexp-quote. (custom-load-symbol, customize-mark-to-save, customize-mark-as-set) (custom-theme-name-valid-p, enable-theme, custom-enabled-themes) (disable-theme): Simplify logic.
-rw-r--r--lisp/custom.el103
1 files changed, 46 insertions, 57 deletions
diff --git a/lisp/custom.el b/lisp/custom.el
index 1c667c8aa2d..a08f7fda705 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -630,14 +630,12 @@ The result is that the change is treated as having been made through Custom."
630 (let ((custom-load-recursion t)) 630 (let ((custom-load-recursion t))
631 ;; Load these files if not already done, 631 ;; Load these files if not already done,
632 ;; to make sure we know all the dependencies of SYMBOL. 632 ;; to make sure we know all the dependencies of SYMBOL.
633 (condition-case nil 633 (ignore-errors
634 (require 'cus-load) 634 (require 'cus-load))
635 (error nil)) 635 (ignore-errors
636 (condition-case nil 636 (require 'cus-start))
637 (require 'cus-start)
638 (error nil))
639 (dolist (load (get symbol 'custom-loads)) 637 (dolist (load (get symbol 'custom-loads))
640 (cond ((symbolp load) (condition-case nil (require load) (error nil))) 638 (cond ((symbolp load) (ignore-errors (require load)))
641 ;; This is subsumed by the test below, but it's much faster. 639 ;; This is subsumed by the test below, but it's much faster.
642 ((assoc load load-history)) 640 ((assoc load load-history))
643 ;; This was just (assoc (locate-library load) load-history) 641 ;; This was just (assoc (locate-library load) load-history)
@@ -655,7 +653,7 @@ The result is that the change is treated as having been made through Custom."
655 ;; We are still loading it when we call this, 653 ;; We are still loading it when we call this,
656 ;; and it is not in load-history yet. 654 ;; and it is not in load-history yet.
657 ((equal load "cus-edit")) 655 ((equal load "cus-edit"))
658 (t (condition-case nil (load load) (error nil)))))))) 656 (t (ignore-errors (load load))))))))
659 657
660(defvar custom-local-buffer nil 658(defvar custom-local-buffer nil
661 "Non-nil, in a Customization buffer, means customize a specific buffer. 659 "Non-nil, in a Customization buffer, means customize a specific buffer.
@@ -688,16 +686,12 @@ this sets the local binding in that buffer instead."
688 686
689(defun custom-quote (sexp) 687(defun custom-quote (sexp)
690 "Quote SEXP if it is not self quoting." 688 "Quote SEXP if it is not self quoting."
691 (if (or (memq sexp '(t nil)) 689 ;; Can't use `macroexp-quote' because it is loaded after `custom.el'
692 (keywordp sexp) 690 ;; during bootstrap. See `loadup.el'.
693 (and (listp sexp) 691 (if (and (not (consp sexp))
694 (memq (car sexp) '(lambda))) 692 (or (keywordp sexp)
695 (stringp sexp) 693 (not (symbolp sexp))
696 (numberp sexp) 694 (booleanp sexp)))
697 (vectorp sexp)
698;;; (and (fboundp 'characterp)
699;;; (characterp sexp))
700 )
701 sexp 695 sexp
702 (list 'quote sexp))) 696 (list 'quote sexp)))
703 697
@@ -718,12 +712,10 @@ Return non-nil if the `saved-value' property actually changed."
718 (standard (get symbol 'standard-value)) 712 (standard (get symbol 'standard-value))
719 (comment (get symbol 'customized-variable-comment))) 713 (comment (get symbol 'customized-variable-comment)))
720 ;; Save default value if different from standard value. 714 ;; Save default value if different from standard value.
721 (if (or (null standard) 715 (put symbol 'saved-value
722 (not (equal value (condition-case nil 716 (unless (and standard
723 (eval (car standard)) 717 (equal value (ignore-errors (eval (car standard)))))
724 (error nil))))) 718 (list (custom-quote value))))
725 (put symbol 'saved-value (list (custom-quote value)))
726 (put symbol 'saved-value nil))
727 ;; Clear customized information (set, but not saved). 719 ;; Clear customized information (set, but not saved).
728 (put symbol 'customized-value nil) 720 (put symbol 'customized-value nil)
729 ;; Save any comment that might have been set. 721 ;; Save any comment that might have been set.
@@ -747,9 +739,8 @@ Return non-nil if the `customized-value' property actually changed."
747 (old (or (get symbol 'saved-value) (get symbol 'standard-value)))) 739 (old (or (get symbol 'saved-value) (get symbol 'standard-value))))
748 ;; Mark default value as set if different from old value. 740 ;; Mark default value as set if different from old value.
749 (if (not (and old 741 (if (not (and old
750 (equal value (condition-case nil 742 (equal value (ignore-errors
751 (eval (car old)) 743 (eval (car old))))))
752 (error nil)))))
753 (progn (put symbol 'customized-value (list (custom-quote value))) 744 (progn (put symbol 'customized-value (list (custom-quote value)))
754 (custom-push-theme 'theme-value symbol 'user 'set 745 (custom-push-theme 'theme-value symbol 'user 'set
755 (custom-quote value))) 746 (custom-quote value)))
@@ -1296,11 +1287,9 @@ query also about adding HASH to `custom-safe-themes'."
1296(defun custom-theme-name-valid-p (name) 1287(defun custom-theme-name-valid-p (name)
1297 "Return t if NAME is a valid name for a Custom theme, nil otherwise. 1288 "Return t if NAME is a valid name for a Custom theme, nil otherwise.
1298NAME should be a symbol." 1289NAME should be a symbol."
1299 (and (symbolp name) 1290 (and (not (memq name '(nil user changed)))
1300 name 1291 (symbolp name)
1301 (not (or (zerop (length (symbol-name name))) 1292 (not (string= "" (symbol-name name)))))
1302 (eq name 'user)
1303 (eq name 'changed)))))
1304 1293
1305(defun custom-available-themes () 1294(defun custom-available-themes ()
1306 "Return a list of Custom themes available for loading. 1295 "Return a list of Custom themes available for loading.
@@ -1356,8 +1345,8 @@ function runs. To disable other themes, use `disable-theme'."
1356 (completing-read 1345 (completing-read
1357 "Enable custom theme: " 1346 "Enable custom theme: "
1358 obarray (lambda (sym) (get sym 'theme-settings)) t)))) 1347 obarray (lambda (sym) (get sym 'theme-settings)) t))))
1359 (if (not (custom-theme-p theme)) 1348 (unless (custom-theme-p theme)
1360 (error "Undefined Custom theme %s" theme)) 1349 (error "Undefined Custom theme %s" theme))
1361 (let ((settings (get theme 'theme-settings))) 1350 (let ((settings (get theme 'theme-settings)))
1362 ;; Loop through theme settings, recalculating vars/faces. 1351 ;; Loop through theme settings, recalculating vars/faces.
1363 (dolist (s settings) 1352 (dolist (s settings)
@@ -1397,18 +1386,18 @@ Setting this variable through Customize calls `enable-theme' or
1397 (let (failures) 1386 (let (failures)
1398 (setq themes (delq 'user (delete-dups themes))) 1387 (setq themes (delq 'user (delete-dups themes)))
1399 ;; Disable all themes not in THEMES. 1388 ;; Disable all themes not in THEMES.
1400 (if (boundp symbol) 1389 (dolist (theme (and (boundp symbol)
1401 (dolist (theme (symbol-value symbol)) 1390 (symbol-value symbol)))
1402 (if (not (memq theme themes)) 1391 (unless (memq theme themes)
1403 (disable-theme theme)))) 1392 (disable-theme theme)))
1404 ;; Call `enable-theme' or `load-theme' on each of THEMES. 1393 ;; Call `enable-theme' or `load-theme' on each of THEMES.
1405 (dolist (theme (reverse themes)) 1394 (dolist (theme (reverse themes))
1406 (condition-case nil 1395 (condition-case nil
1407 (if (custom-theme-p theme) 1396 (if (custom-theme-p theme)
1408 (enable-theme theme) 1397 (enable-theme theme)
1409 (load-theme theme)) 1398 (load-theme theme))
1410 (error (setq failures (cons theme failures) 1399 (error (push theme failures)
1411 themes (delq theme themes))))) 1400 (setq themes (delq theme themes)))))
1412 (enable-theme 'user) 1401 (enable-theme 'user)
1413 (custom-set-default symbol themes) 1402 (custom-set-default symbol themes)
1414 (when failures 1403 (when failures
@@ -1441,23 +1430,23 @@ See `custom-enabled-themes' for a list of enabled themes."
1441 ;; If the face spec specified by this theme is in the 1430 ;; If the face spec specified by this theme is in the
1442 ;; saved-face property, reset that property. 1431 ;; saved-face property, reset that property.
1443 (when (equal (nth 3 s) (get symbol 'saved-face)) 1432 (when (equal (nth 3 s) (get symbol 'saved-face))
1444 (put symbol 'saved-face (and val (cadr (car val))))))))) 1433 (put symbol 'saved-face (cadar val))))))))
1445 ;; Recompute faces on all frames. 1434 ;; Recompute faces on all frames.
1446 (dolist (frame (frame-list)) 1435 (dolist (frame (frame-list))
1447 ;; We must reset the fg and bg color frame parameters, or 1436 ;; We must reset the fg and bg color frame parameters, or
1448 ;; `face-set-after-frame-default' will use the existing 1437 ;; `face-set-after-frame-default' will use the existing
1449 ;; parameters, which could be from the disabled theme. 1438 ;; parameters, which could be from the disabled theme.
1450 (set-frame-parameter frame 'background-color 1439 (set-frame-parameter frame 'background-color
1451 (custom--frame-color-default 1440 (custom--frame-color-default
1452 frame :background "background" "Background" 1441 frame :background "background" "Background"
1453 "unspecified-bg" "white")) 1442 "unspecified-bg" "white"))
1454 (set-frame-parameter frame 'foreground-color 1443 (set-frame-parameter frame 'foreground-color
1455 (custom--frame-color-default 1444 (custom--frame-color-default
1456 frame :foreground "foreground" "Foreground" 1445 frame :foreground "foreground" "Foreground"
1457 "unspecified-fg" "black")) 1446 "unspecified-fg" "black"))
1458 (face-set-after-frame-default frame)) 1447 (face-set-after-frame-default frame))
1459 (setq custom-enabled-themes 1448 (setq custom-enabled-themes
1460 (delq theme custom-enabled-themes))))) 1449 (delq theme custom-enabled-themes))))
1461 1450
1462;; Only used if window-system not null. 1451;; Only used if window-system not null.
1463(declare-function x-get-resource "frame.c" 1452(declare-function x-get-resource "frame.c"