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