(cf. the last paragraph of `kill-buffer' docstring)
[riece] / lisp / riece-server.el
index 4d5b244..20aedf8 100644 (file)
@@ -39,7 +39,7 @@
       (:username riece-username)
       (:password)
       (:function #'open-network-stream)
-      (:coding-system riece-default-coding-system))
+      (:coding riece-default-coding-system))
     "Mapping from keywords to default values.
 All keywords that can be used must be listed here."))
 
@@ -63,18 +63,6 @@ the `riece-server-keyword-map' variable."
 (put 'riece-server-keyword-bind 'lisp-indent-function 1)
 (put 'riece-server-keyword-bind 'edebug-form-spec '(form body))
 
-(defun riece-start-server (server &optional server-name)
-  "Open network stream to remote irc server.
-If optional argument CONFIRM is non-nil, ask the host that the server
-is running on."
-  (if server-name
-      (message "Connecting to IRC server on %s..." server-name)
-    (message "Connecting to IRC server..."))
-  (prog1 (riece-open-server server server-name)
-    (if server-name
-       (message "Connecting to IRC server on %s...done" server-name)
-      (message "Connecting to IRC server...done"))))
-
 (defun riece-clear-system ()
   (while riece-buffer-list
     (if (and (get-buffer (car riece-buffer-list))
@@ -114,20 +102,23 @@ is running on."
            riece-save-variables-are-dirty t))
     (cdr entry)))
 
-(defun riece-open-server (server server-name)
-  "Open chat server on HOST.
-If HOST is nil, use value of environment variable \"IRCSERVER\".
-If optional argument SERVICE is non-nil, open by the service name."
+(defun riece-open-server (server &optional server-name)
+  (if server-name
+      (message "Connecting to %s..." server-name)
+    (message "Connecting to IRC server..."))
   (riece-server-keyword-bind server
     (let* (selective-display
           (coding-system-for-read 'binary)
           (coding-system-for-write 'binary)
           (process
-           (funcall function "IRC" (if server-name
-                                       (format " *IRC*%s" server-name)
-                                     " *IRC*")
+           (funcall function "IRC"
+                    (if server-name
+                        (format " *IRC*%s" server-name)
+                      " *IRC*")
                     host service)))
       (riece-reset-process-buffer process)
+      (with-current-buffer (process-buffer process)
+       (setq riece-server-name server-name))
       (set-process-sentinel process 'riece-sentinel)
       (set-process-filter process 'riece-filter)
       (if (or password
@@ -137,7 +128,6 @@ If optional argument SERVICE is non-nil, open by the service name."
                                             (or password
                                                 (riece-read-passwd
                                                  "Password: ")))))
-      (setq riece-reconnect-with-password nil)
       (riece-process-send-string process
                                 (format "USER %s * * :%s\r\n"
                                         (user-real-login-name)
@@ -147,8 +137,15 @@ If optional argument SERVICE is non-nil, open by the service name."
       (with-current-buffer (process-buffer process)
        (setq riece-last-nickname riece-real-nickname
              riece-nick-accepted 'sent
-             riece-coding-system coding-system))
-      process)))
+             riece-coding-system coding))
+      (if server-name
+         (setq riece-server-process-alist
+               (cons (cons server-name process)
+                     riece-server-process-alist))
+       (setq riece-server-process process))))
+  (if server-name
+      (message "Connecting to %s...done" server-name)
+    (message "Connecting to IRC server...done")))
 
 (defun riece-reset-process-buffer (process)
   (save-excursion
@@ -180,14 +177,14 @@ If optional argument SERVICE is non-nil, open by the service name."
       (set-process-filter process nil))
   (if (eq 'riece-sentinel (process-sentinel process))
       (set-process-sentinel process nil))
-  (when (memq (process-status process) '(open run))
-    (riece-process-send-string process
-                              (if quit-message
-                                  (format "QUIT :%s\r\n" quit-message)
-                                "QUIT\r\n"))
-    (delete-process process)
-    (unless riece-debug
-      (kill-buffer (process-buffer process)))))
+  (if (memq (process-status process) '(open run))
+      (riece-process-send-string process
+                                (if quit-message
+                                    (format "QUIT :%s\r\n" quit-message)
+                                  "QUIT\r\n")))
+  (if riece-debug
+      (delete-process process)
+    (kill-buffer (process-buffer process))))
 
 (eval-when-compile
   (autoload 'riece-exit "riece"))
@@ -196,8 +193,9 @@ If optional argument SERVICE is non-nil, open by the service name."
   (let ((riece-overriding-server-name server-name)
        (channels riece-current-channels))
     (while channels
-      (if (equal (riece-identity-server (car channels))
-                server-name)
+      (if (and (car channels)
+              (equal (riece-identity-server (car channels))
+                     server-name))
          (riece-part-channel (car channels)))
       (setq channels (cdr channels)))
     (riece-redisplay-buffers))