1 ;;; earcon.el --- Sound effects for messages
3 ;; Copyright (C) 1996, 2000 Free Software Foundation
5 ;; Author: Steven L. Baur <steve@miranova.com>
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 (eval-when-compile (require 'cl))
35 "Turn ** sounds ** into noise."
38 (defcustom earcon-auto-play nil
39 "*When True, automatically play sounds as well as buttonize them."
43 (defcustom earcon-prefix "**"
44 "*String denoting the start of an earcon."
48 (defcustom earcon-suffix "**"
49 "String denoting the end of an earcon."
53 (defcustom earcon-regexp-alist
54 '(("boring" 1 "Boring.au")
55 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
56 ("gag\\|puke" 1 "Puke.au")
57 ("snicker" 1 "Snicker.au")
58 ("meow" 1 "catmeow.au")
59 ("sob\\|boohoo" 1 "cry.wav")
60 ("drum[ \t]*roll" 1 "drumroll.au")
61 ("blast" 1 "explosion.au")
62 ("flush\\|plonk!*" 1 "flush.au")
64 ("tee[ \t]*hee" 1 "laugh.au")
65 ("shoot" 1 "shotgun.wav")
66 ("yawn" 1 "snore.wav")
67 ("cackle" 1 "witch.au")
68 ("yell\\|roar" 1 "yell2.au")
69 ("whoop-de-doo" 1 "whistle.au"))
70 "*A list of regexps to map earcons to real sounds."
71 :type '(repeat (list regexp
72 (integer :tag "Match")
73 (string :tag "Sound")))
75 (defvar earcon-button-marker-list nil)
76 (make-variable-buffer-local 'earcon-button-marker-list)
78 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
79 (defun earcon-article-push-button (event)
80 "Check text under the mouse pointer for a callback function.
81 If the text under the mouse pointer has a `earcon-callback' property,
82 call it with the value of the `earcon-data' text property."
84 (set-buffer (window-buffer (posn-window (event-start event))))
85 (let* ((pos (posn-point (event-start event)))
86 (data (get-text-property pos 'earcon-data))
87 (fun (get-text-property pos 'earcon-callback)))
88 (if fun (funcall fun data))))
90 (defun earcon-article-press-button ()
91 "Check text at point for a callback function.
92 If the text at point has a `earcon-callback' property,
93 call it with the value of the `earcon-data' text property."
95 (let* ((data (get-text-property (point) 'earcon-data))
96 (fun (get-text-property (point) 'earcon-callback)))
97 (if fun (funcall fun data))))
99 (defun earcon-article-prev-button (n)
100 "Move point to N buttons backward.
101 If N is negative, move forward instead."
103 (earcon-article-next-button (- n)))
105 (defun earcon-article-next-button (n)
106 "Move point to N buttons forward.
107 If N is negative, move backward instead."
109 (let ((function (if (< n 0) 'previous-single-property-change
110 'next-single-property-change))
111 (inhibit-point-motion-hooks t)
113 (limit (if (< n 0) (point-min) (point-max))))
115 (while (and (not (= limit (point)))
117 ;; Skip past the current button.
118 (when (get-text-property (point) 'earcon-callback)
119 (goto-char (funcall function (point) 'earcon-callback nil limit)))
120 ;; Go to the next (or previous) button.
121 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit))
122 ;; Put point at the start of the button.
123 (when (and backward (not (get-text-property (point) 'earcon-callback)))
124 (goto-char (funcall function (point) 'earcon-callback nil limit)))
125 ;; Skip past intangible buttons.
126 (when (get-text-property (point) 'intangible)
130 (gnus-message 5 "No more buttons"))
133 (defun earcon-article-add-button (from to fun &optional data)
134 "Create a button between FROM and TO with callback FUN and data DATA."
135 (and (boundp gnus-article-button-face)
136 gnus-article-button-face
137 (gnus-overlay-put (gnus-make-overlay from to)
138 'face gnus-article-button-face))
139 (gnus-add-text-properties
141 (nconc (and gnus-article-mouse-face
142 (list gnus-mouse-face-prop gnus-article-mouse-face))
143 (list 'gnus-callback fun)
144 (and data (list 'gnus-data data)))))
146 (defun earcon-button-entry ()
147 ;; Return the first entry in `gnus-button-alist' matching this place.
148 (let ((alist earcon-regexp-alist)
152 (setq entry (pop alist))
153 (if (looking-at (car entry))
158 (defun earcon-button-push (marker)
159 ;; Push button starting at MARKER.
161 (set-buffer gnus-article-buffer)
163 (let* ((entry (earcon-button-entry))
164 (inhibit-point-motion-hooks t)
165 (fun 'gnus-audio-play)
166 (args (list (nth 2 entry))))
171 (fboundp (symbol-value fun)))
172 (apply (symbol-value fun) args))
174 (gnus-message 1 "You must define `%S' to use this button"
175 (cons fun args)))))))
177 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
180 (defun earcon-region (beg end)
181 "Play Sounds in the region between point and mark."
183 (earcon-buffer (current-buffer) beg end))
186 (defun earcon-buffer (&optional buffer st nd)
189 ;; clear old markers.
190 (if (boundp 'earcon-button-marker-list)
191 (while earcon-button-marker-list
192 (set-marker (pop earcon-button-marker-list) nil))
193 (setq earcon-button-marker-list nil))
194 (and buffer (set-buffer buffer))
195 (let ((buffer-read-only nil)
196 (inhibit-point-motion-hooks t)
198 (alist earcon-regexp-alist)
200 (goto-char (point-min))
202 (while (setq entry (pop alist))
203 (setq regexp (concat (regexp-quote earcon-prefix)
207 (regexp-quote earcon-suffix)))
209 (while (re-search-forward regexp nil t)
210 (let* ((start (and entry (match-beginning 1)))
211 (end (and entry (match-end 1)))
212 (from (match-beginning 1)))
213 (earcon-article-add-button
214 start end 'earcon-button-push
215 (car (push (set-marker (make-marker) from)
216 earcon-button-marker-list)))
217 (gnus-audio-play (caddr entry))))))))
220 (defun gnus-earcon-display ()
221 "Play sounds in message buffers."
224 (set-buffer gnus-article-buffer)
225 (goto-char (point-min))
227 (unless (search-forward "\n\n" nil t)
228 (goto-char (point-max)))
230 (earcon-buffer (current-buffer) (point))))
236 (run-hooks 'earcon-load-hook)
238 ;;; earcon.el ends here