]> git.rkrishnan.org Git - .emacs.d.git/blob - emacs/nxhtml/util/buffer-bg.el
d6459d63ae6bb823d3c51d06f77a29968c2a5c10
[.emacs.d.git] / emacs / nxhtml / util / buffer-bg.el
1 ;;; buffer-bg.el --- Changing background color of windows
2 ;;
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2008-05-22T19:06:23+0200 Thu
5 ;; Version: 0.5
6 ;; Last-Updated: 2008-05-22T23:19:55+0200 Thu
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/buffer-bg.el
8 ;; Keywords:
9 ;; Compatibility:
10 ;;
11 ;; Features that might be required by this library:
12 ;;
13 ;;   None
14 ;;
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
16 ;;
17 ;;; Commentary:
18 ;;
19 ;; There is currently no way to change background colors of Emacs
20 ;; windows. This library implements a workaround using overlays.
21 ;;
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
23 ;;
24 ;;; Change log:
25 ;;
26 ;;
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ;;
29 ;; This program is free software; you can redistribute it and/or
30 ;; modify it under the terms of the GNU General Public License as
31 ;; published by the Free Software Foundation; either version 2, or
32 ;; (at your option) any later version.
33 ;;
34 ;; This program is distributed in the hope that it will be useful,
35 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
36 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
37 ;; General Public License for more details.
38 ;;
39 ;; You should have received a copy of the GNU General Public License
40 ;; along with this program; see the file COPYING.  If not, write to
41 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
42 ;; Floor, Boston, MA 02110-1301, USA.
43 ;;
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45 ;;
46 ;;; Code:
47
48 (defvar buffer-bg-overlay nil)
49 (put 'buffer-bg-overlay 'permanent-local t)
50
51 ;;;###autoload
52 (defun buffer-bg-set-color (color buffer)
53   "Add an overlay with background color COLOR to buffer BUFFER.
54 If COLOR is nil remove previously added overlay."
55   (interactive
56    (let* ((prompt (if buffer-bg-overlay
57                       "Background color (empty string to remove): "
58                     "Background color: "))
59           (color (read-color prompt nil t)))
60      (when (= 0 (length color))
61        (setq color nil))
62      (list color (current-buffer))
63      ))
64   (if (not color)
65       (when buffer-bg-overlay
66         (delete-overlay buffer-bg-overlay)
67         (setq buffer-bg-overlay nil))
68     (save-restriction
69       (widen)
70       (setq buffer-bg-overlay
71             (make-overlay (point-min) (point-max) nil nil t))
72       ;; Fix-me: Let the overlay have priority 0 which is the
73       ;; lowest. Change this to below char properties if this is ever
74       ;; allowed in Emacs.
75       (overlay-put buffer-bg-overlay 'priority 0)
76       (let* ((bg-face (list :background color))
77              (bg-after (propertize (make-string 10 ?\n)
78                                    'face bg-face
79                                    'intangible t)))
80         (overlay-put buffer-bg-overlay 'face bg-face)
81         ;; This is just confusing, don't use it:
82         ;;(overlay-put buffer-bg-overlay 'after-string bg-after)
83         )
84       )))
85
86
87 (provide 'buffer-bg)
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 ;;; buffer-bg.el ends here