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.
23 ;; This file is part of GNU Emacs.
27 ;; This file provides access to sound effects in Gnus.
31 (if (null (boundp 'running-xemacs
))
32 (defvar running-xemacs
(string-match "XEmacs\\|Lucid" emacs-version
)))
34 (eval-when-compile (require 'cl
))
40 "Turn ** sounds ** into noise."
43 (defcustom earcon-auto-play nil
44 "*When True, automatically play sounds as well as buttonize them."
48 (defcustom earcon-prefix
"**"
49 "*String denoting the start of an earcon."
53 (defcustom earcon-suffix
"**"
54 "String denoting the end of an earcon."
58 (defcustom earcon-regexp-alist
59 '(("boring" 1 "Boring.au")
60 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
61 ("gag\\|puke" 1 "Puke.au")
62 ("snicker" 1 "Snicker.au")
63 ("meow" 1 "catmeow.au")
64 ("sob\\|boohoo" 1 "cry.wav")
65 ("drum[ \t]*roll" 1 "drumroll.au")
66 ("blast" 1 "explosion.au")
67 ("flush\\|plonk!*" 1 "flush.au")
69 ("tee[ \t]*hee" 1 "laugh.au")
70 ("shoot" 1 "shotgun.wav")
71 ("yawn" 1 "snore.wav")
72 ("cackle" 1 "witch.au")
73 ("yell\\|roar" 1 "yell2.au")
74 ("whoop-de-doo" 1 "whistle.au"))
75 "*A list of regexps to map earcons to real sounds."
76 :type
'(repeat (list regexp
77 (integer :tag
"Match")
78 (string :tag
"Sound")))
80 (defvar earcon-button-marker-list nil
)
81 (make-variable-buffer-local 'earcon-button-marker-list
)
83 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
84 (defun earcon-article-push-button (event)
85 "Check text under the mouse pointer for a callback function.
86 If the text under the mouse pointer has a `earcon-callback' property,
87 call it with the value of the `earcon-data' text property."
89 (set-buffer (window-buffer (posn-window (event-start event
))))
90 (let* ((pos (posn-point (event-start event
)))
91 (data (get-text-property pos
'earcon-data
))
92 (fun (get-text-property pos
'earcon-callback
)))
93 (if fun
(funcall fun data
))))
95 (defun earcon-article-press-button ()
96 "Check text at point for a callback function.
97 If the text at point has a `earcon-callback' property,
98 call it with the value of the `earcon-data' text property."
100 (let* ((data (get-text-property (point) 'earcon-data
))
101 (fun (get-text-property (point) 'earcon-callback
)))
102 (if fun
(funcall fun data
))))
104 (defun earcon-article-prev-button (n)
105 "Move point to N buttons backward.
106 If N is negative, move forward instead."
108 (earcon-article-next-button (- n
)))
110 (defun earcon-article-next-button (n)
111 "Move point to N buttons forward.
112 If N is negative, move backward instead."
114 (let ((function (if (< n
0) 'previous-single-property-change
115 'next-single-property-change
))
116 (inhibit-point-motion-hooks t
)
118 (limit (if (< n
0) (point-min) (point-max))))
120 (while (and (not (= limit
(point)))
122 ;; Skip past the current button.
123 (when (get-text-property (point) 'earcon-callback
)
124 (goto-char (funcall function
(point) 'earcon-callback nil limit
)))
125 ;; Go to the next (or previous) button.
126 (gnus-goto-char (funcall function
(point) 'earcon-callback nil limit
))
127 ;; Put point at the start of the button.
128 (when (and backward
(not (get-text-property (point) 'earcon-callback
)))
129 (goto-char (funcall function
(point) 'earcon-callback nil limit
)))
130 ;; Skip past intangible buttons.
131 (when (get-text-property (point) 'intangible
)
135 (gnus-message 5 "No more buttons"))
138 (defun earcon-article-add-button (from to fun
&optional data
)
139 "Create a button between FROM and TO with callback FUN and data DATA."
140 (and (boundp gnus-article-button-face
)
141 gnus-article-button-face
142 (gnus-overlay-put (gnus-make-overlay from to
)
143 'face gnus-article-button-face
))
144 (gnus-add-text-properties
146 (nconc (and gnus-article-mouse-face
147 (list gnus-mouse-face-prop gnus-article-mouse-face
))
148 (list 'gnus-callback fun
)
149 (and data
(list 'gnus-data data
)))))
151 (defun earcon-button-entry ()
152 ;; Return the first entry in `gnus-button-alist' matching this place.
153 (let ((alist earcon-regexp-alist
)
157 (setq entry
(pop alist
))
158 (if (looking-at (car entry
))
163 (defun earcon-button-push (marker)
164 ;; Push button starting at MARKER.
166 (set-buffer gnus-article-buffer
)
168 (let* ((entry (earcon-button-entry))
169 (inhibit-point-motion-hooks t
)
170 (fun 'gnus-audio-play
)
171 (args (list (nth 2 entry
))))
176 (fboundp (symbol-value fun
)))
177 (apply (symbol-value fun
) args
))
179 (gnus-message 1 "You must define `%S' to use this button"
180 (cons fun args
)))))))
182 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
185 (defun earcon-region (beg end
)
186 "Play Sounds in the region between point and mark."
188 (earcon-buffer (current-buffer) beg end
))
191 (defun earcon-buffer (&optional buffer st nd
)
194 ;; clear old markers.
195 (if (boundp 'earcon-button-marker-list
)
196 (while earcon-button-marker-list
197 (set-marker (pop earcon-button-marker-list
) nil
))
198 (setq earcon-button-marker-list nil
))
199 (and buffer
(set-buffer buffer
))
200 (let ((buffer-read-only nil
)
201 (inhibit-point-motion-hooks t
)
203 (alist earcon-regexp-alist
)
205 (goto-char (point-min))
207 (while (setq entry
(pop alist
))
208 (setq regexp
(concat (regexp-quote earcon-prefix
)
212 (regexp-quote earcon-suffix
)))
214 (while (re-search-forward regexp nil t
)
215 (let* ((start (and entry
(match-beginning 1)))
216 (end (and entry
(match-end 1)))
217 (from (match-beginning 1)))
218 (earcon-article-add-button
219 start end
'earcon-button-push
220 (car (push (set-marker (make-marker) from
)
221 earcon-button-marker-list
)))
222 (gnus-audio-play (caddr entry
))))))))
225 (defun gnus-earcon-display ()
226 "Play sounds in message buffers."
229 (set-buffer gnus-article-buffer
)
230 (goto-char (point-min))
232 (unless (search-forward "\n\n" nil t
)
233 (goto-char (point-max)))
235 (earcon-buffer (current-buffer) (point))))
241 (run-hooks 'earcon-load-hook
)
243 ;;; earcon.el ends here