* liece-commands.el: Add autoload for liece-command-ctcp-version,
[elisp/liece.git] / lisp / liece-commands.el
1 ;;; liece-commands.el --- Interactive commands in command buffer.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Revised: 1999-12-24
7 ;; Keywords: IRC, liece
8
9 ;; This file is part of Liece.
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26
27 ;;; Commentary:
28 ;; 
29
30 ;;; Code:
31
32 (eval-when-compile
33    (require 'liece-crypt)
34    (require 'liece-misc))
35
36 (require 'liece-channel)
37 (require 'liece-nick)
38 (require 'liece-coding)
39 (require 'liece-intl)
40 (require 'liece-minibuf)
41
42 (autoload 'liece-dcc-chat-send "liece-dcc")
43 (autoload 'liece-window-configuration-pop "liece-window")
44
45 (autoload 'liece-command-ctcp-version "liece-ctcp" nil t)
46 (autoload 'liece-command-ctcp-userinfo "liece-ctcp" nil t)
47 (autoload 'liece-command-ctcp-clientinfo "liece-ctcp" nil t)
48 (autoload 'liece-command-ctcp-ping "liece-ctcp" nil t)
49 (autoload 'liece-command-ctcp-time "liece-ctcp" nil t)
50 (autoload 'liece-command-ctcp-x-face "liece-ctcp" nil t)
51 (autoload 'liece-command-ctcp-comment "liece-ctcp" nil t)
52 (autoload 'liece-command-ctcp-help "liece-ctcp" nil t)
53
54 (defun liece-command-poll-names ()
55   "Handler for polling NAMES."
56   (when (liece-server-opened)
57     (setq liece-polling
58           (+ liece-polling
59              (length liece-channel-alist)))
60     (dolist (chnl liece-channel-alist)
61       (liece-send "NAMES %s" (car chnl)))))
62
63 (defun liece-command-poll-friends ()
64   "Handler for polling ISON."
65   (and liece-friends
66        (liece-server-opened)
67        (liece-send "ISON %s" (mapconcat 'identity liece-friends " "))))
68
69 (defun liece-command-find-timestamp ()
70   "Find recent timestamp in dialogue buffer."
71   (interactive)
72   (save-excursion
73     (let ((range "")
74           (regexp (concat "^\\(" liece-time-prefix-regexp "\\)?"
75                           (regexp-quote liece-timestamp-prefix))))
76       (unless (eq 'liece-dialogue-mode (derived-mode-class major-mode))
77         (set-buffer liece-dialogue-buffer)
78         (goto-char (point-max)))
79       (if (re-search-backward regexp (point-min) t)
80           (setq range (concat (buffer-substring (match-end 0)
81                                                 (line-end-position))
82                               "   ---   ")))
83       (if (re-search-forward regexp (point-max) t)
84           (setq range (concat range (buffer-substring (match-end 0)
85                                                       (line-end-position)))))
86       (liece-message range))))
87
88 (defun liece-command-keepalive ()
89   "Handler for polling server connection."
90   (if (not (liece-server-opened))
91       (liece)
92     (liece-ping-if-idle)))
93
94 (defvar liece-last-timestamp-time nil "Last time timestamp was inserted.")
95 (defvar liece-last-timestamp-no-cons-p nil "Last timestamp was no-cons.")
96
97 (defun liece-command-timestamp-if-interval-expired (&optional no-cons)
98   "If interval timer has expired, insert timestamp into dialogue buffer.
99 And save variables into `liece-variable-file' if there are variables to save.
100 Optional argument NO-CONS specifies timestamp format is cons cell."
101   (interactive)
102   (when (and (not (and no-cons
103                        liece-last-timestamp-no-cons-p))
104              (numberp liece-timestamp-interval)
105              (> liece-timestamp-interval 0)
106              (or (null liece-last-timestamp-time)
107                  (> (liece-time-difference liece-last-timestamp-time
108                                             (current-time))
109                     liece-timestamp-interval)))
110     (if liece-save-variables-are-dirty
111         (liece-command-save-vars))
112     (liece-command-timestamp)
113     (setq liece-last-timestamp-no-cons-p no-cons)))
114
115 (defun liece-command-timestamp ()
116   "Insert timestamp into dialogue buffer."
117   (interactive)
118   (let ((stamp (format liece-timestamp-format
119                        (funcall liece-format-time-function (current-time))))
120         (liece-timestamp-interval 0))
121     (liece-insert liece-D-buffer (concat stamp "\n"))
122     (setq liece-last-timestamp-time (current-time))))
123
124 (defun liece-command-point-back-to-command-buffer ()
125   "Set point back to command buffer."
126   (interactive)
127   (let ((win (liece-get-buffer-window liece-command-buffer)))
128     (if win (select-window win))))
129
130 (defun liece-command-send-message
131   (message &optional arg key)
132   "Send MESSAGE to current chat partner of current channel.
133 If argument ARG is non-nil message will be encrypted with KEY."
134   (when arg
135     (setq liece-crypt-mode-active (not liece-crypt-mode-active)))
136   (if (string-equal message "")
137       (progn (liece-message (_ "No text to send")) nil)
138     (let ((addr (if (eq liece-command-buffer-mode 'chat)
139                     liece-current-chat-partner
140                   liece-current-channel))
141           repr method name target
142           (msg message))
143       (with-liece-encryption (msg addr arg key)
144         (cond
145          ((eq liece-command-buffer-mode 'chat)
146           (if (null liece-current-chat-partner)
147               (message
148                (substitute-command-keys
149                 "Type \\[liece-command-join] to start private conversation"))
150             (setq repr (liece-channel-parse-representation
151                         liece-current-chat-partner)
152                   method (aref repr 0)
153                   name (aref repr 1)
154                   target (aref repr 2))
155             (cond ((eq method 'dcc)
156                    (liece-dcc-chat-send target msg))
157                   ((eq method 'irc)
158                    (liece-send "PRIVMSG %s :%s"
159                                 liece-current-chat-partner msg)))
160             (liece-own-private-message message)))
161          ((not liece-current-channel)
162           (beep t)
163           (message (substitute-command-keys
164                     "Type \\[liece-command-join] to join a channel")))
165          (t
166           (liece-send
167            "PRIVMSG %s :%s"
168            (liece-channel-real liece-current-channel) msg)
169           (liece-own-channel-message message))))
170       t)))
171
172 (defun liece-enter-message (&optional arg key)
173   "Enter the current line as an entry in the IRC dialogue.
174 If argument ARG is non-nil message will be encrypted with KEY."
175   (beginning-of-line)
176   (if (liece-command-send-message
177        (buffer-substring (point)(progn (end-of-line) (point)))
178        arg key)
179       (liece-next-line 1)))
180
181 (defun liece-command-enter-message (&optional arg key)
182   "Enter the current line as an entry in the IRC dialogue.
183 If the prefix argument ARG is non-nil, message will be encrypted with KEY."
184   (interactive
185    (let ((completion-ignore-case t))
186      (and (if current-prefix-arg
187               (not liece-crypt-mode-active)
188             liece-crypt-mode-active)
189           (list
190            'encrypt
191            (completing-read
192             (_ "Encrypt message with key [RET for none]: ")
193             (cons (cons "" nil)
194                   liece-crypt-encryption-keys))))))
195   (liece-enter-message arg (if (string-equal key "") nil key)))
196
197 (defun liece-dialogue-enter-message ()
198   "Ask for a line as an entry in the IRC dialogue on the current channel."
199   (interactive)
200   (let (message)
201     (while (not (string-equal (setq message (read-string "> ")) ""))
202       (liece-command-send-message message))))
203
204 (defun liece-command-inline ()
205   "Send current line as a message to the IRC server."
206   (interactive)
207   (beginning-of-line)
208   (liece-send (buffer-substring (point)(progn (end-of-line) (point))))
209   (liece-next-line 1))
210
211 (defun liece-command-join-channel (join-channel-var key)
212   "Join a JOIN-CHANNEL-VAR with KEY."
213   (let ((nicks liece-nick-alist) nick)
214     (while (and nicks
215                 (not (and
216                       (car nick)
217                       (liece-channel-equal join-channel-var (car nick)))))
218       (setq nick (pop nicks)))
219     (when nicks
220       (setq join-channel-var
221             (or (car (get (intern (car nick) liece-obarray) 'chnl))
222                 join-channel-var)))
223     (if (liece-channel-member join-channel-var liece-current-channels)
224         (progn
225           (setq liece-current-channel join-channel-var)
226           (liece-switch-to-channel liece-current-channel)
227           (liece-channel-change))
228       (liece-send "JOIN %s %s" (liece-channel-real join-channel-var) key))))
229
230 (defun liece-command-join-partner (join-channel-var)
231   "Join a JOIN-CHANNEL-VAR."
232   (if (liece-channel-member join-channel-var liece-current-chat-partners)
233       (progn
234         (setq liece-current-chat-partner join-channel-var)
235         (liece-switch-to-channel liece-current-chat-partner))
236     (setq liece-current-chat-partner join-channel-var)
237     (liece-channel-join liece-current-chat-partner))
238   (liece-channel-change))
239
240 (defun liece-command-join (join-channel-var &optional key)
241   "Join a JOIN-CHANNEL-VAR with KEY.
242 If user nickname is given join the same set of channels as the specified user.
243 If command-buffer is in chat-mode, start private conversation
244 with specified user."
245   (interactive
246    (let (join-channel-var key (completion-ignore-case t))
247      (setq join-channel-var
248            (if (numberp current-prefix-arg)
249                current-prefix-arg
250              (liece-channel-virtual
251               (if (eq liece-command-buffer-mode 'chat)
252                   (liece-minibuffer-completing-default-read
253                    (_ "Start private conversation with: ")
254                    liece-nick-alist
255                    nil nil liece-privmsg-partner)
256                 (liece-minibuffer-completing-default-read
257                  (_ "Join channel: ")
258                  (append liece-channel-alist liece-nick-alist)
259                  nil nil liece-default-channel-candidate)))))
260      (if (and current-prefix-arg
261               (not (numberp current-prefix-arg)))
262          (setq key
263                (if (eq current-prefix-arg '-)
264                    (read-string
265                     (format (_ "Key for channel %s: ") join-channel-var))
266                  (let ((passwd-echo ?*))
267                    (read-passwd
268                     (format (_ "Key for channel %s: ") join-channel-var))))))
269      (list join-channel-var key)))
270   (let ((real-chnl (liece-channel-real join-channel-var)))
271     (if (numberp join-channel-var)
272         (liece-switch-to-channel-no join-channel-var)
273       (setq liece-default-channel-candidate nil)
274       (if (liece-channel-p real-chnl)
275           (liece-toggle-command-buffer-mode 'channel)
276         (liece-toggle-command-buffer-mode 'chat))
277       (if (eq liece-command-buffer-mode 'chat)
278           (liece-command-join-partner join-channel-var)
279         (if (null key)
280             (setq key (get (intern join-channel-var liece-obarray) 'key)))
281         (put (intern join-channel-var liece-obarray) 'key key)
282         (if (null key)
283             (setq key ""))
284         (liece-command-join-channel join-channel-var key))
285       (force-mode-line-update))))
286
287 (defun liece-command-part (part-channel-var &optional part-msg)
288   "Part a PART-CHANNEL-VAR with PART-MSG."
289   (interactive
290    (let (part-channel-var
291          (completion-ignore-case t)
292          (part-msg "bye..."))
293      (setq part-channel-var
294            (liece-channel-virtual
295             (if (eq liece-command-buffer-mode 'chat)
296                 (liece-minibuffer-completing-default-read
297                  (_ "End private conversation with: ")
298                  (list-to-alist liece-current-chat-partners)
299                  nil nil liece-current-chat-partner)
300               (liece-minibuffer-completing-default-read
301                (_ "Part channel: ")
302                (list-to-alist liece-current-channels)
303                nil nil liece-current-channel))))
304      (when current-prefix-arg
305        (setq part-msg (read-string (_ "Part Message: "))))
306      (list part-channel-var part-msg)))
307   (let ((real-chnl (liece-channel-real part-channel-var)))
308     (if (liece-channel-p real-chnl)
309         (progn
310           (if (liece-channel-member part-channel-var liece-current-channels)
311               (setq liece-current-channel part-channel-var))
312           (liece-send "PART %s :%s" real-chnl part-msg)
313           (setq liece-default-channel-candidate part-channel-var))
314       (setq liece-current-chat-partners
315             (liece-channel-remove part-channel-var
316                                   liece-current-chat-partners)
317             liece-current-chat-partner
318             (car liece-current-chat-partners))
319       (liece-set-channel-indicator)
320       (liece-set-crypt-indicator)
321       (liece-channel-part part-channel-var))))
322
323 (defun liece-command-kill (kill-nickname-var &optional timeout silent)
324   "Ignore messages from KILL-NICKNAME-VAR.
325 Username can be given as case insensitive regular expression of form
326 \".*@.*\.sub.domain\".
327 If already ignoring him/her, toggle.
328 If `liece-variables-file' is defined and the file is writable,
329 settings are updated automatically for future sessions.
330 Optional argument TIMEOUT says expiration.
331 If SILENT is non-nil, don't notify current status."
332   (interactive
333    (let (kill-nickname-var timeout (completion-ignore-case t))
334      (setq kill-nickname-var (completing-read
335                               (_ "Ignore nickname or regexp: ")
336                               (append liece-nick-alist
337                                       liece-kill-nickname)))
338      (or (string-equal "" kill-nickname-var)
339          (string-assoc-ignore-case kill-nickname-var liece-kill-nickname)
340          (setq timeout (string-to-int (read-from-minibuffer
341                                        (_ "Timeout [RET for none]: ")))))
342      (list kill-nickname-var timeout)))
343   ;; empty, just list them
344   (if (string-equal "" kill-nickname-var)
345       (with-current-buffer liece-dialogue-buffer
346         (let ((ignores liece-kill-nickname) (time (current-time))
347               buffer-read-only expire expiretime)
348           (goto-char (point-max))
349           (liece-insert-info liece-D-buffer (_ "Currently ignoring:"))
350           (dolist (ignore ignores)
351             (setq expiretime (if (cdr ignore)
352                                  (/ (liece-time-difference time (cdr ignore))
353                                     60))
354                   expire (cond ((not expiretime) "")
355                                ((>= expiretime 0)
356                                 (format (_ " (%d min)") expiretime))
357                                ((< expiretime 0)
358                                 (_ " expired"))))
359             (liece-insert liece-D-buffer
360                            (concat " " (car ignore) expire "\n")))))
361     ;; else not empty, check if exists
362     (let ((ignore
363            (string-assoc-ignore-case
364             kill-nickname-var liece-kill-nickname)))
365       (if ignore
366           (when (setq ignore (string-assoc-ignore-case
367                               (car ignore) liece-kill-nickname))
368             (setq liece-kill-nickname
369                   (delq ignore liece-kill-nickname))
370             (liece-insert-info liece-D-buffer
371                                (format (_ "No longer ignoring: %s.\n")
372                                        (car ignore))))
373         ;; did not find, add to ignored ones
374         (let ((expire-time (if (> timeout 0)
375                                (liece-time-add (current-time)
376                                                 (* timeout 60)))))
377           (and silent (> timeout 0)
378                (setcar (cdr (cdr expire-time)) -1))
379           (setq liece-kill-nickname
380                 (cons (cons kill-nickname-var expire-time)
381                       liece-kill-nickname))
382           (unless silent
383             (liece-insert-info liece-D-buffer
384                                 (format (_ "Ignoring %s") kill-nickname-var))
385             (liece-insert-info liece-D-buffer
386                                 (if (> timeout 0)
387                                     (format " for %d minutes.\n" timeout)
388                                   (format ".\n")))))))
389     (setq liece-save-variables-are-dirty t)))
390
391 (defun liece-command-kick (nick &optional msg)
392   "Kick this NICK out with MSG."
393   (interactive
394    (let ((completion-ignore-case t)
395          (nicks (liece-channel-get-nicks)) nick msg)
396      (setq nick (completing-read
397                  (_ "Kick out nickname: ")
398                  (list-to-alist nicks)))
399      (if current-prefix-arg
400          (setq msg (concat " :" (read-string (_ "Kick Message: ")))))
401      (list nick msg)))
402   (liece-send "KICK %s %s%s"
403                (liece-channel-real liece-current-channel)
404                nick (or msg "")))
405
406 (defun liece-command-ban (ban)
407   "BAN this user out."
408   (interactive
409    (let* ((completion-ignore-case t)
410           (nicks (liece-channel-get-nicks))
411           (uahs (mapcar
412                  (function
413                   (lambda (nick)
414                     (list
415                      (concat nick "!" (liece-nick-get-user-at-host nick)))))
416                  nicks))
417           ban nick msg)
418      (setq ban (liece-minibuffer-completing-default-read
419                 (_ "Ban pattern: ") uahs nil nil
420                 (concat nick "!" (liece-nick-get-user-at-host nick))))
421      (list ban)))
422   (liece-send "MODE %s :+b %s"
423                (liece-channel-real liece-current-channel) ban))
424    
425 (defun liece-command-ban-kick (ban nick &optional msg)
426   "BAN kick this NICK out with MSG."
427   (interactive
428    (let* ((completion-ignore-case t)
429           (nicks (liece-channel-get-nicks))
430           (uahs (mapcar
431                  (function
432                   (lambda (nick)
433                     (list
434                      (concat nick "!" (liece-nick-get-user-at-host nick)))))
435                  nicks))
436           ban nick msg)
437      (setq nick (completing-read (_ "Kick out nickname: ")
438                                  (list-to-alist nicks))
439            ban (liece-minibuffer-completing-default-read
440                 (_ "Ban pattern: ") uahs nil nil
441                 (concat nick "!" (liece-nick-get-user-at-host nick))))
442      (if current-prefix-arg
443          (setq msg (concat " :" (read-string (_ "Kick Message: "))))
444        (setq msg ""))
445      (list ban nick msg)))
446   (liece-send "MODE %s :+b %s"
447                (liece-channel-real liece-current-channel) ban)
448   (liece-send "KICK %s %s%s"
449                (liece-channel-real liece-current-channel)
450                nick (or msg "")))
451
452 (defun liece-command-list (&optional channel)
453   "List the given CHANNEL and its topics.
454 If you enter only Control-U as argument, list the current channel.
455 With - as argument, list all channels."
456   (interactive
457    (if (or current-prefix-arg (null liece-current-channel))
458        (if (eq current-prefix-arg '-)
459            (list current-prefix-arg))
460      (let ((completion-ignore-case t) channel)
461        (setq channel (liece-minibuffer-completing-default-read
462                       (_ "LIST channel: ")
463                       liece-channel-alist nil nil liece-current-channel))
464        (unless (string-equal "" channel)
465          (list channel)))))
466   
467   (cond ((not channel)
468          (if liece-current-channel
469              (liece-send "LIST %s"
470                           (liece-channel-real liece-current-channel))))
471         ((and (eq channel '-)
472               (y-or-n-p (_ "Do you really query LIST without argument?")))
473          (liece-send "LIST"))
474         ((not (string-equal channel ""))
475          (liece-send "LIST %s" (liece-channel-real channel))
476          )))
477
478 (defun liece-command-lusers ()
479   "List the number of users and servers."
480   (interactive)
481   (liece-send "LUSERS"))
482
483 (defun liece-command-modec (chnl change)
484   "Send a MODE command to this CHNL.
485 Argument CHANGE ."
486   (interactive
487    (let ((completion-ignore-case t)
488          (chnl liece-current-channel)
489          liece-minibuffer-complete-function prompt)
490      (if current-prefix-arg
491          (setq chnl
492                (liece-minibuffer-completing-default-read
493                 (_ "Channel/User: ")
494                 (append liece-channel-alist liece-nick-alist)
495                 nil nil liece-current-channel)))
496      (cond
497       ((liece-channel-p (liece-channel-real chnl))
498        (setq prompt (format
499                      (_ "Mode for channel %s [%s]: ")
500                      chnl (or (liece-channel-get-modes chnl) ""))
501              liece-minibuffer-complete-function
502              (function liece-minibuffer-complete-channel-modes)))
503       (t
504        (setq prompt (format
505                      (_ "Mode for user %s [%s]: ")
506                      chnl (or (liece-nick-get-modes chnl) ""))
507              liece-minibuffer-complete-function
508              (function liece-minibuffer-complete-user-modes))))
509      (list chnl (read-from-minibuffer prompt nil liece-minibuffer-map))))
510   (liece-send "MODE %s %s" (liece-channel-real chnl) change))
511
512 (defun liece-command-mode+o (opers)
513   "Send a MODE +o OPERS command."
514   (interactive
515    (let ((opers (liece-channel-get-operators)) oper
516          (nicks (liece-channel-get-nicks))
517          (completion-ignore-case t))
518      (setq nicks (filter-elements
519                   nick nicks
520                   (not (liece-nick-member nick opers)))
521            opers (liece-minibuffer-completing-sequential-read
522                   (_ "Set Operator for") 0
523                   (list-to-alist nicks)))
524      (list opers)))
525   (let (ops)
526     (dolist (oper opers)
527       (push oper ops)
528       (when (= (length ops) liece-compress-mode-length)
529         (liece-send "MODE %s +%s %s"
530                      (liece-channel-real liece-current-channel)
531                      (string-times "o" liece-compress-mode-length)
532                      (string-join ops " "))
533         (setq ops nil)))
534     (if ops
535         (liece-send "MODE %s +%s %s"
536                      (liece-channel-real liece-current-channel)
537                      (string-times "o" (length ops))
538                      (string-join ops " ")))))
539
540 (defun liece-command-mode-o (opers)
541   "Send a MODE -o OPERS command."
542   (interactive
543    (let ((completion-ignore-case t)
544          (opers (liece-channel-get-operators)) oper nicks)
545      (setq nicks (liece-minibuffer-completing-sequential-read
546                   (_ "Unset Operator for") 0
547                   (list-to-alist opers)))
548      (list nicks)))
549   (let (ops)
550     (dolist (oper opers)
551       (push oper ops)
552       (when (= (length ops) liece-compress-mode-length)
553         (liece-send "MODE %s -%s %s"
554                      (liece-channel-real liece-current-channel)
555                      (string-times "o" liece-compress-mode-length)
556                      (string-join ops " "))
557         (setq ops nil)))
558     (if ops
559         (liece-send "MODE %s -%s %s"
560                      (liece-channel-real liece-current-channel)
561                      (string-times "o" (length ops))
562                      (string-join ops " ")))))
563
564 (defun liece-command-mode+v (voices)
565   "Send a MODE +v VOICES command."
566   (interactive
567    (let ((voices (append (liece-channel-get-voices)
568                          (liece-channel-get-operators)))
569          voice
570          (nicks (liece-channel-get-nicks))
571          (completion-ignore-case t)
572          (count 0))
573      (setq nicks (filter-elements nick nicks
574                    (not (string-assoc-ignore-case nick voices)))
575            voices (liece-minibuffer-completing-sequential-read
576                    (_ "Set Voice for") 0 (list-to-alist nicks)))
577      (list voices)))
578   (let (vcs)
579     (dolist (voice voices)
580       (push voice vcs)
581       (when (= (length vcs) liece-compress-mode-length)
582         (liece-send "MODE %s +%s %s"
583                      (liece-channel-real liece-current-channel)
584                      (string-times "v" liece-compress-mode-length)
585                      (string-join vcs " "))
586         (setq vcs nil)))
587     (if vcs
588         (liece-send "MODE %s +%s %s"
589                      (liece-channel-real liece-current-channel)
590                      (string-times "v" (length vcs))
591                      (string-join vcs " ")))))
592
593 (defun liece-command-mode-v (voices)
594   "Send a MODE -v VOICES command."
595   (interactive
596    (let ((completion-ignore-case t)
597          (voices (liece-channel-get-voices)) voice nicks)
598      (setq nicks (liece-minibuffer-completing-sequential-read
599                   (_ "Unset Voice for") 0 (list-to-alist voices)))
600      (list nicks)))
601   (let (vcs)
602     (dolist (voice voices)
603       (push voice vcs)
604       (when (= (length vcs) liece-compress-mode-length)
605         (liece-send "MODE %s -%s %s"
606                      (liece-channel-real liece-current-channel)
607                      (string-times "v" liece-compress-mode-length)
608                      (string-join vcs " "))
609         (setq vcs nil)))
610     (if vcs
611         (liece-send "MODE %s -%s %s"
612                      (liece-channel-real liece-current-channel)
613                      (string-times "v" (length vcs))
614                      (string-join vcs " ")))))
615
616 (defun liece-command-message (address message &optional arg key)
617   "Send ADDRESS a private MESSAGE.
618 If argument ARG is non-nil message will be encrypted with KEY."
619   (interactive
620    (let ((completion-ignore-case t) address)
621      (setq address
622            (liece-channel-virtual
623             (liece-minibuffer-completing-default-read
624              (_ "Private message to: ")
625              (append liece-nick-alist liece-channel-alist)
626              nil nil liece-privmsg-partner)))
627      (list address
628            (read-string
629             (format
630              (_ "Private message to %s: ")
631              address))
632            (if current-prefix-arg
633                (not liece-crypt-mode-active)
634              liece-crypt-mode-active)
635            nil)))
636   (if (funcall liece-message-empty-predicate message)
637       (progn (liece-message (_ "No text to send")) nil)
638     (let ((chnl (liece-channel-real address)) (msg message))
639       (with-liece-encryption (msg address arg key)
640         (liece-send "PRIVMSG %s :%s" chnl msg)
641         (if (liece-channel-p chnl)
642             (liece-own-channel-message message
643                                         (liece-channel-virtual address))
644           (liece-own-private-message message address)))
645       t)))
646
647 ;; Added at mta@tut.fi's request...
648 ;; Does not support encryption (yet!?)
649
650 (defun liece-command-mta-private (partner)
651   "Send a private message (current line) to PARTNER."
652   (interactive
653    (let ((completion-ignore-case t))
654      (setq liece-privmsg-partner
655            (liece-channel-virtual
656             (liece-minibuffer-completing-default-read
657              (_ "To whom: ")
658              (append liece-nick-alist liece-channel-alist)
659              nil nil liece-privmsg-partner)))
660      (list liece-privmsg-partner)))
661   (let ((message (buffer-substring (progn (beginning-of-line) (point))
662                                    (progn (end-of-line) (point)))))
663     (if (> (length message) 0)
664         (progn
665           (liece-command-message liece-privmsg-partner message)
666           (liece-next-line 1))
667       (liece-message (_ "No text to send")))))
668
669 (defun liece-command-names (&optional channel)
670   "List the nicknames of the current IRC users on given CHANNEL.
671 With an Control-U as argument, only the current channel is listed.
672 With - as argument, list all channels."
673   (interactive
674    (if (or current-prefix-arg (null liece-current-channel))
675        (if (eq current-prefix-arg '-)
676            (list current-prefix-arg))
677      (let ((completion-ignore-case t) channel)
678        (setq channel (liece-minibuffer-completing-default-read
679                       (_ "Names on channel: ")
680                       liece-channel-alist nil nil liece-current-channel))
681        (unless (string-equal "" channel)
682          (list channel)))))
683   (cond
684    ((not channel)
685     (liece-send "NAMES %s"
686                 (liece-channel-real liece-current-channel)))
687    ((and (eq channel '-)
688          (y-or-n-p (_ "Do you really query NAMES without argument?")))
689     (liece-send "NAMES"))
690    (t
691     (liece-send "NAMES %s" (liece-channel-real channel)))))
692
693 (defun liece-command-nickname (nick)
694   "Set your nickname to NICK."
695   (interactive "sEnter your nickname: ")
696   (let ((nickname (truncate-string nick liece-nick-max-length)))
697     (if (zerop (length nickname))
698         (liece-message (_ "illegal nickname \"%s\"; not changed") nickname)
699       (liece-send "NICK %s" nick))))
700       
701 (defun liece-command-who (&optional expr)
702   "Lists tue users that match the given expression EXPR.
703 If you enter only Control-U as argument, list the current channel.
704 With - as argument, list all users."
705   (interactive
706    (if (or current-prefix-arg (null liece-current-channel))
707        (if (eq current-prefix-arg '-)
708            (list current-prefix-arg))
709      (let ((completion-ignore-case t) expr)
710        (setq expr (liece-minibuffer-completing-default-read
711                    (_ "WHO expression: ")
712                    (append liece-channel-alist liece-nick-alist)))
713        (unless (string-equal "" expr)
714          (list expr)))))
715   (cond
716    ((not expr)
717     (liece-send "WHO %s" (liece-channel-real liece-current-channel)))
718    ((and (eq expr '-)
719          (y-or-n-p (_ "Do you really query WHO without argument?")))
720     (liece-send "WHO"))
721    (t
722     (liece-send "WHO %s" expr)
723     (setq liece-who-expression expr))))
724
725 (defun liece-command-finger (finger-nick-var &optional server)
726   "Get information about a specific user FINGER-NICK-VAR.
727 If called with optional argument SERVER or any prefix argument,
728 query information to the foreign server."
729   (interactive
730    (let (finger-nick-var (completion-ignore-case t))
731      (setq finger-nick-var
732            (completing-read (_ "Finger whom: ") liece-nick-alist))
733      (list finger-nick-var (and current-prefix-arg finger-nick-var))))
734   (if server
735       (liece-send "WHOIS %s %s" server finger-nick-var)
736     (liece-send "WHOIS %s" finger-nick-var)))
737
738 (defun liece-command-topic (topic)
739   "Change TOPIC of the current channel."
740   (interactive
741    (list (read-from-minibuffer
742           "Topic: " (cons (or (liece-channel-get-topic) "") 0))))
743   (liece-send "TOPIC %s :%s"
744               (liece-channel-real liece-current-channel) topic))
745
746 (defun liece-command-invite (&optional invite-nick-var invite-channel-var)
747   "Invite INVITE-NICK-VAR to INVITE-CHANNEL-VAR."
748   (interactive
749    (let ((completion-ignore-case t) invite-channel-var invite-nick-var)
750      (if current-prefix-arg
751          (setq invite-channel-var
752                (liece-channel-virtual
753                 (completing-read
754                  (_ "Invite channel: ")
755                  (list-to-alist liece-current-channels)))))
756      (setq invite-nick-var
757            (completing-read
758             (_ "Invite whom: ")
759             liece-nick-alist))
760      (list invite-nick-var invite-channel-var)))
761   (or invite-channel-var
762       (setq invite-channel-var liece-current-channel))
763   (liece-send "INVITE %s %s"
764                invite-nick-var (liece-channel-real invite-channel-var)))
765
766 (defun liece-command-away (awaymsg)
767   "Mark/unmark yourself as being away.
768 Leave message AWAYMSG."
769   (interactive "sAway message: ")
770   (liece-send "AWAY :%s" awaymsg)
771   (setq liece-away-message awaymsg))
772
773 (defun liece-command-scroll-down (lines)
774   "Scroll LINES down dialogue buffer from command buffer."
775   (interactive "P")
776   (let ((other-window-scroll-buffer
777          (if liece-channel-buffer-mode
778              liece-channel-buffer
779            liece-dialogue-buffer)))
780     (when (liece-get-buffer-window other-window-scroll-buffer)
781       (condition-case nil
782           (scroll-other-window-down lines)
783         (beginning-of-buffer
784          (message "Beginning of buffer"))))))
785
786 (defun liece-command-scroll-up (lines)
787   "Scroll LINES up dialogue buffer from command buffer."
788   (interactive "P")
789   (let* ((other-window-scroll-buffer
790           (if liece-channel-buffer-mode
791               liece-channel-buffer
792             liece-dialogue-buffer)))
793     (when (liece-get-buffer-window other-window-scroll-buffer)
794       (condition-case nil
795           (scroll-other-window lines)
796         (end-of-buffer
797          (message "End of buffer"))))))
798
799 (defun liece-command-nick-scroll-down (lines)
800   "Scroll LINES down nick buffer from command buffer."
801   (interactive "P")
802   (let ((other-window-scroll-buffer liece-nick-buffer))
803     (when (liece-get-buffer-window other-window-scroll-buffer)
804       (condition-case nil
805           (scroll-other-window-down lines)
806         (beginning-of-buffer
807          (message "Beginning of buffer"))))))
808
809 (defun liece-command-nick-scroll-up (lines)
810   "Scroll LINES up nick buffer from command buffer."
811   (interactive "P")
812   (let* ((other-window-scroll-buffer liece-nick-buffer))
813     (when (liece-get-buffer-window other-window-scroll-buffer)
814       (condition-case nil
815           (scroll-other-window lines)
816         (end-of-buffer
817          (message "End of buffer"))))))
818
819 (defun liece-command-toggle-crypt (&optional arg)
820   "Toggle crypt status.
821 If prefix argument ARG is non-nil, force set crypt status."
822   (interactive "P")
823   (if arg
824       (setq liece-crypt-mode-active (prefix-numeric-value arg))
825     (if liece-crypt-mode-active
826         (setq liece-crypt-mode-active nil)
827       (setq liece-crypt-mode-active t)))
828   (liece-set-crypt-indicator)
829   (switch-to-buffer (current-buffer)))
830
831 (defun liece-command-freeze (&optional arg)
832   "Prevent automatic scrolling of the dialogue window.
833 If prefix argument ARG is non-nil, toggle frozen status."
834   (interactive "P")
835   (liece-freeze (if liece-channel-buffer-mode
836                     liece-channel-buffer
837                   liece-dialogue-buffer)
838                 (if arg (prefix-numeric-value arg))))
839
840 (defun liece-command-own-freeze (&optional arg)
841   "Prevent automatic scrolling of the dialogue window.
842 The difference from `liece-command-freeze' is that your messages are hidden.
843 If prefix argument ARG is non-nil, toggle frozen status."
844   (interactive "P")
845   (liece-own-freeze (if liece-channel-buffer-mode
846                         liece-channel-buffer
847                       liece-dialogue-buffer)
848                     (if arg (prefix-numeric-value arg))))
849
850 (defun liece-command-quit (&optional arg)
851   "Quit IRC.
852 If prefix argument ARG is non-nil, leave signoff message."
853   (interactive "P")
854   (when (and (liece-server-opened)
855              (y-or-n-p (_ "Quit IRC? ")))
856     (message "")
857     (let ((quit-string
858            (if arg (read-string (_ "Signoff message: "))
859              (or liece-signoff-message
860                  (product-name (product-find 'liece-version))))))
861       (liece-send "QUIT :%s" quit-string))
862     (liece-clear-system)
863     (liece-close-server)
864     (if liece-save-variables-are-dirty
865         (liece-command-save-vars))
866     (if (interactive-p)
867         (liece-window-configuration-pop))
868     (run-hooks 'liece-exit-hook)))
869
870 (defun liece-command-generic (message)
871   "Enter a generic IRC MESSAGE, which is sent to the server.
872 A ? lists the useful generic messages."
873   (interactive "sIRC command (? to help): ")
874   (if (string-equal message "?")
875       (with-output-to-temp-buffer "*IRC Help*"
876         (princ "The following generic IRC messages may be of interest to you:
877 TOPIC <new topic>               set the topic of your channel
878 INVITE <nickname>               invite another user to join your channel
879 LINKS                           lists the currently reachable IRC servers
880 SUMMON <user@host>              invites an user not currently in IRC
881 USERS <host>                    lists the users on a host
882 AWAY <reason>                   marks you as not really actively using IRC
883                                 (an empty reason clears it)
884 WALL <message>                  send to everyone on IRC
885 NAMES <channel>                 lists users per channel
886 "))
887     (liece-send "%s" message)))
888
889 (defun liece-command-irc-compatible ()
890   "If entered at column 0, allow you to enter a generic IRC message."
891   (interactive)
892   (if (zerop (current-column))
893       (call-interactively (function liece-command-generic))
894     (self-insert-command 1)))
895
896 (defun liece-command-exec (command)
897   "Execute COMMAND, stdout to dialogue."
898   (interactive "sShell command: ")
899   (shell-command command t)
900   (let ((opoint (point)))
901     (while (< (point) (mark))
902       (liece-command-enter-message)
903       (set-buffer liece-command-buffer))
904     (push-mark opoint t)))
905
906 (defun liece-command-yank-send (&optional arg)
907   "Send message from yank buffer.
908 Prefix argument ARG is regarded as distance from yank pointer."
909   (interactive)
910   (when (y-or-n-p (_ "Really SEND from Yank Buffer?"))
911     (save-restriction
912       (narrow-to-region (point) (point))
913       (insert (car kill-ring-yank-pointer))
914       (goto-char (point-min))
915       (while (eobp)
916         (liece-command-enter-message)
917         (set-buffer liece-command-buffer)))))
918
919 (defun liece-command-complete ()
920   "Complete word before point from userlist."
921   (interactive)
922   (let ((completion-ignore-case t)
923         (alist (if liece-current-channel
924                    (list-to-alist (liece-channel-get-nicks))
925                  liece-nick-alist))
926         candidate completion all)
927     (setq candidate (current-word)
928           completion (try-completion candidate alist)
929           all (all-completions candidate alist))
930     (liece-minibuffer-finalize-completion completion candidate all)))
931
932 (defun liece-command-load-vars ()
933   "Load configuration from liece-variables-file."
934   (interactive)
935   (let ((nick liece-real-nickname))
936     (unwind-protect
937         (liece-read-variables-files)
938       (setq liece-real-nickname nick)
939       (liece-command-reconfigure-windows))))
940
941 (defun liece-command-save-vars ()
942   "Save current settings to `liece-variables-file'."
943   (interactive)
944   (let* ((output-buffer
945           (find-file-noselect
946            (expand-file-name liece-variables-file)))
947          output-marker p)
948     (save-excursion
949       (set-buffer output-buffer)
950       (goto-char (point-min))
951       (cond ((re-search-forward "^;; Saved Settings *\n" nil 'move)
952              (setq p (match-beginning 0))
953              (goto-char p)
954              (or (re-search-forward
955                   "^;; End of Saved Settings *\\(\n\\|\\'\\)" nil t)
956                  (error
957                   (concat "can't find END of saved state in "
958                           liece-variables-file)))
959              (delete-region p (match-end 0)))
960             (t
961              (goto-char (point-max))
962              (insert "\n")))
963       (setq output-marker (point-marker))
964       (let ((print-readably t)
965             (print-escape-newlines t)
966             (standard-output output-marker))
967         (princ ";; Saved Settings\n")
968         (dolist (var liece-saved-forms)
969           (if (symbolp var)
970               (prin1 (list 'setq var
971                            (let ((val (symbol-value var)))
972                              (if (memq val '(t nil))
973                                  val
974                                (list 'quote val)))))
975             (setq var (eval var))
976             (cond ((eq (car-safe var) 'progn)
977                    (while (setq var (cdr var))
978                      (prin1 (car var))
979                      (princ "\n")
980                      (if (cdr var) (princ "  "))))
981                   (var
982                    (prin1 "xx")(prin1 var))))
983           (if var (princ "\n")))
984         (princ "\n")
985         (princ ";; End of Saved Settings\n")))
986     (set-marker output-marker nil)
987     (save-excursion
988       (set-buffer output-buffer)
989       (save-buffer)))
990   (setq liece-save-variables-are-dirty nil))
991
992 (defun liece-command-reconfigure-windows ()
993   "Rearrange window splitting."
994   (interactive)
995   (let ((command-window (liece-get-buffer-window liece-command-buffer))
996         (dialogue-window (liece-get-buffer-window liece-dialogue-buffer))
997         (obuffer (current-buffer)))
998     (if (and command-window dialogue-window)
999         (let ((ch (window-height command-window))
1000               (dh (window-height dialogue-window)))
1001           (delete-window command-window)
1002           (pop-to-buffer liece-dialogue-buffer)
1003           (enlarge-window (+ ch dh (- dh))))
1004       (pop-to-buffer liece-dialogue-buffer))
1005     (liece-configure-windows)
1006     (if liece-one-buffer-mode
1007         (pop-to-buffer liece-dialogue-buffer)
1008       (pop-to-buffer obuffer))))
1009
1010 (defun liece-command-end-of-buffer ()
1011   "Get end of the dialogue buffer."
1012   (interactive)
1013   (let (buffer window)
1014     (setq buffer (if liece-channel-buffer-mode
1015                      liece-channel-buffer
1016                    liece-dialogue-buffer))
1017     (or (setq window (liece-get-buffer-window buffer))
1018         (setq window (liece-get-buffer-window liece-dialogue-buffer)
1019               buffer liece-dialogue-buffer))
1020     (when window
1021       (save-selected-window
1022         (select-window window)
1023         (goto-char (point-max))))))
1024
1025 (defun liece-command-private-conversation (arg)
1026   "Toggle between private conversation mode and channel mode.
1027 User can then join and part to a private conversation as he would
1028 join or part to a channel.
1029
1030 If there are no private conversations or argument is given user is
1031 prompted the partner/channel (return as partner/channel means toggle
1032 mode, the current channel and current chat partner are not altered)
1033 Argument ARG is prefix argument of toggle status."
1034   (interactive
1035    (let ((completion-ignore-case t))
1036      (list
1037       (if current-prefix-arg
1038           ;; prefixed, ask where to continue
1039           (if (eq liece-command-buffer-mode 'chat)
1040               (liece-minibuffer-completing-default-read
1041                (_ "Return to channel: ")
1042                (append liece-channel-alist liece-nick-alist)
1043                nil nil liece-current-channel)
1044             (completing-read
1045              (_ "Start private conversation with: ")
1046              liece-nick-alist nil nil))
1047         ;; no prefix, see if going to chat
1048         (if (eq liece-command-buffer-mode 'channel)
1049             ;; and if we have chat partner, select that
1050             (if liece-current-chat-partner
1051                 liece-current-chat-partner
1052               (completing-read
1053                (_ "Start private conversation with: ")
1054                liece-nick-alist )))))))
1055   
1056   (liece-toggle-command-buffer-mode)
1057   (if (and arg (not (string-equal arg "")))
1058       (liece-command-join arg))
1059   (liece-set-channel-indicator)
1060   (liece-set-crypt-indicator)
1061   ;; refresh mode line
1062   (force-mode-line-update))
1063
1064 (defun liece-command-next-channel ()
1065   "Select next channel or chat partner, and *DONT* rotate list."
1066   (interactive)
1067   (let ((rest (copy-sequence
1068                (if (eq liece-command-buffer-mode 'chat)
1069                    liece-current-chat-partners
1070                  liece-current-channels)))
1071         (chnl (if (eq liece-command-buffer-mode 'chat)
1072                   liece-current-chat-partner
1073                 liece-current-channel)))
1074     (liece-switch-to-channel
1075      (or (cadr (liece-channel-member chnl (delq nil rest)))
1076          (car (delq nil rest))
1077          chnl))))
1078
1079 (defun liece-command-previous-channel ()
1080   "Select previous channel or chat partner, and *DONT* rotate list."
1081   (interactive)
1082   (let ((rest
1083          (reverse
1084           (if (eq liece-command-buffer-mode 'chat)
1085               liece-current-chat-partners
1086             liece-current-channels)))
1087         (chnl
1088          (if (eq liece-command-buffer-mode 'chat)
1089              liece-current-chat-partner
1090            liece-current-channel)))
1091     (liece-switch-to-channel
1092      (or (cadr (liece-channel-member chnl (delq nil rest)))
1093          (car (delq nil rest))
1094          chnl))))
1095       
1096 (defun liece-command-push ()
1097   "Select next channel or chat partner, and rotate list."
1098   (interactive)
1099   (let* ((rest
1100           (if (eq liece-command-buffer-mode 'chat)
1101               liece-current-chat-partners
1102             liece-current-channels))
1103          (temp (car (last rest)))
1104          (len (length rest)))
1105     (unwind-protect
1106         (while (< 1 len)
1107           (setcar (nthcdr (1- len) rest) (nth (- len 2) rest))
1108           (decf len))
1109       (when rest
1110         (setcar rest temp)))
1111     (liece-channel-change)))
1112
1113 (defun liece-command-pop ()
1114   "Select previous channel or chat partner, and rotate list."
1115   (interactive)
1116   (let* ((rest
1117           (if (eq liece-command-buffer-mode 'chat)
1118               liece-current-chat-partners
1119             liece-current-channels))
1120          (temp (car rest))
1121          (len (length rest)))
1122     (unwind-protect
1123         (dotimes (i len)
1124           (setcar (nthcdr i rest) (nth (1+ i) rest)))
1125       (when rest
1126         (setcar (last rest) temp)))
1127     (liece-channel-change)))
1128
1129 (defvar liece-redisplay-buffer-functions
1130   '(liece-channel-redisplay-buffer
1131     liece-nick-redisplay-buffer
1132     liece-channel-list-redisplay-buffer))
1133
1134 (defun liece-switch-to-channel (chnl)
1135   "Switch the current channel to CHNL."
1136   (if (liece-channel-p (liece-channel-real chnl))
1137       (progn
1138         (liece-toggle-command-buffer-mode 'channel)
1139         (setq liece-current-channel chnl)
1140         (liece-set-channel-indicator))
1141     (liece-toggle-command-buffer-mode 'chat)
1142     (setq liece-current-chat-partner chnl)
1143     (liece-set-channel-indicator))
1144   (save-excursion
1145     (run-hook-with-args 'liece-redisplay-buffer-functions chnl))
1146   (liece-set-crypt-indicator)
1147   t)
1148
1149 (defun liece-switch-to-channel-no (num)
1150   "Switch the current channel to NUM."
1151   (let* ((mode liece-command-buffer-mode)
1152          (chnls (if (eq mode 'chat)
1153                     liece-current-chat-partners
1154                   liece-current-channels)))
1155     (if (and (integerp num)
1156              (stringp (nth num chnls)))
1157         (let ((chnl (nth num chnls)))
1158           (if (eq mode 'chat)
1159               (progn
1160                 (liece-toggle-command-buffer-mode 'chat)
1161                 (setq liece-current-chat-partner chnl)
1162                 (liece-set-channel-indicator))
1163             (liece-toggle-command-buffer-mode 'channel)
1164             (setq liece-current-channel chnl)
1165             (liece-set-channel-indicator))
1166           (save-excursion
1167             (run-hook-with-args 'liece-redisplay-buffer-functions chnl))
1168           (liece-set-crypt-indicator)
1169           t)
1170       (message "Invalid channel!")
1171       nil)))
1172
1173 (defun liece-command-ping ()
1174   "Send PING to server."
1175   (interactive)
1176   (if (stringp liece-server-name)
1177       (liece-send "PING %s" liece-server-name)))
1178
1179 (defun liece-command-ison (nicks)
1180   "IsON users NICKS."
1181   (interactive
1182    (let (nicks (completion-ignore-case t))
1183      (setq nicks (liece-minibuffer-completing-sequential-read
1184                   "IsON" 0 liece-nick-alist))
1185      (list nicks)))
1186   (liece-send "ISON :%s" (mapconcat #'identity nicks " ")))
1187
1188 (defun liece-command-activate-friends (nicks)
1189   "Register NICKS to the frinends list."
1190   (interactive
1191    (let (nicks (completion-ignore-case t))
1192      (setq nicks
1193            (liece-minibuffer-completing-sequential-read
1194             (_ "Friend") 0
1195             (filter-elements nick liece-nick-alist
1196               (not (string-list-member-ignore-case
1197                     (car nick) liece-friends)))))
1198      (list nicks)))
1199   (setq liece-friends (append nicks liece-friends)))
1200
1201 (defun liece-command-deactivate-friends ()
1202   "Clear current friends list."
1203   (interactive)
1204   (setq liece-friends nil))
1205
1206 (defun liece-command-display-friends ()
1207   "Display status of the friends."
1208   (interactive)
1209   (with-output-to-temp-buffer " *IRC Friends*"
1210     (set-buffer standard-output)
1211     (insert "Friends status: \n\n")
1212     (dolist (friend liece-friends)
1213       (if (string-list-member-ignore-case friend liece-friends-last)
1214           (insert "+ " friend "\n")
1215         (insert "- " friend "\n")))))
1216
1217 (defun liece-command-userhost (nicks)
1218   "Ask for the hostnames of NICKS."
1219   (interactive
1220    (let (nicks (completion-ignore-case t))
1221      (setq nicks (liece-minibuffer-completing-sequential-read
1222                   (_ "Userhost nick") 0
1223                   (list-to-alist liece-nick-alist)))
1224      (list nicks)))
1225   (liece-send "USERHOST :%s" (mapconcat 'identity nicks ",")))
1226
1227 (defun liece-command-show-last-kill ()
1228   "Dig last kill from KILL and show it."
1229   (interactive)
1230   (liece-insert-info
1231    (append liece-D-buffer liece-O-buffer)
1232    (save-excursion
1233      (set-buffer liece-KILLS-buffer)
1234      (goto-char (point-max))
1235      (forward-line -1)
1236      (concat (buffer-substring (point) (point-max)) "\n"))))
1237
1238 (defun liece-command-toggle-private ()
1239   "Toggle private mode / channel mode."
1240   (interactive)
1241   (case (prog1 liece-command-buffer-mode
1242           (liece-toggle-command-buffer-mode))
1243     (chat
1244      (if liece-current-channel
1245          (liece-switch-to-channel liece-current-channel))
1246      (setq liece-command-buffer-mode-indicator "Channels"))
1247     (channel
1248      (if liece-current-chat-partner
1249          (liece-switch-to-channel liece-current-chat-partner))
1250      (setq liece-command-buffer-mode-indicator "Partners")))
1251   (liece-channel-change))
1252
1253 (defun liece-command-tag-region (start end)
1254   "Move current region between START and END to `kill-ring'."
1255   (interactive
1256    (if (region-active-p)
1257        (list (region-beginning)(region-end))
1258      (list (line-beginning-position)(line-end-position))))
1259   (static-if (fboundp 'extent-property)
1260       (kill-ring-save start end)
1261     (let ((start (set-marker (make-marker) start))
1262           (end (set-marker (make-marker) end))
1263           (inhibit-read-only t)
1264           buffer-read-only
1265           buffer-undo-list)
1266       (liece-remove-properties-region start end)
1267       (kill-ring-save start end)
1268       (push nil buffer-undo-list)
1269       (undo))))
1270
1271 (provide 'liece-commands)
1272
1273 ;;; liece-commands.el ends here