* riece-display.el (riece-inhibit-update-buffers): New variable.
[elisp/riece.git] / lisp / riece-identity.el
index 1f58e02..f56e62c 100644 (file)
@@ -83,22 +83,13 @@ RFC2812, 2.2 \"Character codes\" says:
   "Return non-nil if an identity ELT is an element of LIST."
   (catch 'found
     (while list
-      (if (and (vectorp (car list))
+      (if (and (vectorp (car list))    ;needed because
+                                       ;riece-current-channels
+                                       ;contains nil.
               (riece-identity-equal (car list) elt))
          (throw 'found list)
        (setq list (cdr list))))))
 
-(defun riece-identity-member-no-server (elt list)
-  "Return non-nil if an identity ELT is an element of LIST.
-The only difference with `riece-identity-member', this function doesn't
-take server names into account."
-  (catch 'found
-    (while list
-      (if (and (vectorp (car list))
-              (riece-identity-equal-no-server (car list) elt))
-         (throw 'found list)
-       (setq list (cdr list))))))
-
 (defun riece-identity-assoc (elt alist)
   "Return non-nil if an identity ELT matches the car of an element of ALIST."
   (catch 'found
@@ -132,7 +123,7 @@ take server names into account."
      (if process
         (with-current-buffer (process-buffer process)
           ,@body)
-       (error "Server closed."))))
+       (error "Server closed"))))
 
 (put 'riece-with-identity-buffer 'lisp-indent-function 1)
 
@@ -141,7 +132,7 @@ take server names into account."
     (let ((prefix (riece-decode-coding-string
                   (riece-identity-prefix identity)))
          (server (riece-identity-server identity)))
-      (if (equal server "")
+      (if (or prefix-only (equal server ""))
          prefix
        (concat prefix " " server)))))
 
@@ -155,15 +146,24 @@ take server names into account."
     (riece-with-server-buffer server
       (riece-make-identity (riece-encode-coding-string prefix) server))))
 
-(defun riece-completing-read-identity (prompt table
+(defun riece-completing-read-identity (prompt channels
                                              &optional predicate must-match)
-  (riece-encode-identity
-   (completing-read
-    prompt
-    (mapcar (lambda (channel)
-             (list (riece-decode-identity channel)))
-           table)
-    predicate must-match)))
+  (let* ((decoded
+         (completing-read
+          prompt
+          (mapcar (lambda (channel)
+                    (list (riece-decode-identity channel)))
+                  (delq nil (copy-sequence (or channels
+                                               riece-current-channels))))
+          predicate must-match))
+        (encoded
+         (riece-encode-identity decoded)))
+    (if (and (not (string-match "[ ,]" decoded))
+            (string-match "[ ,]" (riece-identity-prefix encoded))
+            (not (y-or-n-p (format "The encoded channel name contains illegal character \"%s\".  continue? "
+                                   (match-string 0 (riece-identity-prefix encoded))))))
+       (error "Invalid channel name!"))
+    encoded))
 
 (provide 'riece-identity)