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 ;; The smilies were drawn by Joe Reiss <joe@jreiss.async.vt.edu>.
38 (require 'annotations)
39 (eval-when-compile (require 'cl))
41 (defvar smiley-data-directory (message-xmas-find-glyph-directory "smilies")
42 "Location of the smiley faces files.")
44 (defvar smiley-regexp-alist
45 '(("\\s-\\(:-*\\]\\)" 1 "FaceGrinning.xpm")
46 ("\\s-\\(:-*[oO]\\)" 1 "FaceStartled.xpm")
47 ("\\s-\\(:-*[)>]\\)" 1 "FaceHappy.xpm")
48 ("\\s-\\(;-*[>)]\\)" 1 "FaceWinking.xpm")
49 ("\\s-\\(:-[/\\]\\)" 1 "FaceIronic.xpm")
50 ("\\s-\\(:-*|\\)" 1 "FaceStraight.xpm")
51 ("\\s-\\(:-*<\\)" 1 "FaceAngry.xpm")
52 ("\\s-\\(:-*d\\)" 1 "FaceTasty.xpm")
53 ("\\s-\\(:-*[pP]\\)" 1 "FaceYukky.xpm")
54 ("\\s-\\(8-*|\\)" 1 "FaceKOed.xpm")
55 ("\\s-\\(:-*(\\)" 1 "FaceAngry.xpm"))
56 "A list of regexps to map smilies to real images.")
58 (defvar smiley-flesh-color "yellow"
61 (defvar smiley-features-color "black"
64 (defvar smiley-tongue-color "red"
67 (defvar smiley-circle-color "black"
70 (defvar smiley-glyph-cache nil)
71 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
73 (defun smiley-create-glyph (smiley pixmap)
77 (cdr-safe (assoc pixmap smiley-glyph-cache))
78 (let* ((xpm-color-symbols
80 (append `(("flesh" ,smiley-flesh-color)
81 ("features" ,smiley-features-color)
82 ("tongue" ,smiley-tongue-color))
86 (cons 'x (expand-file-name pixmap smiley-data-directory))
87 (cons 'tty smiley)))))
88 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
89 (set-glyph-face glyph 'default)
93 (defun smiley-region (beg end)
94 "Smilify the region between point and mark."
96 (smiley-buffer (current-buffer) beg end))
99 (defun smiley-buffer (&optional buffer st nd)
102 (and buffer (set-buffer buffer))
103 (let ((buffer-read-only nil)
104 (alist smiley-regexp-alist)
105 entry regexp beg group file)
106 (goto-char (or st (point-min)))
108 ;; loop through alist
109 (while (setq entry (pop alist))
110 (setq regexp (car entry)
114 (while (re-search-forward regexp nd t)
115 (let* ((start (match-beginning group))
116 (end (match-end group))
117 (glyph (smiley-create-glyph (buffer-substring start end)
120 (mapcar 'delete-annotation (annotations-at end))
121 (let ((ext (make-extent start end)))
122 (set-extent-property ext 'invisible t)
123 (set-extent-property ext 'end-open t)
124 (set-extent-property ext 'intangible t))
125 (make-annotation glyph end 'text)
126 (when (smiley-end-paren-p start end)
127 (make-annotation ")" end 'text))
128 (goto-char end))))))))
130 (defun smiley-end-paren-p (start end)
131 "Try to guess whether the current smiley is an end-paren smiley."
134 (when (and (re-search-backward "[()]" nil t)
135 (= (following-char) ?\()
137 (or (not (re-search-forward "[()]" nil t))
138 (= (char-after (1- (point))) ?\()))
142 (defun gnus-smiley-display ()
145 (set-buffer gnus-article-buffer)
146 (goto-char (point-min))
147 ;; We skip the headers.
148 (unless (search-forward "\n\n" nil t)
149 (goto-char (point-max)))
150 (smiley-buffer (current-buffer) (point))))
154 ;;; smiley.el ends here