1 ;;; riece-log.el --- saving irc logs add-on
2 ;; Copyright (C) 2003 OHASHI Akira
4 ;; Author: OHASHI Akira <bg66@koka-in.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; This add-on saves irc logs for every channel.
28 ;; To use, add the following line to your ~/.riece/init.el:
29 ;; (add-to-list 'riece-addons 'riece-log)
33 (eval-when-compile (require 'riece-message))
35 (defgroup riece-log nil
39 (defcustom riece-log-directory
40 (expand-file-name "log" riece-directory)
41 "*Where to look for log files."
45 (defcustom riece-log-directory-map nil
46 "*The map of channel name and directory name."
47 :type '(repeat (cons (string :tag "Channel name")
48 (string :tag "Directory name")))
51 (defcustom riece-log-flashback 10
52 "*If non-nil, irc messages flash back from log files.
53 If integer, flash back only this line numbers. t means all lines."
54 :type '(choice (integer :tag "line numbers")
55 (boolean :tag "flash back or not"))
58 (defcustom riece-log-coding-system nil
59 "*Coding system used for log files."
63 (defun riece-log-display-message-function (message)
65 (funcall riece-message-make-open-bracket-function message))
67 (funcall riece-message-make-close-bracket-function message))
69 (funcall riece-message-make-name-function message))
70 (file (riece-log-get-file (riece-message-target message)))
71 (coding-system-for-write riece-log-coding-system))
72 (unless (file-directory-p (file-name-directory file))
73 (make-directory (file-name-directory file) t))
74 (write-region (concat (format-time-string "%H:%M") " "
75 open-bracket name close-bracket
76 " " (riece-message-text message) "\n")
79 (defun riece-log-get-file (identity)
81 (concat (format-time-string "%Y%m%d") ".log")
82 (riece-log-get-directory identity)))
84 (defun riece-log-get-directory (identity)
85 (let ((channel (riece-identity-prefix identity))
86 (server (riece-identity-server identity))
87 (map (assoc (riece-format-identity identity) riece-log-directory-map))
89 (cond (map (setq name (cdr map)))
90 ((string-match riece-channel-regexp channel)
91 (let ((suffix (match-string 2 channel)))
92 (setq name (substring channel (match-end 1) (match-beginning 2)))
93 (when (and (stringp suffix)
94 (string-match "^:\\*\\.\\(.*\\)" suffix))
95 (setq name (concat name "-" (match-string 1 suffix))))))
96 (t (setq name "priv")))
98 (expand-file-name name (expand-file-name server riece-log-directory))
99 (expand-file-name name riece-log-directory))))
101 (defun riece-log-flashback (identity)
102 (when riece-log-flashback
103 (let ((file (riece-log-get-file identity)))
104 (when (file-exists-p file)
107 (insert-file-contents file)
108 (if (not (integerp riece-log-flashback))
109 (goto-char (point-min))
110 (goto-char (point-max))
111 (forward-line (- riece-log-flashback)))
112 (setq string (buffer-substring (point) (point-max))))
113 (let (buffer-read-only)
114 (goto-char (point-max))
116 (goto-char (point-max))
117 (set-window-point (get-buffer-window (current-buffer))
120 (defun riece-log-open-directory (&optional channel)
123 (find-file (riece-log-get-directory channel))
124 (find-file riece-log-directory)))
126 (defun riece-log-insinuate ()
127 ;; FIXME: Use `riece-after-insert-functions' for trapping change,
128 ;; notice, wallops and so on. But must add argument.
129 (add-hook 'riece-after-display-message-functions
130 'riece-log-display-message-function)
131 (add-hook 'riece-channel-buffer-create-functions
132 'riece-log-flashback))
136 ;;; riece-log.el ends here