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))) |