X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-commands.el;h=039543d7aa0c1ed6b309a4403c273dd11d06f7ee;hp=ed5dcbdc0f5c75e29d82a031c62abc460fb83af8;hb=9f6396c152d5235237321945ce81a9883b01d609;hpb=57d046780969b7e65645f16ed42e178b43b8e206 diff --git a/lisp/riece-commands.el b/lisp/riece-commands.el index ed5dcbd..039543d 100644 --- a/lisp/riece-commands.el +++ b/lisp/riece-commands.el @@ -24,10 +24,9 @@ ;;; Code: -(eval-when-compile (require 'riece-inlines)) - (require 'riece-channel) (require 'riece-complete) +(require 'riece-layout) (require 'riece-display) (require 'riece-version) (require 'riece-server) @@ -37,12 +36,11 @@ ;;; Channel movement: (defun riece-command-switch-to-channel (channel) - (interactive - (list (completing-read "Channel/User: " - (mapcar #'list riece-current-channels) - nil t))) - (riece-switch-to-channel channel) - (riece-command-configure-windows)) + (interactive (list (riece-completing-read-identity + "Channel/User: " riece-current-channels nil t))) + (unless (equal channel riece-current-channel) + (riece-switch-to-channel channel) + (riece-redisplay-buffers))) (defun riece-command-switch-to-channel-by-number (number) (interactive @@ -50,17 +48,11 @@ (if (string-match "[0-9]+$" command-name) (list (string-to-number (match-string 0 command-name))) (list (string-to-number (read-string "Number: ")))))) - (let ((channels riece-current-channels) - (index 1)) - (while (and channels - (< index number)) - (if (car channels) - (setq index (1+ index))) - (setq channels (cdr channels))) - (if (car channels) - (riece-command-switch-to-channel (car channels)) + (let ((channel (nth (1- number) riece-current-channels))) + (if channel + (riece-command-switch-to-channel channel) (error "No such number!")))) - + (eval-and-compile (let ((number 1)) (while (<= number 20) @@ -73,7 +65,7 @@ "Select the next channel." (interactive) (when (> (length riece-current-channels) 1) - (let ((pointer (cdr (scandinavian-member-ignore-case + (let ((pointer (cdr (riece-identity-member riece-current-channel riece-current-channels)))) (while (and pointer @@ -92,13 +84,14 @@ "Select the previous channel." (interactive) (when (> (length riece-current-channels) 1) - (let ((pointer (scandinavian-member-ignore-case + (let ((pointer (riece-identity-member riece-current-channel riece-current-channels)) (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)) @@ -120,6 +113,14 @@ (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 @@ -144,21 +145,29 @@ (defun riece-command-finger (user &optional recurse) (interactive (let* ((completion-ignore-case t) - (user (completing-read + (user (riece-completing-read-identity "User: " - (mapcar #'list (riece-get-users-on-server))))) + (riece-get-users-on-server (riece-current-server-name))))) (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 - (list (read-from-minibuffer - "Topic: " (cons (or (riece-channel-get-topic - 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))) @@ -166,26 +175,24 @@ (defun riece-command-invite (user) (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 + (riece-check-channel-commands-are-usable t) + (list (riece-completing-read-identity "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" - 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)) - (unless (and riece-current-channel - (riece-channel-p riece-current-channel)) - (error "Not on a channel")) + (riece-check-channel-commands-are-usable t) (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 @@ -203,7 +210,8 @@ (list (read-from-minibuffer "Pattern: " (if (and riece-current-channel - (riece-channel-p riece-current-channel)) + (riece-channel-p (riece-identity-prefix + riece-current-channel))) (cons (riece-identity-prefix riece-current-channel) 0)))))) (if (or (not (equal pattern "")) @@ -216,7 +224,8 @@ (list (read-from-minibuffer "Pattern: " (if (and riece-current-channel - (riece-channel-p riece-current-channel)) + (riece-channel-p (riece-identity-prefix + riece-current-channel))) (cons (riece-identity-prefix riece-current-channel) 0)))))) (if (or (not (equal pattern "")) @@ -229,7 +238,8 @@ (list (read-from-minibuffer "Pattern: " (if (and riece-current-channel - (riece-channel-p riece-current-channel)) + (riece-channel-p (riece-identity-prefix + riece-current-channel))) (cons (riece-identity-prefix riece-current-channel) 0)))))) (if (or (not (equal pattern "")) @@ -241,44 +251,45 @@ (let* ((completion-ignore-case t) (channel (if current-prefix-arg - (completing-read - "Channel/User: " - (mapcar #'list riece-current-channels)) + (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 (concat "[Available modes: " - (riece-with-server-buffer - (if (and (riece-channel-p channel) - riece-supported-channel-modes) - (apply #'string riece-supported-channel-modes) - (if (and (not (riece-channel-p channel)) - riece-supported-user-modes) - (apply #'string riece-supported-user-modes)))) + (riece-with-server-buffer (riece-identity-server channel) + (if (riece-channel-p (riece-identity-prefix channel)) + (if riece-supported-channel-modes + (apply #'string riece-supported-channel-modes)) + (if riece-supported-user-modes + (apply #'string riece-supported-user-modes)))) "]"))) (list channel (read-from-minibuffer - (concat (riece-concat-modes channel "Mode (? for help)") ": ") + (concat (riece-concat-channel-modes + channel "Mode (? for help)") ": ") nil riece-minibuffer-map)))) - (riece-send-string (format "MODE %s :%s\r\n" channel change))) + (riece-send-string (format "MODE %s :%s\r\n" (riece-identity-prefix channel) + change))) (defun riece-command-set-operators (users &optional arg) (interactive - (let ((operators (riece-channel-get-operators 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-channel-get-users - 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) @@ -296,21 +307,21 @@ (defun riece-command-set-speakers (users &optional arg) (interactive - (let ((speakers (riece-channel-get-speakers 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-channel-get-users - 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) @@ -330,21 +341,23 @@ "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 (format "NOTICE %s :%s\r\n" (riece-identity-prefix riece-current-channel) message)) - (riece-own-channel-message message riece-current-channel 'notice)) + (riece-display-message + (riece-make-message (riece-current-nickname) riece-current-channel + message 'notice t))) (riece-send-string (format "PRIVMSG %s :%s\r\n" (riece-identity-prefix riece-current-channel) message)) - (riece-own-channel-message message))) + (riece-display-message + (riece-make-message (riece-current-nickname) riece-current-channel + message nil t)))) (defun riece-command-enter-message () "Send the current line to the current channel." @@ -366,12 +379,25 @@ (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 ((server-name (riece-identity-server target)) - process) - (if server-name - (setq process (cdr (assoc server-name riece-server-process-alist))) - (setq process riece-server-process)) + (let ((process (riece-server-process (riece-identity-server target)))) (unless process (error "%s" (substitute-command-keys "Type \\[riece-command-open-server] to open server."))) @@ -384,7 +410,7 @@ (riece-identity-prefix target)))))) (defun riece-command-join-partner (target) - (let ((pointer (riece-identity-member-safe target riece-current-channels))) + (let ((pointer (riece-identity-member target riece-current-channels))) (if pointer (riece-command-switch-to-channel (car pointer)) (riece-join-channel target) @@ -393,32 +419,32 @@ (defun riece-command-join (target &optional key) (interactive - (let ((completion-ignore-case t) - (target - (completing-read "Channel/User: " - (mapcar #'list riece-current-channels))) - key) + (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 "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 - (riece-channel-p target)) + (riece-channel-p (riece-identity-prefix target))) (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-safe target riece-current-channels))) + (let ((pointer (riece-identity-member target riece-current-channels))) (if pointer (riece-command-switch-to-channel (car pointer)) - (if (riece-channel-p target) + (if (riece-channel-p (riece-identity-prefix target)) (riece-command-join-channel target key) (riece-command-join-partner target))))) (defun riece-command-part-channel (target message) - (let ((server-name (riece-identity-server target)) - process) - (if server-name - (setq process (cdr (assoc server-name riece-server-process-alist))) - (setq process riece-server-process)) - (unless process - (error "%s" (substitute-command-keys - "Type \\[riece-command-open-server] to open server."))) + (let ((process (riece-server-process (riece-identity-server target)))) (riece-process-send-string process (if message (format "PART %s :%s\r\n" @@ -429,18 +455,22 @@ (defun riece-command-part (target &optional message) (interactive - (let ((completion-ignore-case t) - (target - (completing-read "Channel/User: " - (mapcar #'list riece-current-channels) - nil t (cons riece-current-channel 0))) - message) - (if (and current-prefix-arg - (riece-channel-p target)) - (setq message (read-string "Message: "))) - (list target message))) - (if (riece-identity-member-safe target riece-current-channels) - (if (riece-channel-p target) + (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) (riece-part-channel target) (riece-redisplay-buffers)) @@ -500,7 +530,10 @@ (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: "))) @@ -548,8 +581,11 @@ If prefix argument ARG is non-nil, toggle frozen status." (if arg (read-string "Message: ") (or riece-quit-message - (riece-extended-version))))) - (riece-close-all-server message)))) + (riece-extended-version)))) + (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." @@ -579,11 +615,11 @@ 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))) - (if (assoc server-name riece-server-process-alist) - (error "%s is already opened" server-name) - (riece-open-server - (riece-server-name-to-server server-name) - server-name))) + (if (riece-server-process server-name) + (error "%s is already opened" server-name)) + (riece-open-server + (riece-server-name-to-server server-name) + server-name)) (defun riece-command-close-server (server-name &optional message) (interactive @@ -592,13 +628,12 @@ If prefix argument ARG is non-nil, toggle frozen status." (read-string "Message: ") (or riece-quit-message (riece-extended-version))))) - (riece-close-server server-name message)) + (riece-quit-server-process (riece-server-process server-name) message)) (defun riece-command-universal-server-name-argument () (interactive) (let* ((riece-overriding-server-name - (completing-read "Server: " - riece-server-process-alist)) + (completing-read "Server: " riece-server-process-alist)) (command (key-binding (read-key-sequence (format "Command to execute on \"%s\":"