1 ;;; earcon.el --- Sound effects for messages
2 ;; Copyright (C) 1996 Free Software Foundation
4 ;; Author: Steven L. Baur <steve@miranova.com>
5 ;; GNU Emacs is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; GNU Emacs is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs; see the file COPYING. If not, write to the
17 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 ;; Boston, MA 02111-1307, USA.
21 ;; This file provides access to sound effects in Gnus.
25 (if (null (boundp 'running-xemacs))
26 (defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version)))
28 (eval-when-compile (require 'cl))
34 "Turn ** sounds ** into noise."
37 (defcustom earcon-auto-play nil
38 "*When True, automatically play sounds as well as buttonize them."
42 (defcustom earcon-prefix "**"
43 "*String denoting the start of an earcon."
47 (defcustom earcon-suffix "**"
48 "String denoting the end of an earcon."
52 (defcustom earcon-regexp-alist
53 '(("boring" 1 "Boring.au")
54 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
55 ("gag\\|puke" 1 "Puke.au")
56 ("snicker" 1 "Snicker.au")
57 ("meow" 1 "catmeow.au")
58 ("sob\\|boohoo" 1 "cry.wav")
59 ("drum[ \t]*roll" 1 "drumroll.au")
60 ("blast" 1 "explosion.au")
61 ("flush\\|plonk!*" 1 "flush.au")
63 ("tee[ \t]*hee" 1 "laugh.au")
64 ("shoot" 1 "shotgun.wav")
65 ("yawn" 1 "snore.wav")
66 ("cackle" 1 "witch.au")
67 ("yell\\|roar" 1 "yell2.au")
68 ("whoop-de-doo" 1 "whistle.au"))
69 "*A list of regexps to map earcons to real sounds."
70 :type '(repeat (list regexp
71 (integer :tag "Match")
72 (string :tag "Sound")))
74 (defvar earcon-button-marker-list nil)
75 (make-variable-buffer-local 'earcon-button-marker-list)
77 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
78 (defun earcon-article-push-button (event)
79 "Check text under the mouse pointer for a callback function.
80 If the text under the mouse pointer has a `earcon-callback' property,
81 call it with the value of the `earcon-data' text property."
83 (set-buffer (window-buffer (posn-window (event-start event))))
84 (let* ((pos (posn-point (event-start event)))
85 (data (get-text-property pos 'earcon-data))
86 (fun (get-text-property pos 'earcon-callback)))
87 (if fun (funcall fun data))))
89 (defun earcon-article-press-button ()
90 "Check text at point for a callback function.
91 If the text at point has a `earcon-callback' property,
92 call it with the value of the `earcon-data' text property."
94 (let* ((data (get-text-property (point) 'earcon-data))
95 (fun (get-text-property (point) 'earcon-callback)))
96 (if fun (funcall fun data))))
98 (defun earcon-article-prev-button (n)
99 "Move point to N buttons backward.
100 If N is negative, move forward instead."
102 (earcon-article-next-button (- n)))
104 (defun earcon-article-next-button (n)
105 "Move point to N buttons forward.
106 If N is negative, move backward instead."
108 (let ((function (if (< n 0) 'previous-single-property-change
109 'next-single-property-change))
110 (inhibit-point-motion-hooks t)
112 (limit (if (< n 0) (point-min) (point-max))))
114 (while (and (not (= limit (point)))
116 ;; Skip past the current button.
117 (when (get-text-property (point) 'earcon-callback)
118 (goto-char (funcall function (point) 'earcon-callback nil limit)))
119 ;; Go to the next (or previous) button.
120 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit))
121 ;; Put point at the start of the button.
122 (when (and backward (not (get-text-property (point) 'earcon-callback)))
123 (goto-char (funcall function (point) 'earcon-callback nil limit)))
124 ;; Skip past intangible buttons.
125 (when (get-text-property (point) 'intangible)
129 (gnus-message 5 "No more buttons"))
132 (defun earcon-article-add-button (from to fun &optional data)
133 "Create a button between FROM and TO with callback FUN and data DATA."
134 (and (boundp gnus-article-button-face)
135 gnus-article-button-face
136 (gnus-overlay-put (gnus-make-overlay from to)
137 'face gnus-article-button-face))
138 (gnus-add-text-properties
140 (nconc (and gnus-article-mouse-face
141 (list gnus-mouse-face-prop gnus-article-mouse-face))
142 (list 'gnus-callback fun)
143 (and data (list 'gnus-data data)))))
145 (defun earcon-button-entry ()
146 ;; Return the first entry in `gnus-button-alist' matching this place.
147 (let ((alist earcon-regexp-alist)
151 (setq entry (pop alist))
152 (if (looking-at (car entry))
157 (defun earcon-button-push (marker)
158 ;; Push button starting at MARKER.
160 (set-buffer gnus-article-buffer)
162 (let* ((entry (earcon-button-entry))
163 (inhibit-point-motion-hooks t)
164 (fun 'gnus-audio-play)
165 (args (list (nth 2 entry))))
170 (fboundp (symbol-value fun)))
171 (apply (symbol-value fun) args))
173 (gnus-message 1 "You must define `%S' to use this button"
174 (cons fun args)))))))
176 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
179 (defun earcon-region (beg end)
180 "Play Sounds in the region between point and mark."
182 (earcon-buffer (current-buffer) beg end))
185 (defun earcon-buffer (&optional buffer st nd)
188 ;; clear old markers.
189 (if (boundp 'earcon-button-marker-list)
190 (while earcon-button-marker-list
191 (set-marker (pop earcon-button-marker-list) nil))
192 (setq earcon-button-marker-list nil))
193 (and buffer (set-buffer buffer))
194 (let ((buffer-read-only nil)
195 (inhibit-point-motion-hooks t)
197 (alist earcon-regexp-alist)
199 (goto-char (point-min))
201 (while (setq entry (pop alist))
202 (setq regexp (concat (regexp-quote earcon-prefix)
206 (regexp-quote earcon-suffix)))
208 (while (re-search-forward regexp nil t)
209 (let* ((start (and entry (match-beginning 1)))
210 (end (and entry (match-end 1)))
211 (from (match-beginning 1)))
212 (earcon-article-add-button
213 start end 'earcon-button-push
214 (car (push (set-marker (make-marker) from)
215 earcon-button-marker-list)))
216 (gnus-audio-play (caddr entry))))))))
219 (defun gnus-earcon-display ()
220 "Play sounds in message buffers."
223 (set-buffer gnus-article-buffer)
224 (goto-char (point-min))
226 (unless (search-forward "\n\n" nil t)
227 (goto-char (point-max)))
229 (earcon-buffer (current-buffer) (point))))
235 (run-hooks 'earcon-load-hook)
237 ;;; earcon.el ends here