;;============================================================================= ;; ;; custom-faces-file: Makes customize save face customizations into a ;; different file whose location is specified by the custom-save-faces ;; variable. ;; ;; Why I wrote this: ;; ;; - I want my variable customizations in one file. ;; ;; - I want a separate face customization file for each different kind of ;; display: terminal, emacsw32, x, etc. ;; ;; - I find the interface that Customize uses to allow you to set different ;; attributes for different kinds of displays horrid. ;; ;;============================================================================= ;; ;; HOW TO USE ;; ;; Just put this file in your emacs library directory and add this line to ;; your ~/.emacs: ;; ;; (require 'custom-faces-file) ;; ;; Next, you want to set the custom-faces-file variable to something, then ;; load the file it points to. ;; ;; A simple example: ;; (setq custom-faces-file "~/.emacs-custom-faces.el") ;; (load custom-faces-file) ;; ;; A more complex example: ;; (cond ((eq window-system 'x) ;; (setq custom-faces-file "~/.emacs-custom-faces-x.el")) ;; ((eq window-system nil) ;; (setq custom-faces-file "~/.emacs-custom-faces-term.el"))) ;; (load custom-faces-file) ;; ;;============================================================================= ;; ;; This is rough draft code. Consider it GPL2-licensed. I'll deal with ;; formalities and documentation conventions and such later. ;) ;; ;; AUTHOR: Darren Embry -- dse at webonastick dot com ;; ;;============================================================================= ;; ;; NOTES: this relies on certain internal implementation details of emacs22's ;; customize functionality: ;; ;; - that the custom-save-all function uses the return value of the ;; (custom-file) function [which will be based on the value of the ;; custom-file variable] to determine the location of the custom file, loads ;; it into a buffer, then calls (custom-save-variables), then calls ;; (custom-save-faces). ;; ;; - That the custom-save-variables and custom-save-faces functions modify and ;; save the aforementioned buffer. ;; ;; - that the custom-file function uses the value of the custom-file variable ;; as the basis of its return value. ;; ;;============================================================================= (defvar is-saving-custom-faces-file-only nil "If set to t, indicates that only face customizations are being written. This variable is not intended to be set by users.") (defvar is-saving-custom-variables-file-only nil "If set to t, indicates that only variable customizations are being written. This variable is not intended to be set by users.") (defvar custom-faces-file nil "File used for storing face customization information. If set, `custom-file' only stores variable customizations. If nil, all customizations are stored in `custom-file'.") (defun setup-custom-faces-file () "Advise customize to store variables and faces in different files. See the `custom-faces-file' variable." (defadvice custom-file (around custom-file--custom-faces-file) (cond (is-saving-custom-faces-file-only (if custom-faces-file (let ((custom-file custom-faces-file)) ad-do-it) ad-do-it)) (is-saving-custom-variables-file-only ad-do-it) (t ad-do-it))) (defadvice custom-save-variables (around custom-save-variables--custom-faces-file) (if (not is-saving-custom-faces-file-only) ad-do-it)) (defadvice custom-save-faces (around custom-save-faces--custom-faces-file) (if (not is-saving-custom-variables-file-only) ad-do-it)) (defadvice custom-save-all (around custom-save-all--custom-faces-file) (if custom-faces-file (progn (let ((is-saving-custom-variables-file-only t)) ;; so custom-save-variables runs, but custom-save-faces doesn't. ad-do-it) (let ((is-saving-custom-faces-file-only t)) ;; so custom-save-faces runs, but custom-save-variables doesn't. ad-do-it)) ad-do-it)) (activate-custom-faces-file-advice)) (defun activate-custom-faces-file-advice () (ad-activate 'custom-file) (ad-activate 'custom-save-variables) (ad-activate 'custom-save-faces) (ad-activate 'custom-save-all)) (defun disable-custom-faces-file-advice () (interactive) (ad-disable-regexp "--custom-faces-file$") (activate-custom-faces-file-advice)) (defun enable-custom-faces-file-advice () (interactive) (ad-enable-regexp "--custom-faces-file$") (activate-custom-faces-file-advice)) (if (>= emacs-major-version 22) (setup-custom-faces-file)) (provide 'custom-faces-file)