1. 程式人生 > >儲存一下emacs中安裝color-theme的lisp原始碼

儲存一下emacs中安裝color-theme的lisp原始碼

 ;;; color-theme.el --- install color themes
 
;; Copyright (C) 1999, 2000  Jonadab the Unsightly One <[email protected]>
;; Copyright (C) 2000, 2001, 2002, 2003  Alex Schroeder <[email protected]>
;; Copyright (C) 2003, 2004  Xavier Maillard <[email protected]>
 
;; Version: 6.5.5
;; Keywords: faces
;; Author: Jonadab the Unsightly One <
[email protected]
>
;; Maintainer: Xavier Maillard <[email protected]>
;; URL: http://www.emacswiki.org/cgi-bin/wiki.pl?ColorTheme
 
;; This file is not part of GNU Emacs.
 
;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.
 
;;; Commentary:
 
;; Sharing your current color setup:
;;
;; Use `color-theme-submit'.  If you have already invested time in
;; customizing Emacs faces, please consider sharing your current setup.
;; Make sure that color-theme.el is in your `load-path'.  Type M-x
;; load-library RET color-theme RET to load all the functions.  Type M-x
;; color-theme-submit RET and mail the result to the maintainer of this
;; package (see above for mail addres).
;;
;; If you want to make sure that all your customization was exported,
;; type M-x list-faces-display RET to get a list of all faces currently
;; defined.  This is the list of faces that `color-theme-print' uses.
 
;; Installing a color theme:
;;
;; Make sure that color-theme.el is in your `load-path'.  Type M-x
;; load-library RET color-theme RET to load all the functions.
;;
;; The main function to call is color-theme-select.  Type M-x
;; color-theme-select RET.  That creates a Color Theme Selection
;; buffer.  Press RET or `i' on a color theme to install it for the
;; rest of your session.
;;
;; If you want to install the color theme as soon as Emacs is started
;; up, read the description of the theme you like and remember the
;; name of the color theme function.  Press `d' on a color theme in
;; the Color Theme Selection buffer to read the description.  Assuming
;; you like the Gnome2 theme, you'll find that the function to use is
;; called `color-theme-gnome2'.  Add the following to the end of your
;; .emacs (removing the leading `;;').
;;
;; (require 'color-theme)
;; (color-theme-gnome2)
 
;; Changing menu colors:
;;
;; In Emacs 21 on X, you can set the menu colors and font using the
;; menu face.  Example for your .emacs file:
;;
;;   (set-face-font 'menu "7x14")
;;   (set-face-foreground 'menu "white").
;;
;; If are using X, you can set the menu foreground and background using
;; a resource file, usually .Xdefaults or .Xresources.  Usually
;; .Xdefaults is used when you start your session using a display
;; manager such as xdm or gdm.  .Xresources is usually used when you
;; start X directly via a shell script such as startx.  If you set
;; Emacs*Background and Emacs*Foreground in such a resource file, the
;; foreground and background of Emacs including the menu will be set.
;; If your .emacs then loads a color theme, the foreground and
;; background are changed -- with the exception of the menu.  There is
;; no way to manipulate the menu foreground and background color from
;; elisp.  You can also set more specific menu resources for Emacs in
;; the resource file.  Here is a sample entry for your resource file:
;;
;;   Emacs*Background:        DarkSlateGray
;;   Emacs*Foreground:        wheat
 
;; Creating your own color theme:
;;
;; Use M-x customize-face and customize the faces.  Make sure to "Set
;; for Current Session" -- you don't want to save these using custom!
;; When you are done, call M-x color-theme-print to produce the elisp
;; code required to recreate your theme.  Better yet, use M-x
;; color-theme-submit to mail it to the maintainer.  That way it will be
;; added to future versions of color-theme.el.
;;
;; For more information on the elisp format of a color theme, start with
;; the documentation of `color-theme-install' using C-h f
;; color-theme-install.
;;
;; When your color theme is just a variation of an existing color theme,
;; take a look at `color-theme-robin-hood' in order to see an example of
;; how to do it.  Essentially you want to call all the parent color
;; themes before installing your changes.  For all but the first parent
;; color theme, you need to make sure that `color-theme-is-cumulative'
;; is bound to t.  If you don't do that, users that set
;; `color-theme-is-cumulative' to nil will only install your changes
;; without the parent color themes.
 
;; Making a color theme work for both Emacs and XEmacs:
;;
;; Once you have printed the color-theme, you can make sure it looks
;; similar in both Emacs and XEmacs by running
;; `color-theme-analyze-defun' on the printed theme.  This function
;; will check for missing faces for the other editor...
 
;;; Thanks
 
;; Deepak Goel  <
[email protected]
>
;; S. Pokrovsky <[email protected]> for ideas and discussion.
;; Gordon Messmer <[email protected]> for ideas and discussion.
;; Sriram Karra <[email protected]> for the color-theme-submit stuff.
;; Olgierd `Kingsajz' Ziolko <[email protected]
> for the spec-filter idea.
;; All the users that contributed their color themes.
 
;;; Bugs:
 
;; Emacs 20.7: Some faces are created using copy-face; these faces are
;; not printed correctly using M-x color-theme-print.  They will have
;; (nil) in their spec.  M-x customize-face has the same problem.
;; Example:
;; (copy-face 'bold 'new-bold)
;; (color-theme-spec 'bold)
;;   => (bold ((t (:bold t))))
;; (color-theme-spec 'new-bold)
;;   => (new-bold ((t (nil))))
;;
;; XEmacs 21.1: Some faces are defined using a certain font instead of
;; of the correct attribute.  They will have (nil) in their spec.
;; M-x customize-face has the same problem.
;; Example:
;; (color-theme-spec 'bold)
;;   => (bold ((t (nil))))
;;
;; XEmacs 21.2 and up, Emacs 21: Not compatible with the custom-theme
;; mode.  It should be easy to transform the color-theme source into
;; custom-theme source, however.
;;
;; If you are running XEmacs, then only foreground and background color
;; of the default face and only the background color of the text-cursor
;; face will used.  This is due to the fact that these three pieces of
;; information are stored as frame parameters in Emacs.
;;
;; If you are running XEmacs, variables cannot have a frame-local
;; binding.  Therefore, if color-theme-is-global is set to nil, the
;; variable settings in a color theme are ignored.
;;
;; Using Emacs and a non-nil value for color-theme-is-global will
;; install a new color theme for all frames.  Using XEmacs and a non-nil
;; value for color-theme-is-global will install a new color theme only
;; on those frames that are not using a local color theme.
;;
;; If your system does not define the color names used, you will get the
;; error "undefined color".  See the output of `list-colors-display' for
;; a list of colors defined on your display.
;;
;; The :box, :height, and other new attributes will be honored in Emacs
;; 21, but when you print such a color-theme on Emacs 20 or XEmacs 21,
;; the information will get lost.  So don't do that.  Furthermore,
;; customizing these faces may end up showing you a lisp expression
;; instead of the real widgets on Emacs 20 or XEmacs 21 because these
;; attributes are not understood.
;;
;; :inverse-video handling differs in Emacs and XEmacs.  We therefore do
;; away with it.  When printing a color-theme, the inverse-video
;; attribute should be handled correctly without ever appearing in color
;; themes.  For maintenance, the following might be usefull for
;; query-replace-regexp.
;; :background "/([^"]*/)"/(.*/):foreground "/([^"]*/)"/(.*/) :inverse-video t
;; :background "/3"/2:foreground "/1"/4
;;
;; In XEmacs 21.1, some of the face tests don't work.  Example:
;; (custom-face-bold 'bold) returns nil on my system.  A bug report was
;; submitted.
;;
;; Emacs 20 users will loose with new color themes, because these will
;; set the colors of the default face only, leaving frame background
;; untouched.  In Emacs 20, the colors of the default face and of the
;; frame could be changed independently.  In Emacs 21, this is no longer
;; true.  New color themes will not be made backwards compatible.
;;
;; This release was superficially tested with Emacs 21.2 and XEmacs 21.4.
 

 
;;; Code:
 
(require 'cl); set-difference is a function...
 
;; for custom-face-attributes-get or face-custom-attributes-get
(require 'cus-face)
(require 'wid-edit); for widget-apply stuff in cus-face.el
 
(defconst color-theme-maintainer-address "[email protected]"
  "Address used by `submit-color-theme'.")
 
;; Emacs / XEmacs compatibility and workaround layer
 
(cond ((and (facep 'tool-bar)
        (not (facep 'toolbar)))
       (put 'toolbar 'face-alias 'tool-bar))
      ((and (facep 'toolbar)
        (not (facep 'tool-bar)))
       (put 'tool-bar 'face-alias 'toolbar)))
 
(defvar color-theme-xemacs-p (string-match "XEmacs" emacs-version)
  "Non-nil if running XEmacs.")
 
;; face-attr-construct has a problem in Emacs 20.7 and older when
;; dealing with inverse-video faces.  Here is a short test to check
;; wether you are affected.
 
;; (set-background-color "wheat")
;; (set-foreground-color "black")
;; (setq a (make-face 'a-face))
;; (face-spec-set a '((t (:background "white" :foreground "black" :inverse-video t))))
;; (face-attr-construct a)
;;     => (:background "black" :inverse-video t)
 
;; The expected response is the original specification:
;;     => (:background "white" :foreground "black" :inverse-video t)
 
;; That's why we depend on cus-face.el functionality.
 
(cond ((fboundp 'custom-face-attributes-get)
       (defalias 'color-theme-face-attr-construct
     'custom-face-attributes-get))
      ((fboundp 'face-custom-attributes-get)
       (defalias 'color-theme-face-attr-construct
     'face-custom-attributes-get))
      (t
       (defun color-theme-face-attr-construct (&rest ignore)
     (error "Unable to construct face attributes"))))
 
(defun color-theme-alist (plist)
  "Transform PLIST into an alist if it is a plist and return it.
If the first element of PLIST is a cons cell, we just return PLIST,
assuming PLIST to be an alist.  If the first element of plist is not a
symbol, this is an error: We cannot distinguish a plist from an ordinary
list, but a list that doesn't start with a symbol is certainly no plist
and no alist.
 
This is used to make sure `default-frame-alist' really is an alist and not
a plist.  In XEmacs, the alist is deprecated; a plist is used instead."
  (cond ((consp (car plist))
     plist)
    ((not (symbolp (car plist)))
     (error "Wrong type argument: plist, %S" plist))
    (t
     (plist-to-alist plist)))); XEmacs only
 
;; Customization
 
(defgroup color-theme nil
  "Color Themes for Emacs.
A color theme consists of frame parameter settings, variable settings,
and face definitions."
  :version "20.6"
  :group 'faces)
 
(defcustom color-theme-legal-frame-parameters "//(color//|mode//)$"
  "Regexp that matches frame parameter names.
Only frame parameter names that match this regexp can be changed as part
of a color theme."
  :type '(choice (const :tag "Colors only" "//(color//|mode//)$")
         (const :tag "Colors, fonts, and size"
            "//(color//|mode//|font//|height//|width//)$")
         (regexp :tag "Custom regexp"))
  :group 'color-theme
  :link '(info-link "(elisp)Window Frame Parameters"))
 
(defcustom color-theme-legal-variables "//(color//|face//)$"
  "Regexp that matches variable names.
Only variables that match this regexp can be changed as part of a color
theme.  In addition to matching this name, the variables have to be user
variables (see function `user-variable-p')."
  :type 'regexp
  :group 'color-theme)
 
(defcustom color-theme-illegal-faces "^w3-"
  "Regexp that matches face names forbidden in themes.
The default setting /"^w3-/" excludes w3 faces since these
are created dynamically."
  :type 'regexp
  :group 'color-theme
  :link '(info-link "(elisp)Faces for Font Lock")
  :link '(info-link "(elisp)Standard Faces"))
 
(defcustom color-theme-illegal-default-attributes '(:family :height :width)
  "A list of face properties to be ignored when installing faces.
This prevents Emacs from doing terrible things to your display just because
a theme author likes weird fonts."
  :type '(repeat symbol)
  :group 'color-theme)
 
(defcustom color-theme-is-global t
  "*Determines wether a color theme is installed on all frames or not.
If non-nil, color themes will be installed for all frames.
If nil, color themes will be installed for the selected frame only.
 
A possible use for this variable is dynamic binding. Here is a larger
example to put in your ~/.emacs; it will make the Blue Sea color theme
the default used for the first frame, and it will create two additional
frames with different color themes.
 
setup:
    /(require 'color-theme)
    ;; set default color theme
    /(color-theme-blue-sea)
    ;; create some frames with different color themes
    /(let ((color-theme-is-global nil))
      /(select-frame (make-frame))
      /(color-theme-gnome2)
      /(select-frame (make-frame))
      /(color-theme-standard))
 
Please note that using XEmacs and and a nil value for
color-theme-is-global will ignore any variable settings for the color
theme, since XEmacs doesn't have frame-local variable bindings.
 
Also note that using Emacs and a non-nil value for color-theme-is-global
will install a new color theme for all frames.  Using XEmacs and a
non-nil value for color-theme-is-global will install a new color theme
only on those frames that are not using a local color theme."
  :type 'boolean
  :group 'color-theme)
 
(defcustom color-theme-is-cumulative t
  "*Determines wether new color themes are installed on top of each other.
If non-nil, installing a color theme will undo all settings made by
previous color themes."
  :type 'boolean
  :group 'color-theme)
 
(defcustom color-theme-mode-hook nil
  "Hook for color-theme-mode."
  :type 'hook
  :group 'color-theme)
 
(defvar color-theme-mode-map
  (let ((map (make-sparse-keymap)))
    (define-key map (kbd "RET") 'color-theme-install-at-point)
    (define-key map (kbd "c") 'list-colors-display)
    (define-key map (kbd "d") 'color-theme-describe)
    (define-key map (kbd "f") 'list-faces-display)
    (define-key map (kbd "i") 'color-theme-install-at-point)
    (define-key map (kbd "l") 'color-theme-install-at-point-for-current-frame)
    (define-key map (kbd "p") 'color-theme-print)
    (define-key map (kbd "q") 'bury-buffer)
    (define-key map (kbd "?") 'color-theme-describe)
    (if color-theme-xemacs-p
    (define-key map (kbd "<button2>") 'color-theme-install-at-mouse)
      (define-key map (kbd "<mouse-2>") 'color-theme-install-at-mouse))
    map)
  "Mode map used for the buffer created by `color-theme-select'.")
 
(defvar color-theme-buffer-name "*Color Theme Selection*"
  "Name of the color theme selection buffer.")
 
(defvar color-theme-original-frame-alist nil
  "nil until one of the color themes has been installed.")
 
(defvar color-theme-history nil
  "List of color-themes called, in reverse order")
 
(defcustom color-theme-history-max-length nil
  "Max length of history to maintain.
Two other values are acceptable: t means no limit, and
nil means that no history is maintained."
  :type '(choice (const :tag "No history" nil)
         (const :tag "Unlimited length" t)
         integer)
  :group 'color-theme)
 
(defvar color-theme-counter 0
  "Counter for every addition to `color-theme-history'.
This counts how many themes were installed, regardless
of `color-theme-history-max-length'.")
 
(defun color-theme-add-to-history (name)
  "Add color-theme NAME to `color-theme-history'."
  (setq color-theme-history
    (cons (list name color-theme-is-cumulative)
          color-theme-history)
    color-theme-counter (+ 1 color-theme-counter))
  ;; Truncate the list if necessary.
  (when (and (integerp color-theme-history-max-length)
         (>= (length color-theme-history)
         color-theme-history-max-length))
    (setcdr (nthcdr (1- color-theme-history-max-length)
            color-theme-history)
        nil)))
 
;; (let ((l '(1 2 3 4 5)))
;;   (setcdr (nthcdr 2 l) nil)
;;   l)
 

 
;; List of color themes used to create the *Color Theme Selection*
;; buffer.
 
(defvar color-themes
  '((color-theme-aalto-dark "Aalto Dark" "Jari Aalto <[email protected]>")
    (color-theme-aalto-light "Aalto Light" "Jari Aalto <[email protected]>")
    (color-theme-aliceblue "Alice Blue" "Girish Bharadwaj <[email protected]>")
    (color-theme-andreas "Andreas" "Andreas Busch <[email protected]>")
    (color-theme-arjen "Arjen" "Arjen Wiersma <[email protected]>")
    (color-theme-beige-diff "Beige Diff" "Alex Schroeder <[email protected]>" t)
    (color-theme-bharadwaj "Bharadwaj" "Girish Bharadwaj <[email protected]>")
    (color-theme-bharadwaj-slate "Bharadwaj Slate" "Girish Bharadwaj <[email protected]>")
    (color-theme-billw "Billw" "Bill White <[email protected]>")
    (color-theme-black-on-gray "BlackOnGray" "Sudhir Bhojwani <[email protected]>")
    (color-theme-blippblopp "Blipp Blopp" "Thomas Sicheritz-Ponten<[email protected]>")
    (color-theme-simple-1 "Black" "Jonadab <[email protected]>")
    (color-theme-blue-erc "Blue ERC" "Alex Schroeder <[email protected]>" t)
    (color-theme-blue-gnus "Blue Gnus" "Alex Schroeder <[email protected]>" t)
    (color-theme-blue-mood "Blue Mood" "Nelson Loyola <[email protected]>")
    (color-theme-blue-sea "Blue Sea" "Alex Schroeder <[email protected]>")
    (color-theme-calm-forest "Calm Forest" "Artur Hefczyc <[email protected]>")
    (color-theme-charcoal-black "Charcoal Black" "Lars Chr. Hausmann <[email protected]>")
    (color-theme-goldenrod "Cheap Goldenrod" "Alex Schroeder <[email protected]>")
    (color-theme-clarity "Clarity and Beauty" "Richard Wellum <[email protected]>")
    (color-theme-classic "Classic" "Frederic Giroud <[email protected]>")
    (color-theme-comidia "Comidia" "Marcelo Dias de Toledo <[email protected]>")
    (color-theme-jsc-dark "Cooper Dark" "John S Cooper <[email protected]>")
    (color-theme-jsc-light "Cooper Light" "John S Cooper <[email protected]>")
    (color-theme-jsc-light2 "Cooper Light 2" "John S Cooper <[email protected]>")
    (color-theme-dark-blue "Dark Blue" "Chris McMahan <[email protected]>")
    (color-theme-dark-blue2 "Dark Blue 2" "Chris McMahan <[email protected]>")
    (color-theme-dark-green "Dark Green" "[email protected]com")
    (color-theme-dark-laptop "Dark Laptop" "Laurent Michel <[email protected]>")
    (color-theme-deep-blue "Deep Blue" "Tomas Cerha <[email protected]>")
    (color-theme-digital-ofs1 "Digital OFS1" "Gareth Owen <[email protected]>")
    (color-theme-euphoria "Euphoria" "[email protected]")
    (color-theme-feng-shui "Feng Shui" "Walter Higgins <[email protected]>")
    (color-theme-fischmeister "Fischmeister"
                  "Sebastian Fischmeister <[email protected]>")
    (color-theme-gnome "Gnome" "Jonadab <[email protected]>")
    (color-theme-gnome2 "Gnome 2" "Alex Schroeder <[email protected]>")
    (color-theme-gray1 "Gray1" "Paul Pulli <[email protected]>")
    (color-theme-gray30 "Gray30" "Girish Bharadwaj <[email protected]>")
    (color-theme-kingsajz "Green Kingsajz" "Olgierd `Kingsajz' Ziolko <[email protected]>")
    (color-theme-greiner "Greiner" "Kevin Greiner <[email protected]>")
    (color-theme-gtk-ide "GTK IDE" "Gordon Messmer <[email protected]>")
    (color-theme-high-contrast "High Contrast" "Alex Schroeder <[email protected]>")
    (color-theme-hober "Hober" "Edward O'Connor <[email protected]>")
    (color-theme-infodoc "Infodoc" "Frederic Giroud <[email protected]>")
    (color-theme-jb-simple "JB Simple" "[email protected]")
    (color-theme-jedit-grey "Jedit Grey" "Gordon Messmer <[email protected]>")
    (color-theme-jonadabian "Jonadab" "Jonadab <[email protected]>")
    (color-theme-jonadabian-slate "Jonadabian Slate" "Jonadab <[email protected]>")
    (color-theme-katester "Katester" "[email protected]")
    (color-theme-late-night "Late Night" "Alex Schroeder <[email protected]>")
    (color-theme-lawrence "Lawrence" "lawrence mitchell <[email protected]>")
    (color-theme-lethe "Lethe" "Ivica Loncar <[email protected]>")
    (color-theme-ld-dark "Linh Dang Dark" "Linh Dang <[email protected]>")
    (color-theme-marine "Marine" "Girish Bharadwaj <[email protected]>")
    (color-theme-matrix "Matrix" "Walter Higgins <[email protected]>")
    (color-theme-marquardt "Marquardt" "Colin Marquardt <[email protected]>")
    (color-theme-midnight "Midnight" "Gordon Messmer <[email protected]>")
    (color-theme-mistyday "Misty Day" "Hari Kumar <[email protected]>")
    (color-theme-montz "Montz" "Brady Montz <[email protected]>")
    (color-theme-oswald "Oswald" "Tom Oswald <[email protected]>")
    (color-theme-parus "Parus" "Jon K Hellan <[email protected]>")
    (color-theme-pierson "Pierson" "Dan L. Pierson <[email protected]>")
    (color-theme-ramangalahy "Ramangalahy" "Solofo Ramangalahy <[email protected]>")
    (color-theme-raspopovic "Raspopovic" "Pedja Raspopovic <[email protected]>")
    (color-theme-resolve "Resolve" "Damien Elmes <[email protected]>")
    (color-theme-retro-green "Retro Green" "Alex Schroeder <[email protected]>")
    (color-theme-retro-orange "Retro Orange" "Alex Schroeder <[email protected]>")
    (color-theme-robin-hood "Robin Hood" "Alex Schroeder <[email protected]>")
    (color-theme-rotor "Rotor" "Jinwei Shen <[email protected]>")
    (color-theme-ryerson "Ryerson" "Luis Fernandes <[email protected]>")
    (color-theme-salmon-diff "Salmon Diff" "Alex Schroeder <[email protected]>" t)
    (color-theme-salmon-font-lock "Salmon Font-Lock" "Alex Schroeder <[email protected]>" t)
    (color-theme-scintilla "Scintilla" "Gordon Messmer <[email protected]>")
    (color-theme-shaman "Shaman" "[email protected]")
    (color-theme-sitaramv-nt "Sitaram NT"
                 "Sitaram Venkatraman <[email protected]>")
    (color-theme-sitaramv-solaris "Sitaram Solaris"
                  "Sitaram Venkatraman <[email protected]>")
    (color-theme-snow "Snow" "Nicolas Rist <[email protected]>")
    (color-theme-snowish "Snowish" "Girish Bharadwaj <[email protected]>")
    (color-theme-standard-ediff "Standard Ediff" "Emacs Team, added by Alex Schroeder <[email protected]>" t)
    (color-theme-standard "Standard Emacs 20" "Emacs Team, added by Alex Schroeder <[email protected]>")
    (color-theme-emacs-21 "Standard Emacs 21" "Emacs Team, added by Alex Schroeder <[email protected]>")
    (color-theme-emacs-nw "Standard Emacs 21 No Window" "Emacs Team, added by D. Goel <[email protected]>")
    (color-theme-xemacs "Standard XEmacs" "XEmacs Team, added by Alex Schroeder <[email protected]>")
    (color-theme-subtle-blue "Subtle Blue" "Chris McMahan <[email protected]>")
    (color-theme-subtle-hacker "Subtle Hacker" "Colin Walters <[email protected]>")
    (color-theme-taming-mr-arneson "Taming Mr Arneson" "Erik Arneson <[email protected]>")
    (color-theme-taylor "Taylor" "Art Taylor <[email protected]>")
    (color-theme-tty-dark "TTY Dark" "O Polite <[email protected]>")
    (color-theme-vim-colors "Vim Colors" "Michael Soulier <[email protected]>")
    (color-theme-whateveryouwant "Whateveryouwant" "Fabien Penso <[email protected]>, color by Scott Jaderholm <[email protected]>")
    (color-theme-wheat "Wheat" "Alex Schroeder <[email protected]>")
    (color-theme-pok-wob "White On Black" "S. Pokrovsky <[email protected]>")
    (color-theme-pok-wog "White On Grey" "S. Pokrovsky <[email protected]>")
    (color-theme-word-perfect "WordPerfect" "Thomas Gehrlein <[email protected]>")
    (color-theme-xp "XP" "Girish Bharadwaj <[email protected]>"))
  "List of color themes.
 
Each THEME is itself a three element list (FUNC NAME MAINTAINER &optional LIBRARY).
 
FUNC is a color theme function which does the setup.  The function
FUNC may call `color-theme-install'.  The color theme function may be
interactive.
 
NAME is the name of the theme and MAINTAINER is the name and/or email of
the maintainer of the theme.
 
If LIBRARY is non-nil, the color theme will be considered a library and
may not be shown in the default menu.
 
If you defined your own color theme and want to add it to this list,
use something like this:
 
  (add-to-list 'color-themes '(color-theme-gnome2 /"Gnome2/" /"Alex/"))")
 
;;; Functions
 
(defun color-theme-backup-original-values ()
  "Back up the original `default-frame-alist'.
The values are stored in `color-theme-original-frame-alist' on
startup."
  (if (null color-theme-original-frame-alist)
      (setq color-theme-original-frame-alist
        (color-theme-filter (frame-parameters (selected-frame))
                color-theme-legal-frame-parameters))))
(add-hook 'after-init-hook 'color-theme-backup-original-values)
 
(defun color-theme-select (&optional arg)
  "Displays a special buffer for selecting and installing a color theme.
With optional prefix ARG, this buffer will include color theme libraries
as well.  A color theme library is in itself not complete, it must be
used as part of another color theme to be useful.  Thus, color theme
libraries are mainly useful for color theme authors."
  (interactive "P")
  (switch-to-buffer (get-buffer-create color-theme-buffer-name))
  (setq buffer-read-only nil)
  (erase-buffer)
  ;; recreate the snapshot if necessary
  (when (or (not (assq 'color-theme-snapshot color-themes))
        (not (commandp 'color-theme-snapshot)))
    (fset 'color-theme-snapshot (color-theme-make-snapshot))
    (setq color-themes (delq (assq 'color-theme-snapshot color-themes)
                 color-themes)
      color-themes (delq (assq 'bury-buffer color-themes)
                 color-themes)
      color-themes (append '((color-theme-snapshot
                  "[Reset]" "Undo changes, if possible.")
                 (bury-buffer
                  "[Quit]" "Bury this buffer."))
                 color-themes)))
  (dolist (theme color-themes)
    (let ((func (nth 0 theme))
      (name (nth 1 theme))
      (author (nth 2 theme))
      (library (nth 3 theme))
      (desc))
      (when (or (not library) arg)
    (setq desc (format "%-23s %s"  
               (if library (concat name " [lib]") name)
               author))
    (put-text-property 0 (length desc) 'color-theme func desc)
    (put-text-property 0 (length name) 'face 'bold desc)
    (put-text-property 0 (length name) 'mouse-face 'highlight desc)
    (insert desc)
    (newline))))
  (beginning-of-buffer)
  (setq buffer-read-only t)
  (set-buffer-modified-p nil)
  (color-theme-mode))
 
(require 'easymenu)
(easy-menu-add-item nil '("Tools") "--")
(easy-menu-add-item  nil '("Tools")
  ["Color Themes" color-theme-select t])
 
(defun color-theme-mode ()
  "Major mode to select and install color themes.
 
Use //[color-theme-install-at-point] to install a color theme on all frames.
Use //[color-theme-install-at-point-for-current-frame] to install a color theme for the current frame only.
 
The changes are applied on top of your current setup.  This is a
feature.
 
Some of the themes should be considered extensions to the standard color
theme: they modify only a limited number of faces and variables.  To
verify the final look of a color theme, install the standard color
theme, then install the other color theme.  This is a feature. It allows
you to mix several color themes.
 
Use //[color-theme-describe] to read more about the color theme function at point.
If you want to install the color theme permanently, put the call to the
color theme function into your ~/.emacs:
 
    /(require 'color-theme)
    /(color-theme-gnome2)
 
If you worry about the size of color-theme.el: You are right.  Use
//[color-theme-print] to print the current color theme and save the resulting buffer
as ~/.emacs-color-theme.  Now you can install only this specific color
theme in your .emacs:
 
    /(load-file /"~/.emacs-color-theme/")
    /(my-color-theme)
 
The Emacs menu is not affected by color themes within Emacs.  Depending
on the toolkit you used to compile Emacs, you might have to set specific
X ressources.  See the info manual for more information.  Here is an
example ~/.Xdefaults fragment:
 
    emacs*Background: DarkSlateGray
    emacs*Foreground: wheat
 
//{color-theme-mode-map}
 
The color themes are listed in `color-themes', which see."
  (kill-all-local-variables)
  (setq major-mode 'color-theme-mode)
  (setq mode-name "Color Themes")
  (use-local-map color-theme-mode-map)
  (when (functionp 'goto-address); Emacs
    (goto-address))
  (run-hooks 'color-theme-mode-hook))
 
;;; Commands in Color Theme Selection mode
 
(defun color-theme-describe ()
  "Describe color theme listed at point.
This shows the documentation of the value of text-property color-theme
at point.  The text-property color-theme should be a color theme
function.  See `color-themes'."
  (interactive)
  (describe-function (get-text-property (point) 'color-theme)))
 
(defun color-theme-install-at-mouse (event)
  "Install color theme clicked upon using the mouse.
First argument EVENT is used to set point.  Then
`color-theme-install-at-point' is called."
  (interactive "e")
  (save-excursion
    (mouse-set-point event)
    (color-theme-install-at-point)))
 
(defun color-theme-install-at-point ()
  "Install color theme at point.
This calls the value of the text-property `color-theme' at point.
The text-property `color-theme' should be a color theme function.
See `color-themes'."
  (interactive)
  (let ((func (get-text-property (point) 'color-theme)))
    ;; install theme
    (if func
    (funcall func))
    ;; If goto-address is being used, remove all overlays in the current
    ;; buffer and run it again.  The face used for the mail addresses in
    ;; the the color theme selection buffer is based on the variable
    ;; goto-address-mail-face.  Changes in that variable will not affect
    ;; existing overlays, however, thereby confusing users.
    (when (functionp 'goto-address); Emacs
      (dolist (o (overlays-in (point-min) (point-max)))
    (delete-overlay o))
      (goto-address))))
 
(defun color-theme-install-at-point-for-current-frame ()
  "Install color theme at point for current frame only.
Binds `color-theme-is-global' to nil and calls
`color-theme-install-at-point'."
  (interactive)
  (let ((color-theme-is-global nil))
    (color-theme-install-at-point)))
 

 
;; Taking a snapshot of the current color theme and pretty printing it.
 
(defun color-theme-filter (old-list regexp &optional exclude)
  "Filter OLD-LIST.
The resulting list will be newly allocated and contains only elements
with names matching REGEXP.  OLD-LIST may be a list or an alist.  If you
want to filter a plist, use `color-theme-alist' to convert your plist to
an alist, first.
 
If the optional argument EXCLUDE is non-nil, then the sense is
reversed: only non-matching elements will be retained."
  (let (elem new-list)
    (dolist (elem old-list)
      (setq name (symbol-name (if (listp elem) (car elem) elem)))
      (when (or (and (not exclude)
             (string-match regexp name))
        (and exclude
             (not (string-match regexp name))))
    ;; Now make sure that if elem is a cons cell, and the cdr of
    ;; that cons cell is a string, then we need a *new* string in
    ;; the new list.  Having a new cons cell is of no use because
    ;; modify-frame-parameters will modify this string, thus
    ;; modifying our color theme functions!
    (when (and (consp elem)
           (stringp (cdr elem)))
      (setq elem (cons (car elem)
               (copy-sequence (cdr elem)))))
    ;; Now store elem
    (setq new-list (cons elem new-list))))
    new-list))
 
(defun color-theme-spec-filter (spec)
  "Filter the attributes in SPEC.
This makes sure that SPEC has the form ((t (PLIST ...))).
Only properties not in `color-theme-illegal-default-attributes'
are included in the SPEC returned."
  (let ((props (cadar spec))
    result prop val)
    (while props
      (setq prop (nth 0 props)
        val (nth 1 props)
        props (nthcdr 2 props))
      (unless (memq prop color-theme-illegal-default-attributes)
    (setq result (cons val (cons prop result)))))
    `((t ,(nreverse result)))))
 
;; (color-theme-spec-filter '((t (:background "blue3"))))
;; (color-theme-spec-filter '((t (:stipple nil :background "Black" :foreground "SteelBlue" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :width semi-condensed :family "misc-fixed"))))
 
(defun color-theme-plist-delete (plist prop)
  "Delete property PROP from property list PLIST by side effect.
This modifies PLIST."
  ;; deal with prop at the start
  (while (eq (car plist) prop)
    (setq plist (cddr plist)))
  ;; deal with empty plist
  (when plist
    (let ((lastcell (cdr plist))
      (l (cddr plist)))
      (while l
    (if (eq (car l) prop)
        (progn
          (setq l (cddr l))
          (setcdr lastcell l))
      (setq lastcell (cdr l)
        l (cddr l))))))
  plist)
 
;; (color-theme-plist-delete '(a b c d e f g h) 'a)
;; (color-theme-plist-delete '(a b c d e f g h) 'b)
;; (color-theme-plist-delete '(a b c d e f g h) 'c)
;; (color-theme-plist-delete '(a b c d e f g h) 'g)
;; (color-theme-plist-delete '(a b c d c d e f g h) 'c)
;; (color-theme-plist-delete '(a b c d e f c d g h) 'c)
 
(if (or (featurep 'xemacs)
    (< emacs-major-version 21))
    (defalias 'color-theme-spec-compat 'identity)
  (defun color-theme-spec-compat (spec)
    "Filter the attributes in SPEC such that is is never invalid.
Example: Eventhough :bold works in Emacs, it is not recognized by
`customize-face' -- and then the face is uncustomizable.  This
function replaces a :bold attribute with the corresponding :weight
attribute, if there is no :weight, or deletes it.  This undoes the
doings of `color-theme-spec-canonical-font', more or less."
    (let ((props (cadar spec)))
      (when (plist-member props :bold)
    (setq props (color-theme-plist-delete props :bold))
    (unless (plist-member props :weight)
      (setq props (plist-put props :weight 'bold))))
      (when (plist-member props :italic)
    (setq props (color-theme-plist-delete props :italic))
    (unless (plist-member props :slant)
      (setq props (plist-put props :slant 'italic))))
      `((t ,props)))))
 
;; (color-theme-spec-compat '((t (:foreground "blue" :bold t))))
;; (color-theme-spec-compat '((t (:bold t :foreground "blue" :weight extra-bold))))
;; (color-theme-spec-compat '((t (:italic t :foreground "blue"))))
;; (color-theme-spec-compat '((t (:slant oblique :italic t :foreground "blue"))))
 
(defun color-theme-spec-canonical-font (atts)
  "Add :bold and :italic attributes if necessary."
  ;; add these to the front of atts -- this will keept the old value for
  ;; customize-face in Emacs 21.
  (when (and (memq (plist-get atts :weight)
           '(ultra-bold extra-bold bold semi-bold))
         (not (plist-get atts :bold)))
    (setq atts (cons :bold (cons t atts))))
  (when (and (not (memq (plist-get atts :slant)
            '(normal nil)))
         (not (plist-get atts :italic)))
    (setq atts (cons :italic (cons t atts))))
  atts)
;; (color-theme-spec-canonical-font (color-theme-face-attr-construct 'bold (selected-frame)))
;; (defface foo '((t (:weight extra-bold))) "foo")
;; (color-theme-spec-canonical-font (color-theme-face-attr-construct 'foo (selected-frame)))
;; (face-spec-set 'foo '((t (:weight extra-bold))) nil)
;; (face-spec-set 'foo '((t (:bold t))) nil)
;; (face-spec-set 'foo '((t (:bold t :weight extra-bold))) nil)
 
;; Handle :height according to NEWS file for Emacs 21
(defun color-theme-spec-resolve-height (old new)
  "Return the new height given OLD and NEW height.
OLD is the current setting, NEW is the setting inherited from."
  (cond ((not old)
     new)
    ((integerp old)
     old)
    ((and (floatp old)
          (integerp new))
     (round (* old new)))
    ((and (floatp old)
          (floatp new))
     (* old new))
    ((and (functionp old)
          (integerp new))
     (round (funcall old new)))
    ((and (functionp old)
          (float new))
     `(lambda (f) (* (funcall ,old f) ,new)))
    ((and (functionp old)
          (functionp new))
     `(lambda (f) (* (funcall ,old (funcall ,new f)))))
    (t
     (error "Illegal :height attributes: %S or %S" old new))))
;; (color-theme-spec-resolve-height 12 1.2)
;; (color-theme-spec-resolve-height 1.2 1.2)
;; (color-theme-spec-resolve-height 1.2 12)
;; (color-theme-spec-resolve-height 1.2 'foo)
;; (color-theme-spec-resolve-height (lambda (f) (* 2 f)) 5)
;; (color-theme-spec-resolve-height (lambda (f) (* 2 f)) 2.0)
;; the following lambda is the result from the above calculation
;; (color-theme-spec-resolve-height (lambda (f) (* (funcall (lambda (f) (* 2 f)) f) 2.0)) 5)
 
(defun color-theme-spec-resolve-inheritance (atts)
  "Resolve all occurences of the :inherit attribute."
  (let ((face (plist-get atts :inherit)))
    ;; From the Emacs 21 NEWS file: "Attributes from inherited faces are
    ;; merged into the face like an underlying face would be." --
    ;; therefore properties of the inherited face only add missing
    ;; attributes.
    (when face
      ;; remove :inherit face from atts -- this assumes only one
      ;; :inherit attribute.
      (setq atts (delq ':inherit (delq face atts)))
      (let ((more-atts (color-theme-spec-resolve-inheritance
            (color-theme-face-attr-construct
             face (selected-frame))))
        att val)
    (while more-atts
      (setq att (car more-atts)
        val (cadr more-atts)
        more-atts (cddr more-atts))
      ;; Color-theme assumes that no value is ever 'unspecified.
      (cond ((eq att ':height); cumulative effect!
         (setq atts (plist-put atts  
                       ':height  
                       (color-theme-spec-resolve-height
                    (plist-get atts att)  
                    val))))
        ;; Default: Only put if it has not been specified before.
        ((not (plist-get atts att))
         (setq atts (cons att (cons val atts))))
           
))))
    atts))
;; (color-theme-spec-resolve-inheritance '(:bold t))
;; (color-theme-spec-resolve-inheritance '(:bold t :foreground "blue"))
;; (color-theme-face-attr-construct 'font-lock-comment-face (selected-frame))
;; (color-theme-spec-resolve-inheritance '(:bold t :inherit font-lock-comment-face))
;; (color-theme-spec-resolve-inheritance '(:bold t :foreground "red" :inherit font-lock-comment-face))
;; (color-theme-face-attr-construct 'Info-title-2-face (selected-frame))
;; (color-theme-face-attr-construct 'Info-title-3-face (selected-frame))
;; (color-theme-face-attr-construct 'Info-title-4-face (selected-frame))
;; (color-theme-spec-resolve-inheritance '(:inherit Info-title-2-face))
 
;; The :inverse-video attribute causes Emacs to swap foreground and
;; background colors, XEmacs does not.  Therefore, if anybody chooses
;; the inverse-video attribute, we 1. swap the colors ourselves in Emacs
;; and 2. we remove the inverse-video attribute in Emacs and XEmacs.
;; Inverse-video is only useful on a monochrome tty.
(defun color-theme-spec-maybe-invert (atts)
  "Remove the :inverse-video attribute from ATTS.
If ATTS contains :inverse-video t, remove it and swap foreground and
background color.  Return ATTS."
  (let ((inv (plist-get atts ':inverse-video)))
    (if inv
    (let (result att)
      (while atts
        (setq att (car atts)
          atts (cdr atts))
        (cond ((and (eq att :foreground) (not color-theme-xemacs-p))
           (setq result (cons :background result)))
          ((and (eq att :background) (not color-theme-xemacs-p))
           (setq result (cons :foreground result)))
          ((eq att :inverse-video)
           (setq atts (cdr atts))); this prevents using dolist
          (t
           (setq result (cons att result)))))
      (nreverse result))
      ;; else
      atts)))
;; (color-theme-spec-maybe-invert '(:bold t))
;; (color-theme-spec-maybe-invert '(:foreground "blue"))
;; (color-theme-spec-maybe-invert '(:background "red"))
;; (color-theme-spec-maybe-invert '(:inverse-video t))
;; (color-theme-spec-maybe-invert '(:inverse-video t :foreground "red"))
;; (color-theme-spec-maybe-invert '(:inverse-video t :background "red"))
;; (color-theme-spec-maybe-invert '(:inverse-video t :background "red" :foreground "blue" :bold t))
;; (color-theme-spec-maybe-invert '(:inverse-video nil :background "red" :foreground "blue" :bold t))
 
(defun color-theme-spec (face)
  "Return a list for FACE which has the form (FACE SPEC).
See `defface' for the format of SPEC.  In this case we use only one
DISPLAY, t, and determine ATTS using `color-theme-face-attr-construct'.
If ATTS is nil, (nil) is used  instead.
 
If ATTS contains :inverse-video t, we remove it and swap foreground and
background color using `color-theme-spec-maybe-invert'.  We do this
because :inverse-video is handled differently in Emacs and XEmacs.  We
will loose on a tty without colors, because in that situation,
:inverse-video means something."
  (let ((atts
     (color-theme-spec-canonical-font
      (color-theme-spec-maybe-invert
       (color-theme-spec-resolve-inheritance
        (color-theme-face-attr-construct face (selected-frame)))))))
    (if atts
    `(,face ((t ,atts)))
      `(,face ((t (nil)))))))
 
(defun color-theme-get-params ()
  "Return a list of frame parameter settings usable in a color theme.
Such an alist may be installed by `color-theme-install-frame-params'.  The
frame parameters returned must match `color-theme-legal-frame-parameters'."
  (let ((params (color-theme-filter (frame-parameters (selected-frame))
                    color-theme-legal-frame-parameters)))
    (sort params (lambda (a b) (string< (symbol-name (car a))
                    (symbol-name (car b)))))))
 
(defun color-theme-get-vars ()
  "Return a list of variable settings usable in a color theme.
Such an alist may be installed by `color-theme-install-variables'.
The variable names must match `color-theme-legal-variables', and the
variable must be a user variable according to `user-variable-p'."
  (let ((vars)
    (val))
    (mapatoms (lambda (v)
        (and (boundp v)
             (user-variable-p v)
             (string-match color-theme-legal-variables
                   (symbol-name v))
             (setq val (eval v))
             (add-to-list 'vars (cons v val)))))
    (sort vars (lambda (a b) (string< (car a) (car b))))))
 
(defun color-theme-print-alist (alist)
  "Print ALIST."
  (insert "/n     " (if alist "(" "nil"))
  (dolist (elem alist)
    (when (= (preceding-char) ?/))
      (insert "/n      "))
    (prin1 elem (current-buffer)))
  (when (= (preceding-char) ?/)) (insert ")")))
 
(defun color-theme-get-faces ()
  "Return a list of faces usable in a color theme.
Such an alist may be installed by `color-theme-install-faces'.  The
faces returned must not match `color-theme-illegal-faces'."
  (let ((faces (color-theme-filter (face-list) color-theme-illegal-faces t)))
    ;; default face must come first according to comments in
    ;; custom-save-faces, the rest is to be sorted by name
    (cons 'default (sort (delq 'default faces) 'string-lessp))))
 
(defun color-theme-get-face-definitions ()
  "Return face settings usable in a color-theme."
  (let ((faces (color-theme-get-faces)))
    (mapcar 'color-theme-spec faces)))
 
(defun color-theme-print-faces (faces)
  "Print face settings for all faces returned by `color-theme-get-faces'."
  (when faces
    (insert "/n     "))
  (dolist (face faces)
    (when (= (preceding-char) ?/))
      (insert "/n     "))
    (prin1 face (current-buffer))))
 
(defun color-theme-reset-faces ()
  "Reset face settings for all faces returned by `color-theme-get-faces'."
  (let ((faces (color-theme-get-faces))
    (face) (spec) (entry)
    (frame (if color-theme-is-global nil (selected-frame))))
    (while faces
      (setq entry (color-theme-spec (car faces)))
      (setq face (nth 0 entry))
      (setq spec '((t (nil))))
      (setq faces (cdr faces))
      (if (functionp 'face-spec-reset-face)
      (face-spec-reset-face face frame)
    (face-spec-set face spec frame)
    (if color-theme-is-global
        (put face 'face-defface-spec spec))))))
 
(defun color-theme-print-theme (func doc params vars faces)
  "Print a theme into the current buffer.
FUNC is the function name, DOC the doc string, PARAMS the
frame parameters, VARS the variable bindings, and FACES
the list of faces and their specs."
  (insert "(defun " (symbol-name func) " ()/n"
      "  /"" doc "/"/n"
      "  (interactive)/n"
      "  (color-theme-install/n"
      "   '(" (symbol-name func))
  ;; alist of frame parameters
  (color-theme-print-alist params)
  ;; alist of variables
  (color-theme-print-alist vars)
  ;; remaining elements of snapshot: face specs
  (color-theme-print-faces faces)
  (insert ")))")
  (goto-char (point-min)))
 
(defun color-theme-print (&optional