* riece-keepalive.el: Require 'riece-options.
[riece] / lisp / riece-commands.el
index 3436926..e65173a 100644 (file)
 
 (defun riece-command-configure-windows ()
   (interactive)
+  "Reconfigure windows with the current layout."
   (riece-redisplay-buffers t))
 
+(defun riece-command-suspend-resume ()
+  (interactive)
+  "Save or restore the current window configuration."
+  (let ((entry (assq 'riece-window-configuration (frame-parameters))))
+    (modify-frame-parameters (selected-frame)
+                            (list (cons 'riece-window-configuration
+                                        (current-window-configuration))))
+    (if entry
+       (set-window-configuration (cdr entry))
+      (delete-other-windows))
+    (message
+     (substitute-command-keys
+      "\\[riece-command-suspend-resume] to get back the last windows"))))
+
 (defun riece-command-change-layout (name)
   "Select a layout-name from all current available layouts and change
 the layout to the selected layout-name."
@@ -278,7 +293,7 @@ the layout to the selected layout-name."
   (if (equal change "")
       (riece-send-string (format "MODE %s\r\n"
                                 (riece-identity-prefix channel)))
-    (riece-send-string (format "MODE %s :%s\r\n"
+    (riece-send-string (format "MODE %s %s\r\n"
                               (riece-identity-prefix channel)
                               change))))
 
@@ -354,6 +369,7 @@ the layout to the selected layout-name."
 
 (defun riece-command-send-message (message notice)
   "Send MESSAGE to the current channel."
+  (run-hooks 'riece-command-send-message-hook)
   (if (equal message "")
       (error "No text to send"))
   (riece-check-channel-commands-are-usable)
@@ -397,11 +413,13 @@ the layout to the selected layout-name."
 (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
-           "Message to user: "
-           (riece-get-users-on-server (riece-current-server-name))
-           nil nil nil nil nil t))))
+   (if (and (bolp) (eolp))
+       (error "No text to send")
+     (let ((completion-ignore-case t))
+       (list (riece-completing-read-identity
+             "Message to user: "
+             (riece-get-users-on-server (riece-current-server-name))
+             nil nil nil nil nil t)))))
   (let ((text (buffer-substring
               (riece-line-beginning-position)
               (riece-line-end-position))))
@@ -432,32 +450,25 @@ the layout to the selected layout-name."
       (riece-join-channel target)
       (riece-switch-to-channel target))))
 
-(defun riece-command-join (target &optional key)
+(defun riece-command-join (target)
   (interactive
-   (let* ((completion-ignore-case t)
-         (target
-          (if riece-join-channel-candidate
-              (let ((default (riece-format-identity
-                              riece-join-channel-candidate)))
-                (riece-completing-read-identity
-                 (format "Join channel/user (default %s): " default)
-                 (riece-get-identities-on-server (riece-current-server-name))
-                 nil nil nil nil default))
-            (riece-completing-read-identity
-             "Join channel/user: "
-             (riece-get-identities-on-server (riece-current-server-name)))))
-         key)
-     (if (and current-prefix-arg
-             (riece-channel-p (riece-identity-prefix target)))
-        (setq key
-              (riece-read-passwd (format "Key for %s: "
-                                         (riece-format-identity target)))))
-     (list target key)))
+   (let ((completion-ignore-case t))
+     (list
+      (if riece-join-channel-candidate
+         (let ((default (riece-format-identity
+                         riece-join-channel-candidate)))
+           (riece-completing-read-identity
+            (format "Join channel/user (default %s): " default)
+            (riece-get-identities-on-server (riece-current-server-name))
+            nil nil nil nil default))
+       (riece-completing-read-identity
+        "Join channel/user: "
+        (riece-get-identities-on-server (riece-current-server-name)))))))
   (let ((pointer (riece-identity-member target riece-current-channels)))
     (if pointer
        (riece-command-switch-to-channel (car pointer))
       (if (riece-channel-p (riece-identity-prefix target))
-         (riece-command-join-channel target key)
+         (riece-command-join-channel target nil)
        (riece-command-join-partner target)))))
 
 (defun riece-command-part-channel (target message)
@@ -470,7 +481,7 @@ the layout to the selected layout-name."
                                 (format "PART %s\r\n"
                                         (riece-identity-prefix target))))))
 
-(defun riece-command-part (target &optional message)
+(defun riece-command-part (target)
   (interactive
    (progn
      (riece-check-channel-commands-are-usable)
@@ -481,10 +492,10 @@ the layout to the selected layout-name."
                      (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: ")))
+           (message
+            (if current-prefix-arg
+                (read-string "Message: ")
+              riece-part-message)))
        (list target message))))
   (if (riece-identity-member target riece-current-channels)
       (if (riece-channel-p (riece-identity-prefix target))
@@ -613,7 +624,7 @@ If prefix argument ARG is non-nil, toggle frozen status."
        (let ((message
               (if arg
                   (read-string "Message: ")
-              riece-quit-message))
+                riece-quit-message))
              (alist riece-server-process-alist))
          (while alist
            (riece-quit-server-process (cdr (car alist)) message)
@@ -624,8 +635,23 @@ If prefix argument ARG is non-nil, toggle frozen status."
   (interactive "sIRC command: ")
   (riece-send-string (concat command "\r\n")))
 
+(defun riece-command-beginning-of-buffer ()
+  "Scroll channel buffer to the beginning."
+  (interactive)
+  (let (buffer window)
+    (setq buffer (if riece-channel-buffer-mode
+                    riece-channel-buffer
+                  riece-dialogue-buffer))
+    (or (setq window (get-buffer-window buffer))
+       (setq window (get-buffer-window riece-dialogue-buffer)
+             buffer riece-dialogue-buffer))
+    (when window
+      (save-selected-window
+       (select-window window)
+       (goto-char (point-min))))))
+
 (defun riece-command-end-of-buffer ()
-  "Get end of the dialogue buffer."
+  "Scroll channel buffer to the end."
   (interactive)
   (let (buffer window)
     (setq buffer (if riece-channel-buffer-mode
@@ -652,7 +678,7 @@ If prefix argument ARG is non-nil, toggle frozen status."
                          (list (riece-format-identity user t)))
                        (riece-get-users-on-server
                         (riece-current-server-name))))
-        (current (current-word))
+        (current (or (current-word) ""))
         (completion (try-completion current table))
         (all (all-completions current table)))
     (if (eq completion t)
@@ -662,6 +688,7 @@ If prefix argument ARG is non-nil, toggle frozen status."
        (if (equal current completion)
            (with-output-to-temp-buffer "*Help*"
              (display-completion-list all))
+         (re-search-forward "\\>" nil t)
          (delete-region (point) (- (point) (length current)))
          (insert completion))))))