From: Gergely N. <alg...@bo...> - 2001-11-26 17:04:25
|
Hi! To summarise it all, Andreas Fuchs' changes were these: * Disable the public-away stuff by default (cust: erc-public-away-p) * Make away nickname customizeable (cust: erc-away-nickname) By away nickname, I mean the nick you change to when you're away, say: antifuchs -> antigone * Logfile behavior: don't truncate the buffer when saving the logfile any more. Also, insert the logfile contents into the newly created query/channel buffer (see below) (cust: erc-insert-log-on-open, erc-truncate-buffer-on-save) * Bad bouncer behaviour. Some bouncers (i.e. dircproxy) stay on the channel and send you a log of what happened when you re-connect. The messages you missed went into the server buffer, now erc opens a new query window to the channel (cust: erc-query-on-unjoined-chan-privmsg) Mine were: * Customisable log-filename generation (cust: erc-generate-log-filename-function) * Deferred buffer-name setting. Instead of setting it in erc-mode, we set it in erc, when all the information the log-filename generator functions might need are all set up. This should play nicely with the automatic inclusion of previous logs. * Made erc-log-insert-log-on-open customisable Please note that with the deferred buffer-name setting I might have broken erc-generate-log-file-name-default.. And now, the more interesting part, the patch (against vanilla 1.148): --- erc.el.orig Sat Nov 24 02:24:25 2001 +++ erc.el Mon Nov 26 17:47:05 2001 @@ -117,7 +117,6 @@ (set sym (funcall val)) (set sym val)))) - (defvar erc-password nil "ERC password to use in authentication (not necessary)") (defcustom erc-prompt-for-password t @@ -291,6 +290,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 +451,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") + +(defcustom erc-log-insert-log-on-open t + "Insert the log file contentents into the buffer if the log file exists" + :group 'erc + :type 'boolean) + +(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) + (symbol))) + (defvar erc-grab-buffer-name "*erc-grab*" "The name of the buffer created by `erc-grab-region'.") @@ -829,21 +868,10 @@ (set (make-local-variable 'next-line-add-newlines) nil)) (make-variable-buffer-local 'paragraph-separate) (make-variable-buffer-local 'paragraph-start) + (make-variable-buffer-local 'erc-last-saved-position) (setq paragraph-separate (concat "\C-l\\|\\(^" (regexp-quote erc-prompt) "\\)")) (setq paragraph-start (concat "\\(" (regexp-quote erc-prompt) "\\)")) - ;; Saving log file on exit - (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")) - (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)))) ;; Run the mode hooks (run-hooks 'erc-mode-hook)) @@ -1115,6 +1143,24 @@ (when erc-log-p (get-buffer-create (concat "*ERC-DEBUG: " server "*")))) + ;; Saving log file on exit + (when erc-log-channels-directory + (auto-save-mode -1) + (setq buffer-offer-save t + 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))) + (when erc-log-insert-log-on-open + (ignore-errors (insert-file-contents buffer-file-name))) + (setq erc-last-saved-position (point-max))) + (erc-determine-parameters server port nick full-name) (if connect (erc-connect)) (erc-update-mode-line) @@ -1557,7 +1603,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 +2913,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 +3224,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 +3962,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 +3977,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 +3985,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 +5235,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 +5249,17 @@ (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 "/" (if target (concat 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 +5271,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))) |