;;; emchat-track.el --- Event tracking code for EMchat. ;; Copyright (C) 2005 - 2011 Steve Youngs, Alexey Mikhailov ;; Author: Alexey Mikhailov ;; Maintainer: Alexey Mikhailov ;; Created: 2005-04-25 ;; Homepage: http://www.emchat.org/ ;; Keywords: ;; This file is part of EMchat. ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; 1. Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; 2. Redistributions in binary form must reproduce the above copyright ;; notice, this list of conditions and the following disclaimer in the ;; documentation and/or other materials provided with the distribution. ;; ;; 3. Neither the name of the author nor the names of any contributors ;; may be used to endorse or promote products derived from this ;; software without specific prior written permission. ;; ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; Commentary: ;; emchat-track.el tracks ICQ channel activity and notifies user in modeline. ;; To start with emchat-track add to your ~/.sxemacs/init.el: ;; ;; (require 'emchat-track) ;; (emchat-track-mode 1) ;; ;; or simple: ;; ;; (setq emchat-track-enable t) ;; ;; if you dont want emchat-track to be loaded ;; ;; You may want to customize `emchat-track-events-type' and ;; `emchat-track-indicator-type' ;;; Code: (eval-when-compile (defvar emchat-log-buffer)) (defgroup emchat-track nil "Track EMchat events and show activity in the modeline." :group 'emchat) (defcustom emchat-track-enable nil "*Enable tracking." :group 'emchat-track :type 'boolean) (defcustom emchat-track-events-type 'msg "*What event types to track. Possible values are: all -- all events \(anything that gets logged will be tracked\) incoming -- only incoming messages plus system and debug events msg -- incoming user messages only nil -- no events." :group 'emchat-track :type '(choice (item :tag "All Events" all) (item :tag "Incoming msg + sys + debug events" incoming) (item :tag "Incoming user messages" msg) (item :tag "Nothing" nil))) (defcustom emchat-track-indicator-type 'name "*What type of indicator is displayed in the modeline. Possible values are: name -- [nick,nick2,nick3] \(ERC style\). \"nick\" is shortened to `emchat-track-shorten-to'. char -- [E] \(Riece style\)" :type '(radio (item :tag "Multi names \(ERC style\)" name) (item :tag "Single character \(Riece style\)" char)) :group 'emchat-track) (defcustom emchat-track-shorten-to 4 "*All nicks will be shortened to this number of chars." :type 'integer :group 'emchat-track) (defcustom emchat-track-activity-hook nil "*Hooks run when `emchat-track-add-nick' is called." :type 'hook :group 'emchat-track) (defcustom emchat-track-clear-hook nil "*Hooks run when `emchat-track-clear-modeline' is called." :type 'hook :group 'emchat-track) ;;; Internal variables (defvar emchat-track-events-string "") (defun emchat-track-truncate-nick (nick) "Return shortened nick." (if (> (length nick) emchat-track-shorten-to) (substring nick 0 emchat-track-shorten-to) nick)) (defun emchat-track-add-nick (nick) "Add new nick to events strings." (let ((snick (emchat-track-truncate-nick nick))) (setq global-mode-string (delq 'emchat-track-events-string global-mode-string)) (if (eq emchat-track-indicator-type 'char) ;; Riece style indicator. (setq emchat-track-events-string "[E]") ;; ERC style indicator. (if (equal emchat-track-events-string "") (setq emchat-track-events-string (format "[%s]" snick)) (and (not (search snick emchat-track-events-string)) (setq emchat-track-events-string (format "%s,%s]" (substring emchat-track-events-string 0 (1- (length emchat-track-events-string))) snick))))) (setq global-mode-string (append global-mode-string '(emchat-track-events-string))) (run-hooks 'emchat-track-activity-hook) (redraw-modeline t))) (defun emchat-track-clear-modeline () "Remove `emchat-track' messages from modeline." (setq global-mode-string (delq 'emchat-track-events-string global-mode-string)) (setq emchat-track-events-string "") (run-hooks 'emchat-track-clear-hook) (redraw-modeline t)) (defun emchat-track-check-log-buffer () (and (get-buffer-window emchat-log-buffer) (emchat-track-clear-modeline))) (defun emchat-track-init () "Initialize `emchat-track', perform defadvices and hooks" (defadvice switch-to-buffer (after emchat-update (&rest args) activate) "After switching buffers, check to see if emchat-track should be cleared. The emchat-track modeline indicator will only be cleared if `emchat-log-buffer' is visible in the selected frame." (emchat-track-check-log-buffer)) (add-hook 'select-frame-hook 'emchat-track-check-log-buffer) (put 'emchat-track 'initialized t)) (defun emchat-track-mode (&optional arg) "Toggle emchat track mode." (interactive "P") (if (or (and (numberp arg) (< arg 0)) (and (null arg) emchat-track-enable)) (setq emchat-track-enable nil) (setq emchat-track-enable t))) (defun emchat-track-enable () (interactive) (emchat-track-mode 1)) (defun emchat-track-disable () (interactive) (emchat-track-mode -1)) (provide 'emchat-track) ;;; emchat-track.el ends here