0
|
1 ;;; smiley.el --- displaying smiley faces
|
98
|
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
|
0
|
3
|
|
4 ;; Author: Wes Hardaker <hardaker@ece.ucdavis.edu>
|
|
5 ;; Keywords: fun
|
|
6
|
|
7 ;; This file is part of GNU Emacs.
|
|
8
|
|
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
10 ;; it under the terms of the GNU General Public License as published by
|
|
11 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
12 ;; any later version.
|
|
13
|
|
14 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 ;; GNU General Public License for more details.
|
|
18
|
|
19 ;; You should have received a copy of the GNU General Public License
|
|
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
|
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 ;; Boston, MA 02111-1307, USA.
|
|
23
|
|
24 ;;; Commentary:
|
|
25
|
|
26 ;;
|
|
27 ;; comments go here.
|
|
28 ;;
|
|
29
|
|
30 ;;; Test smileys: :-] :-o :-) ;-) :-\ :-| :-d :-P 8-| :-(
|
|
31
|
|
32 ;; To use:
|
|
33 ;; (require 'smiley)
|
|
34 ;; (add-hook 'gnus-article-display-hook 'gnus-smiley-display t)
|
|
35
|
108
|
36 ;; The smilies were drawn by Joe Reiss <jreiss@vt.edu>.
|
2
|
37
|
0
|
38 (require 'annotations)
|
2
|
39 (require 'messagexmas)
|
98
|
40 (require 'cl)
|
|
41 (require 'custom)
|
|
42
|
|
43 (defgroup smiley nil
|
|
44 "Turn :-)'s into real images (XEmacs)."
|
|
45 :group 'gnus-visual)
|
0
|
46
|
98
|
47 (defcustom smiley-data-directory (message-xmas-find-glyph-directory "smilies")
|
|
48 "Location of the smiley faces files."
|
|
49 :type 'directory
|
|
50 :group 'smiley)
|
0
|
51
|
108
|
52 ;; Notice the subtle differences in the regular expressions in the
|
|
53 ;; two alists below.
|
2
|
54
|
98
|
55 (defcustom smiley-deformed-regexp-alist
|
161
|
56 '(("(?\\(\\^_?\\^;;;\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_ase3.xbm")
|
|
57 ("(?\\(\\^_?\\^;;\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_ase2.xbm")
|
|
58 ("(?\\(\\^_?\\^;\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_ase.xbm")
|
|
59 ("(\\(\\^_?\\^\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_smile.xbm")
|
|
60 ("(\\(;_?;\\))" 1 "Face_weep.xbm")
|
|
61 ("(\\(T_?T\\))" 1 "Face_weep.xbm")
|
159
|
62 ("\\(:-*[<«]+\\)\\W" 1 "FaceAngry.xpm")
|
2
|
63 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
|
|
64 ("\\(:-*D\\)\\W" 1 "FaceGrinning.xpm")
|
|
65 ("\\(:-*[)>}»]+\\)\\W" 1 "FaceHappy.xpm")
|
108
|
66 ("\\(:-*[/\\\"]\\)[^/]\\W" 1 "FaceIronic.xpm")
|
2
|
67 ("\\([8|]-*[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
|
|
68 ("\\([:|]-*#+\\)\\W" 1 "FaceNyah.xpm")
|
|
69 ("\\(:-*[({]+\\)\\W" 1 "FaceSad.xpm")
|
|
70 ("\\(:-*[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
|
|
71 ("\\(:-*|\\)\\W" 1 "FaceStraight.xpm")
|
|
72 ("\\(:-*p\\)\\W" 1 "FaceTalking.xpm")
|
|
73 ("\\(:-*d\\)\\W" 1 "FaceTasty.xpm")
|
|
74 ("\\(;-*[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
|
108
|
75 ("\\(:-*[Vvµ]\\)\\W" 1 "FaceWry.xpm")
|
2
|
76 ("\\([:|]-*P\\)\\W" 1 "FaceYukky.xpm"))
|
98
|
77 "Normal and deformed faces for smilies."
|
108
|
78 :type '(repeat (list regexp
|
98
|
79 (integer :tag "Match")
|
|
80 (string :tag "Image")))
|
|
81 :group 'smiley)
|
2
|
82
|
98
|
83 (defcustom smiley-nosey-regexp-alist
|
161
|
84 '(("(?\\(\\^_?\\^;;;\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_ase3.xbm")
|
|
85 ("(?\\(\\^_?\\^;;\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_ase2.xbm")
|
|
86 ("(?\\(\\^_?\\^;\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_ase.xbm")
|
|
87 ("(\\(\\^_?\\^\\)\\()\\|\\W\\|[^\000-\177]\\)" 1 "Face_smile.xbm")
|
|
88 ("(\\(;_?;\\))" 1 "Face_weep.xbm")
|
|
89 ("(\\(T_?T\\))" 1 "Face_weep.xbm")
|
|
90 ("\\(:-+[<«]+\\)\\W" 1 "FaceAngry.xpm")
|
2
|
91 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
|
|
92 ("\\(:-+D\\)\\W" 1 "FaceGrinning.xpm")
|
|
93 ("\\(:-+[}»]+\\)\\W" 1 "FaceHappy.xpm")
|
98
|
94 ("\\(:-*)+\\)\\W" 1 "FaceHappy.xpm")
|
2
|
95 ("\\(:-+[/\\\"]+\\)\\W" 1 "FaceIronic.xpm")
|
|
96 ("\\([8|]-+[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
|
|
97 ("\\([:|]-+#+\\)\\W" 1 "FaceNyah.xpm")
|
|
98 ("\\(:-+[({]+\\)\\W" 1 "FaceSad.xpm")
|
|
99 ("\\(:-+[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
|
|
100 ("\\(:-+|\\)\\W" 1 "FaceStraight.xpm")
|
|
101 ("\\(:-+p\\)\\W" 1 "FaceTalking.xpm")
|
|
102 ("\\(:-+d\\)\\W" 1 "FaceTasty.xpm")
|
|
103 ("\\(;-+[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
|
|
104 ("\\(:-+[Vvµ]\\)\\W" 1 "FaceWry.xpm")
|
98
|
105 ("\\(][:8B]-[)>]\\)\\W" 1 "FaceDevilish.xpm")
|
2
|
106 ("\\([:|]-+P\\)\\W" 1 "FaceYukky.xpm"))
|
98
|
107 "Smileys with noses. These get less false matches."
|
108
|
108 :type '(repeat (list regexp
|
98
|
109 (integer :tag "Match")
|
|
110 (string :tag "Image")))
|
|
111 :group 'smiley)
|
2
|
112
|
98
|
113 (defcustom smiley-regexp-alist smiley-deformed-regexp-alist
|
2
|
114 "A list of regexps to map smilies to real images.
|
108
|
115 Defaults to the contents of `smiley-deformed-regexp-alist'.
|
|
116 An alternative is `smiley-nosey-regexp-alist' that matches less
|
|
117 aggressively.
|
98
|
118 If this is a symbol, take its value."
|
|
119 :type '(radio (variable-item smiley-deformed-regexp-alist)
|
|
120 (variable-item smiley-nosey-regexp-alist)
|
108
|
121 symbol
|
|
122 (repeat (list regexp
|
98
|
123 (integer :tag "Match")
|
|
124 (string :tag "Image"))))
|
|
125 :group 'smiley)
|
0
|
126
|
98
|
127 (defcustom smiley-flesh-color "yellow"
|
|
128 "Flesh color."
|
|
129 :type 'string
|
|
130 :group 'smiley)
|
0
|
131
|
98
|
132 (defcustom smiley-features-color "black"
|
|
133 "Features color."
|
|
134 :type 'string
|
|
135 :group 'smiley)
|
|
136
|
|
137 (defcustom smiley-tongue-color "red"
|
|
138 "Tongue color."
|
|
139 :type 'string
|
|
140 :group 'smiley)
|
16
|
141
|
98
|
142 (defcustom smiley-circle-color "black"
|
|
143 "Circle color."
|
|
144 :type 'string
|
|
145 :group 'smiley)
|
0
|
146
|
98
|
147 (defcustom smiley-mouse-face 'highlight
|
|
148 "Face used for mouse highlighting in the smiley buffer.
|
|
149
|
|
150 Smiley buttons will be displayed in this face when the cursor is
|
|
151 above them."
|
|
152 :type 'face
|
|
153 :group 'smiley)
|
|
154
|
0
|
155
|
|
156 (defvar smiley-glyph-cache nil)
|
|
157 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
|
|
158
|
98
|
159 (defvar smiley-map (make-sparse-keymap "smiley-keys")
|
108
|
160 "Keymap to toggle smiley states.")
|
98
|
161
|
|
162 (define-key smiley-map [(button2)] 'smiley-toggle-extent)
|
|
163
|
0
|
164 (defun smiley-create-glyph (smiley pixmap)
|
|
165 (and
|
|
166 smiley-running-xemacs
|
|
167 (or
|
|
168 (cdr-safe (assoc pixmap smiley-glyph-cache))
|
108
|
169 (let* ((xpm-color-symbols
|
0
|
170 (and (featurep 'xpm)
|
|
171 (append `(("flesh" ,smiley-flesh-color)
|
|
172 ("features" ,smiley-features-color)
|
|
173 ("tongue" ,smiley-tongue-color))
|
|
174 xpm-color-symbols)))
|
|
175 (glyph (make-glyph
|
|
176 (list
|
|
177 (cons 'x (expand-file-name pixmap smiley-data-directory))
|
|
178 (cons 'tty smiley)))))
|
|
179 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
|
|
180 (set-glyph-face glyph 'default)
|
|
181 glyph))))
|
|
182
|
2
|
183 ;;;###autoload
|
0
|
184 (defun smiley-region (beg end)
|
|
185 "Smilify the region between point and mark."
|
|
186 (interactive "r")
|
|
187 (smiley-buffer (current-buffer) beg end))
|
|
188
|
98
|
189 (defun smiley-toggle-extent (event)
|
|
190 "Toggle smiley at given point"
|
|
191 (interactive "e")
|
|
192 (let* ((ant (event-glyph-extent event))
|
|
193 (pt (event-closest-point event))
|
|
194 ext)
|
|
195 (if (annotationp ant)
|
|
196 (when (extentp (setq ext (extent-property ant 'smiley-extent)))
|
|
197 (set-extent-property ext 'invisible nil)
|
|
198 (hide-annotation ant))
|
|
199 (when pt
|
|
200 (while (setq ext (extent-at pt (event-buffer event) nil ext 'at))
|
108
|
201 (when (annotationp (setq ant
|
98
|
202 (extent-property ext 'smiley-annotation)))
|
|
203 (reveal-annotation ant)
|
|
204 (set-extent-property ext 'invisible t)))))))
|
|
205
|
2
|
206 ;;;###autoload
|
0
|
207 (defun smiley-buffer (&optional buffer st nd)
|
|
208 (interactive)
|
2
|
209 (when (featurep 'x)
|
|
210 (save-excursion
|
|
211 (when buffer
|
|
212 (set-buffer buffer))
|
|
213 (let ((buffer-read-only nil)
|
98
|
214 (alist (if (symbolp smiley-regexp-alist)
|
|
215 (symbol-value smiley-regexp-alist)
|
|
216 smiley-regexp-alist))
|
2
|
217 entry regexp beg group file)
|
|
218 (goto-char (or st (point-min)))
|
|
219 (setq beg (point))
|
|
220 ;; loop through alist
|
|
221 (while (setq entry (pop alist))
|
|
222 (setq regexp (car entry)
|
|
223 group (cadr entry)
|
|
224 file (caddr entry))
|
|
225 (goto-char beg)
|
|
226 (while (re-search-forward regexp nd t)
|
|
227 (let* ((start (match-beginning group))
|
|
228 (end (match-end group))
|
|
229 (glyph (smiley-create-glyph (buffer-substring start end)
|
|
230 file)))
|
|
231 (when glyph
|
|
232 (mapcar 'delete-annotation (annotations-at end))
|
98
|
233 (let ((ext (make-extent start end))
|
|
234 (ant (make-annotation glyph end 'text)))
|
|
235 ;; set text extent params
|
70
|
236 (set-extent-property ext 'end-open t)
|
98
|
237 (set-extent-property ext 'start-open t)
|
|
238 (set-extent-property ext 'invisible t)
|
|
239 (set-extent-property ext 'keymap smiley-map)
|
|
240 (set-extent-property ext 'mouse-face smiley-mouse-face)
|
|
241 (set-extent-property ext 'intangible t)
|
|
242 ;; set annotation params
|
|
243 (set-extent-property ant 'mouse-face smiley-mouse-face)
|
|
244 (set-extent-property ant 'keymap smiley-map)
|
|
245 ;; remember each other
|
|
246 (set-extent-property ant 'smiley-extent ext)
|
|
247 (set-extent-property ext 'smiley-annotation ant))
|
2
|
248 (when (smiley-end-paren-p start end)
|
|
249 (make-annotation ")" end 'text))
|
|
250 (goto-char end)))))))))
|
0
|
251
|
|
252 (defun smiley-end-paren-p (start end)
|
|
253 "Try to guess whether the current smiley is an end-paren smiley."
|
|
254 (save-excursion
|
|
255 (goto-char start)
|
|
256 (when (and (re-search-backward "[()]" nil t)
|
|
257 (= (following-char) ?\()
|
|
258 (goto-char end)
|
|
259 (or (not (re-search-forward "[()]" nil t))
|
|
260 (= (char-after (1- (point))) ?\()))
|
|
261 t)))
|
|
262
|
108
|
263 (defvar gnus-article-buffer)
|
|
264 ;;;###autoload
|
0
|
265 (defun gnus-smiley-display ()
|
136
|
266 "Display \"smileys\" as small graphical icons."
|
0
|
267 (interactive)
|
|
268 (save-excursion
|
|
269 (set-buffer gnus-article-buffer)
|
|
270 (goto-char (point-min))
|
|
271 ;; We skip the headers.
|
|
272 (unless (search-forward "\n\n" nil t)
|
|
273 (goto-char (point-max)))
|
|
274 (smiley-buffer (current-buffer) (point))))
|
|
275
|
|
276 (provide 'smiley)
|
|
277
|
|
278 ;;; smiley.el ends here
|