annotate lisp/modes/xpm-mode.el @ 39:06f275776fba

Added tag r19-15b102 for changeset 1a767b41a199
author cvs
date Mon, 13 Aug 2007 08:54:02 +0200
parents 0293115a14e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; xpm-mode.el --- minor mode for editing XPM files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1995 Joe Rumsey <ogre@netcom.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Rich Williams <rdw@hplb.hpl.hp.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Authors: Joe Rumsey <ogre@netcom.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Rich Williams <rdw@hplb.hpl.hp.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Cleanup: Chuck Thompson <cthomp@cs.uiuc.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Version: 1.5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; Last Modified: Rich Williams <rdw@hplb.hpl.hp.com>, 13 July 1995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; Keywords: data tools
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
27 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
29 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; xpm mode: Display xpm files in color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; thanks to Rich Williams for mods to do this without font-lock-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; resulting in much improved performance and a better display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; (headers don't get colored strangely). Also for the palette toolbar.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; Non-standard minor mode in that it starts picture-mode automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; To get this turned on automatically for .xpms, add an entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; ("\\.xpm" . xpm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; to your auto-mode-alist. For example, my .emacs has this: (abbreviated)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; (setq auto-mode-alist (mapcar 'purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; '(("\\.c$" . c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; ("\\.h$" . c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; ("\\.el$" . emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; ("\\.emacs$" . emacs-lisp-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; ("\\.a$" . c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; ("\\.xpm" . xpm-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; (autoload 'xpm-mode "xpm-mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; I am a lisp newbie, practically everything in here I had to look up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; in the manual. It probably shows, suggestions for coding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; improvements are welcomed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; May fail on some xpm's. Seems to be fine with files generated by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; xpaint and ppmtoxpm anyway. Will definitely fail on xpm's with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; more than one character per pixel. Not that hard to fix, but I've
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; never seen one like that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; If your default font is proportional, this will not be very useful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (require 'annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar xpm-pixel-values nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar xpm-glyph nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar xpm-anno nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defvar xpm-paint-string nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvar xpm-chars-per-pixel 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (defvar xpm-palette nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar xpm-always-update-image nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "If non-nil, update actual-size image after every click or drag movement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 Otherwise, only update on button releases or when asked to. This is slow.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (make-variable-buffer-local 'xpm-palette)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (make-variable-buffer-local 'xpm-chars-per-pixel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (make-variable-buffer-local 'xpm-paint-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (make-variable-buffer-local 'xpm-glyph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (make-variable-buffer-local 'xpm-anno)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (make-variable-buffer-local 'xpm-pixel-values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;(make-variable-buffer-local 'xpm-faces-used)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (defun xpm-make-face (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "Makes a face with name xpm-NAME, and colour NAME."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (let ((face (make-face (intern (concat "xpm-" name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Temporary xpm-mode face" t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (set-face-background face name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (set-face-foreground face "black")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (defun xpm-init ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "Treat the current buffer as an xpm file and colorize it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (require 'picture)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (setq xpm-pixel-values nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (xpm-clear-extents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq xpm-palette nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (message "Finding number of colors...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (next-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (next-line 1))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
113
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
114 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
115 (goto-char (point-min))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
116 (if (re-search-forward
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
117 "\"\\s-*\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-*"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
118 (point-max) t)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
119 (setq xpm-chars-per-pixel (string-to-int (match-string 4)))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
120
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (let ((co 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (while (< co (xpm-num-colors))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (xpm-parse-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq co (1+ co))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (beginning-of-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (if (not (eq major-mode 'picture-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (picture-mode))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
130 (if (featurep 'toolbar)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
131 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
132 (set-specifier left-toolbar-width (cons (selected-frame) 16))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
133 (set-specifier left-toolbar (cons (current-buffer) xpm-palette))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (message "Parsing body...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (xpm-color-data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (message "Parsing body...done")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (xpm-show-image))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (defun xpm-clear-extents ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (let (cur-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 next-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq cur-extent (next-extent (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (setq next-extent (next-extent cur-extent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (while cur-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (delete-extent cur-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (setq cur-extent next-extent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq next-extent (next-extent cur-extent)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun xpm-color-data ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (xpm-goto-body-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (let (ext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 pixel-chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 pixel-color)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
156 (while (and (< (point) (point-max))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
157 (< (+ (point) xpm-chars-per-pixel) (point-max)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (setq pixel-chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (buffer-substring (point) (+ (point) xpm-chars-per-pixel))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 pixel-color (assoc pixel-chars xpm-pixel-values)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ext (make-extent (point) (+ (point) xpm-chars-per-pixel)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (if pixel-color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (set-extent-face ext (cdr pixel-color)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (set-extent-face ext 'default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (forward-char xpm-chars-per-pixel)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (defun xpm-num-colors ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (if (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "\"\\s-*\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-+\\([0-9]+\\)\\s-*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (point-max) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (string-to-int (match-string 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (error "Unable to parse xpm information"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (defun xpm-make-solid-pixmap (colour width height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (let ((x 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (y 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (line nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (total nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq line ",\n\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (while (< x width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (setq line (concat line ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 x (+ x 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (setq line (concat line "\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 total (format "/* XPM */\nstatic char * %s[] = {\n\"%d %d 1 1\",\n\". c %s\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 colour width height colour))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (while (< y height)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (setq total (concat total line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 y (+ y 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (make-glyph (concat total "};\n"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (defun xpm-store-color (str color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 "Add STR to xpm-pixel-values with a new face set to background COLOR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 if STR already has an entry, the existing face will be used, with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 new color replacing the old (on the display only, not in the xpm color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 defs!)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (let (new-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (setq new-face (xpm-make-face color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (set-face-background new-face color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (let ((ccc (color-rgb-components (make-color-specifier color))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (if (> (length ccc) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (if (or (or (> (elt ccc 0) 32767)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (> (elt ccc 1) 32767))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (> (elt ccc 2) 32767))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (set-face-foreground new-face "black")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (set-face-foreground new-face "white"))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
209 (setq xpm-pixel-values (cons (cons str new-face) xpm-pixel-values))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
210 (if (featurep 'toolbar)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
211 (setq xpm-palette
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
212 (cons (vector
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
213 (list (xpm-make-solid-pixmap color 12 12))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
214 ;; Major cool things with quotes.....
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
215 (`
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
216 (lambda (event)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
217 (interactive "e")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
218 (xpm-toolbar-select-colour event (, str))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
219 t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
220 color) xpm-palette)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun xpm-parse-color ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Parse xpm color string from current line and set the color"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let (end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (if (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; Generate a regexp on the fly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (concat "\"\\(" (make-string xpm-chars-per-pixel ?.) "\\)" ; chars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 "\\s-+\\([c]\\)" ; there are more classes than 'c'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 "\\s-+\\([^\"]+\\)\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (xpm-store-color (match-string 1) (match-string 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (list (match-string 1) (match-string 3)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (error "Unable to parse color")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (defun xpm-add-color (str color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 "add a color to an xpm's list of color defs"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (interactive "sPixel character:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 sPixel color (any valid X color string):")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (next-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (next-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (let ((co 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (while (< co (xpm-num-colors))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq co (1+ co))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (insert (format "\"%s\tc %s\",\n" str color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (previous-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (xpm-parse-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (next-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (let ((entry 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (while (or (= (char-after (point)) ? ) (= (char-after (point)) ?\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (while (< entry 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (if (eq (char-after (point)) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq entry (1+ entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (while (eq (char-after (point)) ? )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (forward-char 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (let ((old-colors (xpm-num-colors)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (while (and (>= (char-after (point)) ?0) (<= (char-after (point)) ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (delete-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (insert (int-to-string (1+ old-colors)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (defun xpm-goto-color-def (def)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 "move to color DEF in the xpm header"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (interactive "nColor number:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (next-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (next-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (while (not (looking-at "\\s-*\""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (next-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (next-line def))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (defun xpm-goto-body-line (line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 "move to LINE lines down from the start of the body of an xpm"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (interactive "nBody line:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (xpm-goto-color-def (xpm-num-colors))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (next-line line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (defun xpm-show-image ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 "Display the xpm in the current buffer at the end of the topmost line"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (if (annotationp xpm-anno)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (delete-annotation xpm-anno))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (setq xpm-glyph (make-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (vector 'xpm :data
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (buffer-substring (point-min) (point-max)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (setq xpm-anno (make-annotation xpm-glyph (point) 'text))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (defun xpm-hide-image ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 "Remove the image of the xpm from the buffer"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if (annotationp xpm-anno)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (delete-annotation xpm-anno)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (defun xpm-in-body ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (let ((p (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (xpm-goto-body-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (> p (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (defvar xpm-mode nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (make-variable-buffer-local 'xpm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (add-minor-mode 'xpm-mode " XPM" nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defvar xpm-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (defun xpm-toolbar-select-colour (event chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 "Toolbar button"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (let* ((button (event-toolbar-button event))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (help (toolbar-button-help-string button)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (message "Toolbar selected %s (%s)" help chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (setq xpm-palette
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (mapcar #'(lambda (but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (aset but 2 (not (eq help (aref but 3))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 but)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 xpm-palette)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 xpm-paint-string chars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (set-specifier left-toolbar (cons (current-buffer) xpm-palette))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (defun xpm-mouse-paint (event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (interactive "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (if (xpm-in-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; in body, overwrite the paint string where the mouse is clicked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (insert xpm-paint-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (delete-char (length xpm-paint-string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; otherwise, select the color defined by the line where the mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; was clicked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (setq xpm-paint-string (buffer-substring (point) (1+ (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (defun xpm-mouse-down (event n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ; (interactive "ep")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (if (xpm-in-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; in body, overwrite the paint string where the mouse is clicked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (insert xpm-paint-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (delete-char (length xpm-paint-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 (if xpm-always-update-image
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (xpm-show-image))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (let ((ext (make-extent (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (+ (1- (point)) xpm-chars-per-pixel)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (pixel-color (assoc xpm-paint-string xpm-pixel-values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (if pixel-color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (set-extent-face ext (cdr pixel-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (set-extent-face ext 'default))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ;; otherwise, select the color defined by the line where the mouse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 ;; was clicked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (setq xpm-paint-string (buffer-substring (point) (1+ (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (defun xpm-mouse-drag (event n timeout)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (or timeout
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (mouse-set-point event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (if (xpm-in-body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ;; Much improved by not using font-lock-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (or (string= xpm-paint-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (+ (length xpm-paint-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (insert-char (string-to-char xpm-paint-string) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 ; (insert xpm-paint-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (delete-char (length xpm-paint-string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (if xpm-always-update-image
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (xpm-show-image))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (let ((ext (make-extent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (1- (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (+ (1- (point)) xpm-chars-per-pixel)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (pixel-color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (assoc xpm-paint-string xpm-pixel-values)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (if pixel-color
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (set-extent-face ext (cdr pixel-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (set-extent-face ext 'default)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (defun xpm-mouse-up (event n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (xpm-show-image))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun xpm-mode (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "Treat the current buffer as an xpm file and colorize it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 Shift-button-1 lets you paint by dragging the mouse. Shift-button-1 on a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 color definition line will change the current painting color to that line's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 value.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 Characters inserted from the keyboard will NOT be colored properly yet.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 Use the mouse, or do xpm-init (\\[xpm-init]) after making changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 \\[xpm-add-color] Add a new color, prompting for character and value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 \\[xpm-show-image] show the current image at the top of the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 \\[xpm-parse-color] parse the current line's color definition and add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 it to the color table. Provided as a means of changing colors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 XPM minor mode bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 \\{xpm-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (setq xpm-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (if (null arg) (not xpm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (> (prefix-numeric-value arg) 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (if xpm-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (xpm-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (make-local-variable 'mouse-track-down-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (make-local-variable 'mouse-track-drag-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (make-local-variable 'mouse-track-up-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (make-local-variable 'mouse-track-drag-up-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (make-local-variable 'mouse-track-click-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (setq mouse-track-down-hook 'xpm-mouse-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (setq mouse-track-drag-hook 'xpm-mouse-drag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (setq mouse-track-up-hook 'xpm-mouse-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (setq mouse-track-drag-up-hook 'xpm-mouse-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (setq mouse-track-click-hook nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (or (assq 'xpm-mode minor-mode-map-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (define-key xpm-mode-map [(control c) r] 'xpm-show-image)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (define-key xpm-mode-map [(shift button1)] 'mouse-track)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (define-key xpm-mode-map [button1] 'mouse-track-default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (define-key xpm-mode-map [(control c) c] 'xpm-add-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (define-key xpm-mode-map [(control c) p] 'xpm-parse-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (setq minor-mode-map-alist (cons (cons 'xpm-mode xpm-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 minor-mode-map-alist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (provide 'xpm-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ;;; xpm-mode.el ends here