Mercurial > emacs
annotate lisp/gnus/smiley-ems.el @ 34395:2f4a4d355834
(time-stamp-old-format-warn): reorder custom
choices to match documentation string.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Sat, 09 Dec 2000 13:22:51 +0000 |
parents | 7263c1ed74a2 |
children | ce1470fa2100 |
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") | |
34328
7263c1ed74a2
(smiley-data-directory): Fix :type.
Dave Love <fx@gnu.org>
parents:
33293
diff
changeset
|
46 "*If non-nil, a directory to search for the smiley image files. |
33293
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." |
34328
7263c1ed74a2
(smiley-data-directory): Fix :type.
Dave Love <fx@gnu.org>
parents:
33293
diff
changeset
|
48 :type '(choice directory |
7263c1ed74a2
(smiley-data-directory): Fix :type.
Dave Love <fx@gnu.org>
parents:
33293
diff
changeset
|
49 (const nil)) |
31789 | 50 :group 'smiley) |
51 | |
52 ;; The XEmacs version has a baroque, if not rococo, set of these. | |
53 (defcustom smiley-regexp-alist | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
54 ;; 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
|
55 '(("\\([:;]-?)\\)\\W" 1 "smile.pbm") |
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
56 ("\\(:-[/\\]\\)\\W" 1 "wry.pbm") |
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
57 ("\\(:-[({]\\)\\W" 1 "frown.pbm")) |
31789 | 58 "*A list of regexps to map smilies to images. |
59 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
|
60 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
|
61 `smiley-data-directory' or the normal image search path." |
31789 | 62 :type '(repeat (list regexp |
63 (integer :tag "Regexp match number") | |
64 (string :tag "Image name"))) | |
65 :set (lambda (symbol value) | |
66 (set-default symbol value) | |
67 (smiley-update-cache)) | |
68 :initialize 'custom-initialize-default | |
69 :group 'smiley) | |
70 | |
71 (defvar smiley-cached-regexp-alist nil) | |
72 | |
73 (defun smiley-update-cache () | |
74 (dolist (elt smiley-regexp-alist) | |
75 (let* ((data-directory smiley-data-directory) | |
32135
210c188cba41
(smiley-regexp-alist, smiley-update-cache): Use
Dave Love <fx@gnu.org>
parents:
32017
diff
changeset
|
76 (image (find-image (list (list :type 'pbm |
31789 | 77 :file (nth 2 elt) |
32017
6ee543d2c641
(smiley-update-cache): Use `:ascent center'.
Gerd Moellmann <gerd@gnu.org>
parents:
31818
diff
changeset
|
78 :ascent 'center))))) |
31789 | 79 (if image |
80 (push (list (car elt) (cadr elt) image) | |
81 smiley-cached-regexp-alist))))) | |
82 | |
83 (defvar smiley-active nil | |
84 "Non-nil means smilies in the buffer will be displayed.") | |
85 (make-variable-buffer-local 'smiley-active) | |
86 | |
87 (defvar smiley-mouse-map | |
88 (let ((map (make-sparse-keymap))) | |
89 (define-key map [down-mouse-2] 'ignore) ; override widget | |
90 (define-key map [mouse-2] | |
91 'smiley-mouse-toggle-buffer) | |
92 map)) | |
93 | |
94 ;;;###autoload | |
95 (defun smiley-region (start end) | |
96 "Replace in the region `smiley-regexp-alist' matches with corresponding images." | |
97 (interactive "r") | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
98 (when (and (fboundp 'display-graphic-p) |
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
99 (display-graphic-p)) |
31789 | 100 (mapc (lambda (o) |
101 (if (eq 'smiley (overlay-get o 'smiley)) | |
102 (delete-overlay o))) | |
103 (overlays-in start end)) | |
104 (unless smiley-cached-regexp-alist | |
105 (smiley-update-cache)) | |
106 (save-excursion | |
107 (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
|
108 group overlay image) |
31789 | 109 (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
|
110 (setq group (nth 1 entry) |
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
111 image (nth 2 entry)) |
31789 | 112 (goto-char beg) |
113 (while (re-search-forward (car entry) end t) | |
114 (when image | |
115 (setq overlay (make-overlay (match-beginning group) | |
116 (match-end group))) | |
117 (overlay-put overlay | |
31818
1e15c63f0711
(smiley-region): Test if display-graphic-p bound
Dave Love <fx@gnu.org>
parents:
31789
diff
changeset
|
118 'display `(when smiley-active ,@image)) |
31789 | 119 (overlay-put overlay 'mouse-face 'highlight) |
120 (overlay-put overlay 'smiley t) | |
121 (overlay-put overlay | |
122 'help-echo "mouse-2: toggle smilies in buffer") | |
123 (overlay-put overlay 'keymap smiley-mouse-map)))))) | |
124 (setq smiley-active t))) | |
125 | |
126 (defun smiley-toggle-buffer (&optional arg) | |
127 "Toggle displaying smiley faces. | |
128 With arg, turn displaying on if and only if arg is positive." | |
129 (interactive "P") | |
130 (if (numberp arg) | |
131 (setq smiley-active (> arg 0)) | |
132 (setq smiley-active (not smiley-active)))) | |
133 | |
134 (defun smiley-mouse-toggle-buffer (event) | |
135 "Toggle displaying smiley faces. | |
136 With arg, turn displaying on if and only if arg is positive." | |
137 (interactive "e") | |
138 (save-excursion | |
139 (save-window-excursion | |
140 (mouse-set-point event) | |
141 (smiley-toggle-buffer)))) | |
142 | |
143 (eval-when-compile (defvar gnus-article-buffer)) | |
144 | |
145 (defun gnus-smiley-display (&optional arg) | |
146 "Display textual emoticaons (\"smilies\") as small graphical icons. | |
147 With arg, turn displaying on if and only if arg is positive." | |
148 (interactive "P") | |
149 (save-excursion | |
150 (set-buffer gnus-article-buffer) | |
151 (save-restriction | |
152 (widen) | |
153 (article-goto-body) | |
154 (smiley-region (point-min) (point-max)) | |
155 (if (and (numberp arg) (<= arg 0)) | |
156 (smiley-toggle-buffer arg))))) | |
157 | |
158 (provide 'smiley) | |
159 | |
160 ;;; smiley-ems.el ends here |