(frame-background-mode): New variable.
[elisp/apel.git] / tinycustom.el
1 ;; tinycustom.el -- a tiny custom.el for emulating purpose.
2
3 ;; Copyright (C) 1999 Mikio Nakajima <minakaji@osaka.email.ne.jp>
4
5 ;; Author: Mikio Nakajima <minakaji@osaka.email.ne.jp>
6 ;; Maintainer: Mikio Nakajima <minakaji@osaka.email.ne.jp>
7 ;; Keywords: emulating, custom
8
9 ;; This file is part of APEL (A Portable Emacs Library).
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Purpose of this program is emulating for who does not have "custom".
29 ;; (custom.el bundled with v19 is old; does not have following macros.)
30 ;;
31 ;; DEFCUSTOM below has the same effect as the original DEFVAR has.
32 ;; DEFFACE only makes a face.
33 ;; DEFGROUP and DEFINE-WIDGET below are just nop macro.
34
35 ;;; Code:
36
37 (require 'poe)
38
39 (defmacro-maybe defgroup (symbol members doc &rest args)
40   "Declare SYMBOL as a customization group containing MEMBERS.
41 SYMBOL does not need to be quoted.
42 Third arg DOC is the group documentation.
43
44 This is a nop defgroup only for emulating purpose."
45   nil)
46     
47 (defmacro-maybe defcustom (symbol value doc &rest args) 
48   "Declare SYMBOL as a customizable variable that defaults to VALUE.
49 DOC is the variable documentation.
50
51 This is a defcustom only for emulating purpose.
52 Its effect is just as same as that of defvar."
53   (` (defvar (, symbol) (, value) (, doc))))
54     
55 (defvar-maybe frame-background-mode nil
56   "*The brightness of the background.
57 Set this to the symbol dark if your background color is dark, light if
58 your background is light, or nil (default) if you want Emacs to
59 examine the brightness for you.  However, the old Emacsen might not
60 examine the brightness, so you should set this value definitely.")
61
62 (defmacro-maybe-cond defface (face spec doc &rest args)
63   "Declare FACE as a customizable face that defaults to SPEC.
64 FACE does not need to be quoted.  [custom emulating macro]"
65   ((fboundp 'make-face)
66    (` (let ((name (quote (, face))))
67         (or
68          (find-face name)
69          (let ((face (make-face name))
70                (spec (, spec))
71                (colorp (and window-system (x-display-color-p)))
72                display atts req item match done)
73            (while (and spec (not done))
74              (setq display (car (car spec))
75                    atts (car (cdr (car spec)))
76                    spec (cdr spec))
77              (cond
78               ((consp display)
79                (setq match t)
80                (while (and display match)
81                  (setq req (car (car display))
82                        item (car (cdr (car display)))
83                        display (cdr display))
84                  (cond
85                   ((eq 'class req)
86                    (setq match (or (and colorp (eq 'color item))
87                                    (and (not colorp)
88                                         (memq item '(grayscale mono))))))
89                   ((eq 'background req)
90                    (setq match (eq frame-background-mode item)))))
91                (setq done match))
92               ((eq t display)
93                (setq done t))))
94            (if done
95                (let ((alist '((:foreground . set-face-foreground)
96                               (:background . set-face-background)
97                               (:bold . set-face-bold-p)
98                               (:italic . set-face-italic-p)
99                               (:underline . set-face-underline-p)))
100                      function)
101                  (while atts
102                    (if (setq function (cdr (assq (car atts) alist)))
103                        (funcall function face (car (cdr atts))))
104                    (setq atts (cdr (cdr atts))))))
105            face)))))
106   (t
107    ;; do nothing.
108    ))
109
110 (defmacro-maybe define-widget (name class doc &rest args)
111   "Define a new widget type named NAME from CLASS.
112 The third argument DOC is a documentation string for the widget.
113
114 This is a nop define-widget only for emulating purpose."
115   nil)
116
117 (provide 'tinycustom)
118 (provide 'custom)
119
120 ;;; tinycustom.el ends here.