1 ;;; riece-commands.el --- commands available in command buffer
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 (eval-when-compile (require 'riece-inlines))
29 (require 'riece-channel)
30 (require 'riece-complete)
31 (require 'riece-display)
32 (require 'riece-version)
33 (require 'riece-server)
35 (require 'riece-identity)
36 (require 'riece-message)
39 (defun riece-command-switch-to-channel (channel)
41 (list (completing-read "Channel/User: "
42 (mapcar #'list riece-current-channels)
44 (riece-switch-to-channel channel)
45 (riece-command-configure-windows))
47 (defun riece-command-switch-to-channel-by-number (number)
49 (let ((command-name (symbol-name this-command)))
50 (if (string-match "[0-9]+$" command-name)
51 (list (string-to-number (match-string 0 command-name)))
52 (list (string-to-number (read-string "Number: "))))))
53 (let ((channels riece-current-channels)
58 (setq index (1+ index)))
59 (setq channels (cdr channels)))
61 (riece-command-switch-to-channel (car channels))
62 (error "No such number!"))))
67 (defalias (intern (concat "riece-command-switch-to-channel-by-number-"
68 (number-to-string number)))
69 'riece-command-switch-to-channel-by-number)
70 (setq number (1+ number)))))
72 (defun riece-command-next-channel ()
73 "Select the next channel."
75 (let ((pointer (cdr (string-list-member-ignore-case
77 riece-current-channels))))
80 (setq pointer (cdr pointer)))
82 (riece-command-switch-to-channel (car pointer))
83 (error "No such channel!"))))
85 (defun riece-command-previous-channel ()
86 "Select the previous channel."
88 (let ((pointer (string-list-member-ignore-case
90 riece-current-channels))
91 (start riece-current-channels)
93 (while (and start (not (eq start pointer)))
95 (setq channel (car start)))
96 (setq start (cdr start)))
98 (riece-command-switch-to-channel channel)
99 (error "No such channel!"))))
101 (defun riece-command-select-command-buffer ()
102 "Select the command buffer."
104 (let ((window (get-buffer-window riece-command-buffer)))
106 (select-window window))))
108 (defun riece-command-configure-windows ()
110 (riece-redisplay-buffers t))
112 (defun riece-command-toggle-channel-buffer-mode ()
114 (setq riece-channel-buffer-mode
115 (not riece-channel-buffer-mode))
116 (riece-command-configure-windows))
118 (defun riece-command-toggle-user-list-buffer-mode ()
120 (setq riece-user-list-buffer-mode
121 (not riece-user-list-buffer-mode))
122 (riece-command-configure-windows))
124 (defun riece-command-toggle-channel-list-buffer-mode ()
126 (setq riece-channel-list-buffer-mode
127 (not riece-channel-list-buffer-mode))
128 (riece-command-configure-windows))
130 (defun riece-command-finger (user &optional recurse)
132 (let* ((completion-ignore-case t)
133 (user (completing-read
135 (mapcar #'list (riece-get-users-on-server)))))
136 (list user current-prefix-arg)))
138 (riece-send-string (format "WHOIS %s %s\r\n" user user))
139 (riece-send-string (format "WHOIS %s\r\n" user))))
141 (defun riece-command-topic (topic)
143 (list (read-from-minibuffer
144 "Topic: " (cons (or (riece-channel-get-topic
145 riece-current-channel)
148 (riece-send-string (format "TOPIC %s :%s\r\n"
149 (riece-identity-prefix riece-current-channel)
152 (defun riece-command-invite (user)
154 (let ((completion-ignore-case t))
155 (unless (and riece-current-channel
156 (riece-channel-p riece-current-channel))
157 (error "Not on a channel"))
158 (list (completing-read
160 (mapcar #'list (riece-get-users-on-server))))))
161 (riece-send-string (format "INVITE %s %s\r\n"
162 user (riece-identity-prefix
163 riece-current-channel))))
165 (defun riece-command-kick (user &optional message)
167 (let ((completion-ignore-case t))
168 (unless (and riece-current-channel
169 (riece-channel-p riece-current-channel))
170 (error "Not on a channel"))
171 (list (completing-read
173 (mapcar #'list (riece-channel-get-users
174 riece-current-channel)))
175 (if current-prefix-arg
176 (read-string "Message: ")))))
179 (format "KICK %s %s :%s\r\n"
180 (riece-identity-prefix riece-current-channel)
182 (format "KICK %s %s\r\n"
183 (riece-identity-prefix riece-current-channel)
186 (defun riece-command-names (pattern)
188 (let ((completion-ignore-case t))
189 (list (read-from-minibuffer
191 (if (and riece-current-channel
192 (riece-channel-p riece-current-channel))
193 (cons (riece-identity-prefix riece-current-channel)
195 (if (or (not (equal pattern ""))
196 (yes-or-no-p "Really want to query NAMES without argument? "))
197 (riece-send-string (format "NAMES %s\r\n" pattern))))
199 (defun riece-command-who (pattern)
201 (let ((completion-ignore-case t))
202 (list (read-from-minibuffer
204 (if (and riece-current-channel
205 (riece-channel-p riece-current-channel))
206 (cons (riece-identity-prefix riece-current-channel)
208 (if (or (not (equal pattern ""))
209 (yes-or-no-p "Really want to query WHO without argument? "))
210 (riece-send-string (format "WHO %s\r\n" pattern))))
212 (defun riece-command-change-mode (channel change)
214 (let* ((completion-ignore-case t)
216 (if current-prefix-arg
219 (mapcar #'list riece-current-channels))
220 riece-current-channel))
221 (riece-overriding-server-name (riece-identity-server channel))
222 (riece-temp-minibuffer-message
223 (concat "[Available modes: "
224 (riece-with-server-buffer
225 (if (and (riece-channel-p channel)
226 riece-supported-channel-modes)
227 (apply #'string riece-supported-channel-modes)
228 (if (and (not (riece-channel-p channel))
229 riece-supported-user-modes)
230 (apply #'string riece-supported-user-modes))))
233 (read-from-minibuffer
234 (concat (riece-concat-modes channel "Mode (? for help)") ": ")
235 nil riece-minibuffer-map))))
236 (riece-send-string (format "MODE %s :%s\r\n" channel change)))
238 (defun riece-command-set-operators (users &optional arg)
240 (let ((operators (riece-channel-get-operators riece-current-channel))
241 (completion-ignore-case t)
243 (if current-prefix-arg
244 (setq users (riece-completing-read-multiple
246 (mapcar #'list operators)))
247 (setq users (riece-completing-read-multiple
249 (delq nil (mapcar (lambda (user)
250 (unless (member user operators)
252 (riece-channel-get-users
253 riece-current-channel))))))
254 (list users current-prefix-arg)))
257 (setq group (cons (car users) group)
259 (if (or (= (length group) 3)
262 (format "MODE %s %c%s %s\r\n"
263 (riece-identity-prefix riece-current-channel)
264 (if current-prefix-arg
267 (make-string (length group) ?o)
268 (mapconcat #'identity group " ")))))))
270 (defun riece-command-set-speakers (users &optional arg)
272 (let ((speakers (riece-channel-get-speakers riece-current-channel))
273 (completion-ignore-case t)
275 (if current-prefix-arg
276 (setq users (riece-completing-read-multiple
278 (mapcar #'list speakers)))
279 (setq users (riece-completing-read-multiple
281 (delq nil (mapcar (lambda (user)
282 (unless (member user speakers)
284 (riece-channel-get-users
285 riece-current-channel))))))
286 (list users current-prefix-arg)))
289 (setq group (cons (car users) group)
291 (if (or (= (length group) 3)
294 (format "MODE %s %c%s %s\r\n"
295 (riece-identity-prefix riece-current-channel)
296 (if current-prefix-arg
299 (make-string (length group) ?v)
300 (mapconcat #'identity group " ")))))))
302 (defun riece-command-send-message (message)
303 "Send MESSAGE to the current channel."
304 (if (equal message "")
305 (error "No text to send"))
306 (unless riece-current-channel
307 (error (substitute-command-keys
308 "Type \\[riece-command-join] to join a channel")))
310 (format "PRIVMSG %s :%s\r\n"
311 (riece-identity-prefix riece-current-channel)
313 (riece-own-channel-message message))
315 (defun riece-command-enter-message ()
316 "Send the current line to the current channel."
318 (riece-command-send-message (buffer-substring
319 (riece-line-beginning-position)
320 (riece-line-end-position)))
321 (let ((next-line-add-newlines t))
324 (defun riece-command-join-channel (target key)
325 (let ((server-name (riece-identity-server target))
328 (setq process (cdr (assoc server-name riece-server-process-alist)))
329 (setq process riece-server-process))
331 (error "%s" (substitute-command-keys
332 "Type \\[riece-command-open-server] to open server.")))
333 (riece-process-send-string process
335 (format "JOIN %s :%s\r\n"
336 (riece-identity-prefix target)
338 (format "JOIN %s\r\n"
339 (riece-identity-prefix target))))))
341 (defun riece-command-join-partner (target)
342 (let ((pointer (riece-identity-member target riece-current-channels)))
344 (riece-command-switch-to-channel (car pointer))
345 (riece-join-channel target)
346 (riece-switch-to-channel target)
347 (riece-redisplay-buffers))))
349 (defun riece-command-join (target &optional key)
351 (let ((completion-ignore-case t)
353 (completing-read "Channel/User: "
354 (mapcar #'list riece-current-channels)))
356 (if (and current-prefix-arg
357 (riece-channel-p target))
359 (riece-read-passwd (format "Key for %s: " target))))
361 (let ((pointer (riece-identity-member target riece-current-channels)))
363 (riece-command-switch-to-channel (car pointer))
364 (if (riece-channel-p target)
365 (riece-command-join-channel target key)
366 (riece-command-join-partner target)))))
368 (defun riece-command-part-channel (target message)
369 (let ((server-name (riece-identity-server target))
372 (setq process (cdr (assoc server-name riece-server-process-alist)))
373 (setq process riece-server-process))
375 (error "%s" (substitute-command-keys
376 "Type \\[riece-command-open-server] to open server.")))
377 (riece-process-send-string process
379 (format "PART %s :%s\r\n"
380 (riece-identity-prefix target)
382 (format "PART %s\r\n"
383 (riece-identity-prefix target))))))
385 (defun riece-command-part (target &optional message)
387 (let ((completion-ignore-case t)
389 (completing-read "Channel/User: "
390 (mapcar #'list riece-current-channels)
391 nil t (cons riece-current-channel 0)))
393 (if (and current-prefix-arg
394 (riece-channel-p target))
395 (setq message (read-string "Message: ")))
396 (list target message)))
397 (if (riece-identity-member target riece-current-channels)
398 (if (riece-channel-p target)
399 (riece-command-part-channel target message)
400 (riece-part-channel target)
401 (riece-redisplay-buffers))
402 (error "You are not talking with %s" target)))
404 (defun riece-command-change-nickname (nickname)
405 "Change your nickname to NICK."
406 (interactive "sEnter your nickname: ")
407 (riece-send-string (format "NICK %s\r\n" nickname)))
409 (defun riece-command-scroll-down (lines)
410 "Scroll LINES down dialogue buffer from command buffer."
412 (let ((other-window-scroll-buffer
413 (if riece-channel-buffer-mode
415 riece-dialogue-buffer)))
416 (when (get-buffer-window other-window-scroll-buffer)
418 (scroll-other-window-down lines)
420 (message "Beginning of buffer"))))))
422 (defun riece-command-scroll-up (lines)
423 "Scroll LINES up dialogue buffer from command buffer."
425 (let* ((other-window-scroll-buffer
426 (if riece-channel-buffer-mode
428 riece-dialogue-buffer)))
429 (when (get-buffer-window other-window-scroll-buffer)
431 (scroll-other-window lines)
433 (message "End of buffer"))))))
435 (defun riece-command-nick-scroll-down (lines)
436 "Scroll LINES down nick buffer from command buffer."
438 (let ((other-window-scroll-buffer riece-user-list-buffer))
439 (when (get-buffer-window other-window-scroll-buffer)
441 (scroll-other-window-down lines)
443 (message "Beginning of buffer"))))))
445 (defun riece-command-nick-scroll-up (lines)
446 "Scroll LINES up nick buffer from command buffer."
448 (let* ((other-window-scroll-buffer riece-user-list-buffer))
449 (when (get-buffer-window other-window-scroll-buffer)
451 (scroll-other-window lines)
453 (message "End of buffer"))))))
455 (defun riece-command-toggle-away (&optional message)
456 "Mark yourself as being away."
458 (if current-prefix-arg
459 (let ((message (read-string "Away message: ")))
462 (riece-send-string (format "AWAY :%s\r\n" message))
463 (riece-send-string "AWAY\r\n")))
465 (defun riece-command-toggle-freeze (&optional arg)
466 "Prevent automatic scrolling of the dialogue window.
467 If prefix argument ARG is non-nil, toggle frozen status."
469 (riece-freeze (if riece-channel-buffer-mode
471 riece-dialogue-buffer)
472 (if arg (prefix-numeric-value arg))))
474 (defun riece-command-toggle-own-freeze (&optional arg)
475 "Prevent automatic scrolling of the dialogue window.
476 The difference from `riece-command-freeze' is that your messages are hidden.
477 If prefix argument ARG is non-nil, toggle frozen status."
479 (riece-own-freeze (if riece-channel-buffer-mode
481 riece-dialogue-buffer)
482 (if arg (prefix-numeric-value arg))))
484 (defun riece-command-quit (&optional arg)
487 (if (y-or-n-p "Really quit IRC? ")
490 (read-string "Message: ")
491 (or riece-quit-message
492 (riece-extended-version)))))
493 (riece-close-all-server message))))
495 (defun riece-command-raw (command)
496 "Enter raw IRC command, which is sent to the server."
497 (interactive "sIRC command: ")
498 (riece-send-string (concat command "\r\n")))
500 (defun riece-command-end-of-buffer ()
501 "Get end of the dialogue buffer."
504 (setq buffer (if riece-channel-buffer-mode
506 riece-dialogue-buffer))
507 (or (setq window (get-buffer-window buffer))
508 (setq window (get-buffer-window riece-dialogue-buffer)
509 buffer riece-dialogue-buffer))
511 (save-selected-window
512 (select-window window)
513 (goto-char (point-max))))))
515 (defun riece-command-copy-region (start end)
516 "Move current region between START and END to `kill-ring'."
518 (kill-new (buffer-substring-no-properties start end)))
520 (defun riece-command-open-server (server-name)
522 (list (completing-read "Server: " riece-server-alist)))
523 (let ((process (riece-start-server
524 (riece-server-name-to-server server-name)
526 (with-current-buffer (process-buffer process)
527 (setq riece-server-name server-name))
528 (setq riece-server-process-alist
529 (cons (cons server-name process)
530 riece-server-process-alist))))
532 (defun riece-command-close-server (server-name &optional message)
534 (list (completing-read "Server: " riece-server-process-alist)
535 (if current-prefix-arg
536 (read-string "Message: ")
537 (or riece-quit-message
538 (riece-extended-version)))))
539 (riece-close-server server-name message))
541 (defun riece-command-universal-server-name-argument ()
543 (let* ((riece-overriding-server-name
544 (completing-read "Server: "
545 riece-server-process-alist))
547 (key-binding (read-key-sequence
548 (format "Command to execute on \"%s\":"
549 riece-overriding-server-name)))))
551 (call-interactively command)))
553 (provide 'riece-commands)
555 ;;; riece-commands.el ends here