1 ;;; emchat-history.el --- Mode for viewing history in EMchat and its interface.
3 ;; Copyright (C) 2005 - 2011 Steve Youngs, Alexey Mikhailov
5 ;; Author: Alexey Mikhailov <karma@sxemacs.org>
6 ;; Maintainer: Alexey Mikhailov <karma@sxemacs.org>
8 ;; Homepage: http://www.emchat.org/
9 ;; Keywords: comm ICQ history
11 ;; This file is part of EMchat.
13 ;; Redistribution and use in source and binary forms, with or without
14 ;; modification, are permitted provided that the following conditions
17 ;; 1. Redistributions of source code must retain the above copyright
18 ;; notice, this list of conditions and the following disclaimer.
20 ;; 2. Redistributions in binary form must reproduce the above copyright
21 ;; notice, this list of conditions and the following disclaimer in the
22 ;; documentation and/or other materials provided with the distribution.
24 ;; 3. Neither the name of the author nor the names of any contributors
25 ;; may be used to endorse or promote products derived from this
26 ;; software without specific prior written permission.
28 ;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
29 ;; IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 ;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 ;; DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32 ;; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 ;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 ;; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
35 ;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
36 ;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
37 ;; OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
38 ;; IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ;; Provides mode for viewing person history and interface for EMchat.
43 ;; To start using it, add this to your ~/.sxemacs/init.el...
45 ;; (setq emchat-history-enabled-flag t)
53 (defvar emchat-history-old-window-config nil)
55 (defun emchat-history (&optional alias)
56 "Show history log for ALIAS person."
58 (let* ((alias (or alias
59 (emchat-completing-read "Show history for: "
60 emchat-all-aliases nil t)))
61 (histf (emchat-world-getf alias 'history)))
64 (emchat-history-mode))))
66 (defun emchat-history-around ()
67 "Show history around."
69 (emchat-history (emchat-alias-around)))
72 (defun emchat-history-here-other-window (&optional count)
73 "Show history around in other window."
75 (setq emchat-history-old-window-config (current-window-configuration))
76 (unless count (setq count 1))
77 (let ((alias (emchat-alias-here)))
79 (emchat-history alias)))
81 (defvar emchat-history-outline-regexp "\\(^\\s-?[0-9]*[ ][A-Za-z]*[ ][A-Z]..\:..\\)"
82 "Regexp for history header.
83 See `outline-regexp'.")
85 (defvar emchat-history-event-regexp
86 (concat "\\(^\\s-?[0-9]*[ ][A-Za-z]*[ ][A-Z]..\:..\\)"
87 ".\\(\\[[A-Za-z0-9].*\\]\\).\\([\*><]*\\).\\(.*\\)")
88 "Regexp for history event.
90 First paren set matches date header, second -- person nickname, third
91 -- event type, fourth -- all other stuff.")
93 (defun emchat-history-mode ()
94 "Major mode for viewing history in emchat.
95 Commands: \\{emchat-history-mode-map}
97 Turning on `emchat-history-mode' runs the hook `emchat-history-mode-hook'."
99 (kill-all-local-variables)
100 (use-local-map emchat-history-mode-map)
101 (setq mode-name "emchat-history")
102 (setq major-mode 'emchat-history-mode)
103 (easy-menu-add emchat-history-menu)
106 (outline-minor-mode t)
107 (set (make-local-variable 'outline-regexp)
108 emchat-history-outline-regexp)
109 (goto-char (point-max))
111 (run-hooks 'emchat-history-mode-hook))
113 (defun emchat-history-bury-buffer (&optional kill)
114 "Bury buffer in `emchat-history' mode.
116 With optional prefix arg, KILL, kill the buffer instead of burying
119 ;; safeguard against calling this when the current buffer isn't in
120 ;; emchat-history-mode
121 (when (eq major-mode 'emchat-history-mode)
122 (if current-prefix-arg
125 ;; Possibly restore the old window config
126 (when emchat-history-old-window-config
127 (set-window-configuration emchat-history-old-window-config)
128 (setq emchat-history-old-window-config nil)))
130 (defun emchat-history-save (&optional alias)
131 "Save all the open history files."
134 (with-current-buffer (find-buffer-visiting
135 (emchat-world-getf alias 'history))
139 (let ((buf (find-buffer-visiting
140 (emchat-world-getf a 'history))))
142 (with-current-buffer buf
144 emchat-all-aliases)))
146 (defalias 'emchat-history-next 'outline-forward-same-level)
147 (defalias 'emchat-history-prev 'outline-backward-same-level)
149 (defface emchat-history-timestamp-face
150 '((((background light))
151 (:foreground "red4" :bold t)))
152 "Face used to highlight timestamps in `emchat-history' mode."
155 (defface emchat-history-event-type-face
156 '((((background light))
157 (:foreground "magenta3" :bold t)))
158 "Face used to highlight event types in `emchat-history' mode."
161 (defface emchat-history-nick-face
162 '((((background light))
163 (:foreground "green4" :bold t)))
164 "Face used to highlight nicks in `emchat-history' mode."
167 (defconst emchat-history-font-lock-keywords
169 (cons emchat-history-event-regexp '(1 'emchat-history-timestamp-face))
170 (cons emchat-history-event-regexp '(2 'emchat-history-nick-face))
171 (cons emchat-history-event-regexp '(3 'emchat-history-event-type-face)))
172 "Highlighting rules for `emchat-history' buffers.")
174 (provide 'emchat-history)
176 ;;; emchat-history.el ends here