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
|
163
|
56 '(("\\(\\^_?\\^;;;\\)\\W" 1 "WideFaceAse3.xbm")
|
|
57 ("\\(\\^_?\\^;;\\)\\W" 1 "WideFaceAse2.xbm")
|
|
58 ("\\(\\^_?\\^;\\)\\W" 1 "WideFaceAse1.xbm")
|
|
59 ("\\(\\^_?\\^\\)\\W" 1 "WideFaceSmile.xbm")
|
|
60 ("\\(\\;_;\\)\\W" 1 "WideFaceWeep.xbm")
|
|
61 ("\\(\\T_T\\)\\W" 1 "WideFaceWeep.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
|
163
|
84 '(("\\(:-+[<«]+\\)\\W" 1 "FaceAngry.xpm")
|
2
|
85 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
|
|
86 ("\\(:-+D\\)\\W" 1 "FaceGrinning.xpm")
|
|
87 ("\\(:-+[}»]+\\)\\W" 1 "FaceHappy.xpm")
|
98
|
88 ("\\(:-*)+\\)\\W" 1 "FaceHappy.xpm")
|
2
|
89 ("\\(:-+[/\\\"]+\\)\\W" 1 "FaceIronic.xpm")
|
|
90 ("\\([8|]-+[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
|
|
91 ("\\([:|]-+#+\\)\\W" 1 "FaceNyah.xpm")
|
|
92 ("\\(:-+[({]+\\)\\W" 1 "FaceSad.xpm")
|
|
93 ("\\(:-+[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
|
|
94 ("\\(:-+|\\)\\W" 1 "FaceStraight.xpm")
|
|
95 ("\\(:-+p\\)\\W" 1 "FaceTalking.xpm")
|
|
96 ("\\(:-+d\\)\\W" 1 "FaceTasty.xpm")
|
|
97 ("\\(;-+[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
|
|
98 ("\\(:-+[Vvµ]\\)\\W" 1 "FaceWry.xpm")
|
98
|
99 ("\\(][:8B]-[)>]\\)\\W" 1 "FaceDevilish.xpm")
|
2
|
100 ("\\([:|]-+P\\)\\W" 1 "FaceYukky.xpm"))
|
98
|
101 "Smileys with noses. These get less false matches."
|
108
|
102 :type '(repeat (list regexp
|
98
|
103 (integer :tag "Match")
|
|
104 (string :tag "Image")))
|
|
105 :group 'smiley)
|
2
|
106
|
98
|
107 (defcustom smiley-regexp-alist smiley-deformed-regexp-alist
|
2
|
108 "A list of regexps to map smilies to real images.
|
108
|
109 Defaults to the contents of `smiley-deformed-regexp-alist'.
|
|
110 An alternative is `smiley-nosey-regexp-alist' that matches less
|
|
111 aggressively.
|
98
|
112 If this is a symbol, take its value."
|
|
113 :type '(radio (variable-item smiley-deformed-regexp-alist)
|
|
114 (variable-item smiley-nosey-regexp-alist)
|
108
|
115 symbol
|
|
116 (repeat (list regexp
|
98
|
117 (integer :tag "Match")
|
|
118 (string :tag "Image"))))
|
|
119 :group 'smiley)
|
0
|
120
|
98
|
121 (defcustom smiley-flesh-color "yellow"
|
|
122 "Flesh color."
|
|
123 :type 'string
|
|
124 :group 'smiley)
|
0
|
125
|
98
|
126 (defcustom smiley-features-color "black"
|
|
127 "Features color."
|
|
128 :type 'string
|
|
129 :group 'smiley)
|
|
130
|
|
131 (defcustom smiley-tongue-color "red"
|
|
132 "Tongue color."
|
|
133 :type 'string
|
|
134 :group 'smiley)
|
16
|
135
|
98
|
136 (defcustom smiley-circle-color "black"
|
|
137 "Circle color."
|
|
138 :type 'string
|
|
139 :group 'smiley)
|
0
|
140
|
98
|
141 (defcustom smiley-mouse-face 'highlight
|
|
142 "Face used for mouse highlighting in the smiley buffer.
|
|
143
|
|
144 Smiley buttons will be displayed in this face when the cursor is
|
|
145 above them."
|
|
146 :type 'face
|
|
147 :group 'smiley)
|
|
148
|
0
|
149
|
|
150 (defvar smiley-glyph-cache nil)
|
|
151 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
|
|
152
|
98
|
153 (defvar smiley-map (make-sparse-keymap "smiley-keys")
|
108
|
154 "Keymap to toggle smiley states.")
|
98
|
155
|
|
156 (define-key smiley-map [(button2)] 'smiley-toggle-extent)
|
|
157
|
0
|
158 (defun smiley-create-glyph (smiley pixmap)
|
|
159 (and
|
|
160 smiley-running-xemacs
|
|
161 (or
|
|
162 (cdr-safe (assoc pixmap smiley-glyph-cache))
|
108
|
163 (let* ((xpm-color-symbols
|
0
|
164 (and (featurep 'xpm)
|
|
165 (append `(("flesh" ,smiley-flesh-color)
|
|
166 ("features" ,smiley-features-color)
|
|
167 ("tongue" ,smiley-tongue-color))
|
|
168 xpm-color-symbols)))
|
|
169 (glyph (make-glyph
|
|
170 (list
|
|
171 (cons 'x (expand-file-name pixmap smiley-data-directory))
|
|
172 (cons 'tty smiley)))))
|
|
173 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
|
|
174 (set-glyph-face glyph 'default)
|
|
175 glyph))))
|
|
176
|
2
|
177 ;;;###autoload
|
0
|
178 (defun smiley-region (beg end)
|
|
179 "Smilify the region between point and mark."
|
|
180 (interactive "r")
|
|
181 (smiley-buffer (current-buffer) beg end))
|
|
182
|
98
|
183 (defun smiley-toggle-extent (event)
|
|
184 "Toggle smiley at given point"
|
|
185 (interactive "e")
|
|
186 (let* ((ant (event-glyph-extent event))
|
|
187 (pt (event-closest-point event))
|
|
188 ext)
|
|
189 (if (annotationp ant)
|
|
190 (when (extentp (setq ext (extent-property ant 'smiley-extent)))
|
|
191 (set-extent-property ext 'invisible nil)
|
|
192 (hide-annotation ant))
|
|
193 (when pt
|
|
194 (while (setq ext (extent-at pt (event-buffer event) nil ext 'at))
|
108
|
195 (when (annotationp (setq ant
|
98
|
196 (extent-property ext 'smiley-annotation)))
|
|
197 (reveal-annotation ant)
|
|
198 (set-extent-property ext 'invisible t)))))))
|
|
199
|
2
|
200 ;;;###autoload
|
0
|
201 (defun smiley-buffer (&optional buffer st nd)
|
|
202 (interactive)
|
2
|
203 (when (featurep 'x)
|
|
204 (save-excursion
|
|
205 (when buffer
|
|
206 (set-buffer buffer))
|
|
207 (let ((buffer-read-only nil)
|
98
|
208 (alist (if (symbolp smiley-regexp-alist)
|
|
209 (symbol-value smiley-regexp-alist)
|
|
210 smiley-regexp-alist))
|
2
|
211 entry regexp beg group file)
|
|
212 (goto-char (or st (point-min)))
|
|
213 (setq beg (point))
|
|
214 ;; loop through alist
|
|
215 (while (setq entry (pop alist))
|
|
216 (setq regexp (car entry)
|
|
217 group (cadr entry)
|
|
218 file (caddr entry))
|
|
219 (goto-char beg)
|
|
220 (while (re-search-forward regexp nd t)
|
|
221 (let* ((start (match-beginning group))
|
|
222 (end (match-end group))
|
|
223 (glyph (smiley-create-glyph (buffer-substring start end)
|
|
224 file)))
|
|
225 (when glyph
|
|
226 (mapcar 'delete-annotation (annotations-at end))
|
98
|
227 (let ((ext (make-extent start end))
|
|
228 (ant (make-annotation glyph end 'text)))
|
|
229 ;; set text extent params
|
70
|
230 (set-extent-property ext 'end-open t)
|
98
|
231 (set-extent-property ext 'start-open t)
|
|
232 (set-extent-property ext 'invisible t)
|
|
233 (set-extent-property ext 'keymap smiley-map)
|
|
234 (set-extent-property ext 'mouse-face smiley-mouse-face)
|
|
235 (set-extent-property ext 'intangible t)
|
|
236 ;; set annotation params
|
|
237 (set-extent-property ant 'mouse-face smiley-mouse-face)
|
|
238 (set-extent-property ant 'keymap smiley-map)
|
|
239 ;; remember each other
|
|
240 (set-extent-property ant 'smiley-extent ext)
|
|
241 (set-extent-property ext 'smiley-annotation ant))
|
2
|
242 (when (smiley-end-paren-p start end)
|
|
243 (make-annotation ")" end 'text))
|
|
244 (goto-char end)))))))))
|
0
|
245
|
|
246 (defun smiley-end-paren-p (start end)
|
|
247 "Try to guess whether the current smiley is an end-paren smiley."
|
|
248 (save-excursion
|
|
249 (goto-char start)
|
|
250 (when (and (re-search-backward "[()]" nil t)
|
|
251 (= (following-char) ?\()
|
|
252 (goto-char end)
|
|
253 (or (not (re-search-forward "[()]" nil t))
|
|
254 (= (char-after (1- (point))) ?\()))
|
|
255 t)))
|
|
256
|
108
|
257 (defvar gnus-article-buffer)
|
|
258 ;;;###autoload
|
0
|
259 (defun gnus-smiley-display ()
|
136
|
260 "Display \"smileys\" as small graphical icons."
|
0
|
261 (interactive)
|
|
262 (save-excursion
|
|
263 (set-buffer gnus-article-buffer)
|
|
264 (goto-char (point-min))
|
|
265 ;; We skip the headers.
|
|
266 (unless (search-forward "\n\n" nil t)
|
|
267 (goto-char (point-max)))
|
|
268 (smiley-buffer (current-buffer) (point))))
|
|
269
|
|
270 (provide 'smiley)
|
|
271
|
|
272 ;;; smiley.el ends here
|