;;; emchat-history.el --- Mode for viewing history in EMchat and its interface. ;; Copyright (C) 2005 - 2011 Steve Youngs, Alexey Mikhailov ;; Author: Alexey Mikhailov ;; Maintainer: Alexey Mikhailov ;; Created: 2005-04-19 ;; Homepage: http://www.emchat.org/ ;; Keywords: comm ICQ history ;; 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: ;; ;; Provides mode for viewing person history and interface for EMchat. ;; To start using it, add this to your ~/.sxemacs/init.el... ;; ;; (setq emchat-history-enabled-flag t) (eval-and-compile (require 'outline) (require 'emchat) (require 'emchat-log) (require 'font-lock)) (defvar emchat-history-old-window-config nil) (defun emchat-history (&optional alias) "Show history log for ALIAS person." (interactive) (let* ((alias (or alias (emchat-completing-read "Show history for: " emchat-all-aliases nil t))) (histf (emchat-world-getf alias 'history))) (when histf (find-file histf) (emchat-history-mode)))) (defun emchat-history-around () "Show history around." (interactive) (emchat-history (emchat-alias-around))) (defun emchat-history-here-other-window (&optional count) "Show history around in other window." (interactive) (setq emchat-history-old-window-config (current-window-configuration)) (unless count (setq count 1)) (let ((alias (emchat-alias-here))) (other-window count) (emchat-history alias))) (defvar emchat-history-outline-regexp "\\(^\\s-?[0-9]*[ ][A-Za-z]*[ ][A-Z]..\:..\\)" "Regexp for history header. See `outline-regexp'.") (defvar emchat-history-event-regexp (concat "\\(^\\s-?[0-9]*[ ][A-Za-z]*[ ][A-Z]..\:..\\)" ".\\(\\[[A-Za-z0-9].*\\]\\).\\([\*><]*\\).\\(.*\\)") "Regexp for history event. First paren set matches date header, second -- person nickname, third -- event type, fourth -- all other stuff.") (defun emchat-history-mode () "Major mode for viewing history in emchat. Commands: \\{emchat-history-mode-map} Turning on `emchat-history-mode' runs the hook `emchat-history-mode-hook'." (interactive) (kill-all-local-variables) (use-local-map emchat-history-mode-map) (setq mode-name "emchat-history") (setq major-mode 'emchat-history-mode) (easy-menu-add emchat-history-menu) (font-lock-mode t) (toggle-read-only t) (outline-minor-mode t) (set (make-local-variable 'outline-regexp) emchat-history-outline-regexp) (goto-char (point-max)) (forward-line -1) (run-hooks 'emchat-history-mode-hook)) (defun emchat-history-bury-buffer (&optional kill) "Bury buffer in `emchat-history' mode. With optional prefix arg, KILL, kill the buffer instead of burying it." (interactive "P") ;; safeguard against calling this when the current buffer isn't in ;; emchat-history-mode (when (eq major-mode 'emchat-history-mode) (if current-prefix-arg (kill-buffer nil) (bury-buffer nil))) ;; Possibly restore the old window config (when emchat-history-old-window-config (set-window-configuration emchat-history-old-window-config) (setq emchat-history-old-window-config nil))) (defun emchat-history-save (&optional alias) "Save all the open history files." (interactive) (if alias (with-current-buffer (find-buffer-visiting (emchat-world-getf alias 'history)) (save-buffer)) (mapcar #'(lambda (a) (let ((buf (find-buffer-visiting (emchat-world-getf a 'history)))) (and buf (with-current-buffer buf (save-buffer))))) emchat-all-aliases))) (defalias 'emchat-history-next 'outline-forward-same-level) (defalias 'emchat-history-prev 'outline-backward-same-level) (defface emchat-history-timestamp-face '((((background light)) (:foreground "red4" :bold t))) "Face used to highlight timestamps in `emchat-history' mode." :group 'emchat-log) (defface emchat-history-event-type-face '((((background light)) (:foreground "magenta3" :bold t))) "Face used to highlight event types in `emchat-history' mode." :group 'emchat-log) (defface emchat-history-nick-face '((((background light)) (:foreground "green4" :bold t))) "Face used to highlight nicks in `emchat-history' mode." :group 'emchat-log) (defconst emchat-history-font-lock-keywords (list (cons emchat-history-event-regexp '(1 'emchat-history-timestamp-face)) (cons emchat-history-event-regexp '(2 'emchat-history-nick-face)) (cons emchat-history-event-regexp '(3 'emchat-history-event-type-face))) "Highlighting rules for `emchat-history' buffers.") (provide 'emchat-history) ;;; emchat-history.el ends here