annotate lisp/gnus/smiley.el @ 16:0293115a14e9 r19-15b91

Import from CVS: tag r19-15b91
author cvs
date Mon, 13 Aug 2007 08:49:20 +0200
parents ac2d302a0011
children d95e72db5c07
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
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
2 ;; Copyright (C) 1996,97 Free Software Foundation, Inc.
0
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
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
36 ;; The smilies were drawn by Joe Reiss <jreiss@vt.edu>.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
37
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (require 'annotations)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
39 (require 'messagexmas)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
40 (require 'cl)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
41 (require 'custom)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
42
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
43 (defgroup smiley nil
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
44 "Turn :-)'s into real images (XEmacs)."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
45 :group 'gnus-visual)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
47 (defcustom smiley-data-directory (message-xmas-find-glyph-directory "smilies")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
48 "Location of the smiley faces files."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
49 :type 'directory
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
50 :group 'smiley)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
52 ;; Notice the subtle differences in the regular expressions in the two alists below
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
54 (defcustom smiley-deformed-regexp-alist
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55 '(("\\(:-*[<«]+\\)\\W" 1 "FaceAngry.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 ("\\(:-*D\\)\\W" 1 "FaceGrinning.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 ("\\(:-*[)>}»]+\\)\\W" 1 "FaceHappy.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 ("\\(:-*[/\\\"]\\)[^/]" 1 "FaceIronic.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60 ("\\([8|]-*[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 ("\\([:|]-*#+\\)\\W" 1 "FaceNyah.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 ("\\(:-*[({]+\\)\\W" 1 "FaceSad.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 ("\\(:-*[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
64 ("\\(:-*|\\)\\W" 1 "FaceStraight.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 ("\\(:-*p\\)\\W" 1 "FaceTalking.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
66 ("\\(:-*d\\)\\W" 1 "FaceTasty.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 ("\\(;-*[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
68 ("\\(:-*[Vvµ]\\)\\W" 1 "FaceWry.xpm")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
69 ("\\([:|]-*P\\)\\W" 1 "FaceYukky.xpm"))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
70 "Normal and deformed faces for smilies."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
71 :type '(repeat (list regexp
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
72 (integer :tag "Match")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
73 (string :tag "Image")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
74 :group 'smiley)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
75
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
76 (defcustom smiley-nosey-regexp-alist
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 '(("\\(:-+[<«]+\\)\\W" 1 "FaceAngry.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 ("\\(:-+\\]+\\)\\W" 1 "FaceGoofy.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 ("\\(:-+D\\)\\W" 1 "FaceGrinning.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80 ("\\(:-+[}»]+\\)\\W" 1 "FaceHappy.xpm")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
81 ("\\(:-*)+\\)\\W" 1 "FaceHappy.xpm")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
82 ("\\(:-+[/\\\"]+\\)\\W" 1 "FaceIronic.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
83 ("\\([8|]-+[|Oo%]\\)\\W" 1 "FaceKOed.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
84 ("\\([:|]-+#+\\)\\W" 1 "FaceNyah.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
85 ("\\(:-+[({]+\\)\\W" 1 "FaceSad.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
86 ("\\(:-+[Oo\*]\\)\\W" 1 "FaceStartled.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
87 ("\\(:-+|\\)\\W" 1 "FaceStraight.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
88 ("\\(:-+p\\)\\W" 1 "FaceTalking.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
89 ("\\(:-+d\\)\\W" 1 "FaceTasty.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
90 ("\\(;-+[>)}»]+\\)\\W" 1 "FaceWinking.xpm")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
91 ("\\(:-+[Vvµ]\\)\\W" 1 "FaceWry.xpm")
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
92 ("\\(][:8B]-[)>]\\)\\W" 1 "FaceDevilish.xpm")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
93 ("\\([:|]-+P\\)\\W" 1 "FaceYukky.xpm"))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
94 "Smileys with noses. These get less false matches."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
95 :type '(repeat (list regexp
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
96 (integer :tag "Match")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
97 (string :tag "Image")))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
98 :group 'smiley)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
99
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
100 (defcustom smiley-regexp-alist smiley-deformed-regexp-alist
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
101 "A list of regexps to map smilies to real images.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
102 Defaults to the content of smiley-deformed-regexp-alist.
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
103 An alternative smiley-nosey-regexp-alist that
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
104 matches less aggressively is available.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
105 If this is a symbol, take its value."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
106 :type '(radio (variable-item smiley-deformed-regexp-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
107 (variable-item smiley-nosey-regexp-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
108 symbol
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
109 (repeat (list regexp
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
110 (integer :tag "Match")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
111 (string :tag "Image"))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
112 :group 'smiley)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
114 (defcustom smiley-flesh-color "yellow"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
115 "Flesh color."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
116 :type 'string
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
117 :group 'smiley)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
119 (defcustom smiley-features-color "black"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
120 "Features color."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
121 :type 'string
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
122 :group 'smiley)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
123
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
124 (defcustom smiley-tongue-color "red"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
125 "Tongue color."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
126 :type 'string
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
127 :group 'smiley)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
129 (defcustom smiley-circle-color "black"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
130 "Circle color."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
131 :type 'string
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
132 :group 'smiley)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
134 (defcustom smiley-mouse-face 'highlight
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
135 "Face used for mouse highlighting in the smiley buffer.
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
136
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
137 Smiley buttons will be displayed in this face when the cursor is
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
138 above them."
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
139 :type 'face
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
140 :group 'smiley)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
141
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defvar smiley-glyph-cache nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defvar smiley-running-xemacs (string-match "XEmacs" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
146 (defvar smiley-map (make-sparse-keymap "smiley-keys")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
147 "keymap to toggle smiley states")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
148
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
149 (define-key smiley-map [(button2)] 'smiley-toggle-extent)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
150
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defun smiley-create-glyph (smiley pixmap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 smiley-running-xemacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (cdr-safe (assoc pixmap smiley-glyph-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (let* ((xpm-color-symbols
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (and (featurep 'xpm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (append `(("flesh" ,smiley-flesh-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ("features" ,smiley-features-color)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ("tongue" ,smiley-tongue-color))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 xpm-color-symbols)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (glyph (make-glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (cons 'x (expand-file-name pixmap smiley-data-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (cons 'tty smiley)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (setq smiley-glyph-cache (cons (cons pixmap glyph) smiley-glyph-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (set-glyph-face glyph 'default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 glyph))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
170 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (defun smiley-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 "Smilify the region between point and mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (interactive "r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (smiley-buffer (current-buffer) beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
176 (defun smiley-toggle-extent (event)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
177 "Toggle smiley at given point"
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
178 (interactive "e")
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
179 (let* ((ant (event-glyph-extent event))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
180 (pt (event-closest-point event))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
181 ext)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
182 (if (annotationp ant)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
183 (when (extentp (setq ext (extent-property ant 'smiley-extent)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
184 (set-extent-property ext 'invisible nil)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
185 (hide-annotation ant))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
186 (when pt
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
187 (while (setq ext (extent-at pt (event-buffer event) nil ext 'at))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
188 (when (annotationp (setq ant
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
189 (extent-property ext 'smiley-annotation)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
190 (reveal-annotation ant)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
191 (set-extent-property ext 'invisible t)))))))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
192
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
193 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (defun smiley-buffer (&optional buffer st nd)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (interactive)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
196 (when (featurep 'x)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
197 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
198 (when buffer
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
199 (set-buffer buffer))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
200 (let ((buffer-read-only nil)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
201 (alist (if (symbolp smiley-regexp-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
202 (symbol-value smiley-regexp-alist)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
203 smiley-regexp-alist))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
204 entry regexp beg group file)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
205 (goto-char (or st (point-min)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
206 (setq beg (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
207 ;; loop through alist
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
208 (while (setq entry (pop alist))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
209 (setq regexp (car entry)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
210 group (cadr entry)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
211 file (caddr entry))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
212 (goto-char beg)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
213 (while (re-search-forward regexp nd t)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
214 (let* ((start (match-beginning group))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
215 (end (match-end group))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
216 (glyph (smiley-create-glyph (buffer-substring start end)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
217 file)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
218 (when glyph
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
219 (mapcar 'delete-annotation (annotations-at end))
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
220 (let ((ext (make-extent start end))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
221 (ant (make-annotation glyph end 'text)))
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
222 ;; set text extent params
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
223 (set-extent-property ext 'end-open t)
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
224 (set-extent-property ext 'start-open t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
225 (set-extent-property ext 'invisible t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
226 (set-extent-property ext 'keymap smiley-map)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
227 (set-extent-property ext 'mouse-face 'smiley-mouse-face)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
228 (set-extent-property ext 'intangible t)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
229 ;; set annotation params
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
230 (set-extent-property ant 'mouse-face 'smiley-mouse-face)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
231 (set-extent-property ant 'keymap smiley-map)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
232 ;; remember each other
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
233 (set-extent-property ant 'smiley-extent ext)
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
234 (set-extent-property ext 'smiley-annotation ant))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
235 (when (smiley-end-paren-p start end)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
236 (make-annotation ")" end 'text))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
237 (goto-char end)))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (defun smiley-end-paren-p (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 "Try to guess whether the current smiley is an end-paren smiley."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (when (and (re-search-backward "[()]" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (= (following-char) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (or (not (re-search-forward "[()]" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (= (char-after (1- (point))) ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (defun gnus-smiley-display ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (set-buffer gnus-article-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; We skip the headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (unless (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (goto-char (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (smiley-buffer (current-buffer) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (provide 'smiley)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;; smiley.el ends here