Mercurial > emacs
annotate lisp/gnus/smiley-ems.el @ 33308:3b044ee2f94a
Fernandez' icon renamed.
author | Dave Love <fx@gnu.org> |
---|---|
date | Wed, 08 Nov 2000 17:06:19 +0000 |
parents | 2c227ea13cc9 |
children | 7263c1ed74a2 |
rev | line source |
---|---|
31789 | 1 ;;; smiley-ems.el --- displaying smiley faces |
32135
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
2 |
31789 | 3 ;; Copyright (C) 2000 Free Software Foundation, Inc. |
4 | |
5 ;; Author: Dave Love <fx@gnu.org> | |
6 ;; Keywords: news mail multimedia | |
7 | |
8 ;; This file is part of GNU Emacs. | |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
24 | |
25 ;;; Commentary: | |
26 | |
27 ;; A re-written, simplified version of Wes Hardaker's XEmacs smiley.el | |
28 ;; which might be merged back to smiley.el if we get an assignment for | |
29 ;; that. We don't have assignments for the images smiley.el uses, but | |
32135
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
30 ;; I'm not sure we need that degree of rococoness and defaults like a |
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
31 ;; yellow background. Also, using PBM means we can display the images |
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
32 ;; more generally. -- fx |
31789 | 33 |
34 ;;; Test smileys: :-) :-\ :-( :-/ | |
35 | |
36 ;;; Code: | |
37 | |
38 (require 'nnheader) | |
39 | |
40 (defgroup smiley nil | |
41 "Turn :-)'s into real images." | |
42 :group 'gnus-visual) | |
43 | |
44 ;; Maybe this should go. | |
45 (defcustom smiley-data-directory (nnheader-find-etc-directory "smilies") | |
33293
2c227ea13cc9
(smiley-data-directory, smiley-regexp-alist): Doc fix.
Dave Love <fx@gnu.org>
parents:
32135
diff
changeset
|
46 "*Directory to search for the smiley image files. |
2c227ea13cc9
(smiley-data-directory, smiley-regexp-alist): Doc fix.
Dave Love <fx@gnu.org>
parents:
32135
diff
changeset
|
47 This is in addition to the normal image search path." |
31789 | 48 :type 'directory |
49 :group 'smiley) | |
50 | |
51 ;; The XEmacs version has a baroque, if not rococo, set of these. | |
52 (defcustom smiley-regexp-alist | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
53 ;; Perhaps :-) should be distinct -- it does appear in the Jargon File. |
32135
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
54 '(("\\([:;]-?)\\)\\W" 1 "smile.pbm") |
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
55 ("\\(:-[/\\]\\)\\W" 1 "wry.pbm") |
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
56 ("\\(:-[({]\\)\\W" 1 "frown.pbm")) |
31789 | 57 "*A list of regexps to map smilies to images. |
58 The elements are (REGEXP MATCH FILE), where MATCH is the submatch in | |
32135
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
59 rgexp to replace with IMAGE. IMAGE is the name of a PBM file in |
33293
2c227ea13cc9
(smiley-data-directory, smiley-regexp-alist): Doc fix.
Dave Love <fx@gnu.org>
parents:
32135
diff
changeset
|
60 `smiley-data-directory' or the normal image search path." |
31789 | 61 :type '(repeat (list regexp |
62 (integer :tag "Regexp match number") | |
63 (string :tag "Image name"))) | |
64 :set (lambda (symbol value) | |
65 (set-default symbol value) | |
66 (smiley-update-cache)) | |
67 :initialize 'custom-initialize-default | |
68 :group 'smiley) | |
69 | |
70 (defvar smiley-cached-regexp-alist nil) | |
71 | |
72 (defun smiley-update-cache () | |
73 (dolist (elt smiley-regexp-alist) | |
74 (let* ((data-directory smiley-data-directory) | |
32135
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
75 (image (find-image (list (list :type 'pbm |
31789 | 76 :file (nth 2 elt) |
32017
6ee543d2c641
(smiley-update-cache): Use `:ascent center'.
Gerd Moellmann <gerd@gnu.org>
parents:
31818
diff
changeset
|
77 :ascent 'center))))) |
31789 | 78 (if image |
79 (push (list (car elt) (cadr elt) image) | |
80 smiley-cached-regexp-alist))))) | |
81 | |
82 (defvar smiley-active nil | |
83 "Non-nil means smilies in the buffer will be displayed.") | |
84 (make-variable-buffer-local 'smiley-active) | |
85 | |
86 (defvar smiley-mouse-map | |
87 (let ((map (make-sparse-keymap))) | |
88 (define-key map [down-mouse-2] 'ignore) ; override widget | |
89 (define-key map [mouse-2] | |
90 'smiley-mouse-toggle-buffer) | |
91 map)) | |
92 | |
93 ;;;###autoload | |
94 (defun smiley-region (start end) | |
95 "Replace in the region `smiley-regexp-alist' matches with corresponding images." | |
96 (interactive "r") | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
97 (when (and (fboundp 'display-graphic-p) |
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
98 (display-graphic-p)) |
31789 | 99 (mapc (lambda (o) |
100 (if (eq 'smiley (overlay-get o 'smiley)) | |
101 (delete-overlay o))) | |
102 (overlays-in start end)) | |
103 (unless smiley-cached-regexp-alist | |
104 (smiley-update-cache)) | |
105 (save-excursion | |
106 (let ((beg (or start (point-min))) | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
107 group overlay image) |
31789 | 108 (dolist (entry smiley-cached-regexp-alist) |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
109 (setq group (nth 1 entry) |
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
110 image (nth 2 entry)) |
31789 | 111 (goto-char beg) |
112 (while (re-search-forward (car entry) end t) | |
113 (when image | |
114 (setq overlay (make-overlay (match-beginning group) | |
115 (match-end group))) | |
116 (overlay-put overlay | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
117 'display `(when smiley-active ,@image)) |
31789 | 118 (overlay-put overlay 'mouse-face 'highlight) |
119 (overlay-put overlay 'smiley t) | |
120 (overlay-put overlay | |
121 'help-echo "mouse-2: toggle smilies in buffer") | |
122 (overlay-put overlay 'keymap smiley-mouse-map)))))) | |
123 (setq smiley-active t))) | |
124 | |
125 (defun smiley-toggle-buffer (&optional arg) | |
126 "Toggle displaying smiley faces. | |
127 With arg, turn displaying on if and only if arg is positive." | |
128 (interactive "P") | |
129 (if (numberp arg) | |
130 (setq smiley-active (> arg 0)) | |
131 (setq smiley-active (not smiley-active)))) | |
132 | |
133 (defun smiley-mouse-toggle-buffer (event) | |
134 "Toggle displaying smiley faces. | |
135 With arg, turn displaying on if and only if arg is positive." | |
136 (interactive "e") | |
137 (save-excursion | |
138 (save-window-excursion | |
139 (mouse-set-point event) | |
140 (smiley-toggle-buffer)))) | |
141 | |
142 (eval-when-compile (defvar gnus-article-buffer)) | |
143 | |
144 (defun gnus-smiley-display (&optional arg) | |
145 "Display textual emoticaons (\"smilies\") as small graphical icons. | |
146 With arg, turn displaying on if and only if arg is positive." | |
147 (interactive "P") | |
148 (save-excursion | |
149 (set-buffer gnus-article-buffer) | |
150 (save-restriction | |
151 (widen) | |
152 (article-goto-body) | |
153 (smiley-region (point-min) (point-max)) | |
154 (if (and (numberp arg) (<= arg 0)) | |
155 (smiley-toggle-buffer arg))))) | |
156 | |
157 (provide 'smiley) | |
158 | |
159 ;;; smiley-ems.el ends here |