]> gitweb.michael.orlitzky.com - emacs.d.git/blob - erc-nick-notify.el
Autoload octave-mode for *.m files.
[emacs.d.git] / erc-nick-notify.el
1 ;;; erc-nick-notify.el --- Notify popup for ERC
2
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
9 ;; Version: 0.2.1
10 ;; Last-Updated: 2009-01-31 10:47:32
11 ;; By: Andy Stewart
12 ;; URL: http://www.emacswiki.org/emacs/download/erc-nick-notify.el
13 ;; Keywords: erc, notify
14 ;; Compatibility: GNU Emacs 23.0.60.1
15 ;;
16 ;; Features that might be required by this library:
17 ;;
18 ;; `erc'
19 ;;
20
21 ;;; This file is NOT part of GNU Emacs
22
23 ;;; License
24 ;;
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)
28 ;; any later version.
29
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.
34
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.
39
40 ;;; Commentary:
41 ;;
42 ;; Notify popup for ERC
43 ;;
44 ;; This extension use `notify-send' for notify.
45 ;; So make you have install `notify-send' in your system.
46 ;;
47
48 ;;; Installation:
49 ;;
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"))
54 ;;
55 ;; And the following to your ~/.emacs startup file.
56 ;;
57 ;; (require 'erc-nick-notify)
58 ;;
59 ;; No need more.
60
61 ;;; Customize:
62 ;;
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.
71 ;; `erc-nick-notify'
72 ;; The urgency level.
73 ;; `erc-nick-notify-category'
74 ;; The notification category.
75 ;;
76 ;; All of the above can be customize by:
77 ;; M-x customize-group RET erc-nick-notify RET
78 ;;
79
80 ;;; Change log:
81 ;;
82 ;; 2009/01/31
83 ;; Fix doc.
84 ;;
85 ;; 2008/12/21
86 ;; Fix `void-variable' bug.
87 ;;
88 ;; 2008/12/08
89 ;; Add customize support.
90 ;;
91 ;; 2008/12/04
92 ;; First released.
93 ;;
94
95 ;;; Acknowledgements:
96 ;;
97 ;;
98 ;;
99
100 ;;; TODO
101 ;;
102 ;;
103 ;;
104
105 ;;; Require
106 (require 'erc)
107
108 ;;; Code:
109
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111 (defgroup erc-nick-notify nil
112 "Notify popup for ERC."
113 :group 'erc)
114
115 (defcustom erc-nick-notify-delay '(0 5 0)
116 "The delay time that between two message.
117 Default is 5 minutes."
118 :type 'list
119 :group 'erc-nick-notify)
120
121 (defcustom erc-nick-notify-cmd "notify-send"
122 "The command that use for notify."
123 :type 'string
124 :group 'erc-nick-notify)
125
126 (defcustom erc-nick-notify-icon "~/MyEmacs/Image/Irc.png"
127 "Specifies an icon filename or stock icon to display."
128 :type 'string
129 :group 'erc-nick-notify)
130
131 (defcustom erc-nick-notify-timeout 10000
132 "Specifies the timeout in milliseconds at which to expire the notification."
133 :type 'number
134 :group 'erc-nick-notify)
135
136 (defcustom erc-nick-notify-urgency "low"
137 "Specifies the urgency level (low, normal, critical)."
138 :type 'string
139 :group 'erc-nick-notify)
140
141 (defcustom erc-nick-notify-category "im.received"
142 "Specifies the notification category."
143 :type 'string
144 :group 'erc-nick-notify)
145
146 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
147 (defvar erc-nick-notify-last '(0 0 0)
148 "The last time that receive message.")
149
150 (defvar erc-nick-notify-buffer nil
151 "The buffer name of last notify me.")
152
153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
154 (defun erc-nick-notify-jump-last-channel ()
155 "Jump to last channel that notify me."
156 (interactive)
157 (if erc-nick-notify-buffer
158 (switch-to-buffer erc-nick-notify-buffer)
159 (message "Nobody notify you in IRC.")))
160
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
171 (concat "\\("
172 "\\(<\\([^>]*\\)>\\)" ; <someone>
173 "\\|"
174 ;; Don't match if we're saying something
175 "\\(\\* " (regexp-quote (erc-current-nick)) "\\)"
176 "\\)"
177 "\\(.*" (regexp-quote (erc-current-nick)) ".*\\)")
178 nil t)
179 (let ((msg (concat
180 (when (> (length (match-string-no-properties 2)) 0)
181 (concat "<b>&lt;" (match-string-no-properties 3)
182 "&gt;</b> "))
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
191 " -- "
192 " \"" erc-nick-notify-buffer "\""
193 " \""
194 (if (boundp 'msg)
195 msg "")
196 "\"")))))))
197
198 ;; Add `erc-nick-notify' to `erc-insert-post-hook'
199 (add-hook 'erc-insert-post-hook 'erc-nick-notify)
200
201 (provide 'erc-nick-notify)
202
203 ;;; erc-nick-notify.el ends here
204
205 ;;; LocalWords: erc cmd im msg lt