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)))
35 (eval-when-compile (require 'cl))
37 (defvar earcon-auto-play nil
38 "When True, automatically play sounds as well as buttonize them.")
40 (defvar earcon-prefix "**"
41 "The start of an earcon")
43 (defvar earcon-suffix "**"
44 "The end of an earcon")
46 (defvar earcon-regexp-alist
47 '(("boring" 1 "Boring.au")
48 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
49 ("gag\\|puke" 1 "Puke.au")
50 ("snicker" 1 "Snicker.au")
51 ("meow" 1 "catmeow.au")
52 ("sob\\|boohoo" 1 "cry.wav")
53 ("drum[ \t]*roll" 1 "drumroll.au")
54 ("blast" 1 "explosion.au")
55 ("flush\\|plonk!*" 1 "flush.au")
57 ("tee[ \t]*hee" 1 "laugh.au")
58 ("shoot" 1 "shotgun.wav")
59 ("yawn" 1 "snore.wav")
60 ("cackle" 1 "witch.au")
61 ("yell\\|roar" 1 "yell2.au")
62 ("whoop-de-doo" 1 "whistle.au"))
63 "A list of regexps to map earcons to real sounds.")
65 (defvar earcon-button-marker-list nil)
66 (make-variable-buffer-local 'earcon-button-marker-list)
70 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
71 (defun earcon-article-push-button (event)
72 "Check text under the mouse pointer for a callback function.
73 If the text under the mouse pointer has a `earcon-callback' property,
74 call it with the value of the `earcon-data' text property."
76 (set-buffer (window-buffer (posn-window (event-start event))))
77 (let* ((pos (posn-point (event-start event)))
78 (data (get-text-property pos 'earcon-data))
79 (fun (get-text-property pos 'earcon-callback)))
80 (if fun (funcall fun data))))
82 (defun earcon-article-press-button ()
83 "Check text at point for a callback function.
84 If the text at point has a `earcon-callback' property,
85 call it with the value of the `earcon-data' text property."
87 (let* ((data (get-text-property (point) 'earcon-data))
88 (fun (get-text-property (point) 'earcon-callback)))
89 (if fun (funcall fun data))))
91 (defun earcon-article-prev-button (n)
92 "Move point to N buttons backward.
93 If N is negative, move forward instead."
95 (earcon-article-next-button (- n)))
97 (defun earcon-article-next-button (n)
98 "Move point to N buttons forward.
99 If N is negative, move backward instead."
101 (let ((function (if (< n 0) 'previous-single-property-change
102 'next-single-property-change))
103 (inhibit-point-motion-hooks t)
105 (limit (if (< n 0) (point-min) (point-max))))
107 (while (and (not (= limit (point)))
109 ;; Skip past the current button.
110 (when (get-text-property (point) 'earcon-callback)
111 (goto-char (funcall function (point) 'earcon-callback nil limit)))
112 ;; Go to the next (or previous) button.
113 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit))
114 ;; Put point at the start of the button.
115 (when (and backward (not (get-text-property (point) 'earcon-callback)))
116 (goto-char (funcall function (point) 'earcon-callback nil limit)))
117 ;; Skip past intangible buttons.
118 (when (get-text-property (point) 'intangible)
122 (gnus-message 5 "No more buttons"))
125 (defun earcon-article-add-button (from to fun &optional data)
126 "Create a button between FROM and TO with callback FUN and data DATA."
127 (and (boundp gnus-article-button-face)
128 gnus-article-button-face
129 (gnus-overlay-put (gnus-make-overlay from to)
130 'face gnus-article-button-face))
131 (gnus-add-text-properties
133 (nconc (and gnus-article-mouse-face
134 (list gnus-mouse-face-prop gnus-article-mouse-face))
135 (list 'gnus-callback fun)
136 (and data (list 'gnus-data data)))))
138 (defun earcon-button-entry ()
139 ;; Return the first entry in `gnus-button-alist' matching this place.
140 (let ((alist earcon-regexp-alist)
144 (setq entry (pop alist))
145 (if (looking-at (car entry))
151 (defun earcon-button-push (marker)
152 ;; Push button starting at MARKER.
154 (set-buffer gnus-article-buffer)
156 (let* ((entry (earcon-button-entry))
157 (inhibit-point-motion-hooks t)
158 (fun 'gnus-audio-play)
159 (args (list (nth 2 entry))))
164 (fboundp (symbol-value fun)))
165 (apply (symbol-value fun) args))
167 (gnus-message 1 "You must define `%S' to use this button"
168 (cons fun args)))))))
170 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
173 (defun earcon-region (beg end)
174 "Play Sounds in the region between point and mark."
176 (earcon-buffer (current-buffer) beg end))
179 (defun earcon-buffer (&optional buffer st nd)
182 ;; clear old markers.
183 (if (boundp 'earcon-button-marker-list)
184 (while earcon-button-marker-list
185 (set-marker (pop earcon-button-marker-list) nil))
186 (setq earcon-button-marker-list nil))
187 (and buffer (set-buffer buffer))
188 (let ((buffer-read-only nil)
189 (inhibit-point-motion-hooks t)
191 (alist earcon-regexp-alist)
193 (goto-char (point-min))
195 (while (setq entry (pop alist))
196 (setq regexp (concat (regexp-quote earcon-prefix)
200 (regexp-quote earcon-suffix)))
202 (while (re-search-forward regexp nil t)
203 (let* ((start (and entry (match-beginning 1)))
204 (end (and entry (match-end 1)))
205 (from (match-beginning 1)))
206 (earcon-article-add-button
207 start end 'earcon-button-push
208 (car (push (set-marker (make-marker) from)
209 earcon-button-marker-list)))
210 (gnus-audio-play (caddr entry))))))))
213 (defun gnus-earcon-display ()
214 "Play sounds in message buffers."
217 (set-buffer gnus-article-buffer)
218 (goto-char (point-min))
220 (unless (search-forward "\n\n" nil t)
221 (goto-char (point-max)))
223 (earcon-buffer (current-buffer) (point))))
229 (run-hooks 'earcon-load-hook)
231 ;;; earcon.el ends here