|
From: Michael O. <mw...@me...> - 2004-07-15 04:11:28
|
On Wed, 14 Jul 2004 21:19:30 -0500, Michael Olson wrote:
> When I /QUIT from a server and then reconnect to it later, Emacs
> (the CVS version) flashes the visual bell at me so fast that it
> causes Emacs to lock up. It won't respond to any keystrokes.
I figured out what the problem is. My original patch tried to set the
inhibit-read-only variable to `t' in order to be able to kill the
prompt when exiting. What I needed to do was use
erc-remove-text-properties-region to remove the read-only property of
the prompt before killing.
In addition, I'm using the -b and -w options for this diff so I don't
mess things up my manually editing the diff to get rid of unwanted
whitespace changes.
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 03:58:23 -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,70 @@
(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))
+ ;; 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)
+ ;; 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
|