1 ;;; earcon.el --- Sound effects for messages
3 ;; Copyright (C) 1996, 2000, 2001, 2003 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-prefix "**"
39 "*String denoting the start of an earcon."
43 (defcustom earcon-suffix "**"
44 "String denoting the end of an earcon."
48 (defcustom earcon-regexp-alist
49 '(("boring" 1 "Boring.au")
50 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
51 ("gag\\|puke" 1 "Puke.au")
52 ("snicker" 1 "Snicker.au")
53 ("meow" 1 "catmeow.wav")
54 ("sob\\|boohoo" 1 "cry.wav")
55 ("drum[ \t]*roll" 1 "drumroll.au")
56 ("blast" 1 "explosion.au")
57 ("flush\\|plonk!*" 1 "flush.au")
59 ("tee[ \t]*hee" 1 "laugh.au")
60 ("shoot" 1 "shotgun.wav")
61 ("yawn" 1 "snore.wav")
62 ("cackle" 1 "witch.au")
63 ("yell\\|roar" 1 "yell2.au")
64 ("whoop-de-doo" 1 "whistle.au"))
65 "*A list of regexps to map earcons to real sounds."
66 :type '(repeat (list regexp
67 (integer :tag "Match")
68 (string :tag "Sound")))
70 (defvar earcon-button-marker-list nil)
71 (make-variable-buffer-local 'earcon-button-marker-list)
73 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
74 (defun earcon-article-push-button (event)
75 "Check text under the mouse pointer for a callback function.
76 If the text under the mouse pointer has a `earcon-callback' property,
77 call it with the value of the `earcon-data' text property."
79 (set-buffer (window-buffer (posn-window (event-start event))))
80 (let* ((pos (posn-point (event-start event)))
81 (data (get-text-property pos 'earcon-data))
82 (fun (get-text-property pos 'earcon-callback)))
83 (if fun (funcall fun data))))
85 (defun earcon-article-press-button ()
86 "Check text at point for a callback function.
87 If the text at point has a `earcon-callback' property,
88 call it with the value of the `earcon-data' text property."
90 (let* ((data (get-text-property (point) 'earcon-data))
91 (fun (get-text-property (point) 'earcon-callback)))
92 (if fun (funcall fun data))))
94 (defun earcon-article-prev-button (n)
95 "Move point to N buttons backward.
96 If N is negative, move forward instead."
98 (earcon-article-next-button (- n)))
100 (defun earcon-article-next-button (n)
101 "Move point to N buttons forward.
102 If N is negative, move backward instead."
104 (let ((function (if (< n 0) 'previous-single-property-change
105 'next-single-property-change))
106 (inhibit-point-motion-hooks t)
108 (limit (if (< n 0) (point-min) (point-max))))
110 (while (and (not (= limit (point)))
112 ;; Skip past the current button.
113 (when (get-text-property (point) 'earcon-callback)
114 (goto-char (funcall function (point) 'earcon-callback nil limit)))
115 ;; Go to the next (or previous) button.
116 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit))
117 ;; Put point at the start of the button.
118 (when (and backward (not (get-text-property (point) 'earcon-callback)))
119 (goto-char (funcall function (point) 'earcon-callback nil limit)))
120 ;; Skip past intangible buttons.
121 (when (get-text-property (point) 'intangible)
125 (gnus-message 5 "No more buttons"))
128 (defun earcon-article-add-button (from to fun &optional data)
129 "Create a button between FROM and TO with callback FUN and data DATA."
130 (and (boundp gnus-article-button-face)
131 gnus-article-button-face
132 (gnus-overlay-put (gnus-make-overlay from to)
133 'face gnus-article-button-face))
134 (gnus-add-text-properties
136 (nconc (and gnus-article-mouse-face
137 (list gnus-mouse-face-prop gnus-article-mouse-face))
138 (list 'gnus-callback fun)
139 (and data (list 'gnus-data data)))))
141 (defun earcon-button-entry ()
142 ;; Return the first entry in `gnus-button-alist' matching this place.
143 (let ((alist earcon-regexp-alist)
147 (setq entry (pop alist))
148 (if (looking-at (car entry))
153 (defun earcon-button-push (marker)
154 ;; Push button starting at MARKER.
156 (set-buffer gnus-article-buffer)
158 (let* ((entry (earcon-button-entry))
159 (inhibit-point-motion-hooks t)
160 (fun 'gnus-audio-play)
161 (args (list (nth 2 entry))))
166 (fboundp (symbol-value fun)))
167 (apply (symbol-value fun) args))
169 (gnus-message 1 "You must define `%S' to use this button"
170 (cons fun args)))))))
172 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
175 (defun earcon-region (beg end)
176 "Play Sounds in the region between point and mark."
178 (earcon-buffer (current-buffer) beg end))
181 (defun earcon-buffer (&optional buffer st nd)
184 ;; clear old markers.
185 (if (boundp 'earcon-button-marker-list)
186 (while earcon-button-marker-list
187 (set-marker (pop earcon-button-marker-list) nil))
188 (setq earcon-button-marker-list nil))
189 (and buffer (set-buffer buffer))
190 (let ((buffer-read-only nil)
191 (inhibit-point-motion-hooks t)
193 (alist earcon-regexp-alist)
195 (goto-char (point-min))
197 (while (setq entry (pop alist))
198 (setq regexp (concat (regexp-quote earcon-prefix)
202 (regexp-quote earcon-suffix)))
204 (while (re-search-forward regexp nil t)
205 (let* ((start (and entry (match-beginning 1)))
206 (end (and entry (match-end 1)))
207 (from (match-beginning 1)))
208 (earcon-article-add-button
209 start end 'earcon-button-push
210 (car (push (set-marker (make-marker) from)
211 earcon-button-marker-list)))
212 (gnus-audio-play (caddr entry))))))))
215 (defun gnus-earcon-display ()
216 "Play sounds in message buffers."
219 (set-buffer gnus-article-buffer)
220 (goto-char (point-min))
222 (unless (search-forward "\n\n" nil t)
223 (goto-char (point-max)))
225 (earcon-buffer (current-buffer) (point))))
231 (run-hooks 'earcon-load-hook)
233 ;;; earcon.el ends here