1 ;;; buffer-bg.el --- Changing background color of windows
3 ;; Author: Lennart Borgman (lennart O borgman A gmail O com)
4 ;; Created: 2008-05-22T19:06:23+0200 Thu
6 ;; Last-Updated: 2008-05-22T23:19:55+0200 Thu
7 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/buffer-bg.el
11 ;; Features that might be required by this library:
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
19 ;; There is currently no way to change background colors of Emacs
20 ;; windows. This library implements a workaround using overlays.
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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.
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.
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.
44 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
48 (defvar buffer-bg-overlay nil)
49 (put 'buffer-bg-overlay 'permanent-local t)
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."
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))
62 (list color (current-buffer))
65 (when buffer-bg-overlay
66 (delete-overlay buffer-bg-overlay)
67 (setq buffer-bg-overlay nil))
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
75 (overlay-put buffer-bg-overlay 'priority 0)
76 (let* ((bg-face (list :background color))
77 (bg-after (propertize (make-string 10 ?\n)
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)
88 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
89 ;;; buffer-bg.el ends here