* riece-filter.el (riece-sentinel): Simplified.
[riece] / lisp / riece-commands.el
index ea07bd9..f5adb10 100644 (file)
@@ -38,7 +38,7 @@
 ;;; Channel movement:
 (defun riece-command-switch-to-channel (channel)
   (interactive
-   (list (completing-read "Channel/user: "
+   (list (completing-read "Channel/User: "
                          (mapcar #'list riece-current-channels)
                          nil t)))
   (riece-switch-to-channel channel)
 (defun riece-command-next-channel ()
   "Select the next channel."
   (interactive)
-  (let ((pointer (cdr (string-list-member-ignore-case
-                      riece-current-channel
-                      riece-current-channels))))
-    (while (and pointer
-               (null (car pointer)))
-      (setq pointer (cdr pointer)))
-    (if (car pointer)
-       (riece-command-switch-to-channel (car pointer))
-      (error "No such channel!"))))
+  (when (> (length riece-current-channels) 1)
+    (let ((pointer (cdr (string-list-member-ignore-case
+                        riece-current-channel
+                        riece-current-channels))))
+      (while (and pointer
+                 (null (car pointer)))
+       (setq pointer (cdr pointer)))
+      (if (car pointer)
+         (riece-command-switch-to-channel (car pointer))
+       (error "No such channel!")))))
 
 (defun riece-command-previous-channel ()
   "Select the previous channel."
   (interactive)
-  (let ((pointer (string-list-member-ignore-case
-                 riece-current-channel
-                 riece-current-channels))
-       (start riece-current-channels)
-       channel)
-    (while (and start (not (eq start pointer)))
-      (if (car start)
-         (setq channel (car start)))
-      (setq start (cdr start)))
-    (if channel
-       (riece-command-switch-to-channel channel)
-      (error "No such channel!"))))
+  (when (> (length riece-current-channels) 1)
+    (let ((pointer (string-list-member-ignore-case
+                   riece-current-channel
+                   riece-current-channels))
+         (start riece-current-channels)
+         channel)
+      (while (and start (not (eq start pointer)))
+       (if (car start)
+           (setq channel (car start)))
+       (setq start (cdr start)))
+      (if channel
+         (riece-command-switch-to-channel channel)
+       (error "No such channel!")))))
 
 (defun riece-command-select-command-buffer ()
   "Select the command buffer."
 (defun riece-command-toggle-channel-buffer-mode ()
   (interactive)
   (setq riece-channel-buffer-mode
-       (not riece-channel-buffer-mode))
+       (not riece-channel-buffer-mode)
+       riece-save-variables-are-dirty t)
   (riece-command-configure-windows))
 
 (defun riece-command-toggle-user-list-buffer-mode ()
   (interactive)
   (setq riece-user-list-buffer-mode
-       (not riece-user-list-buffer-mode))
+       (not riece-user-list-buffer-mode)
+       riece-save-variables-are-dirty t)
   (riece-command-configure-windows))
 
 (defun riece-command-toggle-channel-list-buffer-mode ()
   (interactive)
   (setq riece-channel-list-buffer-mode
-       (not riece-channel-list-buffer-mode))
+       (not riece-channel-list-buffer-mode)
+       riece-save-variables-are-dirty t)
   (riece-command-configure-windows))
 
-(defun riece-get-users-on-server ()
-  (riece-with-server-buffer
-   (let (users)
-     (mapatoms
-      (lambda (atom)
-       (unless (riece-channel-p (symbol-name atom))
-         (push (symbol-name atom) users)))
-      riece-obarray)
-     (if (member riece-real-nickname users)
-        users
-       (cons riece-real-nickname users)))))
-
 (defun riece-command-finger (user &optional recurse)
   (interactive
    (let* ((completion-ignore-case t)
                             (riece-identity-prefix riece-current-channel)
                             topic)))
 
-(defun riece-command-invite (&optional user channel)
+(defun riece-command-invite (user)
   (interactive
-   (let ((completion-ignore-case t)
-        user channel)
-     (if current-prefix-arg
-        (setq channel
-              (completing-read
-               "Channel: "
-               (mapcar #'list riece-current-channels))))
+   (let ((completion-ignore-case t))
+     (unless (and riece-current-channel
+                 (riece-channel-p riece-current-channel))
+       (error "Not on a channel"))
      (list (completing-read
            "User: "
-           (mapcar #'list (riece-get-users-on-server)))
-          channel)))
-  (if channel
-      (riece-send-string (format "INVITE %s %s\r\n"
-                                user (riece-identity-prefix channel)))
-    (riece-send-string (format "INVITE %s %s\r\n"
-                              user (riece-identity-prefix
-                                    riece-current-channel)))))
+           (mapcar #'list (riece-get-users-on-server))))))
+  (riece-send-string (format "INVITE %s %s\r\n"
+                            user (riece-identity-prefix
+                                  riece-current-channel))))
+
+(defun riece-command-kick (user &optional message)
+  (interactive
+   (let ((completion-ignore-case t))
+     (unless (and riece-current-channel
+                 (riece-channel-p riece-current-channel))
+       (error "Not on a channel"))
+     (list (completing-read
+           "User: "
+           (mapcar #'list (riece-channel-get-users
+                           riece-current-channel)))
+          (if current-prefix-arg
+              (read-string "Message: ")))))
+  (riece-send-string
+   (if message
+       (format "KICK %s %s :%s\r\n"
+              (riece-identity-prefix riece-current-channel)
+              user message)
+     (format "KICK %s %s\r\n"
+            (riece-identity-prefix riece-current-channel)
+            user))))
+
+(defun riece-command-names (pattern)
+  (interactive
+   (let ((completion-ignore-case t))
+     (list (read-from-minibuffer
+           "Pattern: "
+           (if (and riece-current-channel
+                    (riece-channel-p riece-current-channel))
+               (cons (riece-identity-prefix riece-current-channel)
+                     0))))))
+  (if (or (not (equal pattern ""))
+         (yes-or-no-p "Really want to query NAMES without argument? "))
+      (riece-send-string (format "NAMES %s\r\n" pattern))))
+
+(defun riece-command-who (pattern)
+  (interactive
+   (let ((completion-ignore-case t))
+     (list (read-from-minibuffer
+           "Pattern: "
+           (if (and riece-current-channel
+                    (riece-channel-p riece-current-channel))
+               (cons (riece-identity-prefix riece-current-channel)
+                     0))))))
+  (if (or (not (equal pattern ""))
+         (yes-or-no-p "Really want to query WHO without argument? "))
+      (riece-send-string (format "WHO %s\r\n" pattern))))
+
+(defun riece-command-list (pattern)
+  (interactive
+   (let ((completion-ignore-case t))
+     (list (read-from-minibuffer
+           "Pattern: "
+           (if (and riece-current-channel
+                    (riece-channel-p riece-current-channel))
+               (cons (riece-identity-prefix riece-current-channel)
+                     0))))))
+  (if (or (not (equal pattern ""))
+         (yes-or-no-p "Really want to query LIST without argument? "))
+      (riece-send-string (format "LIST %s\r\n" pattern))))
 
 (defun riece-command-change-mode (channel change)
   (interactive
          (channel
           (if current-prefix-arg
               (completing-read
-               "Channel/user: "
+               "Channel/User: "
                (mapcar #'list riece-current-channels))
             riece-current-channel))
          (riece-overriding-server-name (riece-identity-server channel))
      (list users current-prefix-arg)))
   (let (group)
     (while users
-      (push (pop users) group)
+      (setq group (cons (car users) group)
+           users (cdr users))
       (if (or (= (length group) 3)
              (null users))
          (riece-send-string
      (list users current-prefix-arg)))
   (let (group)
     (while users
-      (push (pop users) group)
+      (setq group (cons (car users) group)
+           users (cdr users))
       (if (or (= (length group) 3)
              (null users))
          (riece-send-string
                   (make-string (length group) ?v)
                   (mapconcat #'identity group " ")))))))
 
-(defun riece-command-send-message (message)
+(defun riece-command-send-message (message notice)
   "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-send-string
-   (format "PRIVMSG %s :%s\r\n"
-          (riece-identity-prefix riece-current-channel)
-          message))
-  (riece-own-channel-message message))
+  (if notice
+      (progn
+       (riece-send-string
+        (format "NOTICE %s :%s\r\n"
+                (riece-identity-prefix riece-current-channel)
+                message))
+       (riece-own-channel-message message riece-current-channel 'notice))
+    (riece-send-string
+     (format "PRIVMSG %s :%s\r\n"
+            (riece-identity-prefix riece-current-channel)
+            message))
+    (riece-own-channel-message message)))
 
 (defun riece-command-enter-message ()
   "Send the current line to the current channel."
   (interactive)
   (riece-command-send-message (buffer-substring
                               (riece-line-beginning-position)
-                              (riece-line-end-position)))
+                              (riece-line-end-position))
+                             nil)
+  (let ((next-line-add-newlines t))
+    (next-line 1)))
+
+(defun riece-command-enter-message-as-notice ()
+  "Send the current line to the current channel as NOTICE."
+  (interactive)
+  (riece-command-send-message (buffer-substring
+                              (riece-line-beginning-position)
+                              (riece-line-end-position))
+                             t)
   (let ((next-line-add-newlines t))
     (next-line 1)))
 
   (interactive
    (let ((completion-ignore-case t)
         (target
-         (completing-read "Channel/user: "
+         (completing-read "Channel/User: "
                           (mapcar #'list riece-current-channels)))
         key)
      (if (and current-prefix-arg
   (interactive
    (let ((completion-ignore-case t)
         (target
-         (completing-read "Channel/user: "
+         (completing-read "Channel/User: "
                           (mapcar #'list riece-current-channels)
                           nil t (cons riece-current-channel 0)))
         message)
@@ -490,12 +556,9 @@ If prefix argument ARG is non-nil, toggle frozen status."
 (defun riece-command-open-server (server-name)
   (interactive
    (list (completing-read "Server: " riece-server-alist)))
-  (let ((process (riece-start-server
-                 (riece-server-name-to-server server-name)
-                 server-name)))
-    (with-current-buffer (process-buffer process)
-      (setq riece-server-name server-name))
-    (push (cons server-name process) riece-server-process-alist)))
+  (riece-open-server
+   (riece-server-name-to-server server-name)
+   server-name))
 
 (defun riece-command-close-server (server-name &optional message)
   (interactive