Mercurial > emacs
annotate lisp/gnus/earcon.el @ 63092:80ef8a2a052d
(debug): Don't bury the buffer unless it's in a dedicated window.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Mon, 06 Jun 2005 19:47:05 +0000 |
| parents | 55fd4f77387a |
| children | 18a818a2ee7c cce1c0ee76ee |
| rev | line source |
|---|---|
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
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 |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
3 ;; Copyright (C) 1996, 2000, 2001, 2003 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. | |
| 23 | |
| 24 ;;; Commentary: | |
| 25 ;; This file provides access to sound effects in Gnus. | |
| 26 | |
| 27 ;;; Code: | |
| 28 | |
|
19600
5d6dd68d8889
Require cl at compile time before loading gnus, etc.
Kenichi Handa <handa@m17n.org>
parents:
17493
diff
changeset
|
29 (eval-when-compile (require 'cl)) |
| 17493 | 30 (require 'gnus) |
| 31 (require 'gnus-audio) | |
| 32 (require 'gnus-art) | |
| 33 | |
| 34 (defgroup earcon nil | |
| 35 "Turn ** sounds ** into noise." | |
| 36 :group 'gnus-visual) | |
| 37 | |
| 38 (defcustom earcon-prefix "**" | |
|
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
39 "*String denoting the start of an earcon." |
| 17493 | 40 :type 'string |
| 41 :group 'earcon) | |
| 42 | |
| 43 (defcustom earcon-suffix "**" | |
| 44 "String denoting the end of an earcon." | |
| 45 :type 'string | |
| 46 :group 'earcon) | |
| 47 | |
| 48 (defcustom earcon-regexp-alist | |
| 49 '(("boring" 1 "Boring.au") | |
| 50 ("evil[ \t]+laugh" 1 "Evil_Laugh.au") | |
| 51 ("gag\\|puke" 1 "Puke.au") | |
| 52 ("snicker" 1 "Snicker.au") | |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
53 ("meow" 1 "catmeow.wav") |
| 17493 | 54 ("sob\\|boohoo" 1 "cry.wav") |
| 55 ("drum[ \t]*roll" 1 "drumroll.au") | |
| 56 ("blast" 1 "explosion.au") | |
| 57 ("flush\\|plonk!*" 1 "flush.au") | |
| 58 ("kiss" 1 "kiss.wav") | |
| 59 ("tee[ \t]*hee" 1 "laugh.au") | |
| 60 ("shoot" 1 "shotgun.wav") | |
| 61 ("yawn" 1 "snore.wav") | |
| 62 ("cackle" 1 "witch.au") | |
| 63 ("yell\\|roar" 1 "yell2.au") | |
| 64 ("whoop-de-doo" 1 "whistle.au")) | |
|
24356
a5a611ef40f6
*** empty log message ***
Lars Magne Ingebrigtsen <larsi@gnus.org>
parents:
19600
diff
changeset
|
65 "*A list of regexps to map earcons to real sounds." |
| 17493 | 66 :type '(repeat (list regexp |
| 67 (integer :tag "Match") | |
| 68 (string :tag "Sound"))) | |
| 69 :group 'earcon) | |
| 70 (defvar earcon-button-marker-list nil) | |
| 71 (make-variable-buffer-local 'earcon-button-marker-list) | |
| 72 | |
| 73 ;;; FIXME!! clone of code from gnus-vis.el FIXME!! | |
| 74 (defun earcon-article-push-button (event) | |
| 75 "Check text under the mouse pointer for a callback function. | |
| 76 If the text under the mouse pointer has a `earcon-callback' property, | |
| 77 call it with the value of the `earcon-data' text property." | |
| 78 (interactive "e") | |
| 79 (set-buffer (window-buffer (posn-window (event-start event)))) | |
| 80 (let* ((pos (posn-point (event-start event))) | |
|
56927
55fd4f77387a
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-523
Miles Bader <miles@gnu.org>
parents:
52401
diff
changeset
|
81 (data (get-text-property pos 'earcon-data)) |
| 17493 | 82 (fun (get-text-property pos 'earcon-callback))) |
| 83 (if fun (funcall fun data)))) | |
| 84 | |
| 85 (defun earcon-article-press-button () | |
| 86 "Check text at point for a callback function. | |
| 87 If the text at point has a `earcon-callback' property, | |
| 88 call it with the value of the `earcon-data' text property." | |
| 89 (interactive) | |
| 90 (let* ((data (get-text-property (point) 'earcon-data)) | |
| 91 (fun (get-text-property (point) 'earcon-callback))) | |
| 92 (if fun (funcall fun data)))) | |
| 93 | |
| 94 (defun earcon-article-prev-button (n) | |
| 95 "Move point to N buttons backward. | |
| 96 If N is negative, move forward instead." | |
| 97 (interactive "p") | |
| 98 (earcon-article-next-button (- n))) | |
| 99 | |
| 100 (defun earcon-article-next-button (n) | |
| 101 "Move point to N buttons forward. | |
| 102 If N is negative, move backward instead." | |
| 103 (interactive "p") | |
| 104 (let ((function (if (< n 0) 'previous-single-property-change | |
| 105 'next-single-property-change)) | |
| 106 (inhibit-point-motion-hooks t) | |
| 107 (backward (< n 0)) | |
| 108 (limit (if (< n 0) (point-min) (point-max)))) | |
| 109 (setq n (abs n)) | |
| 110 (while (and (not (= limit (point))) | |
| 111 (> n 0)) | |
| 112 ;; Skip past the current button. | |
| 113 (when (get-text-property (point) 'earcon-callback) | |
| 114 (goto-char (funcall function (point) 'earcon-callback nil limit))) | |
| 115 ;; Go to the next (or previous) button. | |
| 116 (gnus-goto-char (funcall function (point) 'earcon-callback nil limit)) | |
| 117 ;; Put point at the start of the button. | |
| 118 (when (and backward (not (get-text-property (point) 'earcon-callback))) | |
| 119 (goto-char (funcall function (point) 'earcon-callback nil limit))) | |
| 120 ;; Skip past intangible buttons. | |
| 121 (when (get-text-property (point) 'intangible) | |
| 122 (incf n)) | |
| 123 (decf n)) | |
| 124 (unless (zerop n) | |
| 125 (gnus-message 5 "No more buttons")) | |
| 126 n)) | |
| 127 | |
| 128 (defun earcon-article-add-button (from to fun &optional data) | |
| 129 "Create a button between FROM and TO with callback FUN and data DATA." | |
| 130 (and (boundp gnus-article-button-face) | |
| 131 gnus-article-button-face | |
| 132 (gnus-overlay-put (gnus-make-overlay from to) | |
| 133 'face gnus-article-button-face)) | |
| 134 (gnus-add-text-properties | |
| 135 from to | |
| 136 (nconc (and gnus-article-mouse-face | |
| 137 (list gnus-mouse-face-prop gnus-article-mouse-face)) | |
| 138 (list 'gnus-callback fun) | |
| 139 (and data (list 'gnus-data data))))) | |
| 140 | |
| 141 (defun earcon-button-entry () | |
| 142 ;; Return the first entry in `gnus-button-alist' matching this place. | |
| 143 (let ((alist earcon-regexp-alist) | |
| 144 (case-fold-search t) | |
| 145 (entry nil)) | |
| 146 (while alist | |
| 147 (setq entry (pop alist)) | |
| 148 (if (looking-at (car entry)) | |
| 149 (setq alist nil) | |
| 150 (setq entry nil))) | |
| 151 entry)) | |
| 152 | |
| 153 (defun earcon-button-push (marker) | |
| 154 ;; Push button starting at MARKER. | |
| 155 (save-excursion | |
| 156 (set-buffer gnus-article-buffer) | |
| 157 (goto-char marker) | |
| 158 (let* ((entry (earcon-button-entry)) | |
| 159 (inhibit-point-motion-hooks t) | |
| 160 (fun 'gnus-audio-play) | |
| 161 (args (list (nth 2 entry)))) | |
| 162 (cond | |
| 163 ((fboundp fun) | |
| 164 (apply fun args)) | |
| 165 ((and (boundp fun) | |
| 166 (fboundp (symbol-value fun))) | |
| 167 (apply (symbol-value fun) args)) | |
| 168 (t | |
| 169 (gnus-message 1 "You must define `%S' to use this button" | |
| 170 (cons fun args))))))) | |
| 171 | |
| 172 ;;; FIXME!! clone of code from gnus-vis.el FIXME!! | |
| 173 | |
| 174 ;;;###interactive | |
| 175 (defun earcon-region (beg end) | |
| 176 "Play Sounds in the region between point and mark." | |
| 177 (interactive "r") | |
| 178 (earcon-buffer (current-buffer) beg end)) | |
| 179 | |
| 180 ;;;###interactive | |
| 181 (defun earcon-buffer (&optional buffer st nd) | |
| 182 (interactive) | |
| 183 (save-excursion | |
| 184 ;; clear old markers. | |
| 185 (if (boundp 'earcon-button-marker-list) | |
| 186 (while earcon-button-marker-list | |
| 187 (set-marker (pop earcon-button-marker-list) nil)) | |
| 188 (setq earcon-button-marker-list nil)) | |
| 189 (and buffer (set-buffer buffer)) | |
| 190 (let ((buffer-read-only nil) | |
| 191 (inhibit-point-motion-hooks t) | |
| 192 (case-fold-search t) | |
| 193 (alist earcon-regexp-alist) | |
| 194 beg entry regexp) | |
| 195 (goto-char (point-min)) | |
| 196 (setq beg (point)) | |
| 197 (while (setq entry (pop alist)) | |
| 198 (setq regexp (concat (regexp-quote earcon-prefix) | |
| 199 ".*\\(" | |
| 200 (car entry) | |
| 201 "\\).*" | |
| 202 (regexp-quote earcon-suffix))) | |
| 203 (goto-char beg) | |
| 204 (while (re-search-forward regexp nil t) | |
| 205 (let* ((start (and entry (match-beginning 1))) | |
| 206 (end (and entry (match-end 1))) | |
| 207 (from (match-beginning 1))) | |
| 208 (earcon-article-add-button | |
| 209 start end 'earcon-button-push | |
| 210 (car (push (set-marker (make-marker) from) | |
| 211 earcon-button-marker-list))) | |
| 212 (gnus-audio-play (caddr entry)))))))) | |
| 213 | |
| 214 ;;;###autoload | |
| 215 (defun gnus-earcon-display () | |
| 216 "Play sounds in message buffers." | |
| 217 (interactive) | |
| 218 (save-excursion | |
| 219 (set-buffer gnus-article-buffer) | |
| 220 (goto-char (point-min)) | |
| 221 ;; Skip headers | |
| 222 (unless (search-forward "\n\n" nil t) | |
| 223 (goto-char (point-max))) | |
| 224 (sit-for 0) | |
| 225 (earcon-buffer (current-buffer) (point)))) | |
| 226 | |
| 227 ;;;*** | |
| 228 | |
| 229 (provide 'earcon) | |
| 230 | |
| 231 (run-hooks 'earcon-load-hook) | |
| 232 | |
| 52401 | 233 ;;; arch-tag: 844dfeea-980c-4ed0-907f-a30bf139691c |
| 17493 | 234 ;;; earcon.el ends here |
