|
From: Michael O. <mw...@me...> - 2004-07-13 06:40:46
|
On Mon, 12 Jul 2004 16:08:39 -0700, Michael Olson wrote: > I've enclosed a patch to erc.el which does the following things: Silly me, the patch didn't seem to be in the correct format. Here's a better one (hopefully): Index: erc.el =================================================================== RCS file: /cvsroot/erc/erc/erc.el,v retrieving revision 1.672 diff -u -r1.672 erc.el --- erc.el 14 Jun 2004 20:56:47 -0000 1.672 +++ erc.el 13 Jul 2004 06:18:34 -0000 @@ -913,6 +913,11 @@ :group 'erc :type 'boolean) +(defcustom erc-kill-server-buffer-on-quit nil + "Kill the server buffer of the process on QUIT." + :group 'erc + :type 'boolean) + (defcustom erc-quit-reason-various-alist nil "Alist of possible arguments to the /quit command. @@ -2402,58 +2407,69 @@ (erc-parse-server-response proc line)) (erc-split-multiline string)))) +(defun erc-process-sentinel-1 (event) + "This will be called when erc-process-sentinel has decided that we +are going to quit. Determine whether user has quit or whether erc has +been terminated. Conditionally try to reconnect and take appropriate +action." + (if quitting + ;; normal quit + (progn + (let ((string "\n\n*** ERC finished ***\n")) + (erc-put-text-property 0 (length string) + 'face 'erc-error-face string) + (insert string)) + (when erc-kill-server-buffer-on-quit + (set-buffer-modified-p nil) + (kill-buffer (current-buffer)))) + ;; unexpected disconnect + (erc-display-message nil 'error (current-buffer) + (if erc-auto-reconnect + 'disconnected + 'disconnected-noreconnect)) + (erc-update-mode-line) + (setq erc-active-buffer (current-buffer)) + (setq last-sent-time 0) + (setq erc-lines-sent 0) + (if erc-auto-reconnect + (erc erc-session-server erc-session-port current-nick + erc-session-user-full-name t erc-session-password) + ;; terminate, do not reconnect + (let ((string (concat "\n\n*** ERC terminated: " event + "\n"))) + (erc-put-text-property 0 (length string) + 'face 'erc-error-face string) + (insert string))))) + (defun erc-process-sentinel (cproc event) "Sentinel function for ERC process." - (erc-log (format - "SENTINEL: proc: %S status: %S event: %S (quitting: %S)" - erc-process (process-status erc-process) event quitting)) - (save-excursion - (set-buffer (process-buffer cproc)) - (cond - ((equal event "open\n") - ;; newly opened connection for a nowait connection - (erc-login)) - ;; ((eq event 'failed))) - ;; default to this - (t - (erc-with-all-buffers-of-server cproc nil (setq erc-connected nil)) - (when erc-ping-handler - (with-current-buffer (current-buffer) + (with-current-buffer (process-buffer cproc) + (erc-log (format + "SENTINEL: proc: %S status: %S event: %S (quitting: %S)" + erc-process (process-status erc-process) event quitting)) + (if (equal event "open\n") + ;; newly opened connection (no wait) + (erc-login) + ;; assume event is 'failed + (let ((buf (process-buffer cproc))) + (erc-with-all-buffers-of-server cproc nil (setq erc-connected nil)) + (when erc-ping-handler (progn (cancel-timer erc-ping-handler) - (setq erc-ping-handler nil)))) - (run-hook-with-args 'erc-disconnected-hook - (erc-current-nick) (system-name) "") - (if (string= event "exited abnormally with code 256\n") - - ;; Sometimes (eg on a /LIST command) ERC happens to die with - ;; an exit code 256. The icrii client also shows this behavior - ;; and it restarts itself. So do I. - - (cond - ((not quitting) - (erc-display-message nil 'error (current-buffer) - (if erc-auto-reconnect - 'disconnected - 'disconnected-noreconnect)) - (erc-update-mode-line) - (setq erc-active-buffer (current-buffer)) - (setq last-sent-time 0) - (setq erc-lines-sent 0) - (when erc-auto-reconnect - (erc erc-session-server erc-session-port current-nick - erc-session-user-full-name t erc-session-password)) - (goto-char (point-max))) - (t - (let* ((wd (window-width)) - (msg "*** ERC finished ***") - (off (/ (- wd (length msg)) 2)) - (s "")) - (if (> off 0) - (setq s (make-string off ? ))) - (insert (concat "\n\n" s msg "\n"))))) - (insert (concat "\n\n*** ERC terminated: " event "\n")))) - (goto-char (point-max)) - (erc-update-mode-line)))) + (setq erc-ping-handler nil))) + (run-hook-with-args 'erc-disconnected-hook + (erc-current-nick) (system-name) "") + ;; Kill the prompt + ;; (XEmacs users beware: it doesn't seem to work for you) + (let ((inhibit-read-only t)) + (kill-line 0)) + ;; Decide what to do with the buffer + ;; Restart if disconnected + (erc-process-sentinel-1 event) + ;; Make sure we don't write to the buffer if it has been + ;; killed + (when (buffer-live-p buf) + (erc-update-mode-line) + (set-buffer-modified-p nil)))))) ;;; I/O interface ----- patch ends here (don't include the dashed line or anything below) |