1 ;;; earcon.el --- Sound effects for messages
2 ;; Copyright (C) 1996 Free Software Foundation
4 ;; Author: Steven L. Baur <steve@miranova.com>
5 ;; Keywords: news fun sound
7 ;; This file is part of GNU Emacs.
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)
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.
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.
25 ;; This file provides access to sound effects in Gnus.
29 (if (null (boundp 'running-xemacs))
30 (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)))
34 (eval-when-compile (require 'cl))
36 (defvar earcon-auto-play nil
37 "When True, automatically play sounds as well as buttonize them.")
39 (defvar earcon-prefix "**"
40 "The start of an earcon")
42 (defvar earcon-suffix "**"
43 "The end of an earcon")
45 (defvar earcon-regexp-alist
46 '(("boring" 1 "Boring.au")
47 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
48 ("gag\\|puke" 1 "Puke.au")
49 ("snicker" 1 "Snicker.au")
50 ("meow" 1 "catmeow.au")
51 ("sob\\|boohoo" 1 "cry.wav")
52 ("drum[ \t]*roll" 1 "drumroll.au")
53 ("blast" 1 "explosion.au")
54 ("flush\\|plonk!*" 1 "flush.au")
56 ("tee[ \t]*hee" 1 "laugh.au")
57 ("shoot" 1 "shotgun.wav")
58 ("yawn" 1 "snore.wav")
59 ("cackle" 1 "witch.au")
60 ("yell\\|roar" 1 "yell2.au")
61 ("whoop-de-doo" 1 "whistle.au"))
62 "A list of regexps to map earcons to real sounds.")
64 (defvar earcon-button-marker-list nil)
65 (make-variable-buffer-local 'earcon-button-marker-list)
69 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
70 (defun earcon-article-push-button (event)
71 "Check text under the mouse pointer for a callback function.
72 If the text under the mouse pointer has a `earcon-callback' property,
73 call it with the value of the `earcon-data' text property."
75 (set-buffer (window-buffer (posn-window (event-start event))))
76 (let* ((pos (posn-point (event-start event)))
77 (data (get-text-property pos 'earcon-data))
78 (fun (get-text-property pos 'earcon-callback)))
79 (if fun (funcall fun data))))
81 (defun earcon-article-press-button ()
82 "Check text at point for a callback function.
83 If the text at point has a `earcon-callback' property,
84 call it with the value of the `earcon-data' text property."
86 (let* ((data (get-text-property (point) 'earcon-data))
87 (fun (get-text-property (point) 'earcon-callback)))
88 (if fun (funcall fun data))))
90 (defun earcon-article-prev-button (n)
91 "Move point to N buttons backward.
92 If N is negative, move forward instead."
94 (earcon-article-next-button (- n)))
96 (defun earcon-article-next-button (n)
97 "Move point to N buttons forward.
98 If N is negative, move backward instead."
100 (let ((function (if (< n 0) 'previous-single-property-change
101 'next-single-property-change))
102 (inhibit-point-motion-hooks t)
104 (limit (if (< n 0) (point-min) (point-max))))
106 (while (and (not (= limit (point)))
108 ;; Skip past the current button.
109 (when (get-text-property (point) 'earcon-callback)
110 (goto-char (funcall function (point) 'earcon-callback nil limit)))
111 ;; Go to the next (or previous) button.
112 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit))
113 ;; Put point at the start of the button.
114 (when (and backward (not (get-text-property (point) 'earcon-callback)))
115 (goto-char (funcall function (point) 'earcon-callback nil limit)))
116 ;; Skip past intangible buttons.
117 (when (get-text-property (point) 'intangible)
121 (gnus-message 5 "No more buttons"))
124 (defun earcon-article-add-button (from to fun &optional data)
125 "Create a button between FROM and TO with callback FUN and data DATA."
126 (and (boundp gnus-article-button-face)
127 gnus-article-button-face
128 (gnus-overlay-put (gnus-make-overlay from to)
129 'face gnus-article-button-face))
130 (gnus-add-text-properties
132 (nconc (and gnus-article-mouse-face
133 (list gnus-mouse-face-prop gnus-article-mouse-face))
134 (list 'gnus-callback fun)
135 (and data (list 'gnus-data data)))))
137 (defun earcon-button-entry ()
138 ;; Return the first entry in `gnus-button-alist' matching this place.
139 (let ((alist earcon-regexp-alist)
143 (setq entry (pop alist))
144 (if (looking-at (car entry))
150 (defun earcon-button-push (marker)
151 ;; Push button starting at MARKER.
153 (set-buffer gnus-article-buffer)
155 (let* ((entry (earcon-button-entry))
156 (inhibit-point-motion-hooks t)
157 (fun 'gnus-audio-play)
158 (args (list (nth 2 entry))))
163 (fboundp (symbol-value fun)))
164 (apply (symbol-value fun) args))
166 (gnus-message 1 "You must define `%S' to use this button"
167 (cons fun args)))))))
169 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
172 (defun earcon-region (beg end)
173 "Play Sounds in the region between point and mark."
175 (earcon-buffer (current-buffer) beg end))
178 (defun earcon-buffer (&optional buffer st nd)
181 ;; clear old markers.
182 (if (boundp 'earcon-button-marker-list)
183 (while earcon-button-marker-list
184 (set-marker (pop earcon-button-marker-list) nil))
185 (setq earcon-button-marker-list nil))
186 (and buffer (set-buffer buffer))
187 (let ((buffer-read-only nil)
188 (inhibit-point-motion-hooks t)
190 (alist earcon-regexp-alist)
192 (goto-char (point-min))
194 (while (setq entry (pop alist))
195 (setq regexp (concat (regexp-quote earcon-prefix)
199 (regexp-quote earcon-suffix)))
201 (while (re-search-forward regexp nil t)
202 (let* ((start (and entry (match-beginning 1)))
203 (end (and entry (match-end 1)))
204 (from (match-beginning 1)))
205 (earcon-article-add-button
206 start end 'earcon-button-push
207 (car (push (set-marker (make-marker) from)
208 earcon-button-marker-list)))
209 (gnus-audio-play (caddr entry))))))))
212 (defun gnus-earcon-display ()
213 "Play sounds in message buffers."
216 (set-buffer gnus-article-buffer)
217 (goto-char (point-min))
219 (unless (search-forward "\n\n" nil t)
220 (goto-char (point-max)))
222 (earcon-buffer (current-buffer) (point))))
228 (run-hooks 'earcon-load-hook)
230 ;;; earcon.el ends here