From: Michael Orlitzky Date: Mon, 18 Oct 2010 23:40:34 +0000 (-0400) Subject: Add the erc-nick-notify library. X-Git-Url: http://gitweb.michael.orlitzky.com/?p=emacs.d.git;a=commitdiff_plain;h=56e245ab584824a5c25b6c859c12619a61c2c5b4 Add the erc-nick-notify library. Add an erc-mode-hook to enable erc-nick-notify. Add sounds/images to be used by erc-nick-notify. --- diff --git a/audio/beep.mp3 b/audio/beep.mp3 new file mode 100644 index 0000000..cd3a3ec Binary files /dev/null and b/audio/beep.mp3 differ diff --git a/erc-nick-notify.el b/erc-nick-notify.el new file mode 100644 index 0000000..baa15c8 --- /dev/null +++ b/erc-nick-notify.el @@ -0,0 +1,205 @@ +;;; erc-nick-notify.el --- Notify popup for ERC + +;; Filename: erc-nick-notify.el +;; Description: Notify popup for ERC +;; Author: Andy Stewart lazycat.manatee@gmail.com +;; Maintainer: Andy Stewart lazycat.manatee@gmail.com +;; Copyright (C) 2008, 2009, Andy Stewart, all rights reserved. +;; Created: 2008-12-04 12:47:28 +;; Version: 0.2.1 +;; Last-Updated: 2009-01-31 10:47:32 +;; By: Andy Stewart +;; URL: http://www.emacswiki.org/emacs/download/erc-nick-notify.el +;; Keywords: erc, notify +;; Compatibility: GNU Emacs 23.0.60.1 +;; +;; Features that might be required by this library: +;; +;; `erc' +;; + +;;; This file is NOT part of GNU Emacs + +;;; License +;; +;; 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 3, 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; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth +;; Floor, Boston, MA 02110-1301, USA. + +;;; Commentary: +;; +;; Notify popup for ERC +;; +;; This extension use `notify-send' for notify. +;; So make you have install `notify-send' in your system. +;; + +;;; Installation: +;; +;; Put erc-nick-notify.el to your load-path. +;; The load-path is usually ~/elisp/. +;; It's set in your ~/.emacs like this: +;; (add-to-list 'load-path (expand-file-name "~/elisp")) +;; +;; And the following to your ~/.emacs startup file. +;; +;; (require 'erc-nick-notify) +;; +;; No need more. + +;;; Customize: +;; +;; `erc-nick-notify-delay' +;; The delay time that between two messages. +;; `erc-nick-notify-cmd' +;; The command that use for notify. +;; `erc-nick-notify-icon' +;; The file name of icon display. +;; `erc-nick-notify-timeout' +;; The timeout in milliseconds at which to expire the notification. +;; `erc-nick-notify' +;; The urgency level. +;; `erc-nick-notify-category' +;; The notification category. +;; +;; All of the above can be customize by: +;; M-x customize-group RET erc-nick-notify RET +;; + +;;; Change log: +;; +;; 2009/01/31 +;; Fix doc. +;; +;; 2008/12/21 +;; Fix `void-variable' bug. +;; +;; 2008/12/08 +;; Add customize support. +;; +;; 2008/12/04 +;; First released. +;; + +;;; Acknowledgements: +;; +;; +;; + +;;; TODO +;; +;; +;; + +;;; Require +(require 'erc) + +;;; Code: + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Customize ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defgroup erc-nick-notify nil + "Notify popup for ERC." + :group 'erc) + +(defcustom erc-nick-notify-delay '(0 5 0) + "The delay time that between two message. +Default is 5 minutes." + :type 'list + :group 'erc-nick-notify) + +(defcustom erc-nick-notify-cmd "notify-send" + "The command that use for notify." + :type 'string + :group 'erc-nick-notify) + +(defcustom erc-nick-notify-icon "~/MyEmacs/Image/Irc.png" + "Specifies an icon filename or stock icon to display." + :type 'string + :group 'erc-nick-notify) + +(defcustom erc-nick-notify-timeout 10000 + "Specifies the timeout in milliseconds at which to expire the notification." + :type 'number + :group 'erc-nick-notify) + +(defcustom erc-nick-notify-urgency "low" + "Specifies the urgency level (low, normal, critical)." + :type 'string + :group 'erc-nick-notify) + +(defcustom erc-nick-notify-category "im.received" + "Specifies the notification category." + :type 'string + :group 'erc-nick-notify) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Variable ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defvar erc-nick-notify-last '(0 0 0) + "The last time that receive message.") + +(defvar erc-nick-notify-buffer nil + "The buffer name of last notify me.") + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Interactive Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun erc-nick-notify-jump-last-channel () + "Jump to last channel that notify me." + (interactive) + (if erc-nick-notify-buffer + (switch-to-buffer erc-nick-notify-buffer) + (message "Nobody notify you in IRC."))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Utilities Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defun erc-nick-notify () + "Notify me when my nick show up. +This function should be in the insert-post-hook." + (let ((now (current-time))) + (when (time-less-p erc-nick-notify-delay + (time-since erc-nick-notify-last)) + (setq erc-nick-notify-last now) + (goto-char (point-min)) + (when (re-search-forward + (concat "\\(" + "\\(<\\([^>]*\\)>\\)" ; + "\\|" + ;; Don't match if we're saying something + "\\(\\* " (regexp-quote (erc-current-nick)) "\\)" + "\\)" + "\\(.*" (regexp-quote (erc-current-nick)) ".*\\)") + nil t) + (let ((msg (concat + (when (> (length (match-string-no-properties 2)) 0) + (concat "<" (match-string-no-properties 3) + "> ")) + (match-string-no-properties 5)))) + (setq erc-nick-notify-buffer (buffer-name)) + (shell-command (concat erc-nick-notify-cmd + " -i " erc-nick-notify-icon + " -t " (int-to-string + erc-nick-notify-timeout) + " -u " erc-nick-notify-urgency + " -c " erc-nick-notify-category + " -- " + " \"" erc-nick-notify-buffer "\"" + " \"" + (if (boundp 'msg) + msg "") + "\""))))))) + +;; Add `erc-nick-notify' to `erc-insert-post-hook' +(add-hook 'erc-insert-post-hook 'erc-nick-notify) + +(provide 'erc-nick-notify) + +;;; erc-nick-notify.el ends here + +;;; LocalWords: erc cmd im msg lt diff --git a/images/dialog-warning.png b/images/dialog-warning.png new file mode 100644 index 0000000..7233d45 Binary files /dev/null and b/images/dialog-warning.png differ diff --git a/mode-hooks.el b/mode-hooks.el index ac58fab..db3f1e7 100644 --- a/mode-hooks.el +++ b/mode-hooks.el @@ -5,6 +5,7 @@ (load-library "css-mode-hooks") (load-library "dired-mode-hooks") (load-library "ecmascript-mode-hooks") +(load-library "erc-mode-hooks") (load-library "haskell-mode-hooks") (load-library "nxml-mode-hooks") (load-library "ruby-mode-hooks") diff --git a/mode-hooks/erc-mode-hooks.el b/mode-hooks/erc-mode-hooks.el new file mode 100644 index 0000000..280b117 --- /dev/null +++ b/mode-hooks/erc-mode-hooks.el @@ -0,0 +1,9 @@ +(defun ercm-hook() + ;; Load ERC-specific libraries. + (load-library "erc-nick-notify") + (setq erc-nick-notify-cmd "mplayer ~/.home/emacs/audio/beep.mp3; notify-send") + (setq erc-nick-notify-delay '(0 1 0)) + (setq erc-nick-notify-icon "~/.home/emacs/images/dialog-warning.png") + ) + +(add-hook 'erc-mode-hook (function ercm-hook))