* riece-naming.el (riece-naming-assert-rename): Follow the
[riece] / lisp / riece-commands.el
index 2c8cb1a..124a1cd 100644 (file)
@@ -26,6 +26,7 @@
 
 (require 'riece-channel)
 (require 'riece-complete)
 
 (require 'riece-channel)
 (require 'riece-complete)
+(require 'riece-layout)
 (require 'riece-display)
 (require 'riece-version)
 (require 'riece-server)
 (require 'riece-display)
 (require 'riece-version)
 (require 'riece-server)
@@ -51,7 +52,7 @@
     (if channel
        (riece-command-switch-to-channel channel)
       (error "No such number!"))))
     (if channel
        (riece-command-switch-to-channel channel)
       (error "No such number!"))))
-       
+
 (eval-and-compile
   (let ((number 1))
     (while (<= number 20)
 (eval-and-compile
   (let ((number 1))
     (while (<= number 20)
@@ -89,7 +90,8 @@
          (start riece-current-channels)
          channel)
       (while (and start (not (eq start pointer)))
          (start riece-current-channels)
          channel)
       (while (and start (not (eq start pointer)))
-       (setq channel (car start))
+       (if (car start)
+           (setq channel (car start)))
        (setq start (cdr start)))
       (when (null channel)
        (setq start (copy-sequence riece-current-channels))
        (setq start (cdr start)))
       (when (null channel)
        (setq start (copy-sequence riece-current-channels))
   (interactive)
   (riece-redisplay-buffers t))
 
   (interactive)
   (riece-redisplay-buffers t))
 
+(defun riece-command-change-layout (name)
+  "Select a layout-name from all current available layouts and change
+the layout to the selected layout-name."
+  (interactive (list (completing-read "Layout: " riece-layout-alist)))
+  (setq riece-layout name
+       riece-save-variables-are-dirty t)
+  (riece-command-configure-windows))
+
 (defun riece-command-toggle-channel-buffer-mode ()
   (interactive)
   (setq riece-channel-buffer-mode
 (defun riece-command-toggle-channel-buffer-mode ()
   (interactive)
   (setq riece-channel-buffer-mode
 (defun riece-command-finger (user &optional recurse)
   (interactive
    (let* ((completion-ignore-case t)
 (defun riece-command-finger (user &optional recurse)
   (interactive
    (let* ((completion-ignore-case t)
-         (user (completing-read
+         (user (riece-completing-read-identity
                 "User: "
                 "User: "
-                (mapcar #'list (riece-get-users-on-server)))))
+                (riece-get-users-on-server (riece-current-server-name)))))
      (list user current-prefix-arg)))
   (if recurse
      (list user current-prefix-arg)))
   (if recurse
-      (riece-send-string (format "WHOIS %s %s\r\n" user user))
-    (riece-send-string (format "WHOIS %s\r\n" user))))
+      (riece-send-string (format "WHOIS %s %s\r\n"
+                                (riece-identity-prefix user)
+                                (riece-identity-prefix user)))
+    (riece-send-string (format "WHOIS %s\r\n" (riece-identity-prefix user)))))
 
 (defun riece-command-topic (topic)
   (interactive
 
 (defun riece-command-topic (topic)
   (interactive
-   (list (read-from-minibuffer
-         "Topic: " (cons (or (riece-with-server-buffer
-                                 (riece-identity-server riece-current-channel)
-                               (riece-channel-get-topic
-                                (riece-identity-prefix
-                                 riece-current-channel)))
-                             "")
-                         0))))
+   (progn
+     (riece-check-channel-commands-are-usable t)
+     (list (read-from-minibuffer
+           "Topic: " (cons (or (riece-with-server-buffer
+                                   (riece-identity-server
+                                    riece-current-channel)
+                                 (riece-channel-get-topic
+                                  (riece-identity-prefix
+                                   riece-current-channel)))
+                               "")
+                           0)))))
   (riece-send-string (format "TOPIC %s :%s\r\n"
                             (riece-identity-prefix riece-current-channel)
                             topic)))
   (riece-send-string (format "TOPIC %s :%s\r\n"
                             (riece-identity-prefix riece-current-channel)
                             topic)))
 (defun riece-command-invite (user)
   (interactive
    (let ((completion-ignore-case t))
 (defun riece-command-invite (user)
   (interactive
    (let ((completion-ignore-case t))
-     (unless (and riece-current-channel
-                 (riece-channel-p (riece-identity-prefix
-                                   riece-current-channel)))
-       (error "Not on a channel"))
-     (list (completing-read
+     (riece-check-channel-commands-are-usable t)
+     (list (riece-completing-read-identity
            "User: "
            "User: "
-           (mapcar #'list (riece-get-users-on-server))))))
+           (riece-get-users-on-server (riece-current-server-name))))))
   (riece-send-string (format "INVITE %s %s\r\n"
   (riece-send-string (format "INVITE %s %s\r\n"
-                            user (riece-identity-prefix
-                                  riece-current-channel))))
+                            (riece-identity-prefix user)
+                            (riece-identity-prefix riece-current-channel))))
 
 (defun riece-command-kick (user &optional message)
   (interactive
    (let ((completion-ignore-case t))
 
 (defun riece-command-kick (user &optional message)
   (interactive
    (let ((completion-ignore-case t))
-     (unless (and riece-current-channel
-                 (riece-channel-p (riece-identity-prefix
-                                   riece-current-channel)))
-       (error "Not on a channel"))
+     (riece-check-channel-commands-are-usable t)
      (list (completing-read
            "User: "
      (list (completing-read
            "User: "
-           (mapcar #'list (riece-channel-get-users
-                           riece-current-channel)))
+           (riece-with-server-buffer
+               (riece-identity-server riece-current-channel)
+             (riece-channel-get-users (riece-identity-prefix
+                                       riece-current-channel))))
           (if current-prefix-arg
               (read-string "Message: ")))))
   (riece-send-string
           (if current-prefix-arg
               (read-string "Message: ")))))
   (riece-send-string
            (if (and riece-current-channel
                     (riece-channel-p (riece-identity-prefix
                                       riece-current-channel)))
            (if (and riece-current-channel
                     (riece-channel-p (riece-identity-prefix
                                       riece-current-channel)))
-               (cons (riece-format-identity riece-current-channel t)
+               (cons (riece-identity-prefix riece-current-channel)
                      0))))))
   (if (or (not (equal pattern ""))
          (yes-or-no-p "Really want to query NAMES without argument? "))
                      0))))))
   (if (or (not (equal pattern ""))
          (yes-or-no-p "Really want to query NAMES without argument? "))
            (if (and riece-current-channel
                     (riece-channel-p (riece-identity-prefix
                                       riece-current-channel)))
            (if (and riece-current-channel
                     (riece-channel-p (riece-identity-prefix
                                       riece-current-channel)))
-               (cons (riece-format-identity riece-current-channel t)
+               (cons (riece-identity-prefix riece-current-channel)
                      0))))))
   (if (or (not (equal pattern ""))
          (yes-or-no-p "Really want to query WHO without argument? "))
                      0))))))
   (if (or (not (equal pattern ""))
          (yes-or-no-p "Really want to query WHO without argument? "))
            (if (and riece-current-channel
                     (riece-channel-p (riece-identity-prefix
                                       riece-current-channel)))
            (if (and riece-current-channel
                     (riece-channel-p (riece-identity-prefix
                                       riece-current-channel)))
-               (cons (riece-format-identity riece-current-channel t)
+               (cons (riece-identity-prefix riece-current-channel)
                      0))))))
   (if (or (not (equal pattern ""))
          (yes-or-no-p "Really want to query LIST without argument? "))
                      0))))))
   (if (or (not (equal pattern ""))
          (yes-or-no-p "Really want to query LIST without argument? "))
           (if current-prefix-arg
               (riece-completing-read-identity
                "Channel/User: " riece-current-channels)
           (if current-prefix-arg
               (riece-completing-read-identity
                "Channel/User: " riece-current-channels)
+            (riece-check-channel-commands-are-usable t)
             riece-current-channel))
          (riece-overriding-server-name (riece-identity-server channel))
          (riece-temp-minibuffer-message
             riece-current-channel))
          (riece-overriding-server-name (riece-identity-server channel))
          (riece-temp-minibuffer-message
 
 (defun riece-command-set-operators (users &optional arg)
   (interactive
 
 (defun riece-command-set-operators (users &optional arg)
   (interactive
-   (let ((operators
-         (riece-with-server-buffer
-             (riece-identity-server riece-current-channel)
-           (riece-channel-get-operators
-            (riece-identity-prefix riece-current-channel))))
-        (completion-ignore-case t)
-        users)
-     (if current-prefix-arg
-        (setq users (riece-completing-read-multiple
-                     "Users"
-                     (mapcar #'list operators)))
-       (setq users (riece-completing-read-multiple
-                   "Users"
-                   (delq nil (mapcar
-                              (lambda (user)
-                                (unless (member user operators)
-                                  (list user)))
-                              (riece-with-server-buffer
-                                  (riece-identity-server
-                                   riece-current-channel)
-                                (riece-channel-get-users
-                                 (riece-identity-prefix
-                                  riece-current-channel))))))))
-     (list users current-prefix-arg)))
+   (progn
+     (riece-check-channel-commands-are-usable t)
+     (let ((completion-ignore-case t))
+       (list (riece-completing-read-multiple
+             "Users"
+             (riece-with-server-buffer
+                 (riece-identity-server riece-current-channel)
+               (riece-channel-get-users (riece-identity-prefix
+                                        riece-current-channel)))
+             (if current-prefix-arg
+                 (lambda (user)
+                   (memq ?o (cdr user)))
+               (lambda (user)
+                 (not (memq ?o (cdr user))))))
+            current-prefix-arg))))
   (let (group)
     (while users
       (setq group (cons (car users) group)
   (let (group)
     (while users
       (setq group (cons (car users) group)
 
 (defun riece-command-set-speakers (users &optional arg)
   (interactive
 
 (defun riece-command-set-speakers (users &optional arg)
   (interactive
-   (let ((speakers
-         (riece-with-server-buffer
-             (riece-identity-server riece-current-channel)
-           (riece-channel-get-speakers
-            (riece-identity-prefix riece-current-channel))))
-        (completion-ignore-case t)
-        users)
-     (if current-prefix-arg
-        (setq users (riece-completing-read-multiple
-                     "Users"
-                     (mapcar #'list speakers)))
-       (setq users (riece-completing-read-multiple
-                   "Users"
-                   (delq nil (mapcar
-                              (lambda (user)
-                                (unless (member user speakers)
-                                  (list user)))
-                              (riece-with-server-buffer
-                                  (riece-identity-server
-                                   riece-current-channel)
-                                (riece-channel-get-users
-                                 (riece-identity-prefix
-                                  riece-current-channel))))))))
-     (list users current-prefix-arg)))
+   (progn
+     (riece-check-channel-commands-are-usable t)
+     (let ((completion-ignore-case t))
+       (list (riece-completing-read-multiple
+             "Users"
+             (riece-with-server-buffer
+                 (riece-identity-server riece-current-channel)
+               (riece-channel-get-users (riece-identity-prefix
+                                         riece-current-channel)))
+             (if current-prefix-arg
+                 (lambda (user)
+                   (memq ?v (cdr user)))
+               (lambda (user)
+                 (not (memq ?v (cdr user))))))
+            current-prefix-arg))))
   (let (group)
     (while users
       (setq group (cons (car users) group)
   (let (group)
     (while users
       (setq group (cons (car users) group)
   "Send MESSAGE to the current channel."
   (if (equal message "")
       (error "No text to send"))
   "Send MESSAGE to the current channel."
   (if (equal message "")
       (error "No text to send"))
-  (unless riece-current-channel
-    (error (substitute-command-keys
-           "Type \\[riece-command-join] to join a channel")))
+  (riece-check-channel-commands-are-usable)
   (if notice
       (progn
        (riece-send-string
   (if notice
       (progn
        (riece-send-string
   (let ((next-line-add-newlines t))
     (next-line 1)))
 
   (let ((next-line-add-newlines t))
     (next-line 1)))
 
+(defun riece-command-enter-message-to-user (user)
+  "Send the current line to USER."
+  (interactive
+   (let ((completion-ignore-case t))
+     (list (riece-completing-read-identity
+           "User: "
+           (riece-get-users-on-server (riece-current-server-name))))))
+  (let ((text (buffer-substring
+              (riece-line-beginning-position)
+              (riece-line-end-position))))
+    (riece-send-string
+     (format "PRIVMSG %s :%s\r\n" (riece-identity-prefix user) text))
+    (riece-display-message
+     (riece-make-message (riece-current-nickname) user text nil t)))
+  (let ((next-line-add-newlines t))
+    (next-line 1)))
+
 (defun riece-command-join-channel (target key)
   (let ((process (riece-server-process (riece-identity-server target))))
     (unless process
 (defun riece-command-join-channel (target key)
   (let ((process (riece-server-process (riece-identity-server target))))
     (unless process
   (interactive
    (let* ((completion-ignore-case t)
          (target
   (interactive
    (let* ((completion-ignore-case t)
          (target
-          (riece-completing-read-identity
-           "Channel/User: " riece-current-channels))
+          (if riece-join-channel-candidate
+              (let ((default (riece-format-identity
+                              riece-join-channel-candidate)))
+                (riece-completing-read-identity
+                 (format "Channel/User (default %s): " default)
+                 riece-current-channels nil nil nil nil default))
+            (riece-completing-read-identity
+             "Channel/User: " riece-current-channels)))
          key)
      (if (and current-prefix-arg
          key)
      (if (and current-prefix-arg
-             (riece-channel-p target))
+             (riece-channel-p (riece-identity-prefix target)))
         (setq key
         (setq key
-              (riece-read-passwd (format "Key for %s: " target))))
+              (riece-read-passwd (format "Key for %s: "
+                                         (riece-format-identity target)))))
      (list target key)))
   (let ((pointer (riece-identity-member target riece-current-channels)))
     (if pointer
      (list target key)))
   (let ((pointer (riece-identity-member target riece-current-channels)))
     (if pointer
 
 (defun riece-command-part-channel (target message)
   (let ((process (riece-server-process (riece-identity-server target))))
 
 (defun riece-command-part-channel (target message)
   (let ((process (riece-server-process (riece-identity-server target))))
-    (unless process
-      (error "%s" (substitute-command-keys
-                  "Type \\[riece-command-open-server] to open server.")))
     (riece-process-send-string process
                               (if message
                                   (format "PART %s :%s\r\n"
     (riece-process-send-string process
                               (if message
                                   (format "PART %s :%s\r\n"
 
 (defun riece-command-part (target &optional message)
   (interactive
 
 (defun riece-command-part (target &optional message)
   (interactive
-   (let* ((completion-ignore-case t)
-        (target
-         (riece-completing-read-identity
-          "Channel/User: " riece-current-channels nil nil
-          (cons (riece-format-identity riece-current-channel) 0)))
-        message)
-     (if (and current-prefix-arg
-             (riece-channel-p (riece-identity-prefix target)))
-        (setq message (read-string "Message: ")))
-     (list target message)))
+   (progn
+     (riece-check-channel-commands-are-usable)
+     (let* ((completion-ignore-case t)
+           (target
+            (riece-completing-read-identity
+             (format "Channel/User (default %s): "
+                     (riece-format-identity riece-current-channel))
+             riece-current-channels nil nil nil nil
+             (riece-format-identity riece-current-channel)))
+           message)
+       (if (and current-prefix-arg
+               (riece-channel-p (riece-identity-prefix target)))
+          (setq message (read-string "Message: ")))
+       (list target message))))
   (if (riece-identity-member target riece-current-channels)
       (if (riece-channel-p (riece-identity-prefix target))
          (riece-command-part-channel target message)
   (if (riece-identity-member target riece-current-channels)
       (if (riece-channel-p (riece-identity-prefix target))
          (riece-command-part-channel target message)
 (defun riece-command-toggle-away (&optional message)
   "Mark yourself as being away."
   (interactive
 (defun riece-command-toggle-away (&optional message)
   "Mark yourself as being away."
   (interactive
-   (if (and (not (riece-user-get-away (riece-current-nickname)))
+   (if (and (not (riece-with-server-buffer (riece-identity-server
+                                           (riece-current-nickname))
+                  (riece-user-get-away (riece-identity-prefix
+                                        (riece-current-nickname)))))
            (or (null riece-away-message)
                current-prefix-arg))
        (let ((message (read-string "Away message: ")))
            (or (null riece-away-message)
                current-prefix-arg))
        (let ((message (read-string "Away message: ")))
@@ -562,13 +582,10 @@ If prefix argument ARG is non-nil, toggle frozen status."
                 (read-string "Message: ")
               (or riece-quit-message
                   (riece-extended-version))))
                 (read-string "Message: ")
               (or riece-quit-message
                   (riece-extended-version))))
-           (process-list riece-process-list))
-       (while process-list
-         (riece-process-send-string (car process-list)
-                                    (if message
-                                      (format "QUIT :%s\r\n" message)
-                                    "QUIT\r\n"))
-         (setq process-list (cdr process-list))))))
+           (alist riece-server-process-alist))
+       (while alist
+         (riece-quit-server-process (cdr (car alist)) message)
+         (setq alist (cdr alist))))))
 
 (defun riece-command-raw (command)
   "Enter raw IRC command, which is sent to the server."
 
 (defun riece-command-raw (command)
   "Enter raw IRC command, which is sent to the server."
@@ -606,32 +623,17 @@ If prefix argument ARG is non-nil, toggle frozen status."
 
 (defun riece-command-close-server (server-name &optional message)
   (interactive
 
 (defun riece-command-close-server (server-name &optional message)
   (interactive
-   (list (completing-read
-         "Server: "
-         (mapcar
-          (lambda (process)
-            (with-current-buffer (process-buffer process)
-              (list riece-server-name)))
-          riece-process-list))
+   (list (completing-read "Server: " riece-server-process-alist)
         (if current-prefix-arg
             (read-string "Message: ")
           (or riece-quit-message
               (riece-extended-version)))))
         (if current-prefix-arg
             (read-string "Message: ")
           (or riece-quit-message
               (riece-extended-version)))))
-  (riece-process-send-string (riece-server-process server-name)
-                            (if message
-                                (format "QUIT :%s\r\n" message)
-                              "QUIT\r\n")))
+  (riece-quit-server-process (riece-server-process server-name) message))
 
 (defun riece-command-universal-server-name-argument ()
   (interactive)
   (let* ((riece-overriding-server-name
 
 (defun riece-command-universal-server-name-argument ()
   (interactive)
   (let* ((riece-overriding-server-name
-         (completing-read
-          "Server: "
-          (mapcar
-           (lambda (process)
-             (with-current-buffer (process-buffer process)
-               (list riece-server-name)))
-           riece-process-list)))
+         (completing-read "Server: " riece-server-process-alist))
         (command
          (key-binding (read-key-sequence
                        (format "Command to execute on \"%s\":"
         (command
          (key-binding (read-key-sequence
                        (format "Command to execute on \"%s\":"