annotate lisp/gnus/smiley.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; smiley.el --- displaying smiley faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Wes Hardaker <hardaker@ece.ucdavis.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: fun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; comments go here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Test smileys: :-] :-o :-) ;-) :-\ :-| :-d :-P 8-| :-(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; To use:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; (require 'smiley)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; (add-hook 'gnus-article-display-hook 'gnus-smiley-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (require 'annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (eval-when-compile (require 'cl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (defvar smiley-data-directory (message-xmas-find-glyph-directory "smilies")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 "Location of the smiley faces files.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (defvar smiley-regexp-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 '(("\\s-\\(:-*\\]\\)" 1 "FaceGrinning.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ("\\s-\\(:-*[oO]\\)" 1 "FaceStartled.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ("\\s-\\(:-*[)>]\\)" 1 "FaceHappy.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ("\\s-\\(;-*[>)]\\)" 1 "FaceWinking.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ("\\s-\\(:-[/\\]\\)" 1 "FaceIronic.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ("\\s-\\(:-*|\\)" 1 "FaceStraight.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ("\\s-\\(:-*<\\)" 1 "FaceAngry.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ("\\s-\\(:-*d\\)" 1 "FaceTasty.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ("\\s-\\(:-*[pP]\\)" 1 "FaceYukky.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ("\\s-\\(8-*|\\)" 1 "FaceKOed.xpm")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ("\\s-\\(:-*(\\)" 1 "FaceAngry.xpm"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 "A list of regexps to map smilies to real images.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (defvar smiley-flesh-color "yellow"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 "Flesh color.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (defvar smiley-features-color "black"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 "Features color.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar smiley-tongue-color "red"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Tongue color.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar smiley-circle-color "black"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "Tongue color.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (defvar smiley-glyph-cache nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (defun smiley-create-glyph (smiley pixmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 smiley-running-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (cdr-safe (assoc pixmap smiley-glyph-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (let* ((xpm-color-symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (and (featurep 'xpm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (append `(("flesh" ,smiley-flesh-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ("features" ,smiley-features-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ("tongue" ,smiley-tongue-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 xpm-color-symbols)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (glyph (make-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (cons 'x (expand-file-name pixmap smiley-data-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (cons 'tty smiley)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (set-glyph-face glyph 'default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 glyph))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;;###interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defun smiley-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "Smilify the region between point and mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (smiley-buffer (current-buffer) beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;;;###interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defun smiley-buffer (&optional buffer st nd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (and buffer (set-buffer buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (let ((buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (alist smiley-regexp-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 entry regexp beg group file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (goto-char (or st (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; loop through alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (while (setq entry (pop alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (setq regexp (car entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 group (cadr entry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 file (caddr entry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (while (re-search-forward regexp nd t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (let* ((start (match-beginning group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (end (match-end group))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (glyph (smiley-create-glyph (buffer-substring start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (when glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (mapcar 'delete-annotation (annotations-at end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (let ((ext (make-extent start end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (set-extent-property ext 'invisible t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (set-extent-property ext 'end-open t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (set-extent-property ext 'intangible t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (make-annotation glyph end 'text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (when (smiley-end-paren-p start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (make-annotation ")" end 'text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (goto-char end))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defun smiley-end-paren-p (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "Try to guess whether the current smiley is an end-paren smiley."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (when (and (re-search-backward "[()]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (= (following-char) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (or (not (re-search-forward "[()]" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (= (char-after (1- (point))) ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (defun gnus-smiley-display ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (set-buffer gnus-article-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ;; We skip the headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (unless (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (smiley-buffer (current-buffer) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (provide 'smiley)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ;;; smiley.el ends here