-(defun riece-current-nickname ()
- "Return the current nickname."
- (riece-with-server-buffer
- (if riece-real-nickname
- (riece-make-identity riece-real-nickname))))
+(defun riece-format-identity (identity &optional prefix-only)
+ (let ((string
+ (if (or prefix-only
+ (equal (riece-identity-server identity) ""))
+ (riece-identity-prefix identity)
+ (concat (riece-identity-prefix identity) " "
+ (riece-identity-server identity)))))
+ (if riece-abbrev-identity-string-function
+ (setq string (funcall riece-abbrev-identity-string-function string)))
+ (put-text-property 0 (length string) 'riece-identity identity string)
+ string))
+
+(defun riece-parse-identity (string)
+ (if riece-expand-identity-string-function
+ (setq string (funcall riece-expand-identity-string-function string)))
+ (riece-make-identity (if (string-match " " string)
+ (substring string 0 (match-beginning 0))
+ string)
+ (if (string-match " " string)
+ (substring string (match-end 0))
+ "")))
+
+(defun riece-completing-read-identity (prompt channels
+ &optional predicate require-match
+ initial history default)
+ (let* ((string
+ (completing-read
+ prompt
+ (mapcar (lambda (channel)
+ (list (riece-format-identity channel)))
+ (delq nil (copy-sequence (or channels
+ riece-current-channels))))
+ predicate require-match initial history default))
+ (identity
+ (riece-parse-identity string)))
+ (unless (string-match (concat "^\\(" riece-channel-regexp "\\|"
+ riece-user-regexp "\\)")
+ (riece-identity-prefix identity))
+ (error "Invalid channel name!"))
+ identity))