From: Michael O. <mw...@me...> - 2004-07-15 20:04:39
|
On Thu, 15 Jul 2004 13:11:53 +0100, lawrence mitchell wrote: > Why does let-binding (I assume that's what you're doing) > inhibit-read-only to t not allow reconnection. That sounds like > a deeper problem, but, without looking, I'm not really sure. I think this is a problem with Emacs from CVS. I never experienced that problem with Emacs 21.3 . I'm thinking about reporting this problem to the emacs-devel list. XEmacs handled an attempt to kill read-only text by refusing to do it, even though the buffer had the inhibit-read-only flag set. >>> ;; Kill the prompt >>> ;; (XEmacs users beware: it doesn't seem to work for you) >>> (beginning-of-line) >>> (erc-remove-text-properties-region (point) (point-max)) >>> (kill-line nil) > > Better written as: > > (forward-line 0) > (erc-remove-text-properties-region (point) (point-max)) > (delete-region (point) (point-max)) > > That way you don't have to worry about the dodgy behaviour of > beginning-of-line with invisible/intangible stuff, and you don't > add the prompt to the kill ring, which would definitely not be > expected by the user. You're right. The included patch incorporates this change. Also: I forgot to remove the comment about XEmacs; as far as I know, this method works just as well for XEmacs as with GNU Emacs. *** Beginning of patch *** Index: erc.el =================================================================== RCS file: /cvsroot/erc/erc/erc.el,v retrieving revision 1.672 diff -u -b -w -r1.672 erc.el --- erc.el 14 Jun 2004 20:56:47 -0000 1.672 +++ erc.el 15 Jul 2004 20:01:39 -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." + (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)) - (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 + (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 - (with-current-buffer (current-buffer) (progn (cancel-timer erc-ping-handler) - (setq erc-ping-handler nil)))) + (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)) + ;; Remove the prompt + (forward-line 0) + (erc-remove-text-properties-region (point) (point-max)) + (delete-region (point) (point-max)) + ;; 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) - (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)))) + (set-buffer-modified-p nil)))))) ;;; I/O interface *** End of patch *** |