annotate lisp/erc/erc-log.el @ 94244:6ff724be7391

(Info-complete-menu-item): Save point.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 22 Apr 2008 15:36:53 +0000
parents 107ccd98fa12
children 2a734255bcc7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
1 ;;; erc-log.el --- Logging facilities for ERC.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
2
79706
5f92874bde07 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 79413
diff changeset
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
4
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
5 ;; Author: Lawrence Mitchell <wence@gmx.li>
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
6 ;; Keywords: IRC, chat, client, Internet, logging
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
7
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
8 ;; Created 2003-04-26
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
9 ;; Logging code taken from erc.el and modified to use markers.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
10
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
12
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
78219
85d67fae9a94 Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 76856
diff changeset
15 ;; the Free Software Foundation; either version 3, or (at your option)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
16 ;; any later version.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
17
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
21 ;; GNU General Public License for more details.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
22
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
26 ;; Boston, MA 02110-1301, USA.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
27
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
28 ;;; Commentary:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
29
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
30 ;; This file implements log file writing support for ERC.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
31
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
32 ;; Quick start:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
33 ;;
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
34 ;; (require 'erc-log)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
35 ;; (setq erc-log-channels-directory "/path/to/logfiles") ; must be writable
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
36 ;; (erc-log-enable)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
37 ;;
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
38 ;; Or:
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
39 ;;
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
40 ;; M-x customize-variable erc-modules, and add "log".
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
41 ;;
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
42 ;; There are two ways to setup logging. The first (default) method
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
43 ;; will save buffers on /part, /quit, or killing the channel
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
44 ;; buffer.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
45 ;;
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
46 ;; The second will write to the log files on each incoming or outgoing
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
47 ;; line - this may not be optimal on a laptop HDD. To use this
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
48 ;; method, add the following to the above instructions.
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
49 ;;
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
50 ;; (setq erc-save-buffer-on-part nil
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
51 ;; erc-save-queries-on-quit nil
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
52 ;; erc-log-write-after-send t
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
53 ;; erc-log-write-after-insert t)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
54 ;;
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
55 ;; If you only want to save logs for some buffers, customise the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
56 ;; variable `erc-enable-logging'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
57
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
58 ;; How it works:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
59 ;;
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
60 ;; If logging is enabled, at some point, `erc-save-buffer-in-logs'
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
61 ;; will be called. The "end" of the buffer is taken from
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
62 ;; `erc-insert-marker', while `erc-last-saved-position' holds the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
63 ;; position the buffer was last saved at (as a marker, or if the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
64 ;; buffer hasn't been saved before, as the number 1 (point-min)).
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
65
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
66 ;; The region between `erc-last-saved-position' and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
67 ;; `erc-insert-marker' is saved to the current buffer's logfile, and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
68 ;; `erc-last-saved-position' is updated to reflect this.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
69
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
70 ;;; History:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
71 ;; 2003-04-26: logging code pulled out of erc.el. Switched to using
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
72 ;; markers.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
73
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
74 ;;; TODO:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
75 ;;
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
76 ;; * Really, we need to lock the logfiles somehow, so that if a user
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
77 ;; is running multiple emacsen and/or on the same channel as more
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
78 ;; than one user, only one process writes to the logfile. This is
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
79 ;; especially needed for those logfiles with no nick in them, as
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
80 ;; these would become corrupted.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
81 ;; For a single emacs process, the problem could be solved using a
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
82 ;; variable which contained the names of buffers already being
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
83 ;; logged. This would require that logging be buffer-local,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
84 ;; possibly not a bad thing anyway, since many people don't want to
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
85 ;; log the server buffer.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
86 ;; For multiple emacsen the problem is trickier. On some systems,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
87 ;; on could use the function `lock-buffer' and `unlock-buffer'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
88 ;; However, file locking isn't implemented on all platforms, for
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
89 ;; example, there is none on w32 systems.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
90 ;; A third possibility might be to fake lockfiles. However, this
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
91 ;; might lead to problems if an emacs crashes, as the lockfile
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
92 ;; would be left lying around.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
93
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
94 ;;; Code:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
95
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
96 (require 'erc)
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
97 (eval-when-compile
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
98 (require 'erc-networks)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
99 (require 'cl))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
100
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
101 (defgroup erc-log nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
102 "Logging facilities for ERC."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
103 :group 'erc)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
104
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
105 (defcustom erc-generate-log-file-name-function 'erc-generate-log-file-name-long
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
106 "*A function to generate a log filename.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
107 The function must take five arguments: BUFFER, TARGET, NICK, SERVER and PORT.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
108 BUFFER is the buffer to be saved,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
109 TARGET is the name of the channel, or the target of the query,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
110 NICK is the current nick,
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
111 SERVER and PORT are the parameters that were used to connect to BUFFERs
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
112 `erc-server-process'.
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
113
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
114 If you want to write logs into different directories, make a
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
115 custom function which returns the directory part and set
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
116 `erc-log-channels-directory' to its name."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
117 :group 'erc-log
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
118 :type '(choice (const :tag "Long style" erc-generate-log-file-name-long)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
119 (const :tag "Long, but with network name rather than server"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
120 erc-generate-log-file-name-network)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
121 (const :tag "Short" erc-generate-log-file-name-short)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
122 (const :tag "With date" erc-generate-log-file-name-with-date)
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
123 (function :tag "Other function")))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
124
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
125 (defcustom erc-truncate-buffer-on-save nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
126 "Truncate any ERC (channel, query, server) buffer when it is saved."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
127 :group 'erc-log
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
128 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
129
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
130 (defcustom erc-enable-logging t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
131 "If non-nil, ERC will log IRC conversations.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
132 This can either be a boolean value of nil or t, or a function.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
133 If the value is a function, it will be called with one argument, the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
134 name of the current ERC buffer. One possible function, which saves
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
135 all but server buffers is `erc-log-all-but-server-buffers'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
136
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
137 This variable is buffer local. Setting it via \\[customize] sets the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
138 default value.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
139
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
140 Log files are stored in `erc-log-channels-directory'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
141 :group 'erc-log
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
142 :type '(choice boolean
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
143 function))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
144 (make-variable-buffer-local 'erc-enable-logging)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
145
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
146 (defcustom erc-log-channels-directory "~/log"
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
147 "The directory to place log files for channels.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
148 Leave blank to disable logging. If not nil, all the channel
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
149 buffers are logged in separate files in that directory. The
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
150 directory should not end with a trailing slash.
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
151
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
152 If this is the name of a function, the function will be called
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
153 with the buffer, target, nick, server, and port arguments. See
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
154 `erc-generate-log-file-name-function' for a description of these
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
155 arguments."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
156 :group 'erc-log
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
157 :type '(choice directory
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
158 (function "Function")
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
159 (const :tag "Disable logging" nil)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
160
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
161 (defcustom erc-log-insert-log-on-open nil
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
162 "*Insert log file contents into the buffer if a log file exists."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
163 :group 'erc-log
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
164 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
165
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
166 (defcustom erc-save-buffer-on-part t
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
167 "*Save the channel buffer content using `erc-save-buffer-in-logs' on PART.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
168
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
169 If you set this to nil, you may want to enable both
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
170 `erc-log-write-after-send' and `erc-log-write-after-insert'."
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
171 :group 'erc-log
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
172 :type 'boolean)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
173
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
174 (defcustom erc-save-queries-on-quit t
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
175 "*Save all query (also channel) buffers of the server on QUIT.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
176
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
177 If you set this to nil, you may want to enable both
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
178 `erc-log-write-after-send' and `erc-log-write-after-insert'."
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
179 :group 'erc-log
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
180 :type 'boolean)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
181
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
182 (defcustom erc-log-write-after-send nil
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
183 "*If non-nil, write to log file after every message you send.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
184
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
185 If you set this to nil, you may want to enable both
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
186 `erc-save-buffer-on-part' and `erc-save-queries-on-quit'."
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
187 :group 'erc-log
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
188 :type 'boolean)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
189
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
190 (defcustom erc-log-write-after-insert nil
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
191 "*If non-nil, write to log file when new text is added to a
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
192 logged ERC buffer.
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
193
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
194 If you set this to nil, you may want to enable both
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
195 `erc-save-buffer-on-part' and `erc-save-queries-on-quit'."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
196 :group 'erc-log
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
197 :type 'boolean)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
198
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
199 (defcustom erc-log-file-coding-system (if (featurep 'xemacs)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
200 'binary
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
201 'emacs-mule)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
202 "*The coding system ERC should use for writing log files.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
203
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
204 This should ideally, be a \"catch-all\" coding system, like
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
205 `emacs-mule', or `iso-2022-7bit'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
206 :group 'erc-log)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
207
84636
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
208 (defcustom erc-log-filter-function nil
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
209 "*If non-nil, pass text through the given function before writing it to
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
210 a log file.
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
211
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
212 The function should take one argument, which is the text to filter."
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
213 :group 'erc-log
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
214 :type '(choice (function "Function")
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
215 (const :tag "No filtering" nil)))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
216
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
217
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
218 ;;;###autoload (autoload 'erc-log-mode "erc-log" nil t)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
219 (define-erc-module log nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
220 "Automatically logs things you receive on IRC into files.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
221 Files are stored in `erc-log-channels-directory'; file name
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
222 format is defined through a formatting function on
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
223 `erc-generate-log-file-name-function'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
224
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
225 Since automatic logging is not always a Good Thing (especially if
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
226 people say things in different coding systems), you can turn logging
79413
857da0a07a42 (log): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 78476
diff changeset
227 behavior on and off with the variable `erc-enable-logging', which can
86109
c785443b57f8 (log): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 85845
diff changeset
228 also be a predicate function. To only log when you are not set away, use:
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
229
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
230 \(setq erc-enable-logging
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
231 (lambda (buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
232 (with-current-buffer buffer
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
233 (null (erc-away-time)))))"
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
234 ;; enable
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
235 ((when erc-log-write-after-insert
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
236 (add-hook 'erc-insert-post-hook 'erc-save-buffer-in-logs))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
237 (when erc-log-write-after-send
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
238 (add-hook 'erc-send-post-hook 'erc-save-buffer-in-logs))
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
239 (add-hook 'erc-kill-buffer-hook 'erc-save-buffer-in-logs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
240 (add-hook 'erc-kill-channel-hook 'erc-save-buffer-in-logs)
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
241 (add-hook 'kill-emacs-hook 'erc-log-save-all-buffers)
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
242 (add-hook 'erc-quit-hook 'erc-conditional-save-queries)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
243 (add-hook 'erc-part-hook 'erc-conditional-save-buffer)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
244 ;; append, so that 'erc-initialize-log-marker runs first
72249
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
245 (add-hook 'erc-connect-pre-hook 'erc-log-setup-logging 'append)
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
246 (dolist (buffer (erc-buffer-list))
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
247 (erc-log-setup-logging buffer)))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
248 ;; disable
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
249 ((remove-hook 'erc-insert-post-hook 'erc-save-buffer-in-logs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
250 (remove-hook 'erc-send-post-hook 'erc-save-buffer-in-logs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
251 (remove-hook 'erc-kill-buffer-hook 'erc-save-buffer-in-logs)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
252 (remove-hook 'erc-kill-channel-hook 'erc-save-buffer-in-logs)
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
253 (remove-hook 'kill-emacs-hook 'erc-log-save-all-buffers)
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
254 (remove-hook 'erc-quit-hook 'erc-conditional-save-queries)
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
255 (remove-hook 'erc-part-hook 'erc-conditional-save-buffer)
72249
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
256 (remove-hook 'erc-connect-pre-hook 'erc-log-setup-logging)
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
257 (dolist (buffer (erc-buffer-list))
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
258 (erc-log-disable-logging buffer))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
259
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
260 (define-key erc-mode-map "\C-c\C-l" 'erc-save-buffer-in-logs)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
261
71883
3d0d6e217db9 Update for ERC 5.1.3.
Miles Bader <miles@gnu.org>
parents: 68822
diff changeset
262 ;;; functionality referenced from erc.el
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
263 (defun erc-log-setup-logging (buffer)
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
264 "Setup the buffer-local logging variables in the current buffer.
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
265 This function is destined to be run from `erc-connect-pre-hook'.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
266 The current buffer is given by BUFFER."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
267 (when (erc-logging-enabled buffer)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
268 (with-current-buffer buffer
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
269 (auto-save-mode -1)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
270 (setq buffer-file-name nil)
85845
e95712050fdc Silence some byte-compiler warnings in ERC
Michael Olson <mwolson@gnu.org>
parents: 85743
diff changeset
271 (erc-set-write-file-functions '(erc-save-buffer-in-logs))
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
272 (when erc-log-insert-log-on-open
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
273 (ignore-errors (insert-file-contents (erc-current-logfile))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
274 (move-marker erc-last-saved-position
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
275 (1- (point-max))))))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
276
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
277 (defun erc-log-disable-logging (buffer)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
278 "Disable logging in BUFFER."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
279 (when (erc-logging-enabled buffer)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
280 (with-current-buffer buffer
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
281 (setq buffer-offer-save nil
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
282 erc-enable-logging nil))))
72249
268989954f79 Merge from erc--emacs--21
Miles Bader <miles@gnu.org>
parents: 71883
diff changeset
283
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
284 (defun erc-log-all-but-server-buffers (buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
285 "Returns t if logging should be enabled in BUFFER.
78476
4f90f1cb8ef0 Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78219
diff changeset
286 Returns nil if `erc-server-buffer-p' returns t."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
287 (save-excursion
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
288 (save-window-excursion
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
289 (set-buffer buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
290 (not (erc-server-buffer-p)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
291
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
292 (defun erc-save-query-buffers (process)
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
293 "Save all buffers of the given PROCESS."
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
294 (erc-with-all-buffers-of-server process
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
295 nil
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
296 (erc-save-buffer-in-logs)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
297
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
298 (defun erc-conditional-save-buffer (buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
299 "Save Query BUFFER if `erc-save-queries-on-quit' is t."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
300 (when erc-save-buffer-on-part
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
301 (erc-save-buffer-in-logs buffer)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
302
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
303 (defun erc-conditional-save-queries (process)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
304 "Save Query buffers of PROCESS if `erc-save-queries-on-quit' is t."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
305 (when erc-save-queries-on-quit
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
306 (erc-save-query-buffers process)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
307
74093
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
308 ;; Make sure that logs get saved, even if someone overrides the active
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
309 ;; process prompt for a quick exit from Emacs
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
310 (defun erc-log-save-all-buffers ()
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
311 (dolist (buffer (erc-buffer-list))
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
312 (erc-save-buffer-in-logs buffer)))
bc5d69739d5e Merge from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72301
diff changeset
313
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
314 ;;;###autoload
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
315 (defun erc-logging-enabled (&optional buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
316 "Return non-nil if logging is enabled for BUFFER.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
317 If BUFFER is nil, the value of `current-buffer' is used.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
318 Logging is enabled if `erc-log-channels-directory' is non-nil, the directory
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
319 is writeable (it will be created as necessary) and
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
320 `erc-enable-logging' returns a non-nil value."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
321 (and erc-log-channels-directory
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
322 (or (functionp erc-log-channels-directory)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
323 (erc-directory-writable-p erc-log-channels-directory))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
324 (if (functionp erc-enable-logging)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
325 (funcall erc-enable-logging (or buffer (current-buffer)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
326 erc-enable-logging)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
327
72301
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
328 (defun erc-log-standardize-name (filename)
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
329 "Make FILENAME safe to use as the name of an ERC log.
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
330 This will not work with full paths, only names.
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
331
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
332 Any unsafe characters in the name are replaced with \"!\". The
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
333 filename is downcased."
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
334 (downcase (erc-replace-regexp-in-string
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
335 "[/\\]" "!" (convert-standard-filename filename))))
0bacf06559e2 Update from erc--emacs--22
Miles Bader <miles@gnu.org>
parents: 72249
diff changeset
336
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
337 (defun erc-current-logfile (&optional buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
338 "Return the logfile to use for BUFFER.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
339 If BUFFER is nil, the value of `current-buffer' is used.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
340 This is determined by `erc-generate-log-file-name-function'.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
341 The result is converted to lowercase, as IRC is case-insensitive"
84387
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
342 (unless buffer (setq buffer (current-buffer)))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
343 (let ((target (or (buffer-name buffer) (erc-default-target)))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
344 (nick (erc-current-nick))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
345 (server erc-session-server)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
346 (port erc-session-port))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
347 (expand-file-name
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
348 (erc-log-standardize-name
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
349 (funcall erc-generate-log-file-name-function
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
350 buffer target nick server port))
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
351 (if (functionp erc-log-channels-directory)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
352 (funcall erc-log-channels-directory
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
353 buffer target nick server port)
4ee03308c9b6 Sync ERC 5.3 (devel) from upstream
Michael Olson <mwolson@gnu.org>
parents: 78476
diff changeset
354 erc-log-channels-directory))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
355
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
356 (defun erc-generate-log-file-name-with-date (buffer &rest ignore)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
357 "This function computes a short log file name.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
358 The name of the log file is composed of BUFFER and the current date.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
359 This function is a possible value for `erc-generate-log-file-name-function'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
360 (concat (buffer-name buffer) "-" (format-time-string "%Y-%m-%d") ".txt"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
361
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
362 (defun erc-generate-log-file-name-short (buffer &rest ignore)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
363 "This function computes a short log file name.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
364 In fact, it only uses the buffer name of the BUFFER argument, so
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
365 you can affect that using `rename-buffer' and the-like. This
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
366 function is a possible value for
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
367 `erc-generate-log-file-name-function'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
368 (concat (buffer-name buffer) ".txt"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
369
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
370 (defun erc-generate-log-file-name-long (buffer target nick server port)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
371 "Generates a log-file name in the way ERC always did it.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
372 This results in a file name of the form #channel!nick@server:port.txt.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
373 This function is a possible value for `erc-generate-log-file-name-function'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
374 (let ((file (concat
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
375 (if target (concat target "!"))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
376 nick "@" server ":" (cond ((stringp port) port)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
377 ((numberp port)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
378 (number-to-string port))) ".txt")))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
379 ;; we need a make-safe-file-name function.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
380 (convert-standard-filename file)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
381
76856
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
382 (defun erc-generate-log-file-name-network (buffer target nick server port)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
383 "Generates a log-file name using the network name rather than server name.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
384 This results in a file name of the form #channel!nick@network.txt.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
385 This function is a possible value for `erc-generate-log-file-name-function'."
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
386 (require 'erc-networks)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
387 (let ((file (concat
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
388 (if target (concat target "!"))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
389 nick "@"
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
390 (or (with-current-buffer buffer (erc-network-name)) server)
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
391 ".txt")))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
392 ;; we need a make-safe-file-name function.
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
393 (convert-standard-filename file)))
2fae574a2382 Release ERC 5.2.
Miles Bader <miles@gnu.org>
parents: 75346
diff changeset
394
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
395 ;;;###autoload
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
396 (defun erc-save-buffer-in-logs (&optional buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
397 "Append BUFFER contents to the log file, if logging is enabled.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
398 If BUFFER is not provided, current buffer is used.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
399 Logging is enabled if `erc-logging-enabled' returns non-nil.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
400
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
401 This is normally done on exit, to save the unsaved portion of the
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
402 buffer, since only the text that runs off the buffer limit is logged
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
403 automatically.
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
404
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
405 You can save every individual message by putting this function on
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
406 `erc-insert-post-hook'."
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
407 (interactive)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
408 (or buffer (setq buffer (current-buffer)))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
409 (when (erc-logging-enabled buffer)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
410 (let ((file (erc-current-logfile buffer))
85743
763be5e829a7 Sync from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84636
diff changeset
411 (coding-system erc-log-file-coding-system)
763be5e829a7 Sync from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84636
diff changeset
412 (inhibit-clash-detection t)) ; needed for XEmacs
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
413 (save-excursion
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
414 (with-current-buffer buffer
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
415 (save-restriction
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
416 (widen)
79413
857da0a07a42 (log): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 78476
diff changeset
417 ;; early on in the initialization, don't try and write the log out
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
418 (when (and (markerp erc-last-saved-position)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
419 (> erc-insert-marker (1+ erc-last-saved-position)))
84636
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
420 (let ((start (1+ (marker-position erc-last-saved-position)))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
421 (end (marker-position erc-insert-marker)))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
422 (if (functionp erc-log-filter-function)
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
423 (let ((text (buffer-substring start end)))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
424 (with-temp-buffer
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
425 (insert (funcall erc-log-filter-function text))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
426 (let ((coding-system-for-write coding-system))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
427 (write-region (point-min) (point-max)
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
428 file t 'nomessage))))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
429 (let ((coding-system-for-write coding-system))
ffc87ddd4025 Sync changes from upstream ERC
Michael Olson <mwolson@gnu.org>
parents: 84387
diff changeset
430 (write-region start end file t 'nomessage))))
68451
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
431 (if (and erc-truncate-buffer-on-save (interactive-p))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
432 (progn
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
433 (let ((inhibit-read-only t)) (erase-buffer))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
434 (move-marker erc-last-saved-position (point-max))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
435 (erc-display-prompt))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
436 (move-marker erc-last-saved-position
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
437 ;; If we place erc-last-saved-position at
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
438 ;; erc-insert-marker, because text gets
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
439 ;; inserted /before/ erc-insert-marker,
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
440 ;; the log file will not be saved
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
441 ;; (erc-last-saved-position will always
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
442 ;; be equal to erc-insert-marker).
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
443 (1- (marker-position erc-insert-marker)))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
444 (set-buffer-modified-p nil))))))
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
445 t)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
446
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
447 (provide 'erc-log)
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
448
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
449 ;;; erc-log.el ends here
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
450 ;;
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
451 ;; Local Variables:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
452 ;; indent-tabs-mode: t
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
453 ;; tab-width: 8
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
454 ;; End:
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
455
fc745b05e928 Revision: emacs@sv.gnu.org/emacs--devo--0--patch-22
Miles Bader <miles@gnu.org>
parents:
diff changeset
456 ;; arch-tag: 54072f99-9f0a-4846-8908-2ccde92221de