1 ;;; smiley.el --- displaying smiley faces
3 ;; Copyright (C) 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: Dave Love <fx@gnu.org>
7 ;; Keywords: news mail multimedia
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; A re-written, simplified version of Wes Hardaker's XEmacs smiley.el
29 ;; which might be merged back to smiley.el if we get an assignment for
30 ;; that. We don't have assignments for the images smiley.el uses, but
31 ;; I'm not sure we need that degree of rococoness and defaults like a
32 ;; yellow background. Also, using PBM means we can display the images
33 ;; more generally. -- fx
34 ;; `smiley.el' was replaced by `smiley-ems.el' on 2002-01-26 (after fx'
53 (eval-when-compile (require 'cl
))
58 "Turn :-)'s into real images."
61 ;; Maybe this should go.
62 (defcustom smiley-data-directory
63 (nnheader-find-etc-directory "images/smilies")
64 "Location of the smiley faces files."
68 ;; The XEmacs version has a baroque, if not rococo, set of these.
69 (defcustom smiley-regexp-alist
70 '(("\\(:-?)\\)\\W" 1 "smile")
71 ("\\(;-?)\\)\\W" 1 "blink")
72 ("\\(:-]\\)\\W" 1 "forced")
73 ("\\(8-)\\)\\W" 1 "braindamaged")
74 ("\\(:-|\\)\\W" 1 "indifferent")
75 ("\\(:-[/\\]\\)\\W" 1 "wry")
76 ("\\(:-(\\)\\W" 1 "sad")
77 ("\\(:-{\\)\\W" 1 "frown"))
78 "*A list of regexps to map smilies to images.
79 The elements are (REGEXP MATCH IMAGE), where MATCH is the submatch in
80 regexp to replace with IMAGE. IMAGE is the name of an image file in
81 `smiley-data-directory'."
82 :type
'(repeat (list regexp
83 (integer :tag
"Regexp match number")
84 (string :tag
"Image name")))
85 :set
(lambda (symbol value
)
86 (set-default symbol value
)
87 (smiley-update-cache))
88 :initialize
'custom-initialize-default
91 (defcustom gnus-smiley-file-types
92 (let ((types (list "pbm")))
93 (when (gnus-image-type-available-p 'xpm
)
96 "*List of suffixes on smiley file names to try."
98 :type
'(repeat string
)
101 (defvar smiley-cached-regexp-alist nil
)
103 (defun smiley-update-cache ()
104 (setq smiley-cached-regexp-alist nil
)
105 (dolist (elt (if (symbolp smiley-regexp-alist
)
106 (symbol-value smiley-regexp-alist
)
107 smiley-regexp-alist
))
108 (let ((types gnus-smiley-file-types
)
110 (while (and (not file
)
111 (setq type
(pop types
)))
112 (unless (file-exists-p
113 (setq file
(expand-file-name (concat (nth 2 elt
) "." type
)
114 smiley-data-directory
)))
117 (let ((image (gnus-create-image file
(intern type
) nil
120 (push (list (car elt
) (cadr elt
) image
)
121 smiley-cached-regexp-alist
)))))))
124 ;; (defvar smiley-mouse-map
125 ;; (let ((map (make-sparse-keymap)))
126 ;; (define-key map [down-mouse-2] 'ignore) ; override widget
127 ;; (define-key map [mouse-2]
128 ;; 'smiley-mouse-toggle-buffer)
132 (defun smiley-region (start end
)
133 "Replace in the region `smiley-regexp-alist' matches with corresponding images.
134 A list of images is returned."
136 (when (gnus-graphic-display-p)
137 (unless smiley-cached-regexp-alist
138 (smiley-update-cache))
140 (let ((beg (or start
(point-min)))
141 group image images string
)
142 (dolist (entry smiley-cached-regexp-alist
)
143 (setq group
(nth 1 entry
)
146 (while (re-search-forward (car entry
) end t
)
147 (setq string
(match-string group
))
148 (goto-char (match-end group
))
149 (delete-region (match-beginning group
) (match-end group
))
152 (gnus-add-wash-type 'smiley
)
153 (gnus-add-image 'smiley image
)
154 (gnus-put-image image string
'smiley
))))
158 (defun smiley-buffer (&optional buffer
)
159 "Run `smiley-region' at the buffer, specified in the argument or
160 interactively. If there's no argument, do it at the current buffer"
161 (interactive "bBuffer to run smiley-region: ")
164 (set-buffer (get-buffer buffer
)))
165 (smiley-region (point-min) (point-max))))
167 (defun smiley-toggle-buffer (&optional arg
)
168 "Toggle displaying smiley faces in article buffer.
169 With arg, turn displaying on if and only if arg is positive."
171 (gnus-with-article-buffer
172 (if (if (numberp arg
)
174 (not (memq 'smiley gnus-article-wash-types
)))
175 (smiley-region (point-min) (point-max))
176 (gnus-delete-images 'smiley
))))
178 (defun smiley-mouse-toggle-buffer (event)
179 "Toggle displaying smiley faces.
180 With arg, turn displaying on if and only if arg is positive."
183 (save-window-excursion
184 (mouse-set-point event
)
185 (smiley-toggle-buffer))))
189 ;;; arch-tag: 5beb161b-4321-40af-8ac9-876afb8ee818
190 ;;; smiley.el ends here