1 ;;; earcon.el --- Sound effects for messages
3 ;; Copyright (C) 1996, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Author: Steven L. Baur <steve@miranova.com>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
26 ;; This file provides access to sound effects in Gnus.
30 (eval-when-compile (require 'cl
))
36 "Turn ** sounds ** into noise."
39 (defcustom earcon-prefix
"**"
40 "*String denoting the start of an earcon."
44 (defcustom earcon-suffix
"**"
45 "String denoting the end of an earcon."
49 (defcustom earcon-regexp-alist
50 '(("boring" 1 "Boring.au")
51 ("evil[ \t]+laugh" 1 "Evil_Laugh.au")
52 ("gag\\|puke" 1 "Puke.au")
53 ("snicker" 1 "Snicker.au")
54 ("meow" 1 "catmeow.wav")
55 ("sob\\|boohoo" 1 "cry.wav")
56 ("drum[ \t]*roll" 1 "drumroll.au")
57 ("blast" 1 "explosion.au")
58 ("flush\\|plonk!*" 1 "flush.au")
60 ("tee[ \t]*hee" 1 "laugh.au")
61 ("shoot" 1 "shotgun.wav")
62 ("yawn" 1 "snore.wav")
63 ("cackle" 1 "witch.au")
64 ("yell\\|roar" 1 "yell2.au")
65 ("whoop-de-doo" 1 "whistle.au"))
66 "*A list of regexps to map earcons to real sounds."
67 :type
'(repeat (list regexp
68 (integer :tag
"Match")
69 (string :tag
"Sound")))
71 (defvar earcon-button-marker-list nil
)
72 (make-variable-buffer-local 'earcon-button-marker-list
)
74 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
75 (defun earcon-article-push-button (event)
76 "Check text under the mouse pointer for a callback function.
77 If the text under the mouse pointer has a `earcon-callback' property,
78 call it with the value of the `earcon-data' text property."
80 (set-buffer (window-buffer (posn-window (event-start event
))))
81 (let* ((pos (posn-point (event-start event
)))
82 (data (get-text-property pos
'earcon-data
))
83 (fun (get-text-property pos
'earcon-callback
)))
84 (if fun
(funcall fun data
))))
86 (defun earcon-article-press-button ()
87 "Check text at point for a callback function.
88 If the text at point has a `earcon-callback' property,
89 call it with the value of the `earcon-data' text property."
91 (let* ((data (get-text-property (point) 'earcon-data
))
92 (fun (get-text-property (point) 'earcon-callback
)))
93 (if fun
(funcall fun data
))))
95 (defun earcon-article-prev-button (n)
96 "Move point to N buttons backward.
97 If N is negative, move forward instead."
99 (earcon-article-next-button (- n
)))
101 (defun earcon-article-next-button (n)
102 "Move point to N buttons forward.
103 If N is negative, move backward instead."
105 (let ((function (if (< n
0) 'previous-single-property-change
106 'next-single-property-change
))
107 (inhibit-point-motion-hooks t
)
109 (limit (if (< n
0) (point-min) (point-max))))
111 (while (and (not (= limit
(point)))
113 ;; Skip past the current button.
114 (when (get-text-property (point) 'earcon-callback
)
115 (goto-char (funcall function
(point) 'earcon-callback nil limit
)))
116 ;; Go to the next (or previous) button.
117 (gnus-goto-char (funcall function
(point) 'earcon-callback nil limit
))
118 ;; Put point at the start of the button.
119 (when (and backward
(not (get-text-property (point) 'earcon-callback
)))
120 (goto-char (funcall function
(point) 'earcon-callback nil limit
)))
121 ;; Skip past intangible buttons.
122 (when (get-text-property (point) 'intangible
)
126 (gnus-message 5 "No more buttons"))
129 (defun earcon-article-add-button (from to fun
&optional data
)
130 "Create a button between FROM and TO with callback FUN and data DATA."
131 (and (boundp gnus-article-button-face
)
132 gnus-article-button-face
133 (gnus-overlay-put (gnus-make-overlay from to
)
134 'face gnus-article-button-face
))
135 (gnus-add-text-properties
137 (nconc (and gnus-article-mouse-face
138 (list gnus-mouse-face-prop gnus-article-mouse-face
))
139 (list 'gnus-callback fun
)
140 (and data
(list 'gnus-data data
)))))
142 (defun earcon-button-entry ()
143 ;; Return the first entry in `gnus-button-alist' matching this place.
144 (let ((alist earcon-regexp-alist
)
148 (setq entry
(pop alist
))
149 (if (looking-at (car entry
))
154 (defun earcon-button-push (marker)
155 ;; Push button starting at MARKER.
157 (set-buffer gnus-article-buffer
)
159 (let* ((entry (earcon-button-entry))
160 (inhibit-point-motion-hooks t
)
161 (fun 'gnus-audio-play
)
162 (args (list (nth 2 entry
))))
167 (fboundp (symbol-value fun
)))
168 (apply (symbol-value fun
) args
))
170 (gnus-message 1 "You must define `%S' to use this button"
171 (cons fun args
)))))))
173 ;;; FIXME!! clone of code from gnus-vis.el FIXME!!
176 (defun earcon-region (beg end
)
177 "Play Sounds in the region between point and mark."
179 (earcon-buffer (current-buffer) beg end
))
182 (defun earcon-buffer (&optional buffer st nd
)
185 ;; clear old markers.
186 (if (boundp 'earcon-button-marker-list
)
187 (while earcon-button-marker-list
188 (set-marker (pop earcon-button-marker-list
) nil
))
189 (setq earcon-button-marker-list nil
))
190 (and buffer
(set-buffer buffer
))
191 (let ((buffer-read-only nil
)
192 (inhibit-point-motion-hooks t
)
194 (alist earcon-regexp-alist
)
196 (goto-char (point-min))
198 (while (setq entry
(pop alist
))
199 (setq regexp
(concat (regexp-quote earcon-prefix
)
203 (regexp-quote earcon-suffix
)))
205 (while (re-search-forward regexp nil t
)
206 (let* ((start (and entry
(match-beginning 1)))
207 (end (and entry
(match-end 1)))
208 (from (match-beginning 1)))
209 (earcon-article-add-button
210 start end
'earcon-button-push
211 (car (push (set-marker (make-marker) from
)
212 earcon-button-marker-list
)))
213 (gnus-audio-play (caddr entry
))))))))
216 (defun gnus-earcon-display ()
217 "Play sounds in message buffers."
220 (set-buffer gnus-article-buffer
)
221 (goto-char (point-min))
223 (unless (search-forward "\n\n" nil t
)
224 (goto-char (point-max)))
226 (earcon-buffer (current-buffer) (point))))
232 (run-hooks 'earcon-load-hook
)
234 ;;; arch-tag: 844dfeea-980c-4ed0-907f-a30bf139691c
235 ;;; earcon.el ends here