Fixed.
[riece] / lisp / riece-server.el
index 4762802..d2ae3b6 100644 (file)
@@ -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))
@@ -97,11 +85,11 @@ is running on."
          (service (match-string 2 string))
          (password (substring string (match-end 0)))
          plist)
-      (push `(:host ,host) plist)
+      (setq plist (cons `(:host ,host) plist))
       (unless (equal service "")
-       (push `(:service ,(string-to-int service)) plist))
+       (setq plist (cons `(:service ,(string-to-int service)) plist)))
       (unless (equal password "")
-       (push `(:password ,(substring password 1)) plist))
+       (setq plist (cons `(:password ,(substring password 1)) plist)))
       (apply #'nconc plist))))
 
 (defun riece-server-name-to-server (server-name)
@@ -109,25 +97,29 @@ is running on."
     (if entry
        (unless (listp (cdr entry))
          (setcdr entry (riece-server-parse-string (cdr entry))))
-      (setq entry (cons server-name (riece-server-parse-string server-name)))
-      (push entry riece-server-alist)
-      (setq riece-save-variables-are-dirty t))
+      (setq entry (cons server-name (riece-server-parse-string server-name))
+           riece-server-alist (cons entry riece-server-alist)
+           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 IRC server %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"
+                    (get-buffer-create
+                     (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 +129,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)
@@ -148,7 +139,14 @@ If optional argument SERVICE is non-nil, open by the service name."
        (setq riece-last-nickname riece-real-nickname
              riece-nick-accepted 'sent
              riece-coding-system coding-system))
-      process)))
+      (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 IRC server %s...done" server-name)
+    (message "Connecting to IRC server...done")))
 
 (defun riece-reset-process-buffer (process)
   (save-excursion
@@ -185,9 +183,9 @@ If optional argument SERVICE is non-nil, open by the service name."
                               (if quit-message
                                   (format "QUIT :%s\r\n" quit-message)
                                 "QUIT\r\n"))
-    (delete-process process)
     (unless riece-debug
-      (kill-buffer (process-buffer process)))))
+      (kill-buffer (process-buffer process))))
+  (delete-process process))
 
 (eval-when-compile
   (autoload 'riece-exit "riece"))
@@ -196,8 +194,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))