Mercurial > emacs
annotate lisp/gnus/earcon.el @ 32604:c8b8e93bf2fd
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Wed, 18 Oct 2000 08:52:23 +0000 |
parents | 9968f55ad26e |
children | 6550e76163d7 |
rev | line source |
---|---|
17493 | 1 ;;; earcon.el --- Sound effects for messages |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
2 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
3 ;; Copyright (C) 1996, 2000 Free Software Foundation |
17493 | 4 |
5 ;; Author: Steven L. Baur <steve@miranova.com> | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
6 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
8 |
17493 | 9 ;; GNU Emacs is free software; you can redistribute it and/or modify |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 2, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; GNU Emacs is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 ;; Boston, MA 02111-1307, USA. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
23 ;; This file is part of GNU Emacs. |
17493 | 24 |
25 ;;; Commentary: | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
26 |
17493 | 27 ;; This file provides access to sound effects in Gnus. |
28 | |
29 ;;; Code: | |
30 | |
31 (if (null (boundp 'running-xemacs)) | |
32 (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))) | |
33 | |
19600
5d6dd68d8889
Require cl at compile time before loading gnus, etc.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
34 (eval-when-compile (require 'cl)) |
17493 | 35 (require 'gnus) |
36 (require 'gnus-audio) | |
37 (require 'gnus-art) | |
38 | |
39 (defgroup earcon nil | |
40 "Turn ** sounds ** into noise." | |
41 :group 'gnus-visual) | |
42 | |
43 (defcustom earcon-auto-play nil | |
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
44 "*When True, automatically play sounds as well as buttonize them." |
17493 | 45 :type 'boolean |
46 :group 'earcon) | |
47 | |
48 (defcustom earcon-prefix "**" | |
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
49 "*String denoting the start of an earcon." |
17493 | 50 :type 'string |
51 :group 'earcon) | |
52 | |
53 (defcustom earcon-suffix "**" | |
54 "String denoting the end of an earcon." | |
55 :type 'string | |
56 :group 'earcon) | |
57 | |
58 (defcustom earcon-regexp-alist | |
59 '(("boring" 1 "Boring.au") | |
60 ("evil[ \t]+laugh" 1 "Evil_Laugh.au") | |
61 ("gag\\|puke" 1 "Puke.au") | |
62 ("snicker" 1 "Snicker.au") | |
63 ("meow" 1 "catmeow.au") | |
64 ("sob\\|boohoo" 1 "cry.wav") | |
65 ("drum[ \t]*roll" 1 "drumroll.au") | |
66 ("blast" 1 "explosion.au") | |
67 ("flush\\|plonk!*" 1 "flush.au") | |
68 ("kiss" 1 "kiss.wav") | |
69 ("tee[ \t]*hee" 1 "laugh.au") | |
70 ("shoot" 1 "shotgun.wav") | |
71 ("yawn" 1 "snore.wav") | |
72 ("cackle" 1 "witch.au") | |
73 ("yell\\|roar" 1 "yell2.au") | |
74 ("whoop-de-doo" 1 "whistle.au")) | |
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
75 "*A list of regexps to map earcons to real sounds." |
17493 | 76 :type '(repeat (list regexp |
77 (integer :tag "Match") | |
78 (string :tag "Sound"))) | |
79 :group 'earcon) | |
80 (defvar earcon-button-marker-list nil) | |
81 (make-variable-buffer-local 'earcon-button-marker-list) | |
82 | |
83 ;;; FIXME!! clone of code from gnus-vis.el FIXME!! | |
84 (defun earcon-article-push-button (event) | |
85 "Check text under the mouse pointer for a callback function. | |
86 If the text under the mouse pointer has a `earcon-callback' property, | |
87 call it with the value of the `earcon-data' text property." | |
88 (interactive "e") | |
89 (set-buffer (window-buffer (posn-window (event-start event)))) | |
90 (let* ((pos (posn-point (event-start event))) | |
91 (data (get-text-property pos 'earcon-data)) | |
92 (fun (get-text-property pos 'earcon-callback))) | |
93 (if fun (funcall fun data)))) | |
94 | |
95 (defun earcon-article-press-button () | |
96 "Check text at point for a callback function. | |
97 If the text at point has a `earcon-callback' property, | |
98 call it with the value of the `earcon-data' text property." | |
99 (interactive) | |
100 (let* ((data (get-text-property (point) 'earcon-data)) | |
101 (fun (get-text-property (point) 'earcon-callback))) | |
102 (if fun (funcall fun data)))) | |
103 | |
104 (defun earcon-article-prev-button (n) | |
105 "Move point to N buttons backward. | |
106 If N is negative, move forward instead." | |
107 (interactive "p") | |
108 (earcon-article-next-button (- n))) | |
109 | |
110 (defun earcon-article-next-button (n) | |
111 "Move point to N buttons forward. | |
112 If N is negative, move backward instead." | |
113 (interactive "p") | |
114 (let ((function (if (< n 0) 'previous-single-property-change | |
115 'next-single-property-change)) | |
116 (inhibit-point-motion-hooks t) | |
117 (backward (< n 0)) | |
118 (limit (if (< n 0) (point-min) (point-max)))) | |
119 (setq n (abs n)) | |
120 (while (and (not (= limit (point))) | |
121 (> n 0)) | |
122 ;; Skip past the current button. | |
123 (when (get-text-property (point) 'earcon-callback) | |
124 (goto-char (funcall function (point) 'earcon-callback nil limit))) | |
125 ;; Go to the next (or previous) button. | |
126 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit)) | |
127 ;; Put point at the start of the button. | |
128 (when (and backward (not (get-text-property (point) 'earcon-callback))) | |
129 (goto-char (funcall function (point) 'earcon-callback nil limit))) | |
130 ;; Skip past intangible buttons. | |
131 (when (get-text-property (point) 'intangible) | |
132 (incf n)) | |
133 (decf n)) | |
134 (unless (zerop n) | |
135 (gnus-message 5 "No more buttons")) | |
136 n)) | |
137 | |
138 (defun earcon-article-add-button (from to fun &optional data) | |
139 "Create a button between FROM and TO with callback FUN and data DATA." | |
140 (and (boundp gnus-article-button-face) | |
141 gnus-article-button-face | |
142 (gnus-overlay-put (gnus-make-overlay from to) | |
143 'face gnus-article-button-face)) | |
144 (gnus-add-text-properties | |
145 from to | |
146 (nconc (and gnus-article-mouse-face | |
147 (list gnus-mouse-face-prop gnus-article-mouse-face)) | |
148 (list 'gnus-callback fun) | |
149 (and data (list 'gnus-data data))))) | |
150 | |
151 (defun earcon-button-entry () | |
152 ;; Return the first entry in `gnus-button-alist' matching this place. | |
153 (let ((alist earcon-regexp-alist) | |
154 (case-fold-search t) | |
155 (entry nil)) | |
156 (while alist | |
157 (setq entry (pop alist)) | |
158 (if (looking-at (car entry)) | |
159 (setq alist nil) | |
160 (setq entry nil))) | |
161 entry)) | |
162 | |
163 (defun earcon-button-push (marker) | |
164 ;; Push button starting at MARKER. | |
165 (save-excursion | |
166 (set-buffer gnus-article-buffer) | |
167 (goto-char marker) | |
168 (let* ((entry (earcon-button-entry)) | |
169 (inhibit-point-motion-hooks t) | |
170 (fun 'gnus-audio-play) | |
171 (args (list (nth 2 entry)))) | |
172 (cond | |
173 ((fboundp fun) | |
174 (apply fun args)) | |
175 ((and (boundp fun) | |
176 (fboundp (symbol-value fun))) | |
177 (apply (symbol-value fun) args)) | |
178 (t | |
179 (gnus-message 1 "You must define `%S' to use this button" | |
180 (cons fun args))))))) | |
181 | |
182 ;;; FIXME!! clone of code from gnus-vis.el FIXME!! | |
183 | |
184 ;;;###interactive | |
185 (defun earcon-region (beg end) | |
186 "Play Sounds in the region between point and mark." | |
187 (interactive "r") | |
188 (earcon-buffer (current-buffer) beg end)) | |
189 | |
190 ;;;###interactive | |
191 (defun earcon-buffer (&optional buffer st nd) | |
192 (interactive) | |
193 (save-excursion | |
194 ;; clear old markers. | |
195 (if (boundp 'earcon-button-marker-list) | |
196 (while earcon-button-marker-list | |
197 (set-marker (pop earcon-button-marker-list) nil)) | |
198 (setq earcon-button-marker-list nil)) | |
199 (and buffer (set-buffer buffer)) | |
200 (let ((buffer-read-only nil) | |
201 (inhibit-point-motion-hooks t) | |
202 (case-fold-search t) | |
203 (alist earcon-regexp-alist) | |
204 beg entry regexp) | |
205 (goto-char (point-min)) | |
206 (setq beg (point)) | |
207 (while (setq entry (pop alist)) | |
208 (setq regexp (concat (regexp-quote earcon-prefix) | |
209 ".*\\(" | |
210 (car entry) | |
211 "\\).*" | |
212 (regexp-quote earcon-suffix))) | |
213 (goto-char beg) | |
214 (while (re-search-forward regexp nil t) | |
215 (let* ((start (and entry (match-beginning 1))) | |
216 (end (and entry (match-end 1))) | |
217 (from (match-beginning 1))) | |
218 (earcon-article-add-button | |
219 start end 'earcon-button-push | |
220 (car (push (set-marker (make-marker) from) | |
221 earcon-button-marker-list))) | |
222 (gnus-audio-play (caddr entry)))))))) | |
223 | |
224 ;;;###autoload | |
225 (defun gnus-earcon-display () | |
226 "Play sounds in message buffers." | |
227 (interactive) | |
228 (save-excursion | |
229 (set-buffer gnus-article-buffer) | |
230 (goto-char (point-min)) | |
231 ;; Skip headers | |
232 (unless (search-forward "\n\n" nil t) | |
233 (goto-char (point-max))) | |
234 (sit-for 0) | |
235 (earcon-buffer (current-buffer) (point)))) | |
236 | |
237 ;;;*** | |
238 | |
239 (provide 'earcon) | |
240 | |
241 (run-hooks 'earcon-load-hook) | |
242 | |
243 ;;; earcon.el ends here |