Mercurial > emacs
annotate lisp/gnus/earcon.el @ 46533:701fdda31b83
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Fri, 19 Jul 2002 06:25:06 +0000 |
parents | 1daef9a5589e |
children | 695cf19ef79e d7ddb3e565de |
rev | line source |
---|---|
38413
a26d9b55abb6
Some fixes to follow coding conventions in files from Gnus.
Pavel Janík <Pavel@Janik.cz>
parents:
33266
diff
changeset
|
1 ;;; earcon.el --- sound effects for messages |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
2 |
38876
1daef9a5589e
(earcon-auto-play): Remove unused option.
Gerd Moellmann <gerd@gnu.org>
parents:
38413
diff
changeset
|
3 ;; Copyright (C) 1996, 2000, 2001 Free Software Foundation |
17493 | 4 |
5 ;; Author: Steven L. Baur <steve@miranova.com> | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
6 |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
7 ;; This file is part of GNU Emacs. |
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
8 |
17493 | 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) | |
12 ;; any later version. | |
13 | |
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. | |
18 | |
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. | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
23 ;; This file is part of GNU Emacs. |
17493 | 24 |
25 ;;; Commentary: | |
31716
9968f55ad26e
Update to emacs-21-branch of the Gnus CVS repository.
Gerd Moellmann <gerd@gnu.org>
parents:
24356
diff
changeset
|
26 |
17493 | 27 ;; This file provides access to sound effects in Gnus. |
28 | |
29 ;;; Code: | |
30 | |
19600
5d6dd68d8889
Require cl at compile time before loading gnus, etc.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
31 (eval-when-compile (require 'cl)) |
17493 | 32 (require 'gnus) |
33 (require 'gnus-audio) | |
34 (require 'gnus-art) | |
35 | |
36 (defgroup earcon nil | |
37 "Turn ** sounds ** into noise." | |
38 :group 'gnus-visual) | |
39 | |
40 (defcustom earcon-prefix "**" | |
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
41 "*String denoting the start of an earcon." |
17493 | 42 :type 'string |
43 :group 'earcon) | |
44 | |
45 (defcustom earcon-suffix "**" | |
46 "String denoting the end of an earcon." | |
47 :type 'string | |
48 :group 'earcon) | |
49 | |
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") | |
60 ("kiss" 1 "kiss.wav") | |
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")) | |
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
67 "*A list of regexps to map earcons to real sounds." |
17493 | 68 :type '(repeat (list regexp |
69 (integer :tag "Match") | |
70 (string :tag "Sound"))) | |
71 :group 'earcon) | |
72 (defvar earcon-button-marker-list nil) | |
73 (make-variable-buffer-local 'earcon-button-marker-list) | |
74 | |
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." | |
80 (interactive "e") | |
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)))) | |
86 | |
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." | |
91 (interactive) | |
92 (let* ((data (get-text-property (point) 'earcon-data)) | |
93 (fun (get-text-property (point) 'earcon-callback))) | |
94 (if fun (funcall fun data)))) | |
95 | |
96 (defun earcon-article-prev-button (n) | |
97 "Move point to N buttons backward. | |
98 If N is negative, move forward instead." | |
99 (interactive "p") | |
100 (earcon-article-next-button (- n))) | |
101 | |
102 (defun earcon-article-next-button (n) | |
103 "Move point to N buttons forward. | |
104 If N is negative, move backward instead." | |
105 (interactive "p") | |
106 (let ((function (if (< n 0) 'previous-single-property-change | |
107 'next-single-property-change)) | |
108 (inhibit-point-motion-hooks t) | |
109 (backward (< n 0)) | |
110 (limit (if (< n 0) (point-min) (point-max)))) | |
111 (setq n (abs n)) | |
112 (while (and (not (= limit (point))) | |
113 (> n 0)) | |
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) | |
124 (incf n)) | |
125 (decf n)) | |
126 (unless (zerop n) | |
127 (gnus-message 5 "No more buttons")) | |
128 n)) | |
129 | |
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 | |
137 from to | |
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))))) | |
142 | |
143 (defun earcon-button-entry () | |
144 ;; Return the first entry in `gnus-button-alist' matching this place. | |
145 (let ((alist earcon-regexp-alist) | |
146 (case-fold-search t) | |
147 (entry nil)) | |
148 (while alist | |
149 (setq entry (pop alist)) | |
150 (if (looking-at (car entry)) | |
151 (setq alist nil) | |
152 (setq entry nil))) | |
153 entry)) | |
154 | |
155 (defun earcon-button-push (marker) | |
156 ;; Push button starting at MARKER. | |
157 (save-excursion | |
158 (set-buffer gnus-article-buffer) | |
159 (goto-char marker) | |
160 (let* ((entry (earcon-button-entry)) | |
161 (inhibit-point-motion-hooks t) | |
162 (fun 'gnus-audio-play) | |
163 (args (list (nth 2 entry)))) | |
164 (cond | |
165 ((fboundp fun) | |
166 (apply fun args)) | |
167 ((and (boundp fun) | |
168 (fboundp (symbol-value fun))) | |
169 (apply (symbol-value fun) args)) | |
170 (t | |
171 (gnus-message 1 "You must define `%S' to use this button" | |
172 (cons fun args))))))) | |
173 | |
174 ;;; FIXME!! clone of code from gnus-vis.el FIXME!! | |
175 | |
176 ;;;###interactive | |
177 (defun earcon-region (beg end) | |
178 "Play Sounds in the region between point and mark." | |
179 (interactive "r") | |
180 (earcon-buffer (current-buffer) beg end)) | |
181 | |
182 ;;;###interactive | |
183 (defun earcon-buffer (&optional buffer st nd) | |
184 (interactive) | |
185 (save-excursion | |
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) | |
194 (case-fold-search t) | |
195 (alist earcon-regexp-alist) | |
196 beg entry regexp) | |
197 (goto-char (point-min)) | |
198 (setq beg (point)) | |
199 (while (setq entry (pop alist)) | |
200 (setq regexp (concat (regexp-quote earcon-prefix) | |
201 ".*\\(" | |
202 (car entry) | |
203 "\\).*" | |
204 (regexp-quote earcon-suffix))) | |
205 (goto-char beg) | |
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)))))))) | |
215 | |
216 ;;;###autoload | |
217 (defun gnus-earcon-display () | |
218 "Play sounds in message buffers." | |
219 (interactive) | |
220 (save-excursion | |
221 (set-buffer gnus-article-buffer) | |
222 (goto-char (point-min)) | |
223 ;; Skip headers | |
224 (unless (search-forward "\n\n" nil t) | |
225 (goto-char (point-max))) | |
226 (sit-for 0) | |
227 (earcon-buffer (current-buffer) (point)))) | |
228 | |
229 ;;;*** | |
230 | |
231 (provide 'earcon) | |
232 | |
233 (run-hooks 'earcon-load-hook) | |
234 | |
235 ;;; earcon.el ends here |