* riece-options.el (riece-part-message): New user option.
[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   (run-hooks 'riece-command-send-message-hook)
358   (if (equal message "")
359       (error "No text to send"))
360   (riece-check-channel-commands-are-usable)
361   (if notice
362       (progn
363         (riece-send-string
364          (format "NOTICE %s :%s\r\n"
365                  (riece-identity-prefix riece-current-channel)
366                  message))
367         (riece-display-message
368          (riece-make-message (riece-current-nickname) riece-current-channel
369                              message 'notice t)))
370     (riece-send-string
371      (format "PRIVMSG %s :%s\r\n"
372              (riece-identity-prefix riece-current-channel)
373              message))
374     (riece-display-message
375      (riece-make-message (riece-current-nickname) riece-current-channel
376                          message nil t))))
377
378 (defun riece-command-enter-message ()
379   "Send the current line to the current channel."
380   (interactive)
381   (riece-command-send-message (buffer-substring
382                                (riece-line-beginning-position)
383                                (riece-line-end-position))
384                               nil)
385   (let ((next-line-add-newlines t))
386     (next-line 1)))
387
388 (defun riece-command-enter-message-as-notice ()
389   "Send the current line to the current channel as NOTICE."
390   (interactive)
391   (riece-command-send-message (buffer-substring
392                                (riece-line-beginning-position)
393                                (riece-line-end-position))
394                               t)
395   (let ((next-line-add-newlines t))
396     (next-line 1)))
397
398 (defun riece-command-enter-message-to-user (user)
399   "Send the current line to USER."
400   (interactive
401    (if (and (bolp) (eolp))
402        (error "No text to send")
403      (let ((completion-ignore-case t))
404        (list (riece-completing-read-identity
405               "Message to user: "
406               (riece-get-users-on-server (riece-current-server-name))
407               nil nil nil nil nil t)))))
408   (let ((text (buffer-substring
409                (riece-line-beginning-position)
410                (riece-line-end-position))))
411     (riece-send-string
412      (format "PRIVMSG %s :%s\r\n" (riece-identity-prefix user) text))
413     (riece-display-message
414      (riece-make-message (riece-current-nickname) user text nil t)))
415   (let ((next-line-add-newlines t))
416     (next-line 1)))
417
418 (defun riece-command-join-channel (target key)
419   (let ((process (riece-server-process (riece-identity-server target))))
420     (unless process
421       (error "%s" (substitute-command-keys
422                    "Type \\[riece-command-open-server] to open server.")))
423     (riece-process-send-string process
424                                (if key
425                                    (format "JOIN %s :%s\r\n"
426                                            (riece-identity-prefix target)
427                                            key)
428                                  (format "JOIN %s\r\n"
429                                          (riece-identity-prefix target))))))
430
431 (defun riece-command-join-partner (target)
432   (let ((pointer (riece-identity-member target riece-current-channels)))
433     (if pointer
434         (riece-command-switch-to-channel (car pointer))
435       (riece-join-channel target)
436       (riece-switch-to-channel target))))
437
438 (defun riece-command-join (target)
439   (interactive
440    (let ((completion-ignore-case t))
441      (list
442       (if riece-join-channel-candidate
443           (let ((default (riece-format-identity
444                           riece-join-channel-candidate)))
445             (riece-completing-read-identity
446              (format "Join channel/user (default %s): " default)
447              (riece-get-identities-on-server (riece-current-server-name))
448              nil nil nil nil default))
449         (riece-completing-read-identity
450          "Join channel/user: "
451          (riece-get-identities-on-server (riece-current-server-name)))))))
452   (let ((pointer (riece-identity-member target riece-current-channels)))
453     (if pointer
454         (riece-command-switch-to-channel (car pointer))
455       (if (riece-channel-p (riece-identity-prefix target))
456           (riece-command-join-channel target nil)
457         (riece-command-join-partner target)))))
458
459 (defun riece-command-part-channel (target message)
460   (let ((process (riece-server-process (riece-identity-server target))))
461     (riece-process-send-string process
462                                (if message
463                                    (format "PART %s :%s\r\n"
464                                            (riece-identity-prefix target)
465                                            message)
466                                  (format "PART %s\r\n"
467                                          (riece-identity-prefix target))))))
468
469 (defun riece-command-part (target)
470   (interactive
471    (progn
472      (riece-check-channel-commands-are-usable)
473      (let* ((completion-ignore-case t)
474             (target
475              (riece-completing-read-identity
476               (format "Part from channel/user (default %s): "
477                       (riece-format-identity riece-current-channel))
478               riece-current-channels nil nil nil nil
479               (riece-format-identity riece-current-channel)))
480             (message
481              (if current-prefix-arg
482                  (read-string "Message: ")
483                riece-part-message)))
484        (list target message))))
485   (if (riece-identity-member target riece-current-channels)
486       (if (riece-channel-p (riece-identity-prefix target))
487           (riece-command-part-channel target message)
488         (riece-part-channel target))
489     (error "You are not talking with %s" target)))
490
491 (defun riece-command-change-nickname (nickname)
492   "Change your nickname to NICK."
493   (interactive "sEnter your nickname: ")
494   (riece-send-string (format "NICK %s\r\n" nickname)))
495
496 (defun riece-command-scroll-down (lines)
497   "Scroll LINES down dialogue buffer from command buffer."
498   (interactive "P")
499   (let ((buffer (if (and riece-channel-buffer-mode
500                          riece-current-channel)
501                     riece-channel-buffer
502                   riece-dialogue-buffer)))
503     (if (get-buffer-window buffer)
504         (condition-case nil
505             (let ((other-window-scroll-buffer buffer))
506               (scroll-other-window-down lines))
507           (beginning-of-buffer
508            (message "Beginning of buffer"))))))
509
510 (defun riece-command-scroll-up (lines)
511   "Scroll LINES up dialogue buffer from command buffer."
512   (interactive "P")
513   (let ((buffer (if (and riece-channel-buffer-mode
514                          riece-current-channel)
515                     riece-channel-buffer
516                   riece-dialogue-buffer)))
517     (if (get-buffer-window buffer)
518         (condition-case nil
519             (let ((other-window-scroll-buffer buffer))
520               (scroll-other-window lines))
521           (end-of-buffer
522            (message "End of buffer"))))))
523
524 (defun riece-command-user-list-scroll-down (lines)
525   "Scroll LINES down user list buffer from command buffer."
526   (interactive "P")
527   (if (get-buffer-window riece-user-list-buffer)
528       (condition-case nil
529           (let ((other-window-scroll-buffer riece-user-list-buffer))
530             (scroll-other-window-down lines))
531         (beginning-of-buffer
532          (message "Beginning of buffer")))))
533
534 (defun riece-command-user-list-scroll-up (lines)
535   "Scroll LINES up user list buffer from command buffer."
536   (interactive "P")
537   (if (get-buffer-window riece-user-list-buffer)
538       (condition-case nil
539           (let ((other-window-scroll-buffer riece-user-list-buffer))
540             (scroll-other-window lines))
541         (end-of-buffer
542          (message "End of buffer")))))
543
544 (defun riece-command-toggle-away (&optional message)
545   "Mark yourself as being away."
546   (interactive
547    (if (and (not (riece-with-server-buffer (riece-identity-server
548                                             (riece-current-nickname))
549                    (riece-user-get-away (riece-identity-prefix
550                                          (riece-current-nickname)))))
551             current-prefix-arg)
552        (list (read-from-minibuffer
553               "Away message: " (cons (or riece-away-message "") 0)))))
554   (if (riece-with-server-buffer (riece-identity-server
555                                  (riece-current-nickname))
556         (riece-user-get-away (riece-identity-prefix
557                               (riece-current-nickname))))
558       (riece-send-string "AWAY\r\n")
559     (riece-send-string (format "AWAY :%s\r\n" (or message
560                                                   riece-away-message)))))
561
562 (defun riece-command-toggle-freeze (&optional arg)
563   "Prevent automatic scrolling of the dialogue window.
564 If prefix argument ARG is non-nil, toggle frozen status."
565   (interactive "P")
566   (with-current-buffer (if (eq (derived-mode-class major-mode)
567                                'riece-dialogue-mode)
568                            (current-buffer)
569                          (if (and riece-channel-buffer-mode
570                                   riece-channel-buffer)
571                              riece-channel-buffer
572                            riece-dialogue-buffer))
573     (setq riece-freeze (if arg
574                            (< 0 (prefix-numeric-value arg))
575                          (not riece-freeze)))
576     (riece-emit-signal 'buffer-freeze-changed
577                        (current-buffer) riece-freeze)))
578
579 (defun riece-command-toggle-own-freeze (&optional arg)
580   "Prevent automatic scrolling of the dialogue window.
581 The difference from `riece-command-freeze' is that your messages are hidden.
582 If prefix argument ARG is non-nil, toggle frozen status."
583   (interactive "P")
584   (with-current-buffer (if (eq (derived-mode-class major-mode)
585                                'riece-dialogue-mode)
586                            (current-buffer)
587                          (if (and riece-channel-buffer-mode
588                                   riece-channel-buffer)
589                              riece-channel-buffer
590                            riece-dialogue-buffer))
591     (if (if arg
592             (< 0 (prefix-numeric-value arg))
593           (not (eq riece-freeze 'own)))
594         (setq riece-freeze 'own)
595       (setq riece-freeze nil))
596     (riece-emit-signal 'buffer-freeze-changed
597                        (current-buffer) riece-freeze)))
598
599 (eval-when-compile
600   (autoload 'riece-exit "riece"))
601 (defun riece-command-quit (&optional arg)
602   "Quit IRC."
603   (interactive "P")
604   (if (null riece-server-process-alist)
605       (progn
606         (message "No server process")
607         (ding))
608     (if (y-or-n-p "Really quit IRC? ")
609         (let ((message
610                (if arg
611                    (read-string "Message: ")
612                  riece-quit-message))
613               (alist riece-server-process-alist))
614           (while alist
615             (riece-quit-server-process (cdr (car alist)) message)
616             (setq alist (cdr alist)))))))
617
618 (defun riece-command-raw (command)
619   "Enter raw IRC command, which is sent to the server."
620   (interactive "sIRC command: ")
621   (riece-send-string (concat command "\r\n")))
622
623 (defun riece-command-beginning-of-buffer ()
624   "Scroll channel buffer to the beginning."
625   (interactive)
626   (let (buffer window)
627     (setq buffer (if riece-channel-buffer-mode
628                      riece-channel-buffer
629                    riece-dialogue-buffer))
630     (or (setq window (get-buffer-window buffer))
631         (setq window (get-buffer-window riece-dialogue-buffer)
632               buffer riece-dialogue-buffer))
633     (when window
634       (save-selected-window
635         (select-window window)
636         (goto-char (point-min))))))
637
638 (defun riece-command-end-of-buffer ()
639   "Scroll channel buffer to the end."
640   (interactive)
641   (let (buffer window)
642     (setq buffer (if riece-channel-buffer-mode
643                      riece-channel-buffer
644                    riece-dialogue-buffer))
645     (or (setq window (get-buffer-window buffer))
646         (setq window (get-buffer-window riece-dialogue-buffer)
647               buffer riece-dialogue-buffer))
648     (when window
649       (save-selected-window
650         (select-window window)
651         (goto-char (point-max))))))
652
653 (defun riece-command-copy-region (start end)
654   "Move current region between START and END to `kill-ring'."
655   (interactive "r")
656   (kill-new (buffer-substring-no-properties start end)))
657
658 (defun riece-command-complete-user ()
659   "Complete a user name in the current buffer."
660   (interactive)
661   (let* ((completion-ignore-case t)
662          (table (mapcar (lambda (user)
663                           (list (riece-format-identity user t)))
664                         (riece-get-users-on-server
665                          (riece-current-server-name))))
666          (current (or (current-word) ""))
667          (completion (try-completion current table))
668          (all (all-completions current table)))
669     (if (eq completion t)
670         nil
671       (if (null completion)
672           (message "Can't find completion for \"%s\"" current)
673         (if (equal current completion)
674             (with-output-to-temp-buffer "*Help*"
675               (display-completion-list all))
676           (re-search-forward "\\>" nil t)
677           (delete-region (point) (- (point) (length current)))
678           (insert completion))))))
679
680 (defun riece-command-open-server (server-name)
681   (interactive
682    (list (completing-read "Open server: " riece-server-alist)))
683   (if (riece-server-process server-name)
684       (error "%s is already opened" server-name))
685   (riece-open-server
686    (riece-server-name-to-server server-name)
687    server-name))
688
689 (defun riece-command-close-server (server-name &optional message)
690   (interactive
691    (list (completing-read "Close server: " riece-server-process-alist)
692          (if current-prefix-arg
693              (read-string "Message: ")
694            riece-quit-message)))
695   (riece-quit-server-process (riece-server-process server-name) message))
696
697 (defun riece-command-universal-server-name-argument ()
698   (interactive)
699   (let* ((riece-overriding-server-name
700           (completing-read "Server: " riece-server-process-alist))
701          (command
702           (key-binding (read-key-sequence
703                         (format "Command to execute on \"%s\":"
704                                 riece-overriding-server-name)))))
705     (message "")
706     (call-interactively command)))
707
708 (provide 'riece-commands)
709
710 ;;; riece-commands.el ends here