* riece-foolproof.el (riece-foolproof-dmacro-override): New
[riece] / lisp / riece-commands.el
1 ;;; riece-commands.el --- commands available in command buffer
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece
7
8 ;; This file is part of Riece.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Code:
26
27 (require 'riece-channel)
28 (require 'riece-complete)
29 (require 'riece-layout)
30 (require 'riece-display)
31 (require 'riece-server)
32 (require 'riece-misc)
33 (require 'riece-identity)
34 (require 'riece-message)
35
36 (autoload 'derived-mode-class "derived")
37
38 ;;; Channel movement:
39 (defun riece-command-switch-to-channel (channel)
40   (interactive (list (riece-completing-read-identity
41                       "Switch to channel/user: "
42                       riece-current-channels nil t)))
43   (unless (equal channel riece-current-channel)
44     (riece-switch-to-channel channel)))
45
46 (defun riece-command-switch-to-channel-by-number (number)
47   (interactive
48    (let ((command-name (symbol-name this-command)))
49      (if (string-match "[0-9]+$" command-name)
50          (list (string-to-number (match-string 0 command-name)))
51        (list (string-to-number (read-string "Switch to number: "))))))
52   (let ((channel (nth (1- number) riece-current-channels)))
53     (if channel
54         (riece-command-switch-to-channel channel)
55       (error "No such number!"))))
56
57 (eval-and-compile
58   (let ((number 1))
59     (while (<= number 20)
60       (defalias (intern (concat "riece-command-switch-to-channel-by-number-"
61                                 (number-to-string number)))
62         'riece-command-switch-to-channel-by-number)
63       (setq number (1+ number)))))
64
65 (defun riece-command-next-channel ()
66   "Select the next channel."
67   (interactive)
68   (when (> (length riece-current-channels) 1)
69     (let ((pointer (cdr (riece-identity-member
70                          riece-current-channel
71                          riece-current-channels))))
72       (while (and pointer
73                   (null (car pointer)))
74         (setq pointer (cdr pointer)))
75       (when (null pointer)
76         (setq pointer riece-current-channels)
77         (while (and pointer
78                     (null (car pointer)))
79           (setq pointer (cdr pointer))))
80       (if (car pointer)
81           (riece-command-switch-to-channel (car pointer))
82         (error "No such channel!")))))
83
84 (defun riece-command-previous-channel ()
85   "Select the previous channel."
86   (interactive)
87   (when (> (length riece-current-channels) 1)
88     (let ((pointer (riece-identity-member
89                     riece-current-channel
90                     riece-current-channels))
91           (start riece-current-channels)
92           channel)
93       (while (and start (not (eq start pointer)))
94         (if (car start)
95             (setq channel (car start)))
96         (setq start (cdr start)))
97       (when (null channel)
98         (setq start (copy-sequence riece-current-channels))
99         (setq start (delq nil start))
100         (and (> (length start) 1)
101              (setq channel (nth (1- (length start)) start))))
102       (if channel
103           (riece-command-switch-to-channel channel)
104         (error "No such channel!")))))
105
106 (defun riece-command-select-command-buffer ()
107   "Select the command buffer."
108   (interactive)
109   (let ((window (get-buffer-window riece-command-buffer)))
110     (if window
111         (select-window window))))
112
113 (defun riece-command-configure-windows ()
114   (interactive)
115   (riece-redisplay-buffers t))
116
117 (defun riece-command-change-layout (name)
118   "Select a layout-name from all current available layouts and change
119 the layout to the selected layout-name."
120   (interactive (list (completing-read "Change layout: " riece-layout-alist)))
121   (setq riece-layout name
122         riece-save-variables-are-dirty t)
123   (riece-command-configure-windows))
124
125 (defun riece-command-toggle-channel-buffer-mode ()
126   (interactive)
127   (setq riece-channel-buffer-mode
128         (not riece-channel-buffer-mode)
129         riece-save-variables-are-dirty t)
130   (riece-command-configure-windows))
131
132 (defun riece-command-toggle-user-list-buffer-mode ()
133   (interactive)
134   (setq riece-user-list-buffer-mode
135         (not riece-user-list-buffer-mode)
136         riece-save-variables-are-dirty t)
137   (riece-command-configure-windows))
138
139 (defun riece-command-toggle-channel-list-buffer-mode ()
140   (interactive)
141   (setq riece-channel-list-buffer-mode
142         (not riece-channel-list-buffer-mode)
143         riece-save-variables-are-dirty t)
144   (riece-command-configure-windows))
145
146 (defun riece-command-finger (user &optional recurse)
147   (interactive
148    (let* ((completion-ignore-case t)
149           (user (riece-completing-read-identity
150                  "Finger user: "
151                  (riece-get-users-on-server (riece-current-server-name))
152                  nil nil nil nil nil t)))
153      (list user current-prefix-arg)))
154   (if recurse
155       (riece-send-string (format "WHOIS %s %s\r\n"
156                                  (riece-identity-prefix user)
157                                  (riece-identity-prefix user)))
158     (riece-send-string (format "WHOIS %s\r\n" (riece-identity-prefix user)))))
159
160 (defun riece-command-topic (topic)
161   (interactive
162    (progn
163      (riece-check-channel-commands-are-usable t)
164      (list (read-from-minibuffer
165             "Set topic: " (cons (or (riece-with-server-buffer
166                                      (riece-identity-server
167                                       riece-current-channel)
168                                      (riece-channel-get-topic
169                                       (riece-identity-prefix
170                                        riece-current-channel)))
171                                     "")
172                                 0)))))
173   (riece-send-string (format "TOPIC %s :%s\r\n"
174                              (riece-identity-prefix riece-current-channel)
175                              topic)))
176
177 (defun riece-command-invite (user)
178   (interactive
179    (let ((completion-ignore-case t))
180      (riece-check-channel-commands-are-usable t)
181      (list (riece-completing-read-identity
182             "Invite user: "
183             (riece-get-users-on-server (riece-current-server-name))
184             nil nil nil nil nil t))))
185   (riece-send-string (format "INVITE %s %s\r\n"
186                              (riece-identity-prefix user)
187                              (riece-identity-prefix riece-current-channel))))
188
189 (defun riece-command-kick (user &optional message)
190   (interactive
191    (let ((completion-ignore-case t))
192      (riece-check-channel-commands-are-usable t)
193      (list (completing-read
194             "Kick user: "
195             (riece-with-server-buffer
196                 (riece-identity-server riece-current-channel)
197               (riece-channel-get-users (riece-identity-prefix
198                                         riece-current-channel))))
199            (if current-prefix-arg
200                (read-string "Message: ")))))
201   (riece-send-string
202    (if message
203        (format "KICK %s %s :%s\r\n"
204                (riece-identity-prefix riece-current-channel)
205                user message)
206      (format "KICK %s %s\r\n"
207              (riece-identity-prefix riece-current-channel)
208              user))))
209
210 (defun riece-command-names (pattern)
211   (interactive
212    (let ((completion-ignore-case t))
213      (list (read-from-minibuffer
214             "NAMES pattern: "
215             (if (and riece-current-channel
216                      (riece-channel-p (riece-identity-prefix
217                                        riece-current-channel)))
218                 (cons (riece-identity-prefix riece-current-channel)
219                       0))))))
220   (if (or (not (equal pattern ""))
221           (yes-or-no-p "Really want to query NAMES without argument? "))
222       (riece-send-string (format "NAMES %s\r\n" pattern))))
223
224 (defun riece-command-who (pattern)
225   (interactive
226    (let ((completion-ignore-case t))
227      (list (read-from-minibuffer
228             "WHO pattern: "
229             (if (and riece-current-channel
230                      (riece-channel-p (riece-identity-prefix
231                                        riece-current-channel)))
232                 (cons (riece-identity-prefix riece-current-channel)
233                       0))))))
234   (if (or (not (equal pattern ""))
235           (yes-or-no-p "Really want to query WHO without argument? "))
236       (riece-send-string (format "WHO %s\r\n" pattern))))
237
238 (defun riece-command-list (pattern)
239   (interactive
240    (let ((completion-ignore-case t))
241      (list (read-from-minibuffer
242             "LIST pattern: "
243             (if (and riece-current-channel
244                      (riece-channel-p (riece-identity-prefix
245                                        riece-current-channel)))
246                 (cons (riece-identity-prefix riece-current-channel)
247                       0))))))
248   (if (or (not (equal pattern ""))
249           (yes-or-no-p "Really want to query LIST without argument? "))
250       (riece-send-string (format "LIST %s\r\n" pattern))))
251
252 (defun riece-command-change-mode (channel change)
253   (interactive
254    (let* ((completion-ignore-case t)
255           (channel
256            (if current-prefix-arg
257                (riece-completing-read-identity
258                 "Change mode for channel/user: "
259                 (riece-get-identities-on-server (riece-current-server-name))
260                 nil nil nil nil nil t)
261              (riece-check-channel-commands-are-usable t)
262              riece-current-channel))
263           (riece-overriding-server-name (riece-identity-server channel))
264           (riece-temp-minibuffer-message
265            (concat "[Available modes: "
266                    (riece-with-server-buffer (riece-identity-server channel)
267                      (if (riece-channel-p (riece-identity-prefix channel))
268                          (if riece-supported-channel-modes
269                              (apply #'string riece-supported-channel-modes))
270                        (if riece-supported-user-modes
271                            (apply #'string riece-supported-user-modes))))
272                    "]")))
273      (list channel
274            (read-from-minibuffer
275             (concat (riece-concat-channel-modes
276                      channel "Mode (? for help)") ": ")
277             nil riece-minibuffer-map))))
278   (if (equal change "")
279       (riece-send-string (format "MODE %s\r\n"
280                                  (riece-identity-prefix channel)))
281     (riece-send-string (format "MODE %s :%s\r\n"
282                                (riece-identity-prefix channel)
283                                change))))
284
285 (defun riece-command-set-operators (users &optional arg)
286   (interactive
287    (progn
288      (riece-check-channel-commands-are-usable t)
289      (let ((completion-ignore-case t))
290        (list (riece-completing-read-multiple
291               (if current-prefix-arg
292                   "Unset +o for users"
293                 "Set +o for users")
294               (riece-with-server-buffer
295                   (riece-identity-server riece-current-channel)
296                 (riece-channel-get-users (riece-identity-prefix
297                                          riece-current-channel)))
298               (if current-prefix-arg
299                   (lambda (user)
300                     (memq ?o (cdr user)))
301                 (lambda (user)
302                   (not (memq ?o (cdr user))))))
303              current-prefix-arg))))
304   (let (group)
305     (while users
306       (setq group (cons (car users) group)
307             users (cdr users))
308       (when (or (= (length group) 3)
309                 (null users))
310         (riece-send-string
311          (format "MODE %s %c%s %s\r\n"
312                  (riece-identity-prefix riece-current-channel)
313                  (if current-prefix-arg
314                      ?-
315                    ?+)
316                  (make-string (length group) ?o)
317                  (mapconcat #'identity (nreverse group) " ")))
318         (setq group nil)))))
319
320 (defun riece-command-set-speakers (users &optional arg)
321   (interactive
322    (progn
323      (riece-check-channel-commands-are-usable t)
324      (let ((completion-ignore-case t))
325        (list (riece-completing-read-multiple
326               (if current-prefix-arg
327                   "Unset +v for users"
328                 "Set +v for users")
329               (riece-with-server-buffer
330                   (riece-identity-server riece-current-channel)
331                 (riece-channel-get-users (riece-identity-prefix
332                                           riece-current-channel)))
333               (if current-prefix-arg
334                   (lambda (user)
335                     (memq ?v (cdr user)))
336                 (lambda (user)
337                   (not (memq ?v (cdr user))))))
338              current-prefix-arg))))
339   (let (group)
340     (while users
341       (setq group (cons (car users) group)
342             users (cdr users))
343       (when (or (= (length group) 3)
344                 (null users))
345         (riece-send-string
346          (format "MODE %s %c%s %s\r\n"
347                  (riece-identity-prefix riece-current-channel)
348                  (if current-prefix-arg
349                      ?-
350                    ?+)
351                  (make-string (length group) ?v)
352                  (mapconcat #'identity (nreverse group) " ")))
353         (setq group nil)))))
354
355 (defun riece-command-send-message (message notice)
356   "Send MESSAGE to the current channel."
357   (if (equal message "")
358       (error "No text to send"))
359   (riece-check-channel-commands-are-usable)
360   (if notice
361       (progn
362         (riece-send-string
363          (format "NOTICE %s :%s\r\n"
364                  (riece-identity-prefix riece-current-channel)
365                  message))
366         (riece-display-message
367          (riece-make-message (riece-current-nickname) riece-current-channel
368                              message 'notice t)))
369     (riece-send-string
370      (format "PRIVMSG %s :%s\r\n"
371              (riece-identity-prefix riece-current-channel)
372              message))
373     (riece-display-message
374      (riece-make-message (riece-current-nickname) riece-current-channel
375                          message nil t))))
376
377 (defun riece-command-enter-message ()
378   "Send the current line to the current channel."
379   (interactive)
380   (riece-command-send-message (buffer-substring
381                                (riece-line-beginning-position)
382                                (riece-line-end-position))
383                               nil)
384   (let ((next-line-add-newlines t))
385     (next-line 1)))
386
387 (defun riece-command-enter-message-as-notice ()
388   "Send the current line to the current channel as NOTICE."
389   (interactive)
390   (riece-command-send-message (buffer-substring
391                                (riece-line-beginning-position)
392                                (riece-line-end-position))
393                               t)
394   (let ((next-line-add-newlines t))
395     (next-line 1)))
396
397 (defun riece-command-enter-message-to-user (user)
398   "Send the current line to USER."
399   (interactive
400    (let ((completion-ignore-case t))
401      (list (riece-completing-read-identity
402             "Message to user: "
403             (riece-get-users-on-server (riece-current-server-name))
404             nil nil nil nil nil t))))
405   (let ((text (buffer-substring
406                (riece-line-beginning-position)
407                (riece-line-end-position))))
408     (riece-send-string
409      (format "PRIVMSG %s :%s\r\n" (riece-identity-prefix user) text))
410     (riece-display-message
411      (riece-make-message (riece-current-nickname) user text nil t)))
412   (let ((next-line-add-newlines t))
413     (next-line 1)))
414
415 (defun riece-command-join-channel (target key)
416   (let ((process (riece-server-process (riece-identity-server target))))
417     (unless process
418       (error "%s" (substitute-command-keys
419                    "Type \\[riece-command-open-server] to open server.")))
420     (riece-process-send-string process
421                                (if key
422                                    (format "JOIN %s :%s\r\n"
423                                            (riece-identity-prefix target)
424                                            key)
425                                  (format "JOIN %s\r\n"
426                                          (riece-identity-prefix target))))))
427
428 (defun riece-command-join-partner (target)
429   (let ((pointer (riece-identity-member target riece-current-channels)))
430     (if pointer
431         (riece-command-switch-to-channel (car pointer))
432       (riece-join-channel target)
433       (riece-switch-to-channel target))))
434
435 (defun riece-command-join (target &optional key)
436   (interactive
437    (let* ((completion-ignore-case t)
438           (target
439            (if riece-join-channel-candidate
440                (let ((default (riece-format-identity
441                                riece-join-channel-candidate)))
442                  (riece-completing-read-identity
443                   (format "Join channel/user (default %s): " default)
444                   (riece-get-identities-on-server (riece-current-server-name))
445                   nil nil nil nil default))
446              (riece-completing-read-identity
447               "Join channel/user: "
448               (riece-get-identities-on-server (riece-current-server-name)))))
449           key)
450      (if (and current-prefix-arg
451               (riece-channel-p (riece-identity-prefix target)))
452          (setq key
453                (riece-read-passwd (format "Key for %s: "
454                                           (riece-format-identity target)))))
455      (list target key)))
456   (let ((pointer (riece-identity-member target riece-current-channels)))
457     (if pointer
458         (riece-command-switch-to-channel (car pointer))
459       (if (riece-channel-p (riece-identity-prefix target))
460           (riece-command-join-channel target key)
461         (riece-command-join-partner target)))))
462
463 (defun riece-command-part-channel (target message)
464   (let ((process (riece-server-process (riece-identity-server target))))
465     (riece-process-send-string process
466                                (if message
467                                    (format "PART %s :%s\r\n"
468                                            (riece-identity-prefix target)
469                                            message)
470                                  (format "PART %s\r\n"
471                                          (riece-identity-prefix target))))))
472
473 (defun riece-command-part (target &optional message)
474   (interactive
475    (progn
476      (riece-check-channel-commands-are-usable)
477      (let* ((completion-ignore-case t)
478             (target
479              (riece-completing-read-identity
480               (format "Part from channel/user (default %s): "
481                       (riece-format-identity riece-current-channel))
482               riece-current-channels nil nil nil nil
483               (riece-format-identity riece-current-channel)))
484             message)
485        (if (and current-prefix-arg
486                 (riece-channel-p (riece-identity-prefix target)))
487            (setq message (read-string "Message: ")))
488        (list target message))))
489   (if (riece-identity-member target riece-current-channels)
490       (if (riece-channel-p (riece-identity-prefix target))
491           (riece-command-part-channel target message)
492         (riece-part-channel target))
493     (error "You are not talking with %s" target)))
494
495 (defun riece-command-change-nickname (nickname)
496   "Change your nickname to NICK."
497   (interactive "sEnter your nickname: ")
498   (riece-send-string (format "NICK %s\r\n" nickname)))
499
500 (defun riece-command-scroll-down (lines)
501   "Scroll LINES down dialogue buffer from command buffer."
502   (interactive "P")
503   (let ((buffer (if (and riece-channel-buffer-mode
504                          riece-current-channel)
505                     riece-channel-buffer
506                   riece-dialogue-buffer)))
507     (if (get-buffer-window buffer)
508         (condition-case nil
509             (let ((other-window-scroll-buffer buffer))
510               (scroll-other-window-down lines))
511           (beginning-of-buffer
512            (message "Beginning of buffer"))))))
513
514 (defun riece-command-scroll-up (lines)
515   "Scroll LINES up dialogue buffer from command buffer."
516   (interactive "P")
517   (let ((buffer (if (and riece-channel-buffer-mode
518                          riece-current-channel)
519                     riece-channel-buffer
520                   riece-dialogue-buffer)))
521     (if (get-buffer-window buffer)
522         (condition-case nil
523             (let ((other-window-scroll-buffer buffer))
524               (scroll-other-window lines))
525           (end-of-buffer
526            (message "End of buffer"))))))
527
528 (defun riece-command-user-list-scroll-down (lines)
529   "Scroll LINES down user list buffer from command buffer."
530   (interactive "P")
531   (if (get-buffer-window riece-user-list-buffer)
532       (condition-case nil
533           (let ((other-window-scroll-buffer riece-user-list-buffer))
534             (scroll-other-window-down lines))
535         (beginning-of-buffer
536          (message "Beginning of buffer")))))
537
538 (defun riece-command-user-list-scroll-up (lines)
539   "Scroll LINES up user list buffer from command buffer."
540   (interactive "P")
541   (if (get-buffer-window riece-user-list-buffer)
542       (condition-case nil
543           (let ((other-window-scroll-buffer riece-user-list-buffer))
544             (scroll-other-window lines))
545         (end-of-buffer
546          (message "End of buffer")))))
547
548 (defun riece-command-toggle-away (&optional message)
549   "Mark yourself as being away."
550   (interactive
551    (if (and (not (riece-with-server-buffer (riece-identity-server
552                                             (riece-current-nickname))
553                    (riece-user-get-away (riece-identity-prefix
554                                          (riece-current-nickname)))))
555             current-prefix-arg)
556        (list (read-from-minibuffer
557               "Away message: " (cons (or riece-away-message "") 0)))))
558   (if (riece-with-server-buffer (riece-identity-server
559                                  (riece-current-nickname))
560         (riece-user-get-away (riece-identity-prefix
561                               (riece-current-nickname))))
562       (riece-send-string "AWAY\r\n")
563     (riece-send-string (format "AWAY :%s\r\n" (or message
564                                                   riece-away-message)))))
565
566 (defun riece-command-toggle-freeze (&optional arg)
567   "Prevent automatic scrolling of the dialogue window.
568 If prefix argument ARG is non-nil, toggle frozen status."
569   (interactive "P")
570   (with-current-buffer (if (eq (derived-mode-class major-mode)
571                                'riece-dialogue-mode)
572                            (current-buffer)
573                          (if (and riece-channel-buffer-mode
574                                   riece-channel-buffer)
575                              riece-channel-buffer
576                            riece-dialogue-buffer))
577     (setq riece-freeze (if arg
578                            (< 0 (prefix-numeric-value arg))
579                          (not riece-freeze)))
580     (riece-emit-signal 'buffer-freeze-changed
581                        (current-buffer) riece-freeze)))
582
583 (defun riece-command-toggle-own-freeze (&optional arg)
584   "Prevent automatic scrolling of the dialogue window.
585 The difference from `riece-command-freeze' is that your messages are hidden.
586 If prefix argument ARG is non-nil, toggle frozen status."
587   (interactive "P")
588   (with-current-buffer (if (eq (derived-mode-class major-mode)
589                                'riece-dialogue-mode)
590                            (current-buffer)
591                          (if (and riece-channel-buffer-mode
592                                   riece-channel-buffer)
593                              riece-channel-buffer
594                            riece-dialogue-buffer))
595     (if (if arg
596             (< 0 (prefix-numeric-value arg))
597           (not (eq riece-freeze 'own)))
598         (setq riece-freeze 'own)
599       (setq riece-freeze nil))
600     (riece-emit-signal 'buffer-freeze-changed
601                        (current-buffer) riece-freeze)))
602
603 (eval-when-compile
604   (autoload 'riece-exit "riece"))
605 (defun riece-command-quit (&optional arg)
606   "Quit IRC."
607   (interactive "P")
608   (if (null riece-server-process-alist)
609       (progn
610         (message "No server process")
611         (ding))
612     (if (y-or-n-p "Really quit IRC? ")
613         (let ((message
614                (if arg
615                    (read-string "Message: ")
616                riece-quit-message))
617               (alist riece-server-process-alist))
618           (while alist
619             (riece-quit-server-process (cdr (car alist)) message)
620             (setq alist (cdr alist)))))))
621
622 (defun riece-command-raw (command)
623   "Enter raw IRC command, which is sent to the server."
624   (interactive "sIRC command: ")
625   (riece-send-string (concat command "\r\n")))
626
627 (defun riece-command-end-of-buffer ()
628   "Get end of the dialogue buffer."
629   (interactive)
630   (let (buffer window)
631     (setq buffer (if riece-channel-buffer-mode
632                      riece-channel-buffer
633                    riece-dialogue-buffer))
634     (or (setq window (get-buffer-window buffer))
635         (setq window (get-buffer-window riece-dialogue-buffer)
636               buffer riece-dialogue-buffer))
637     (when window
638       (save-selected-window
639         (select-window window)
640         (goto-char (point-max))))))
641
642 (defun riece-command-copy-region (start end)
643   "Move current region between START and END to `kill-ring'."
644   (interactive "r")
645   (kill-new (buffer-substring-no-properties start end)))
646
647 (defun riece-command-complete-user ()
648   "Complete a user name in the current buffer."
649   (interactive)
650   (let* ((completion-ignore-case t)
651          (table (mapcar (lambda (user)
652                           (list (riece-format-identity user t)))
653                         (riece-get-users-on-server
654                          (riece-current-server-name))))
655          (current (current-word))
656          (completion (try-completion current table))
657          (all (all-completions current table)))
658     (if (eq completion t)
659         nil
660       (if (null completion)
661           (message "Can't find completion for \"%s\"" current)
662         (if (equal current completion)
663             (with-output-to-temp-buffer "*Help*"
664               (display-completion-list all))
665           (delete-region (point) (- (point) (length current)))
666           (insert completion))))))
667
668 (defun riece-command-open-server (server-name)
669   (interactive
670    (list (completing-read "Open server: " riece-server-alist)))
671   (if (riece-server-process server-name)
672       (error "%s is already opened" server-name))
673   (riece-open-server
674    (riece-server-name-to-server server-name)
675    server-name))
676
677 (defun riece-command-close-server (server-name &optional message)
678   (interactive
679    (list (completing-read "Close server: " riece-server-process-alist)
680          (if current-prefix-arg
681              (read-string "Message: ")
682            riece-quit-message)))
683   (riece-quit-server-process (riece-server-process server-name) message))
684
685 (defun riece-command-universal-server-name-argument ()
686   (interactive)
687   (let* ((riece-overriding-server-name
688           (completing-read "Server: " riece-server-process-alist))
689          (command
690           (key-binding (read-key-sequence
691                         (format "Command to execute on \"%s\":"
692                                 riece-overriding-server-name)))))
693     (message "")
694     (call-interactively command)))
695
696 (provide 'riece-commands)
697
698 ;;; riece-commands.el ends here