1 ;;; erc-nick-notify.el --- Notify popup for ERC
3 ;; Filename: erc-nick-notify.el
4 ;; Description: Notify popup for ERC
5 ;; Author: Andy Stewart lazycat.manatee@gmail.com
6 ;; Maintainer: Andy Stewart lazycat.manatee@gmail.com
7 ;; Copyright (C) 2008, 2009, Andy Stewart, all rights reserved.
8 ;; Created: 2008-12-04 12:47:28
10 ;; Last-Updated: 2009-01-31 10:47:32
12 ;; URL: http://www.emacswiki.org/emacs/download/erc-nick-notify.el
13 ;; Keywords: erc, notify
14 ;; Compatibility: GNU Emacs 23.0.60.1
16 ;; Features that might be required by this library:
21 ;;; This file is NOT part of GNU Emacs
25 ;; This program is free software; you can redistribute it and/or modify
26 ;; it under the terms of the GNU General Public License as published by
27 ;; the Free Software Foundation; either version 3, or (at your option)
30 ;; This program is distributed in the hope that it will be useful,
31 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
32 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 ;; GNU General Public License for more details.
35 ;; You should have received a copy of the GNU General Public License
36 ;; along with this program; see the file COPYING. If not, write to
37 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
38 ;; Floor, Boston, MA 02110-1301, USA.
42 ;; Notify popup for ERC
44 ;; This extension use `notify-send' for notify.
45 ;; So make you have install `notify-send' in your system.
50 ;; Put erc-nick-notify.el to your load-path.
51 ;; The load-path is usually ~/elisp/.
52 ;; It's set in your ~/.emacs like this:
53 ;; (add-to-list 'load-path (expand-file-name "~/elisp"))
55 ;; And the following to your ~/.emacs startup file.
57 ;; (require 'erc-nick-notify)
63 ;; `erc-nick-notify-delay'
64 ;; The delay time that between two messages.
65 ;; `erc-nick-notify-cmd'
66 ;; The command that use for notify.
67 ;; `erc-nick-notify-icon'
68 ;; The file name of icon display.
69 ;; `erc-nick-notify-timeout'
70 ;; The timeout in milliseconds at which to expire the notification.
73 ;; `erc-nick-notify-category'
74 ;; The notification category.
76 ;; All of the above can be customize by:
77 ;; M-x customize-group RET erc-nick-notify RET
86 ;; Fix `void-variable' bug.
89 ;; Add customize support.
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111 (defgroup erc-nick-notify nil
112 "Notify popup for ERC."
115 (defcustom erc-nick-notify-delay '(0 5 0)
116 "The delay time that between two message.
117 Default is 5 minutes."
119 :group 'erc-nick-notify)
121 (defcustom erc-nick-notify-cmd "notify-send"
122 "The command that use for notify."
124 :group 'erc-nick-notify)
126 (defcustom erc-nick-notify-icon "~/MyEmacs/Image/Irc.png"
127 "Specifies an icon filename or stock icon to display."
129 :group 'erc-nick-notify)
131 (defcustom erc-nick-notify-timeout 10000
132 "Specifies the timeout in milliseconds at which to expire the notification."
134 :group 'erc-nick-notify)
136 (defcustom erc-nick-notify-urgency "low"
137 "Specifies the urgency level (low, normal, critical)."
139 :group 'erc-nick-notify)
141 (defcustom erc-nick-notify-category "im.received"
142 "Specifies the notification category."
144 :group 'erc-nick-notify)
146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147 (defvar erc-nick-notify-last '(0 0 0)
148 "The last time that receive message.")
150 (defvar erc-nick-notify-buffer nil
151 "The buffer name of last notify me.")
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154 (defun erc-nick-notify-jump-last-channel ()
155 "Jump to last channel that notify me."
157 (if erc-nick-notify-buffer
158 (switch-to-buffer erc-nick-notify-buffer)
159 (message "Nobody notify you in IRC.")))
161 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
162 (defun erc-nick-notify ()
163 "Notify me when my nick show up.
164 This function should be in the insert-post-hook."
165 (let ((now (current-time)))
166 (when (time-less-p erc-nick-notify-delay
167 (time-since erc-nick-notify-last))
168 (setq erc-nick-notify-last now)
169 (goto-char (point-min))
170 (when (re-search-forward
172 "\\(<\\([^>]*\\)>\\)" ; <someone>
174 ;; Don't match if we're saying something
175 "\\(\\* " (regexp-quote (erc-current-nick)) "\\)"
177 "\\(.*" (regexp-quote (erc-current-nick)) ".*\\)")
180 (when (> (length (match-string-no-properties 2)) 0)
181 (concat "<b><" (match-string-no-properties 3)
183 (match-string-no-properties 5))))
184 (setq erc-nick-notify-buffer (buffer-name))
185 (shell-command (concat erc-nick-notify-cmd
186 " -i " erc-nick-notify-icon
187 " -t " (int-to-string
188 erc-nick-notify-timeout)
189 " -u " erc-nick-notify-urgency
190 " -c " erc-nick-notify-category
192 " \"" erc-nick-notify-buffer "\""
198 ;; Add `erc-nick-notify' to `erc-insert-post-hook'
199 (add-hook 'erc-insert-post-hook 'erc-nick-notify)
201 (provide 'erc-nick-notify)
203 ;;; erc-nick-notify.el ends here
205 ;;; LocalWords: erc cmd im msg lt