X-Git-Url: https://cgit.sxemacs.org/?p=riece;a=blobdiff_plain;f=lisp%2Friece-commands.el;h=3442c5d3c6be0f3a4a861564749dd38564a6df06;hp=7ed3322fab145e258d1faee3bfdf997971d018c5;hb=befd19f4c604901fe3e5ac71ac7151a6e3d3dc60;hpb=a5e19c37af7b4d289e9b8fe0c44c223305322a38 diff --git a/lisp/riece-commands.el b/lisp/riece-commands.el index 7ed3322..3442c5d 100644 --- a/lisp/riece-commands.el +++ b/lisp/riece-commands.el @@ -24,8 +24,6 @@ ;;; Code: -(eval-when-compile (require 'riece-inlines)) - (require 'riece-channel) (require 'riece-complete) (require 'riece-display) @@ -72,31 +70,42 @@ (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 (riece-identity-member-no-server + riece-current-channel + riece-current-channels)))) + (while (and pointer + (null (car pointer))) + (setq pointer (cdr pointer))) + (when (null pointer) + (setq pointer 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 (riece-identity-member-no-server + riece-current-channel + riece-current-channels)) + (start riece-current-channels) + channel) + (while (and start (not (eq start pointer))) + (setq channel (car start)) + (setq start (cdr start))) + (when (null channel) + (setq start (copy-sequence riece-current-channels)) + (setq start (delq nil start)) + (and (> (length start) 1) + (setq channel (nth (1- (length start)) start)))) + (if channel + (riece-command-switch-to-channel channel) + (error "No such channel!"))))) (defun riece-command-select-command-buffer () "Select the command buffer." @@ -112,19 +121,22 @@ (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-command-finger (user &optional recurse) @@ -209,6 +221,19 @@ (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 (let* ((completion-ignore-case t) @@ -254,7 +279,8 @@ (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 @@ -285,7 +311,8 @@ (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 @@ -297,25 +324,43 @@ (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))) @@ -337,7 +382,7 @@ (riece-identity-prefix target)))))) (defun riece-command-join-partner (target) - (let ((pointer (riece-identity-member target riece-current-channels))) + (let ((pointer (riece-identity-member-safe target riece-current-channels))) (if pointer (riece-command-switch-to-channel (car pointer)) (riece-join-channel target) @@ -346,17 +391,17 @@ (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 + (completing-read "Channel/User: " + (mapcar #'list riece-current-channels))) + key) (if (and current-prefix-arg (riece-channel-p target)) (setq key (riece-read-passwd (format "Key for %s: " target)))) (list target key))) - (let ((pointer (riece-identity-member target riece-current-channels))) + (let ((pointer (riece-identity-member-safe target riece-current-channels))) (if pointer (riece-command-switch-to-channel (car pointer)) (if (riece-channel-p target) @@ -382,17 +427,17 @@ (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) + (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 target riece-current-channels) + (if (riece-identity-member-safe target riece-current-channels) (if (riece-channel-p target) (riece-command-part-channel target message) (riece-part-channel target) @@ -453,7 +498,9 @@ (defun riece-command-toggle-away (&optional message) "Mark yourself as being away." (interactive - (if current-prefix-arg + (if (and (not (riece-user-get-away (riece-current-nickname))) + (or (null riece-away-message) + current-prefix-arg)) (let ((message (read-string "Away message: "))) (list message)))) (if message @@ -464,20 +511,32 @@ "Prevent automatic scrolling of the dialogue window. If prefix argument ARG is non-nil, toggle frozen status." (interactive "P") - (riece-freeze (if riece-channel-buffer-mode - riece-channel-buffer - riece-dialogue-buffer) - (if arg (prefix-numeric-value arg)))) + (with-current-buffer (if (and riece-channel-buffer-mode + riece-channel-buffer) + riece-channel-buffer + riece-dialogue-buffer) + (setq riece-freeze (if arg + (< 0 (prefix-numeric-value arg)) + (not riece-freeze)))) + (riece-update-status-indicators) + (force-mode-line-update t)) (defun riece-command-toggle-own-freeze (&optional arg) "Prevent automatic scrolling of the dialogue window. The difference from `riece-command-freeze' is that your messages are hidden. If prefix argument ARG is non-nil, toggle frozen status." (interactive "P") - (riece-own-freeze (if riece-channel-buffer-mode - riece-channel-buffer - riece-dialogue-buffer) - (if arg (prefix-numeric-value arg)))) + (with-current-buffer (if (and riece-channel-buffer-mode + riece-channel-buffer) + riece-channel-buffer + riece-dialogue-buffer) + (if (if arg + (< 0 (prefix-numeric-value arg)) + (not (eq riece-freeze 'own))) + (setq riece-freeze 'own) + (setq riece-freeze nil))) + (riece-update-status-indicators) + (force-mode-line-update t)) (defun riece-command-quit (&optional arg) "Quit IRC." @@ -518,12 +577,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))) - (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))) + (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))) (defun riece-command-close-server (server-name &optional message) (interactive