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))
38 "Turn ** sounds ** into noise."
41 (defcustom earcon-auto-play nil
42 "When True, automatically play sounds as well as buttonize them."
46 (defcustom earcon-prefix "**"
47 "String denoting the start of an earcon."
51 (defcustom earcon-suffix "**"
52 "String denoting the end of an earcon."
56 (defcustom earcon-regexp-alist
57 '(("boring" 1 "Boring.au")
58 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
59 ("gag\\|puke" 1 "Puke.au")
60 ("snicker" 1 "Snicker.au")
61 ("meow" 1 "catmeow.au")
62 ("sob\\|boohoo" 1 "cry.wav")
63 ("drum[ \t]*roll" 1 "drumroll.au")
64 ("blast" 1 "explosion.au")
65 ("flush\\|plonk!*" 1 "flush.au")
67 ("tee[ \t]*hee" 1 "laugh.au")
68 ("shoot" 1 "shotgun.wav")
69 ("yawn" 1 "snore.wav")
70 ("cackle" 1 "witch.au")
71 ("yell\\|roar" 1 "yell2.au")
72 ("whoop-de-doo" 1 "whistle.au"))
73 "A list of regexps to map earcons to real sounds."
74 :type '(repeat (list regexp
75 (integer :tag "Match")
76 (string :tag "Sound")))
79 (defvar earcon-button-marker-list nil)
80 (make-variable-buffer-local 'earcon-button-marker-list)
84 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
85 (defun earcon-article-push-button (event)
86 "Check text under the mouse pointer for a callback function.
87 If the text under the mouse pointer has a `earcon-callback' property,
88 call it with the value of the `earcon-data' text property."
90 (set-buffer (window-buffer (posn-window (event-start event))))
91 (let* ((pos (posn-point (event-start event)))
92 (data (get-text-property pos 'earcon-data))
93 (fun (get-text-property pos 'earcon-callback)))
94 (if fun (funcall fun data))))
96 (defun earcon-article-press-button ()
97 "Check text at point for a callback function.
98 If the text at point has a `earcon-callback' property,
99 call it with the value of the `earcon-data' text property."
101 (let* ((data (get-text-property (point) 'earcon-data))
102 (fun (get-text-property (point) 'earcon-callback)))
103 (if fun (funcall fun data))))
105 (defun earcon-article-prev-button (n)
106 "Move point to N buttons backward.
107 If N is negative, move forward instead."
109 (earcon-article-next-button (- n)))
111 (defun earcon-article-next-button (n)
112 "Move point to N buttons forward.
113 If N is negative, move backward instead."
115 (let ((function (if (< n 0) 'previous-single-property-change
116 'next-single-property-change))
117 (inhibit-point-motion-hooks t)
119 (limit (if (< n 0) (point-min) (point-max))))
121 (while (and (not (= limit (point)))
123 ;; Skip past the current button.
124 (when (get-text-property (point) 'earcon-callback)
125 (goto-char (funcall function (point) 'earcon-callback nil limit)))
126 ;; Go to the next (or previous) button.
127 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit))
128 ;; Put point at the start of the button.
129 (when (and backward (not (get-text-property (point) 'earcon-callback)))
130 (goto-char (funcall function (point) 'earcon-callback nil limit)))
131 ;; Skip past intangible buttons.
132 (when (get-text-property (point) 'intangible)
136 (gnus-message 5 "No more buttons"))
139 (defun earcon-article-add-button (from to fun &optional data)
140 "Create a button between FROM and TO with callback FUN and data DATA."
141 (and (boundp gnus-article-button-face)
142 gnus-article-button-face
143 (gnus-overlay-put (gnus-make-overlay from to)
144 'face gnus-article-button-face))
145 (gnus-add-text-properties
147 (nconc (and gnus-article-mouse-face
148 (list gnus-mouse-face-prop gnus-article-mouse-face))
149 (list 'gnus-callback fun)
150 (and data (list 'gnus-data data)))))
152 (defun earcon-button-entry ()
153 ;; Return the first entry in `gnus-button-alist' matching this place.
154 (let ((alist earcon-regexp-alist)
158 (setq entry (pop alist))
159 (if (looking-at (car entry))
165 (defun earcon-button-push (marker)
166 ;; Push button starting at MARKER.
168 (set-buffer gnus-article-buffer)
170 (let* ((entry (earcon-button-entry))
171 (inhibit-point-motion-hooks t)
172 (fun 'gnus-audio-play)
173 (args (list (nth 2 entry))))
178 (fboundp (symbol-value fun)))
179 (apply (symbol-value fun) args))
181 (gnus-message 1 "You must define `%S' to use this button"
182 (cons fun args)))))))
184 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
187 (defun earcon-region (beg end)
188 "Play Sounds in the region between point and mark."
190 (earcon-buffer (current-buffer) beg end))
193 (defun earcon-buffer (&optional buffer st nd)
196 ;; clear old markers.
197 (if (boundp 'earcon-button-marker-list)
198 (while earcon-button-marker-list
199 (set-marker (pop earcon-button-marker-list) nil))
200 (setq earcon-button-marker-list nil))
201 (and buffer (set-buffer buffer))
202 (let ((buffer-read-only nil)
203 (inhibit-point-motion-hooks t)
205 (alist earcon-regexp-alist)
207 (goto-char (point-min))
209 (while (setq entry (pop alist))
210 (setq regexp (concat (regexp-quote earcon-prefix)
214 (regexp-quote earcon-suffix)))
216 (while (re-search-forward regexp nil t)
217 (let* ((start (and entry (match-beginning 1)))
218 (end (and entry (match-end 1)))
219 (from (match-beginning 1)))
220 (earcon-article-add-button
221 start end 'earcon-button-push
222 (car (push (set-marker (make-marker) from)
223 earcon-button-marker-list)))
224 (gnus-audio-play (caddr entry))))))))
227 (defun gnus-earcon-display ()
228 "Play sounds in message buffers."
231 (set-buffer gnus-article-buffer)
232 (goto-char (point-min))
234 (unless (search-forward "\n\n" nil t)
235 (goto-char (point-max)))
237 (earcon-buffer (current-buffer) (point))))
243 (run-hooks 'earcon-load-hook)
245 ;;; earcon.el ends here