1 ;;; smiley.el --- displaying smiley faces
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4 ;; Author: Wes Hardaker <hardaker@ece.ucdavis.edu>
7 ;; This file is part of GNU Emacs.
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)
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.
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.
30 ;;; Test smileys: :-] :-o :-) ;-) :-< :-d :-P 8-| :-(
34 ;; (add-hook 'gnus-article-display-hook 'gnus-smiley-display t)
36 (eval-when-compile (require 'cl))
38 (defvar smiley-data-directory (message-xmas-find-glyph-directory "smilies")
39 "Location of the smiley faces files.")
41 (defvar smiley-regexp-alist
42 '((":-*\\]" 0 "FaceGrinning.xpm")
43 (":-*[oO]" 0 "FaceStartled.xpm")
44 (":-*[)>]" 0 "FaceHappy.xpm")
45 (";-*[>)]" 0 "FaceWinking.xpm")
46 (":-[/\\]" 0 "FaceIronic.xpm")
47 (":-*|" 0 "FaceStraight.xpm")
48 (":-*<" 0 "FaceAngry.xpm")
49 (":-*d" 0 "FaceTasty.xpm")
50 (":-*[pP]" 0 "FaceYukky.xpm")
51 ("8-*|" 0 "FaceKOed.xpm")
52 (":-*(" 0 "FaceAngry.xpm"))
53 "A list of regexps to map smilies to real images.")
55 (defvar smiley-flesh-color "yellow"
58 (defvar smiley-features-color "black"
61 (defvar smiley-tongue-color "red"
64 (defvar smiley-glyph-cache nil)
65 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
67 (defun smiley-create-glyph (smiley pixmap)
71 (cdr-safe (assoc pixmap smiley-glyph-cache))
72 (let* ((xpm-color-symbols
74 (append `(("flesh" ,smiley-flesh-color)
75 ("features" ,smiley-features-color)
76 ("tongue" ,smiley-tongue-color))
80 (cons 'x (expand-file-name pixmap smiley-data-directory))
81 (cons 'tty smiley)))))
82 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
83 (set-glyph-face glyph 'default)
87 (defun smiley-region (beg end)
88 "Smilify the region between point and mark."
90 (smiley-buffer (current-buffer) beg end))
93 (defun smiley-buffer (&optional buffer st nd)
96 (and buffer (set-buffer buffer))
97 (let ((buffer-read-only nil)
98 (alist smiley-regexp-alist)
99 entry regexp beg group file)
100 (goto-char (or st (point-min)))
102 ;; loop through alist
103 (while (setq entry (pop alist))
104 (setq regexp (car entry)
108 (while (re-search-forward regexp nd t)
109 (let* ((start (match-beginning group))
110 (end (match-end group))
111 (glyph (smiley-create-glyph (buffer-substring start end)
115 (mapcar 'delete-annotation (annotations-at end))
116 (let ((ext (make-extent start end)))
117 (set-extent-property ext 'invisible t)
118 (set-extent-property ext 'end-open t)
119 (set-extent-property ext 'intangible t))
120 (make-annotation glyph end 'text)
121 (goto-char end)))))))))
124 (defun gnus-smiley-display ()
127 (set-buffer gnus-article-buffer)
128 (goto-char (point-min))
129 ;; We skip the headers.
130 (unless (search-forward "\n\n" nil t)
131 (goto-char (point-max)))
132 (smiley-buffer (current-buffer) (point))))
136 ;;; smiley.el ends here