Revision: mange@freemail.hu--2004/emacs-jabber--cvs-head--0--patch-166

Creator:  Magnus Henoch <mange@freemail.hu>

Hack external notifiers

echo and beep alerts are now defined through define-jabber-alert.
New directory: external-notifiers.
ratpoison and screen alerts moved there, and defined through
define-jabber-alert.
New alerts: sawfish and festival.
This commit is contained in:
Magnus Henoch 2005-01-02 22:57:36 +00:00 committed by Kirill A. Korinskiy
parent 152389d29d
commit 31fe3b4a22
7 changed files with 179 additions and 102 deletions

View File

@ -0,0 +1,33 @@
;;; jabber-festival.el --- Festival alert hooks
;; Copyright (C) 2005 Magnus Henoch
;; This file is a part of jabber.el.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
(condition-case e
(progn
;; Most people don't have Festival, so this will often fail
(require 'festival)
(define-jabber-alert festival "Voice messages through Festival"
'festival-say-string))
(error nil))
(provide 'jabber-festival)
;; arch-tag: 8922D096-5D07-11D9-B4C2-000A95C2FCD0

View File

@ -0,0 +1,30 @@
;; jabber-ratpoison.el - emacs-jabber interface to ratpoison
;; Copyright (C) 2005 - Magnus Henoch - mange@freemail.hu
;; This file is a part of jabber.el.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(defun jabber-ratpoison-message (msg)
"Show MSG in Ratpoison"
(let ((process-connection-type))
(start-process "ratpoison" nil "ratpoison" "-c" (concat "echo " msg))))
(define-jabber-alert ratpoison "Show a message through the Ratpoison window manager"
'jabber-ratpoison-message)
(provide 'jabber-ratpoison)
;; arch-tag: 19650075-5D05-11D9-B80F-000A95C2FCD0

View File

@ -0,0 +1,40 @@
;; jabber-sawfish.el - emacs-jabber interface to sawfish
;; Copyright (C) 2005 - Mario Domenech Goulart
;; This file is a part of jabber.el.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(defcustom jabber-sawfish-display-time 3
"Time in seconds for displaying a jabber message through the
Sawfish window manager."
:type 'integer
:group 'jabber-alerts)
(defun jabber-sawfish-display-message (message)
"Displays MESSAGE through the Sawfish window manager."
(let ((process-connection-type nil))
(start-process-shell-command
"jabber-sawfish" nil "echo"
(concat "'((display-message \""
message
"\")(make-timer (lambda () (display-message nil)) 3))' | sawfish-client - &> /dev/null"))))
(define-jabber-alert sawfish "Display a message through the Sawfish window manager"
'jabber-sawfish-display-message)
(provide 'jabber-sawfish)
;; arch-tag: 4F0154ED-5D05-11D9-9E6B-000A95C2FCD0

View File

@ -0,0 +1,29 @@
;; jabber-screen.el - emacs-jabber interface to screen
;; Copyright (C) 2005 - Magnus Henoch - mange@freemail.hu
;; This file is a part of jabber.el.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(defun jabber-screen-message (msg)
"Show MSG in screen"
(call-process "screen" nil nil nil "-X" "echo" msg))
(define-jabber-alert screen "Show a message through the Screen terminal manager"
'jabber-screen-message)
(provide 'jabber-screen)
;; arch-tag: B576ADDA-5D04-11D9-AA52-000A95C2FCD0

View File

@ -1,7 +1,7 @@
;; jabber-alert.el - alert hooks
;; Copyright (C) 2002, 2003, 2004 - tom berger - object@intelectronica.net
;; Copyright (C) 2003, 2004 - Magnus Henoch - mange@freemail.hu
;; Copyright (C) 2003, 2004, 2005 - Magnus Henoch - mange@freemail.hu
;; This file is a part of jabber.el.
@ -38,7 +38,11 @@ hooks do not have to call it themselves.
This hook is meant for user customization of message alerts. For
other uses, see `jabber-message-hooks'."
:type 'hook
:options '(jabber-message-beep jabber-message-wave jabber-message-echo jabber-message-switch jabber-message-display jabber-message-ratpoison jabber-message-screen)
:options '(jabber-message-beep
jabber-message-wave
jabber-message-echo
jabber-message-switch
jabber-message-display)
:group 'jabber-alerts)
(defvar jabber-message-hooks '(jabber-message-history)
@ -75,9 +79,7 @@ so that hooks do not have to call it themselves."
jabber-muc-wave
jabber-muc-echo
jabber-muc-switch
jabber-muc-display
jabber-muc-ratpoison
jabber-muc-screen)
jabber-muc-display)
:group 'jabber-alerts)
(defvar jabber-muc-hooks '()
@ -119,8 +121,6 @@ one of \"subscribe\", \"unsubscribe\", \"subscribed\" and
jabber-presence-update-roster
jabber-presence-switch
jabber-presence-display
jabber-presence-ratpoison
jabber-presence-screen
jabber-presence-echo)
:group 'jabber-alerts)
@ -155,8 +155,6 @@ Third argument is PROPOSED-ALERT, containing the string returned by
:type 'hook
:options '(jabber-info-beep
jabber-info-wave
jabber-info-ratpoison
jabber-info-screen
jabber-info-echo
jabber-info-switch
jabber-info-display)
@ -207,6 +205,10 @@ and BUFFER, a buffer containing the result."
(defmacro define-jabber-alert (name docstring function)
"Define a new family of external alert hooks.
Use this macro when your hooks do nothing except displaying a string
in some new innovative way. You write a string display function, and
this macro does all the boring and repetitive work.
NAME is the name of the alert family. The resulting hooks will be
called jabber-{message,muc,presence,info}-NAME.
DOCSTRING is the docstring to use for those hooks.
@ -247,6 +249,15 @@ Examples:
(pushnew (quote ,info) (get 'jabber-alert-info-message-hooks 'custom-options))))))
;; Alert hooks
(define-jabber-alert echo "Show a message in the echo area"
(lambda (msg) (message "%s" msg)))
(define-jabber-alert beep "Beep on event"
(lambda (&rest ignore) (beep)))
(require 'jabber-screen)
(require 'jabber-ratpoison)
(require 'jabber-sawfish)
(require 'jabber-festival)
;; Message alert hooks
(defun jabber-message-default-message (from buffer text)
@ -259,16 +270,6 @@ Examples:
:type 'boolean
:group 'jabber-alerts)
(defun jabber-message-beep (from buffer text proposed-alert)
"Beep when a message arrives"
(when proposed-alert
(beep)))
(defun jabber-message-echo (from buffer text proposed-alert)
"Show a message in the echo area when a message arrives"
(if proposed-alert
(message "%s" proposed-alert)))
(defun jabber-message-wave (from buffer text proposed-alert)
"Play the wave file specified in `jabber-alert-message-wave'"
(when proposed-alert
@ -284,17 +285,6 @@ Examples:
(when proposed-alert
(switch-to-buffer buffer)))
(defun jabber-message-ratpoison (from buffer text proposed-alert)
"Show a message through the Ratpoison window manager"
(if proposed-alert
(let ((process-connection-type nil))
(start-process "ratpoison" nil "ratpoison" "-c" (format "echo %s" proposed-alert)))))
(defun jabber-message-screen (from buffer text proposed-alert)
"Show a message through the Screen terminal manager"
(if proposed-alert
(call-process "screen" nil nil nil "-X" "echo" proposed-alert)))
;; MUC alert hooks
(defun jabber-muc-default-message (nick group buffer text)
(when (or jabber-message-alert-same-buffer
@ -304,16 +294,6 @@ Examples:
group))
(format "Message in %s" (jabber-jid-displayname group)))))
(defun jabber-muc-beep (nick group buffer text proposed-alert)
"Beep when a MUC message arrives"
(when proposed-alert
(beep)))
(defun jabber-muc-echo (nick group buffer text proposed-alert)
"Show a message in the echo area when a MUC message arrives"
(if proposed-alert
(message "%s" proposed-alert)))
(defun jabber-muc-wave (nick group buffer text proposed-alert)
"Play the wave file specified in `jabber-alert-muc-wave'"
(when proposed-alert
@ -329,17 +309,6 @@ Examples:
(when proposed-alert
(switch-to-buffer buffer)))
(defun jabber-muc-ratpoison (nick group buffer text proposed-alert)
"Show a message through the Ratpoison window manager"
(if proposed-alert
(let ((process-connection-type nil))
(start-process "ratpoison" nil "ratpoison" "-c" (format "echo %s" proposed-alert)))))
(defun jabber-muc-screen (nick group buffer text proposed-alert)
"Show a message through the Screen terminal manager"
(if proposed-alert
(call-process "screen" nil nil nil "-X" "echo" proposed-alert)))
;; Presence alert hooks
(defun jabber-presence-default-message (who oldstatus newstatus statustext)
"This function returns nil if OLDSTATUS and NEWSTATUS are equal, and in other
@ -372,16 +341,6 @@ This function is not called directly, but is the default for
"")))
(concat formattedname formattedstatus formattedtext)))))
(defun jabber-presence-beep (who oldstatus newstatus statustext proposed-alert)
"Beep when someone's presence changes"
(if proposed-alert
(beep)))
(defun jabber-presence-echo (who oldstatus newstatus statustext proposed-alert)
"Show a message in the echo area"
(if proposed-alert
(message "%s" proposed-alert)))
(defun jabber-presence-wave (who oldstatus newstatus statustext proposed-alert)
"Play the wave file specified in `jabber-alert-presence-wave'"
(if proposed-alert
@ -401,19 +360,6 @@ This function is not called directly, but is the default for
(when proposed-alert
(switch-to-buffer (process-buffer *jabber-connection*))))
(defun jabber-presence-ratpoison (who oldstatus newstatus statustext proposed-alert)
"Show a message through the Ratpoison window manager"
(if proposed-alert
(let ((process-connection-type))
(start-process "ratpoison" nil "ratpoison" "-c" (concat "echo " proposed-alert)))))
(defun jabber-presence-screen (who oldstatus newstatus statustext proposed-alert)
"Show a message through the Screen terminal manager"
(if proposed-alert
(call-process "screen" nil nil nil "-X" "echo" proposed-alert)))
;;; Info alert hooks
(defun jabber-info-default-message (infotype buffer)
@ -424,32 +370,11 @@ This function uses `jabber-info-message-alist' to find a message."
(concat (cdr (assq infotype jabber-info-message-alist))
" (buffer "(buffer-name buffer) ")"))
(defun jabber-info-echo (infotype buffer proposed-alert)
"Show a message in the echo area"
(if proposed-alert
(message "%s" proposed-alert)))
(defun jabber-info-beep (infotype buffer proposed-alert)
"Beep on completed info requests"
(if proposed-alert
(beep)))
(defun jabber-info-wave (infotype buffer proposed-alert)
"Play the wave file specified in `jabber-alert-info-wave'"
(if proposed-alert
(jabber-play-sound-file jabber-alert-info-wave)))
(defun jabber-info-ratpoison (infotype buffer proposed-alert)
"Show a message through the Ratpoison window manager"
(if proposed-alert
(let ((process-connection-type nil))
(start-process "ratpoison" nil "ratpoison" "-c" (concat "echo " proposed-alert)))))
(defun jabber-info-screen (infotype buffer proposed-alert)
"Show a message through the Screen terminal manager"
(if proposed-alert
(call-process "screen" nil nil nil "-X" "echo" proposed-alert)))
(defun jabber-info-display (infotype buffer proposed-alert)
"Display buffer of completed request"
(when proposed-alert

View File

@ -726,6 +726,7 @@ Format, elisp, GNU Emacs Lisp Reference Manual}.
@section Customizing alerts
@cindex Alert hooks
@findex define-jabber-alert
When an event happens (currently including presence changes, incoming
messages, and completed queries) you will usually want to be
@ -741,14 +742,25 @@ certain mechanism. This text message is provided by a function which
you can rewrite or replace. If this function returns @code{nil}, no
message is displayed, and non-textual alerts refrain from action.
If you want to write alert hooks that do nothing except displaying the
supplied message in some way, use the macro
@code{define-jabber-alert}. For example, if @var{foo} is a function
that takes a string as an argument, write
@example
(define-jabber-alert foo
"Display a message in a fooish way"
'foo)
@end example
and all details will be taken care of for you.
The hooks take different arguments depending on category. However,
they all have in common that the last argument is the result of the
message function. The message function for each category takes the
same arguments as the corresponding hooks, except for that last
argument.
Alert hook contributions are very welcome. Either submit them to the
Sourceforge patch tracker, or contact us directly.
Alert hook contributions are very welcome. You can send them to the
mailing list, or to the Sourceforge patch tracker.
Alert hooks are meant for optional UI things, that are subject to
varying user tastes, and that can be toggled by simply adding or
@ -768,7 +780,7 @@ the alert hooks minus the @code{-alert} part.
@node Standard alerts, Presence alerts, Customizing alerts, Customizing alerts
@subsection Standard alerts
Six alerts are already written for all three alert categories. These
Eight alerts are already written for all three alert categories. These
all obey the result from the corresponding message function.
The @code{beep} alerts simply sound the terminal bell by calling
@ -802,11 +814,17 @@ The @code{ratpoison} alerts send a message through the Ratpoison
window manager (see @uref{http://ratpoison.sourceforge.net/}). They
do no harm if used when you're not running X, but if you are running X
with another window manager, the ratpoison processes will never exit.
You can look at them with @code{list-processes}.@footnote{In jabber.el
0.4, ratpoison alerts were sent synchronously, which meant that Emacs
would stall if ratpoison wasn't there to answer.}
You can look at them with @code{list-processes}.
All these functions are in the @file{jabber-alert.el} file. You can
The @code{sawfish} alerts send a message through the Sawfish window
manager.
The @code{festival} alerts speak the message using the Emacs interface
of the Festival speech synthesis system (see
@uref{http://www.cstr.ed.ac.uk/projects/festival/}).
Some of these functions are in the @file{jabber-alert.el} file, and
the others are in the directory @file{external-notifiers}. You can
use them as templates or inspiration for your own alerts.
@node Presence alerts, Message alerts, Standard alerts, Customizing alerts

2
subdirs.el Normal file
View File

@ -0,0 +1,2 @@
(normal-top-level-add-to-load-path '("external-notifiers"))
;; arch-tag: CF9A5416-5D05-11D9-8B58-000A95C2FCD0