annotate lisp/modes/xpm-mode.el @ 5:49b78a777eb4

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