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