0
|
1 ;;; smiley.el --- displaying smiley faces
|
70
|
2 ;; Copyright (C) 1996 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
|
70
|
36 ;; The smilies were drawn by Joe Reiss <joe@jreiss.async.vt.edu>.
|
2
|
37
|
0
|
38 (require 'annotations)
|
2
|
39 (require 'messagexmas)
|
70
|
40 (eval-when-compile (require 'cl))
|
0
|
41
|
70
|
42 (defvar smiley-data-directory (message-xmas-find-glyph-directory "smilies")
|
|
43 "Location of the smiley faces files.")
|
0
|
44
|
70
|
45 ;; Notice the subtle differences in the regular expessions in the two alists below
|
2
|
46
|
70
|
47 (defvar smiley-deformed-regexp-alist
|
2
|
48 '(("\\(:-*[<«]+\\)\\W" 1 "FaceAngry.xpm")
|
|
49 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
|
|
50 ("\\(:-*D\\)\\W" 1 "FaceGrinning.xpm")
|
|
51 ("\\(:-*[)>}»]+\\)\\W" 1 "FaceHappy.xpm")
|
70
|
52 ("\\(:-*[/\\\"]\\)[^/]" 1 "FaceIronic.xpm")
|
2
|
53 ("\\([8|]-*[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
|
|
54 ("\\([:|]-*#+\\)\\W" 1 "FaceNyah.xpm")
|
|
55 ("\\(:-*[({]+\\)\\W" 1 "FaceSad.xpm")
|
|
56 ("\\(:-*[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
|
|
57 ("\\(:-*|\\)\\W" 1 "FaceStraight.xpm")
|
|
58 ("\\(:-*p\\)\\W" 1 "FaceTalking.xpm")
|
|
59 ("\\(:-*d\\)\\W" 1 "FaceTasty.xpm")
|
|
60 ("\\(;-*[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
|
30
|
61 ("\\(:-*[Vvµ]\\)\\W" 1 "FaceWry.xpm")
|
2
|
62 ("\\([:|]-*P\\)\\W" 1 "FaceYukky.xpm"))
|
70
|
63 "Normal and deformed faces for smilies.")
|
2
|
64
|
70
|
65 (defvar smiley-nosey-regexp-alist
|
2
|
66 '(("\\(:-+[<«]+\\)\\W" 1 "FaceAngry.xpm")
|
|
67 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
|
|
68 ("\\(:-+D\\)\\W" 1 "FaceGrinning.xpm")
|
|
69 ("\\(:-+[}»]+\\)\\W" 1 "FaceHappy.xpm")
|
70
|
70 ("\\(:-*)+\\)\\W" 1 "FaceHappy.xpm") ;; The exception that confirms the rule
|
2
|
71 ("\\(:-+[/\\\"]+\\)\\W" 1 "FaceIronic.xpm")
|
|
72 ("\\([8|]-+[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
|
|
73 ("\\([:|]-+#+\\)\\W" 1 "FaceNyah.xpm")
|
|
74 ("\\(:-+[({]+\\)\\W" 1 "FaceSad.xpm")
|
|
75 ("\\(:-+[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
|
|
76 ("\\(:-+|\\)\\W" 1 "FaceStraight.xpm")
|
|
77 ("\\(:-+p\\)\\W" 1 "FaceTalking.xpm")
|
|
78 ("\\(:-+d\\)\\W" 1 "FaceTasty.xpm")
|
|
79 ("\\(;-+[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
|
|
80 ("\\(:-+[Vvµ]\\)\\W" 1 "FaceWry.xpm")
|
|
81 ("\\([:|]-+P\\)\\W" 1 "FaceYukky.xpm"))
|
70
|
82 "Smileys with noses. These get less false matches.")
|
2
|
83
|
70
|
84 (defvar smiley-regexp-alist smiley-deformed-regexp-alist
|
2
|
85 "A list of regexps to map smilies to real images.
|
70
|
86 Defaults to the content of smiley-deformed-regexp-alist.
|
|
87 An alternative smiley-nose-regexp-alist that
|
|
88 matches less aggresively is available.")
|
0
|
89
|
70
|
90 (defvar smiley-flesh-color "yellow"
|
|
91 "Flesh color.")
|
0
|
92
|
70
|
93 (defvar smiley-features-color "black"
|
|
94 "Features color.")
|
16
|
95
|
70
|
96 (defvar smiley-tongue-color "red"
|
|
97 "Tongue color.")
|
0
|
98
|
70
|
99 (defvar smiley-circle-color "black"
|
|
100 "Circle color.")
|
0
|
101
|
|
102 (defvar smiley-glyph-cache nil)
|
|
103 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
|
|
104
|
|
105 (defun smiley-create-glyph (smiley pixmap)
|
|
106 (and
|
|
107 smiley-running-xemacs
|
|
108 (or
|
|
109 (cdr-safe (assoc pixmap smiley-glyph-cache))
|
70
|
110 (let* ((xpm-color-symbols
|
0
|
111 (and (featurep 'xpm)
|
|
112 (append `(("flesh" ,smiley-flesh-color)
|
|
113 ("features" ,smiley-features-color)
|
|
114 ("tongue" ,smiley-tongue-color))
|
|
115 xpm-color-symbols)))
|
|
116 (glyph (make-glyph
|
|
117 (list
|
|
118 (cons 'x (expand-file-name pixmap smiley-data-directory))
|
|
119 (cons 'tty smiley)))))
|
|
120 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
|
|
121 (set-glyph-face glyph 'default)
|
|
122 glyph))))
|
|
123
|
2
|
124 ;;;###autoload
|
0
|
125 (defun smiley-region (beg end)
|
|
126 "Smilify the region between point and mark."
|
|
127 (interactive "r")
|
|
128 (smiley-buffer (current-buffer) beg end))
|
|
129
|
2
|
130 ;;;###autoload
|
0
|
131 (defun smiley-buffer (&optional buffer st nd)
|
|
132 (interactive)
|
2
|
133 (when (featurep 'x)
|
|
134 (save-excursion
|
|
135 (when buffer
|
|
136 (set-buffer buffer))
|
|
137 (let ((buffer-read-only nil)
|
70
|
138 (alist smiley-regexp-alist)
|
2
|
139 entry regexp beg group file)
|
|
140 (goto-char (or st (point-min)))
|
|
141 (setq beg (point))
|
|
142 ;; loop through alist
|
|
143 (while (setq entry (pop alist))
|
|
144 (setq regexp (car entry)
|
|
145 group (cadr entry)
|
|
146 file (caddr entry))
|
|
147 (goto-char beg)
|
|
148 (while (re-search-forward regexp nd t)
|
|
149 (let* ((start (match-beginning group))
|
|
150 (end (match-end group))
|
|
151 (glyph (smiley-create-glyph (buffer-substring start end)
|
|
152 file)))
|
|
153 (when glyph
|
|
154 (mapcar 'delete-annotation (annotations-at end))
|
70
|
155 (let ((ext (make-extent start end)))
|
16
|
156 (set-extent-property ext 'invisible t)
|
70
|
157 (set-extent-property ext 'end-open t)
|
|
158 (set-extent-property ext 'intangible t))
|
|
159 (make-annotation glyph end 'text)
|
2
|
160 (when (smiley-end-paren-p start end)
|
|
161 (make-annotation ")" end 'text))
|
|
162 (goto-char end)))))))))
|
0
|
163
|
|
164 (defun smiley-end-paren-p (start end)
|
|
165 "Try to guess whether the current smiley is an end-paren smiley."
|
|
166 (save-excursion
|
|
167 (goto-char start)
|
|
168 (when (and (re-search-backward "[()]" nil t)
|
|
169 (= (following-char) ?\()
|
|
170 (goto-char end)
|
|
171 (or (not (re-search-forward "[()]" nil t))
|
|
172 (= (char-after (1- (point))) ?\()))
|
|
173 t)))
|
|
174
|
70
|
175 ;;;###autoload
|
0
|
176 (defun gnus-smiley-display ()
|
|
177 (interactive)
|
|
178 (save-excursion
|
|
179 (set-buffer gnus-article-buffer)
|
|
180 (goto-char (point-min))
|
|
181 ;; We skip the headers.
|
|
182 (unless (search-forward "\n\n" nil t)
|
|
183 (goto-char (point-max)))
|
|
184 (smiley-buffer (current-buffer) (point))))
|
|
185
|
|
186 (provide 'smiley)
|
|
187
|
|
188 ;;; smiley.el ends here
|