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 (eval-when-compile (require 'cl
))
37 "Turn ** sounds ** into noise."
40 (defcustom earcon-auto-play nil
41 "*When True, automatically play sounds as well as buttonize them."
45 (defcustom earcon-prefix
"**"
46 "*String denoting the start of an earcon."
50 (defcustom earcon-suffix
"**"
51 "String denoting the end of an earcon."
55 (defcustom earcon-regexp-alist
56 '(("boring" 1 "Boring.au")
57 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
58 ("gag\\|puke" 1 "Puke.au")
59 ("snicker" 1 "Snicker.au")
60 ("meow" 1 "catmeow.au")
61 ("sob\\|boohoo" 1 "cry.wav")
62 ("drum[ \t]*roll" 1 "drumroll.au")
63 ("blast" 1 "explosion.au")
64 ("flush\\|plonk!*" 1 "flush.au")
66 ("tee[ \t]*hee" 1 "laugh.au")
67 ("shoot" 1 "shotgun.wav")
68 ("yawn" 1 "snore.wav")
69 ("cackle" 1 "witch.au")
70 ("yell\\|roar" 1 "yell2.au")
71 ("whoop-de-doo" 1 "whistle.au"))
72 "*A list of regexps to map earcons to real sounds."
73 :type
'(repeat (list regexp
74 (integer :tag
"Match")
75 (string :tag
"Sound")))
77 (defvar earcon-button-marker-list nil
)
78 (make-variable-buffer-local 'earcon-button-marker-list
)
80 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
81 (defun earcon-article-push-button (event)
82 "Check text under the mouse pointer for a callback function.
83 If the text under the mouse pointer has a `earcon-callback' property,
84 call it with the value of the `earcon-data' text property."
86 (set-buffer (window-buffer (posn-window (event-start event
))))
87 (let* ((pos (posn-point (event-start event
)))
88 (data (get-text-property pos
'earcon-data
))
89 (fun (get-text-property pos
'earcon-callback
)))
90 (if fun
(funcall fun data
))))
92 (defun earcon-article-press-button ()
93 "Check text at point for a callback function.
94 If the text at point has a `earcon-callback' property,
95 call it with the value of the `earcon-data' text property."
97 (let* ((data (get-text-property (point) 'earcon-data
))
98 (fun (get-text-property (point) 'earcon-callback
)))
99 (if fun
(funcall fun data
))))
101 (defun earcon-article-prev-button (n)
102 "Move point to N buttons backward.
103 If N is negative, move forward instead."
105 (earcon-article-next-button (- n
)))
107 (defun earcon-article-next-button (n)
108 "Move point to N buttons forward.
109 If N is negative, move backward instead."
111 (let ((function (if (< n
0) 'previous-single-property-change
112 'next-single-property-change
))
113 (inhibit-point-motion-hooks t
)
115 (limit (if (< n
0) (point-min) (point-max))))
117 (while (and (not (= limit
(point)))
119 ;; Skip past the current button.
120 (when (get-text-property (point) 'earcon-callback
)
121 (goto-char (funcall function
(point) 'earcon-callback nil limit
)))
122 ;; Go to the next (or previous) button.
123 (gnus-goto-char (funcall function
(point) 'earcon-callback nil limit
))
124 ;; Put point at the start of the button.
125 (when (and backward
(not (get-text-property (point) 'earcon-callback
)))
126 (goto-char (funcall function
(point) 'earcon-callback nil limit
)))
127 ;; Skip past intangible buttons.
128 (when (get-text-property (point) 'intangible
)
132 (gnus-message 5 "No more buttons"))
135 (defun earcon-article-add-button (from to fun
&optional data
)
136 "Create a button between FROM and TO with callback FUN and data DATA."
137 (and (boundp gnus-article-button-face
)
138 gnus-article-button-face
139 (gnus-overlay-put (gnus-make-overlay from to
)
140 'face gnus-article-button-face
))
141 (gnus-add-text-properties
143 (nconc (and gnus-article-mouse-face
144 (list gnus-mouse-face-prop gnus-article-mouse-face
))
145 (list 'gnus-callback fun
)
146 (and data
(list 'gnus-data data
)))))
148 (defun earcon-button-entry ()
149 ;; Return the first entry in `gnus-button-alist' matching this place.
150 (let ((alist earcon-regexp-alist
)
154 (setq entry
(pop alist
))
155 (if (looking-at (car entry
))
160 (defun earcon-button-push (marker)
161 ;; Push button starting at MARKER.
163 (set-buffer gnus-article-buffer
)
165 (let* ((entry (earcon-button-entry))
166 (inhibit-point-motion-hooks t
)
167 (fun 'gnus-audio-play
)
168 (args (list (nth 2 entry
))))
173 (fboundp (symbol-value fun
)))
174 (apply (symbol-value fun
) args
))
176 (gnus-message 1 "You must define `%S' to use this button"
177 (cons fun args
)))))))
179 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
182 (defun earcon-region (beg end
)
183 "Play Sounds in the region between point and mark."
185 (earcon-buffer (current-buffer) beg end
))
188 (defun earcon-buffer (&optional buffer st nd
)
191 ;; clear old markers.
192 (if (boundp 'earcon-button-marker-list
)
193 (while earcon-button-marker-list
194 (set-marker (pop earcon-button-marker-list
) nil
))
195 (setq earcon-button-marker-list nil
))
196 (and buffer
(set-buffer buffer
))
197 (let ((buffer-read-only nil
)
198 (inhibit-point-motion-hooks t
)
200 (alist earcon-regexp-alist
)
202 (goto-char (point-min))
204 (while (setq entry
(pop alist
))
205 (setq regexp
(concat (regexp-quote earcon-prefix
)
209 (regexp-quote earcon-suffix
)))
211 (while (re-search-forward regexp nil t
)
212 (let* ((start (and entry
(match-beginning 1)))
213 (end (and entry
(match-end 1)))
214 (from (match-beginning 1)))
215 (earcon-article-add-button
216 start end
'earcon-button-push
217 (car (push (set-marker (make-marker) from
)
218 earcon-button-marker-list
)))
219 (gnus-audio-play (caddr entry
))))))))
222 (defun gnus-earcon-display ()
223 "Play sounds in message buffers."
226 (set-buffer gnus-article-buffer
)
227 (goto-char (point-min))
229 (unless (search-forward "\n\n" nil t
)
230 (goto-char (point-max)))
232 (earcon-buffer (current-buffer) (point))))
238 (run-hooks 'earcon-load-hook
)
240 ;;; earcon.el ends here