From: Gergely N. <alg...@bo...> - 2001-11-24 16:21:41
|
Greetings! The hard-coded filenames of the ERC logs bothered me for some time, so I sat down and wrote a smallish patch, which partly fixes the problem. What I did, was to modify erc-save-buffer-in-logs, to call a custom defun, which will compute the actual filename. The only problem is that this does not work if the logs are not saved through this function, so, the buffer filenames should be set using this customisable function, I think. But that's way beyond my lisp knowledge. Anyway, the patch against last nights CVS is attached below. --- erc.el.orig Sat Nov 24 02:24:25 2001 +++ erc.el Sat Nov 24 14:49:23 2001 @@ -437,6 +437,17 @@ :group 'erc :type 'boolean) +(defcustom erc-generate-log-file-name-p 'erc-generate-log-file-name-default + "A function name to generate a log filename. The function must take +four arguments: BUFFER, TARGET, NICK and SERVER. BUFFER is the buffer +to be saved, TARGET is the name of the channel, or the target of the +query, NICK is the current nick, and SERVER is the server the buffer +is on." + :group 'erc + :type '(choice (const 'erc-generate-log-file-name-default) + (const 'erc-generate-log-file-name-old) + (function-item))) + (defvar erc-grab-buffer-name "*erc-grab*" "The name of the buffer created by `erc-grab-region'.") @@ -5181,6 +5192,13 @@ (buffer-enable-undo)) (set-buffer ob))) +(defun erc-generate-log-file-name-default (buffer target nick server) + "Default log filename generator." + (concat erc-log-channels-directory "/" (buffer-name buffer) ".txt")) +(defun erc-generate-log-file-name-old (buffer target nick server) + "Old-style (#channel!nick@server.txt) log filename generator" + (concat erc-log-channels-directory "/" target "!" nick "@" server ".txt")) + (defun erc-save-buffer-in-logs (&optional buffer) "When the logs are enabled, that is `erc-log-channels' is non-nil and `erc-log-channels-directory' is a valid directory, appends the @@ -5198,8 +5216,9 @@ erc-log-channels-directory (erc-directory-writable-p erc-log-channels-directory)) (append-to-file (point-min) (point-max) - (concat erc-log-channels-directory - "/" (buffer-name buffer) ".txt")) + (eval (list erc-generate-log-file-name-p buffer + (erc-default-target) (erc-current-nick) + erc-announced-server-name))) (erase-buffer) (erc-display-prompt) (goto-char (point-max))) |
From: Andreas F. <as...@vo...> - 2001-11-24 16:37:07
|
Today, Gergely Nagy <alg...@mi...> wrote: > What I did, was to modify erc-save-buffer-in-logs, to call a custom > defun, which will compute the actual filename. The only problem is > that this does not work if the logs are not saved through this > function, so, the buffer filenames should be set using this > customisable function, I think. I have modified the patch a little to conform more to naming conventions (-function, not -p which would make it a predicate), and also added the session's port to the function parameters. Your modified patch is below (with you added to the contributor's list): For my patch (see my previous message to this list): |
From: Gergely N. <alg...@bo...> - 2001-11-25 04:03:35
|
Hello again! Attached below is the very latest version of the antifuchs+mhp patch. The only change between the previous one and this is that I modified erc-mode to set the initial filename of the buffer using my customise function. I also changed erc-save-buffer-in-logs to set the filename too, albeit this might not be necessary. Anyway, let the patch speak for itself: --- erc.el.orig Sat Nov 24 02:24:25 2001 +++ erc.el Sun Nov 25 00:28:40 2001 @@ -291,6 +291,21 @@ :group 'erc :type 'boolean) +(defcustom erc-public-away-p nil + "Let others know you are back when you are no longer marked away. +This happens in this form: +* <nick> is back (gone for <time>) + +Many consider it impolite to do so automatically." + :group 'erc + :type 'boolean) + +(defcustom erc-away-nickname nil + "The nickname to take when you are marked as being away." + :group 'erc + :type '(choice (const nil) + string)) + (defcustom erc-play-sound t "*Play sound on SOUND ctcp requests (used in ICQ chat)" :group 'erc @@ -437,6 +452,31 @@ :group 'erc :type 'boolean) +(defvar erc-last-saved-position 1 + "The position in which appears last in the log file for the channel +buffer") + +(make-variable-buffer-local 'erc-last-saved-position) + +(defvar erc-log-insert-log-on-open t + "Insert the log file contentents into the buffer if the log file exists") + +(defcustom erc-truncate-buffer-on-save nil + "Truncate any ERC (channel, query, server) buffer when it is saved. +When nil, no buffer is ever truncated. Nonetheless, only the relevant +part of the buffer will be saved.") + +(defcustom erc-generate-log-file-name-function 'erc-generate-log-file-name-default + "A function name to generate a log filename. The function must take +four arguments: BUFFER, TARGET, NICK and SERVER. BUFFER is the buffer +to be saved, TARGET is the name of the channel, or the target of the +query, NICK is the current nick, and SERVER is the server the buffer +is on." + :group 'erc + :type '(choice (const 'erc-generate-log-file-name-default) + (const 'erc-generate-log-file-name-old) + (function))) + (defvar erc-grab-buffer-name "*erc-grab*" "The name of the buffer created by `erc-grab-region'.") @@ -836,14 +876,19 @@ (when erc-log-channels-directory (auto-save-mode -1) (setq buffer-offer-save t - buffer-file-name (concat erc-log-channels-directory "/" - (buffer-name buffer) ".txt")) + buffer-file-name (funcall erc-generate-log-file-name-function + buffer (erc-default-target) + (erc-current-nick) erc-session-server + erc-session-port)) (if (boundp 'local-write-file-hooks) (setq local-write-file-hooks '(erc-save-buffer-in-logs)) ;Emacs >=19 (make-local-variable 'write-file-hooks) (setq write-file-hooks ;Emacs 18 - '(erc-save-buffer-in-logs)))) + '(erc-save-buffer-in-logs))) + (when erc-log-insert-log-on-open + (ignore-errors (insert-file-contents buffer-file-name))) + (setq erc-last-saved-position (point-max))) ;; Run the mode hooks (run-hooks 'erc-mode-hook)) @@ -1557,7 +1602,7 @@ `(timestamp ,(current-time))) (add-text-properties insert-position (point) '(point-entered erc-echo-timestamp)) - (setq insert-end-position (point))) + (setq insert-end-position (point))) ;; really restore old point. ;; run insertion hook, with point at restored location (erc-chain-hook-with-args 'erc-insert-hook insert-position insert-end-position))))) @@ -2867,6 +2912,14 @@ :group 'erc :type 'boolean) +(defcustom erc-query-on-unjoined-chan-privmsg t + "If non-nil create query buffer on receiving any PRIVMSG at all, +including PRIVMSGs directed to channels. If you are using an IRC +bouncer, such as dircproxy, to keep a log of channels when you are +disconnected, you should set this option to t." + :group 'erc + :type 'boolean) + (defcustom erc-minibuffer-notice nil "If non-nil, ERC will print notices in the minibuffer in case the session buffer isn't visible." @@ -3170,12 +3223,18 @@ (defun erc-auto-query (proc parsed) "Put this on `erc-server-PRIVMSG-hook'." - (let ((nick (car (erc-parse-user (aref parsed 1)))) - (target (aref parsed 2))) + (let* ((nick (car (erc-parse-user (aref parsed 1)))) + (target (aref parsed 2)) + (query (if (not erc-query-on-unjoined-chan-privmsg) + nick + (if (string= target (erc-current-nick)) + nick + target)))) (and erc-auto-query - (string= target (erc-current-nick)) - (not (erc-get-buffer nick proc)) - (erc-cmd-query nick)))) + (or erc-query-on-unjoined-chan-privmsg + (string= target (erc-current-nick))) + (not (erc-get-buffer query proc)) + (erc-cmd-query query)))) ;;; PRIVMSG and NOTICE @@ -3902,6 +3961,11 @@ (let ((sessionbuf (process-buffer proc))) (when sessionbuf (with-current-buffer sessionbuf + (when erc-away-nickname + (erc-log (format "erc-process-away: away-nick: %s, away-p: %s" erc-away-nickname away-p)) + (erc-cmd-nick (if away-p + erc-away-nickname + erc-nick))) (cond (away-p (setq away (current-time))) @@ -3912,6 +3976,7 @@ (setq away nil) (save-excursion (set-buffer erc-active-buffer) + (when erc-public-away-p (erc-send-action (erc-default-target) (if away-time @@ -3919,7 +3984,7 @@ (erc-sec-to-time (erc-time-diff (erc-emacs-time-to-erc-time away-time) (erc-current-time)))) - "is back")))))))) + "is back"))))))))) (erc-update-mode-line))) ;;;; List of channel members handling @@ -5169,7 +5234,9 @@ (let ((ob (current-buffer))) (if (and buffer (get-buffer buffer)) (set-buffer (get-buffer buffer))) - (when (> (point-max) (+ size 512)) + (when (and + erc-truncate-buffer-on-save + (> (point-max) (+ size 512))) (buffer-disable-undo) (if (and erc-log-channels erc-log-channels-directory @@ -5181,6 +5248,16 @@ (buffer-enable-undo)) (set-buffer ob))) +(defun erc-generate-log-file-name-default (buffer target nick server port) + "Default log filename generator." + (concat erc-log-channels-directory "/" (buffer-name buffer) ".txt")) +(defun erc-generate-log-file-name-old (buffer target nick server port) + "Old-style (#channel!nick@server.txt) log filename generator" + (concat erc-log-channels-directory "/" target "!" nick "@" server + ":" (message (cond ((stringp port) port) + ((numberp port) + (number-to-string port)))) ".txt")) + (defun erc-save-buffer-in-logs (&optional buffer) "When the logs are enabled, that is `erc-log-channels' is non-nil and `erc-log-channels-directory' is a valid directory, appends the @@ -5192,16 +5269,20 @@ automatically." (interactive) (if (not buffer) (setq buffer (current-buffer))) - (let ((file buffer-file-name)) + (let ((file (funcall erc-generate-log-file-name-function + buffer (erc-default-target) (erc-current-nick) + erc-session-server erc-session-port))) (setq buffer-file-name nil) (when (and erc-log-channels erc-log-channels-directory (erc-directory-writable-p erc-log-channels-directory)) - (append-to-file (point-min) (point-max) - (concat erc-log-channels-directory - "/" (buffer-name buffer) ".txt")) + (append-to-file erc-last-saved-position (point-max) file) + (if erc-truncate-buffer-on-save + (progn (erase-buffer) - (erc-display-prompt) + (setq erc-last-saved-position (point-max)) + (erc-display-prompt)) + (setq erc-last-saved-position (point-max))) (goto-char (point-max))) (set-buffer-modified-p nil) (setq buffer-file-name file))) |
From: Mario L. <ml...@ho...> - 2001-11-26 17:32:22
|
Gergely Nagy <alg...@bo...> writes: > Hello again! > > Attached below is the very latest version of the antifuchs+mhp > patch. The only change between the previous one and this is that I > modified erc-mode to set the initial filename of the buffer using my > customise function. I also changed erc-save-buffer-in-logs to set the > filename too, albeit this might not be necessary. > > Anyway, let the patch speak for itself: > Below are some comments. Any suggestions/ideas. Anyone already fallen int hose pits? > --- erc.el.orig Sat Nov 24 02:24:25 2001 > +++ erc.el Sun Nov 25 00:28:40 2001 > @@ -291,6 +291,21 @@ > :group 'erc > :type 'boolean) > > +(defcustom erc-public-away-p nil > + "Let others know you are back when you are no longer marked away. > +This happens in this form: > +* <nick> is back (gone for <time>) > + > +Many consider it impolite to do so automatically." > + :group 'erc > + :type 'boolean) > + > +(defcustom erc-away-nickname nil > + "The nickname to take when you are marked as being away." > + :group 'erc > + :type '(choice (const nil) > + string)) > + > (defcustom erc-play-sound t > "*Play sound on SOUND ctcp requests (used in ICQ chat)" > :group 'erc > @@ -437,6 +452,31 @@ > :group 'erc > :type 'boolean) > > +(defvar erc-last-saved-position 1 > + "The position in which appears last in the log file for the channel > +buffer") > + > +(make-variable-buffer-local 'erc-last-saved-position) > + > +(defvar erc-log-insert-log-on-open t > + "Insert the log file contentents into the buffer if the log file exists") > + > +(defcustom erc-truncate-buffer-on-save nil > + "Truncate any ERC (channel, query, server) buffer when it is saved. > +When nil, no buffer is ever truncated. Nonetheless, only the relevant > +part of the buffer will be saved.") > + > +(defcustom erc-generate-log-file-name-function 'erc-generate-log-file-name-default hmm, maybe the default function should save the filename in the expanded form, like #name!nick@host:port, because the buffers have short names now, and therefore, logfiles cant be really destinguished from each other in case of multiserver usage? > + "A function name to generate a log filename. The function must take > +four arguments: BUFFER, TARGET, NICK and SERVER. BUFFER is the buffer The code uses five arguments. > +to be saved, TARGET is the name of the channel, or the target of the > +query, NICK is the current nick, and SERVER is the server the buffer > +is on." > + :group 'erc > + :type '(choice (const 'erc-generate-log-file-name-default) > + (const 'erc-generate-log-file-name-old) > + (function))) > + > (defvar erc-grab-buffer-name "*erc-grab*" > "The name of the buffer created by `erc-grab-region'.") > [...] > @@ -2867,6 +2912,14 @@ > :group 'erc > :type 'boolean) > > +(defcustom erc-query-on-unjoined-chan-privmsg t Uggh, I'd really like to find a better name :-). Any suggestions? > + "If non-nil create query buffer on receiving any PRIVMSG at all, > +including PRIVMSGs directed to channels. If you are using an IRC > +bouncer, such as dircproxy, to keep a log of channels when you are > +disconnected, you should set this option to t." See below. > + :group 'erc > + :type 'boolean) > + > (defcustom erc-minibuffer-notice nil > "If non-nil, ERC will print notices in the minibuffer in case the > session buffer isn't visible." > @@ -3170,12 +3223,18 @@ > > (defun erc-auto-query (proc parsed) > "Put this on `erc-server-PRIVMSG-hook'." > - (let ((nick (car (erc-parse-user (aref parsed 1)))) > - (target (aref parsed 2))) > + (let* ((nick (car (erc-parse-user (aref parsed 1)))) > + (target (aref parsed 2)) > + (query (if (not erc-query-on-unjoined-chan-privmsg) > + nick > + (if (string= target (erc-current-nick)) > + nick > + target)))) > (and erc-auto-query > - (string= target (erc-current-nick)) > - (not (erc-get-buffer nick proc)) > - (erc-cmd-query nick)))) > + (or erc-query-on-unjoined-chan-privmsg > + (string= target (erc-current-nick))) > + (not (erc-get-buffer query proc)) > + (erc-cmd-query query)))) I am not sure, but shouldn't we issue a /name #channel, and perhaps /topic #channel somewhere in here? At least from reading that, I think that the info buffers would get screwed in some way? > > ;;; PRIVMSG and NOTICE > [...] > @@ -5181,6 +5248,16 @@ > (buffer-enable-undo)) > (set-buffer ob))) > > +(defun erc-generate-log-file-name-default (buffer target nick server port) > + "Default log filename generator." > + (concat erc-log-channels-directory "/" (buffer-name buffer) ".txt")) See above. The default would mean we can get files like #emacs<4>.txt #channel!nick@server:port.ext should be more convinient? > +(defun erc-generate-log-file-name-old (buffer target nick server port) > + "Old-style (#channel!nick@server.txt) log filename generator" > + (concat erc-log-channels-directory "/" target "!" nick "@" server > + ":" (message (cond ((stringp port) port) > + ((numberp port) > + (number-to-string port)))) ".txt")) > + > (defun erc-save-buffer-in-logs (&optional buffer) > "When the logs are enabled, that is `erc-log-channels' is non-nil > and `erc-log-channels-directory' is a valid directory, appends the [...] Yup! Very cool ideas, thanks for the contributions! I just wanted to check for comments about what I thought while reading the patch before I aplly it. If anyone has an extended version from the above already, go for it and check it in, we can work from there in cvs... -- CYa, Mario <ml...@de...> Homepage(s): http://delysid.org | http://piss.at/ Nature, to be commanded, must be obeyed. -- Francis Bacon |
From: Gergely N. <alg...@bo...> - 2001-11-24 16:56:13
|
> --- erc.el.orig Sat Nov 24 17:08:30 2001 > +++ erc.el Sat Nov 24 17:28:10 2001 > @@ -6,6 +6,7 @@ > ;; Contributors: Sergey Berezin (ser...@cs...), > ;; Mario Lang (ml...@de...), > ;; Alex Schroeder (al...@gn...) > +;; Gergely Nagy (alg...@mi...) I don't think I contributed that much to justify my inclusion in that list.. if someone wants to add me there, the address should be alg...@de.... BTW, there is a slight problem with my original patch, which I didn't test with antifuchs' version: when I get disconnected, I can't save the logs with C-c C-l, because one or more of the variables/functions I use is undefined (something about a deleted buffer). However, the message disappeared fast. I'll try to memorize it next time my ISP decides I'm better put offline. |
From: Gergely N. <alg...@bo...> - 2001-11-24 20:08:26
|
Greetings! Attached below is my latest patch (which includes antifuchs' patch too), which fixes an annoying buglet in erc-generate-log-file-name-old: if the port argument was an integer, the concat failed. It also fixes a typo, noticed by delYsid. I'm using these for a few hours now, and most of the changes appear to work nicely. Comments anyone? --- erc.el.orig Sat Nov 24 02:24:25 2001 +++ erc.el Sat Nov 24 20:58:56 2001 @@ -291,6 +291,21 @@ :group 'erc :type 'boolean) +(defcustom erc-public-away-p nil + "Let others know you are back when you are no longer marked away. +This happens in this form: +* <nick> is back (gone for <time>) + +Many consider it impolite to do so automatically." + :group 'erc + :type 'boolean) + +(defcustom erc-away-nickname nil + "The nickname to take when you are marked as being away." + :group 'erc + :type '(choice (const nil) + string)) + (defcustom erc-play-sound t "*Play sound on SOUND ctcp requests (used in ICQ chat)" :group 'erc @@ -437,6 +452,31 @@ :group 'erc :type 'boolean) +(defvar erc-last-saved-position 1 + "The position in which appears last in the log file for the channel +buffer") + +(make-variable-buffer-local 'erc-last-saved-position) + +(defvar erc-log-insert-log-on-open t + "Insert the log file contentents into the buffer if the log file exists") + +(defcustom erc-truncate-buffer-on-save nil + "Truncate any ERC (channel, query, server) buffer when it is saved. +When nil, no buffer is ever truncated. Nonetheless, only the relevant +part of the buffer will be saved.") + +(defcustom erc-generate-log-file-name-function 'erc-generate-log-file-name-default + "A function name to generate a log filename. The function must take +four arguments: BUFFER, TARGET, NICK and SERVER. BUFFER is the buffer +to be saved, TARGET is the name of the channel, or the target of the +query, NICK is the current nick, and SERVER is the server the buffer +is on." + :group 'erc + :type '(choice (const 'erc-generate-log-file-name-default) + (const 'erc-generate-log-file-name-old) + (function-item))) + (defvar erc-grab-buffer-name "*erc-grab*" "The name of the buffer created by `erc-grab-region'.") @@ -843,7 +883,10 @@ '(erc-save-buffer-in-logs)) ;Emacs >=19 (make-local-variable 'write-file-hooks) (setq write-file-hooks ;Emacs 18 - '(erc-save-buffer-in-logs)))) + '(erc-save-buffer-in-logs))) + (when erc-log-insert-log-on-open + (ignore-errors (insert-file-contents buffer-file-name))) + (setq erc-last-saved-position (point-max))) ;; Run the mode hooks (run-hooks 'erc-mode-hook)) @@ -1557,7 +1600,7 @@ `(timestamp ,(current-time))) (add-text-properties insert-position (point) '(point-entered erc-echo-timestamp)) - (setq insert-end-position (point))) + (setq insert-end-position (point))) ;; really restore old point. ;; run insertion hook, with point at restored location (erc-chain-hook-with-args 'erc-insert-hook insert-position insert-end-position))))) @@ -2867,6 +2910,14 @@ :group 'erc :type 'boolean) +(defcustom erc-query-on-unjoined-chan-privmsg t + "If non-nil create query buffer on receiving any PRIVMSG at all, +including PRIVMSGs directed to channels. If you are using an IRC +bouncer, such as dircproxy, to keep a log of channels when you are +disconnected, you should set this option to t." + :group 'erc + :type 'boolean) + (defcustom erc-minibuffer-notice nil "If non-nil, ERC will print notices in the minibuffer in case the session buffer isn't visible." @@ -3170,12 +3221,18 @@ (defun erc-auto-query (proc parsed) "Put this on `erc-server-PRIVMSG-hook'." - (let ((nick (car (erc-parse-user (aref parsed 1)))) - (target (aref parsed 2))) + (let* ((nick (car (erc-parse-user (aref parsed 1)))) + (target (aref parsed 2)) + (query (if (not erc-query-on-unjoined-chan-privmsg) + nick + (if (string= target (erc-current-nick)) + nick + target)))) (and erc-auto-query - (string= target (erc-current-nick)) - (not (erc-get-buffer nick proc)) - (erc-cmd-query nick)))) + (or erc-query-on-unjoined-chan-privmsg + (string= target (erc-current-nick))) + (not (erc-get-buffer query proc)) + (erc-cmd-query query)))) ;;; PRIVMSG and NOTICE @@ -3902,6 +3959,11 @@ (let ((sessionbuf (process-buffer proc))) (when sessionbuf (with-current-buffer sessionbuf + (when erc-away-nickname + (erc-log (format "erc-process-away: away-nick: %s, away-p: %s" erc-away-nickname away-p)) + (erc-cmd-nick (if away-p + erc-away-nickname + erc-nick))) (cond (away-p (setq away (current-time))) @@ -3912,6 +3974,7 @@ (setq away nil) (save-excursion (set-buffer erc-active-buffer) + (when erc-public-away-p (erc-send-action (erc-default-target) (if away-time @@ -3919,7 +3982,7 @@ (erc-sec-to-time (erc-time-diff (erc-emacs-time-to-erc-time away-time) (erc-current-time)))) - "is back")))))))) + "is back"))))))))) (erc-update-mode-line))) ;;;; List of channel members handling @@ -5169,7 +5232,9 @@ (let ((ob (current-buffer))) (if (and buffer (get-buffer buffer)) (set-buffer (get-buffer buffer))) - (when (> (point-max) (+ size 512)) + (when (and + erc-truncate-buffer-on-save + (> (point-max) (+ size 512))) (buffer-disable-undo) (if (and erc-log-channels erc-log-channels-directory @@ -5181,6 +5246,16 @@ (buffer-enable-undo)) (set-buffer ob))) +(defun erc-generate-log-file-name-default (buffer target nick server port) + "Default log filename generator." + (concat erc-log-channels-directory "/" (buffer-name buffer) ".txt")) +(defun erc-generate-log-file-name-old (buffer target nick server port) + "Old-style (#channel!nick@server.txt) log filename generator" + (concat erc-log-channels-directory "/" target "!" nick "@" server + ":" (message (cond ((stringp port) port) + ((numberp port) + (number-to-string port)))) ".txt")) + (defun erc-save-buffer-in-logs (&optional buffer) "When the logs are enabled, that is `erc-log-channels' is non-nil and `erc-log-channels-directory' is a valid directory, appends the @@ -5197,11 +5272,16 @@ (when (and erc-log-channels erc-log-channels-directory (erc-directory-writable-p erc-log-channels-directory)) - (append-to-file (point-min) (point-max) - (concat erc-log-channels-directory - "/" (buffer-name buffer) ".txt")) + (append-to-file erc-last-saved-position (point-max) + (funcall erc-generate-log-file-name-function + buffer (erc-default-target) (erc-current-nick) + erc-session-server erc-session-port)) + (if erc-truncate-buffer-on-save + (progn (erase-buffer) - (erc-display-prompt) + (setq erc-last-saved-position (point-max)) + (erc-display-prompt)) + (setq erc-last-saved-position (point-max))) (goto-char (point-max))) (set-buffer-modified-p nil) (setq buffer-file-name file))) |