| Paste number 1674: | patch to erc that allows auto-closing of server buffers on exit, and fixes a few bugs |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| #emacs | |
| Paste contents: |
| --- erc/erc.el 2004-07-09 22:42:59.000000000 -0500 +++ erc-dev/erc.el 2004-07-09 23:51:53.000000000 -0500 @@ -338,7 +338,7 @@ s)) (defstruct (erc-server-user (:type vector) :named) - + ;; User data nickname host login full-name info @@ -350,9 +350,9 @@ ) (defstruct (erc-channel-user (:type vector) :named) - + op voice - + ;; Last message time (in the form of the return value of ;; (current-time) ;; @@ -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. @@ -1854,7 +1859,7 @@ (if user (erc-server-user-buffers user) nil)))) - + ;; Some local variables @@ -2407,53 +2412,61 @@ (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) - (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. + (let ((erc-server-buffer-was-killed nil)) + (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) + (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)))) + (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")) + (when erc-kill-server-buffer-on-quit + (set-buffer-modified-p nil) + (kill-buffer (current-buffer)) + (setq erc-server-buffer-was-killed t))))) + (when (not erc-server-buffer-was-killed) + (insert (concat "\n\n*** ERC terminated: " event "\n")))) + (when (not erc-server-buffer-was-killed) + (goto-char (point-max)) + (erc-update-mode-line) + (set-buffer-modified-p nil))))))) ;;; I/O interface @@ -5325,7 +5338,7 @@ host login full-name info))) (when add (if (null user) - (progn + (progn (setq user (make-erc-server-user :nickname nick :host host |
Annotations for this paste:
| Annotation number 10: | annotation 10 (erc-process-sentinel): another attempt at making XEmacs kill the prompt |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
(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)) (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) "") ;; Kill the prompt ;; (XEmacs users beware: it doesn't seem to work for you) (let ((inhibit-read-only t) (inhibit-field-text-motion 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)))))) |
| Annotation number 9: | last-ditch email to erc-help@sourceforge.net |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
| I've enclosed a patch to erc.el which does the following things: - Add a new configurable variable called `erc-kill-server-buffer-on-quit' that defaults to nil - Significant rewrite of erc-process-sentinel. I split off some of the code into erc-process-sentinel-1 in order to make it more readable. - Modify erc-process-sentinel to mark server buffers as unread so that they are easier to kill manually. - Modify erc-process-sentinel to insinuate the new `erc-kill-server-buffer-on-quit' option. - Colorize the disconnect and finished messages. - Kill the last ERC prompt in the server buffer before displaying the message(s). The only unresolved issue with the patch is that XEmacs apparently complains when I try to kill the prompt. bpalmer from #emacs is working on that. Apparently XEmacs seems to have another layer of complexity in that it can have a non-read-only buffer with read-only text. Kudos to jbms from #emacs for the help. Mike Olson |
| Annotation number 8: | "final" patch for emacs-process-sentinel (i'm even leaving the whitespace alone; can you believe it?) |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
| 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 12 Jul 2004 07:21:33 -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." - (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) + (beginning-of-line) + (setq inhibit-read-only t) + (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) + (set-buffer-modified-p nil)))))) ;;; I/O interface |
| Annotation number 7: | ver 5 (erc-process-sentinel): from jbms's annotation 6, cleanup a few more comment strings |
| Pasted by: | bigmike |
| 4 years, 5 months ago | |
| Paste contents: |
(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)) (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) "") ;; Kill the prompt ;; (XEmacs users beware: it doesn't seem to work for you) (beginning-of-line) (setq inhibit-read-only t) (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) (set-buffer-modified-p nil)))))) |
| Annotation number 6: | ver 5: (erc-process-sentinel): add (with-current-buffer (process-buffer cproc) ...) |
| Pasted by: | jbms |
| 4 years, 5 months ago | |
| Paste contents: |
| (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)) (if (equal event "open\n") ;; newly opened connection for a nowait connection (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) "") ;; Kill the prompt (XEmacs users beware: it doesn't seem to ;; work for you) (beginning-of-line) (setq inhibit-read-only t) (kill-line nil) ;; Decide what to do with the buffer, or 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)))))) |
| Annotation number 5: | ver 4: (erc-process-sentinel): remove unnecessary comment, remove passing of current-buffer, reorder if-statement in erc-process-sentinel-1 |
| Pasted by: | jbms |
| 4 years, 5 months ago | |
| Paste contents: |
| (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)) (if (equal event "open\n") ;; newly opened connection for a nowait connection (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) "") ;; Kill the prompt (XEmacs users beware: it doesn't seem to ;; work for you) (beginning-of-line) (setq inhibit-read-only t) (kill-line nil) ;; Decide what to do with the buffer, or 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))))) |
| Annotation number 4: | ver 3 (erc-process-sentinel): get rid of some progn's |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
(defun erc-process-sentinel-1 (buf 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 (null quitting) (progn ;; 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. (erc-display-message nil 'error buf (if erc-auto-reconnect 'disconnected 'disconnected-noreconnect)) (erc-update-mode-line) (setq erc-active-buffer buf) (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)))) ;; normal quit (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 buf)))) (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)) (if (equal event "open\n") ;; newly opened connection for a nowait connection (erc-login) ;; Assume event is 'failed (let ((buf (process-buffer cproc))) (set-buffer buf) (erc-with-all-buffers-of-server cproc nil (setq erc-connected nil)) (when erc-ping-handler (with-current-buffer buf (progn (cancel-timer erc-ping-handler) (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) (beginning-of-line) (setq inhibit-read-only t) (kill-line nil) ;; Decide what to do with the buffer, or restart if ;; disconnected (erc-process-sentinel-1 buf 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))))) |
| Annotation number 3: | sane version no. 2 of the new erc-process-sentinel: make jbms happy (hopefully) :^) by getting rid of the cond statements |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
| (defun erc-process-sentinel-1 (buf 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 (null quitting) (progn ;; 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. (erc-display-message nil 'error buf (if erc-auto-reconnect 'disconnected 'disconnected-noreconnect)) (erc-update-mode-line) (setq erc-active-buffer buf) (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 (progn (let ((string (concat "\n\n*** ERC terminated: " event "\n"))) (erc-put-text-property 0 (length string) 'face 'erc-error-face string) (insert string))))) (progn ;; normal quit (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 buf))))) (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)) (if (equal event "open\n") ;; newly opened connection for a nowait connection (erc-login) ;; Assume event is 'failed (progn (let ((buf (process-buffer cproc))) (set-buffer buf) (erc-with-all-buffers-of-server cproc nil (setq erc-connected nil)) (when erc-ping-handler (with-current-buffer buf (progn (cancel-timer erc-ping-handler) (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) (beginning-of-line) (setq inhibit-read-only t) (kill-line nil) ;; Decide what to do with the buffer, or restart if ;; disconnected (erc-process-sentinel-1 buf 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)))))) |
| Annotation number 2: | This will remove the prompt from the server buffer on exit and conditionally close the buffer (if customized to do so). First usable version. |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
(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. Return nil if server buffer is still alive, or t if it has been killed." (cond ((and (string= event "exited abnormally with code 256\n") (not quitting)) ;; 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. (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 (progn (let ((string (concat "\n\n*** ERC terminated: " event "\n"))) (erc-put-text-property 0 (length string) 'face 'erc-error-face string) (insert string)))) nil) (t ;; normal quit (let ((string "\n\n*** ERC finished ***\n")) (erc-put-text-property 0 (length string) 'face 'erc-error-face string) (insert string)) (if erc-kill-server-buffer-on-quit (progn (set-buffer-modified-p nil) (kill-buffer (current-buffer)) t) nil)))) (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)) (cond ((equal event "open\n") ;; newly opened connection for a nowait connection (erc-login)) ;; ((eq event 'failed))) ;; default to this (t (set-buffer (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)))) (run-hook-with-args 'erc-disconnected-hook (erc-current-nick) (system-name) "") ;; Kill the prompt (setq inhibit-read-only t) (kill-line 0) ;; If erc-process-sentinel-1 returns nil, it means that the ;; server buffer is still alive (when (null (erc-process-sentinel-1 event)) (erc-update-mode-line) (set-buffer-modified-p nil))))) |
| Annotation number 1: | another try at erc-process-sentinel, splitting it up (no more yucky (let) statement); still gives annoying message about "error in process sentinel: forward-paragraph: Beginning of buffer" |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
(defun erc-process-sentinel-1 (event) "Finish what erc-process-sentinel started. Return nil if server buffer is still alive, or t if it has been killed." (cond ((and (string= event "exited abnormally with code 256\n") (not quitting)) ;; 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. (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) (erc-display-message nil 'error (current-buffer) (concat "\n\n*** ERC terminated: " event "\n"))) nil) (t ;; normal quit (erc-display-message nil 'error (current-buffer) "\n\n*** ERC finished ***\n") (if erc-kill-server-buffer-on-quit (progn (set-buffer-modified-p nil) (kill-buffer (current-buffer)) t) nil)))) (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) (progn (cancel-timer erc-ping-handler) (setq erc-ping-handler nil)))) (run-hook-with-args 'erc-disconnected-hook (erc-current-nick) (system-name) "") ;; If erc-process-sentinel-1 returns nil, it means that the ;; server buffer is still alive (when (not (erc-process-sentinel-1 event)) (set-buffer-modified-p nil) (erc-update-mode-line)))))) |
| Annotation number 11: | (erc-process-sentinel): final patch, done with diff -u -b -w, fixes read-only prompt problem |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
| 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 |
| Annotation number 12: | changelog entry for erc-process-sentinel patch |
| Pasted by: | bigmike160 |
| 4 years, 5 months ago | |
| Paste contents: |
| 2004-07-20 Michael Olson <mwolson@member.fsf.org> * erc.el (erc-process-sentinel-1): New function (erc-kill-server-buffer-on-quit): New variable (erc-process-sentinel): Put `with-current-buffer' around everything. Use `if' instead of `cond' in places where the decision is binary. New local variable `buf' is needed to see if the server buffer still exists, so we don't write to a buffer that doesn't exist. Clarify a few comments. Kill the last prompt in the server buffer, since it serves no purpose as the user cannot launch new server processes once erc is finished. Color "erc terminated" and "erc finished" messages. Use set-buffer-modified-p to make the buffer appear unmodified, so it is easier to kill manually. Interpret `erc-kill-server-buffer-on-quit' to mean that if non-nil, close the server buffer automatically when erc has been quit normally. |
| Annotation number 13: | revised changelog |
| Pasted by: | bpalmer |
| 4 years, 5 months ago | |
| Paste contents: |
| (erc-process-sentinel-1): New function. This is an auxiliary function refactored out of erc-process-sentinel to decide a server buffer's fate (whether it should be killed, and whether erc should attempt to auto-reconnect). (erc-kill-server-buffer-on-quit): New variable. Used in erc-process-sentinel-1 to decide whether to kill a server buffer when the user quit normally. (erc-process-sentinel): Auxiliary function erc-process-sentinel-1 split out. The function body has `with-current-buffer' wrapped around it. Use `if' instead of `cond' in places where the decision is binary.The last (useless, since the server connection is closed) prompt in the server buffer is removed. Color "erc terminated" and "erc finished" messages with erc-error-face. Mark the buffer unmodified so that, if not killed automatically, the user is not prompted to save it. |