* riece.el (riece-command-mode): Set
[riece] / lisp / riece.el
1 ;;; riece.el --- IRC client for Emacsen
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-display)
28 (require 'riece-server)
29 (require 'riece-compat)
30 (require 'riece-commands)
31 (require 'riece-addon)
32 (require 'riece-signal)
33
34 (autoload 'derived-mode-class "derived")
35
36 (defvar riece-channel-list-mode-map (make-sparse-keymap))
37 (defvar riece-user-list-mode-map (make-sparse-keymap))
38
39 (defvar riece-dialogue-mode-map
40   (let ((keymap (make-keymap)))
41     (suppress-keymap keymap 'nodigit)
42     keymap))
43
44 (defvar riece-command-mode-map (make-keymap))
45 (defvar riece-command-map (make-sparse-keymap))
46
47 (defvar riece-command-mode-syntax-table nil)
48
49 (put 'riece-command-mode 'mode-class 'special)
50 (put 'riece-dialogue-mode 'mode-class 'special)
51 (put 'riece-others-mode 'derived-mode-parent 'riece-dialogue-mode)
52 (put 'riece-channel-list-mode 'mode-class 'special)
53 (put 'riece-user-list-mode 'mode-class 'special)
54 (put 'riece-channel-mode 'derived-mode-parent 'riece-dialogue-mode)
55
56 (defvar riece-buffer-alist
57   '((riece-command-buffer "*Command*" riece-command-mode)
58     (riece-dialogue-buffer "*Dialogue*" riece-dialogue-mode)
59     (riece-others-buffer "*Others*" riece-others-mode)
60     (riece-channel-list-buffer "*Channels*" riece-channel-list-mode)
61     (riece-user-list-buffer " *Users*" riece-user-list-mode)
62     (riece-temp-buffer " *Temp*")
63     (riece-debug-buffer " *Debug*")))
64
65 (defvar riece-shrink-buffer-idle-timer nil
66   "Timer object to periodically shrink channel buffers.")
67
68 (defvar riece-select-keys
69   `("#" riece-command-switch-to-channel-by-number
70     "1" riece-command-switch-to-channel-by-number-1
71     "2" riece-command-switch-to-channel-by-number-2
72     "3" riece-command-switch-to-channel-by-number-3
73     "4" riece-command-switch-to-channel-by-number-4
74     "5" riece-command-switch-to-channel-by-number-5
75     "6" riece-command-switch-to-channel-by-number-6
76     "7" riece-command-switch-to-channel-by-number-7
77     "8" riece-command-switch-to-channel-by-number-8
78     "9" riece-command-switch-to-channel-by-number-9
79     "0" riece-command-switch-to-channel-by-number-10
80     ,(concat riece-command-prefix "1")
81     riece-command-switch-to-channel-by-number-11
82     ,(concat riece-command-prefix "2")
83     riece-command-switch-to-channel-by-number-12
84     ,(concat riece-command-prefix "3")
85     riece-command-switch-to-channel-by-number-13
86     ,(concat riece-command-prefix "4")
87     riece-command-switch-to-channel-by-number-14
88     ,(concat riece-command-prefix "5")
89     riece-command-switch-to-channel-by-number-15
90     ,(concat riece-command-prefix "6")
91     riece-command-switch-to-channel-by-number-16
92     ,(concat riece-command-prefix "7")
93     riece-command-switch-to-channel-by-number-17
94     ,(concat riece-command-prefix "8")
95     riece-command-switch-to-channel-by-number-18
96     ,(concat riece-command-prefix "9")
97     riece-command-switch-to-channel-by-number-19
98     ,(concat riece-command-prefix "0")
99     riece-command-switch-to-channel-by-number-20))
100
101 ;;; Keymap macros. -- borrowed from `gnus-util.el'.
102 (defmacro riece-local-set-keys (&rest plist)
103   "Set the keys in PLIST in the current keymap."
104   `(riece-define-keys-1 (current-local-map) ',plist))
105
106 (defmacro riece-define-keys (keymap &rest plist)
107   "Assign KEYMAP keys from PLIST."
108   `(riece-define-keys-1 ',keymap ',plist))
109
110 (defmacro riece-define-keys-safe (keymap &rest plist)
111   "Assign KEYMAP keys from PLIST without overwriting previous definitions."
112   `(riece-define-keys-1 ',keymap ',plist t))
113
114 (put 'riece-define-keys 'lisp-indent-function 1)
115 (put 'riece-define-keys-safe 'lisp-indent-function 1)
116 (put 'riece-local-set-keys 'lisp-indent-function 1)
117
118 (defun riece-define-keys-1 (keymap plist &optional safe)
119   "Assign KEYMAP keys from PLIST.
120 If optional argument SAFE is nil, overwrite previous definitions."
121   (unless keymap
122     (error "Can't set keys in a null keymap"))
123   (cond
124    ((symbolp keymap)
125     (setq keymap (symbol-value keymap)))
126    ((keymapp keymap))
127    ((listp keymap)
128     (set (car keymap) nil)
129     (define-prefix-command (car keymap))
130     (define-key (symbol-value (nth 2 keymap))
131       (if (symbolp (nth 1 keymap))
132           (symbol-value (nth 1 keymap))
133         (nth 1 keymap))
134       (car keymap))
135     (setq keymap (symbol-value (car keymap)))))
136   (let (key)
137     (while plist
138       (if (symbolp (setq key (car plist)))
139           (setq key (symbol-value key)))
140       (setq plist (cdr plist))
141       (if (or (not safe)
142               (eq (lookup-key keymap key) 'undefined))
143           (define-key keymap key (car plist))
144         (car plist))
145       (setq plist (cdr plist)))))
146
147 (when t
148   (riece-define-keys riece-dialogue-mode-map
149     "\177" scroll-down
150     [delete] scroll-down
151     [backspace] scroll-down
152     [return] scroll-up
153     " " scroll-up
154     [home] beginning-of-buffer
155     "$" end-of-buffer
156     [end] end-of-buffer
157     "/" riece-command-raw
158     ">" end-of-buffer
159     "<" beginning-of-buffer
160     "^" riece-command-list-addons
161     "\C-ta" riece-command-toggle-away
162     "c" riece-command-select-command-buffer
163     "f" riece-command-finger
164     "\C-tf" riece-command-toggle-freeze
165     "\C-to" riece-command-toggle-own-freeze
166     "\C-tO" riece-command-toggle-others-buffer-mode
167     "\C-tu" riece-command-toggle-user-list-buffer-mode
168     "\C-tc" riece-command-toggle-channel-buffer-mode
169     "\C-tC" riece-command-toggle-channel-list-buffer-mode
170     "\C-tl" riece-command-change-layout
171     "i" riece-command-invite
172     "j" riece-command-join
173     "\C-k" riece-command-kick
174     "l" riece-command-list
175     "M" riece-command-change-mode
176     "n" riece-command-change-nickname
177     "N" riece-command-names
178     "o" other-window
179     "O" riece-command-open-server
180     "C" riece-command-close-server
181     "M" riece-command-universal-server-name-argument
182     "p" riece-command-enter-message-to-user
183     "q" riece-command-quit
184     "r" riece-command-configure-windows
185     "x" riece-command-copy-region
186     "t" riece-command-topic
187     "w" riece-command-who
188     "z" riece-command-suspend-resume)
189
190   (riece-define-keys riece-command-mode-map
191     "\r" riece-command-enter-message
192     [(control return)] riece-command-enter-message-as-notice
193     [tab] riece-command-complete-user)
194
195   (riece-define-keys (riece-command-map riece-command-prefix
196                                         riece-command-mode-map)
197     "\177" riece-command-scroll-down
198     [delete] riece-command-scroll-down
199     [backspace] riece-command-scroll-down
200     " " riece-command-scroll-up
201     [home] riece-command-beginning-of-buffer
202     "$" riece-command-end-of-buffer
203     [end] riece-command-end-of-buffer
204     ">" riece-command-next-channel
205     "<" riece-command-previous-channel
206     "\C-j" riece-command-next-channel
207     "\C-n" riece-command-names
208     "l" riece-command-list
209     "\C-m" riece-command-change-mode
210     "o" riece-command-set-operators
211     "\C-p" riece-command-part
212     "r" riece-command-configure-windows
213     "v" riece-command-set-speakers
214     "V" riece-version)
215   (set-keymap-parent riece-command-map riece-dialogue-mode-map)
216
217   (riece-define-keys riece-user-list-mode-map
218     "o" riece-command-set-operators
219     "v" riece-command-set-voices
220     "f" riece-command-finger
221     " " riece-command-user-list-scroll-up
222     "\177" riece-command-user-list-scroll-down
223     [delete] riece-command-user-list-scroll-down
224     [backspace] riece-command-user-list-scroll-down
225     "c" riece-command-select-command-buffer)
226
227   (riece-define-keys riece-channel-list-mode-map
228     ">" riece-command-next-channel
229     "<" riece-command-previous-channel
230     "o" other-window
231     "c" riece-command-select-command-buffer)
232
233   (riece-define-keys-1 riece-dialogue-mode-map riece-select-keys)
234   (riece-define-keys-1 riece-channel-list-mode-map riece-select-keys))
235
236 (defun riece-read-variables-files (&optional file)
237   "Read variables FILEs."
238   (or (file-directory-p riece-directory)
239       (make-directory riece-directory))
240   (let ((files (if file
241                    (setq riece-variables-file file
242                          riece-variables-files (list file))
243                  riece-variables-files)))
244     (while files
245       (condition-case nil
246           (load (expand-file-name (car files)))
247         (file-error nil))
248       (setq files (cdr files)))))
249
250 (defvar print-quoted)
251 (defvar print-escape-multibyte)
252 (defun riece-save-variables-files ()
253   "Save current settings to `riece-variables-file'."
254   (with-temp-file riece-saved-variables-file
255     (let ((print-quoted t)
256           (print-readably t)
257           print-escape-multibyte
258           print-level
259           print-length
260           (variables riece-saved-forms))
261       (while variables
262         (prin1 `(setq ,(car variables)
263                       ',(symbol-value (car variables)))
264                (current-buffer))
265         (insert "\n")
266         (setq variables (cdr variables)))))
267   (setq riece-save-variables-are-dirty nil))
268
269 ;;;###autoload
270 (defun riece (&optional confirm)
271   "Connect to the IRC server and start chatting.
272 If optional argument CONFIRM is non-nil, ask which IRC server to connect."
273   (interactive "P")
274   (riece-read-variables-files (if noninteractive
275                                   (car command-line-args-left)))
276   (run-hooks 'riece-after-load-startup-hook)
277   (if (riece-server-opened)
278       (riece-command-configure-windows)
279     (modify-frame-parameters (selected-frame)
280                              (list (cons 'riece-window-configuration
281                                          (current-window-configuration))))
282     (setq riece-addon-dependencies (riece-resolve-addons
283                                     (copy-sequence riece-addons)))
284     (let ((pointer riece-addon-dependencies))
285       (while pointer
286         (riece-insinuate-addon (car (car pointer)) riece-debug)
287         (setq pointer (cdr pointer))))
288     (if (or confirm (null riece-server))
289         (setq riece-server (completing-read "Server: " riece-server-alist)))
290     (if (stringp riece-server)
291         (setq riece-server (riece-server-name-to-server riece-server)))
292     (riece-create-buffers)
293     (if riece-max-buffer-size
294         (setq riece-shrink-buffer-idle-timer
295               (riece-run-with-idle-timer
296                riece-shrink-buffer-idle-time-delay t
297                (lambda ()
298                  (let ((buffers riece-buffer-list))
299                    (while buffers
300                      (if (buffer-live-p (car buffers))
301                          (if (eq (derived-mode-class
302                                   (with-current-buffer (car buffers)
303                                     major-mode))
304                                  'riece-dialogue-mode)
305                              (riece-shrink-buffer (car buffers)))
306                        (delq (car buffers) riece-buffer-list))
307                      (setq buffers (cdr buffers))))))))
308     (switch-to-buffer riece-command-buffer)
309     (riece-display-connect-signals)
310     (riece-redisplay-buffers)
311     (riece-open-server riece-server "")
312     ;; If no server process is available, exit.
313     (if (null riece-server-process-alist)
314         (riece-exit)
315       (let ((server-list riece-startup-server-list))
316         (while server-list
317           (riece-command-open-server (car server-list))
318           (setq server-list (cdr server-list))))
319       (let ((channel-list riece-startup-channel-list)
320             server)
321         (while channel-list
322           (setq server (riece-identity-server
323                         (riece-parse-identity (car channel-list))))
324           (unless (riece-server-opened server)
325             (riece-command-open-server server))
326           (setq channel-list (cdr channel-list))))
327       (let ((pointer riece-addon-dependencies))
328         (while pointer
329           (unless (get (car (car pointer)) 'riece-addon-default-disabled)
330             (riece-enable-addon (car (car pointer)) riece-debug))
331           (setq pointer (cdr pointer))))
332       (run-hooks 'riece-startup-hook)
333       (message "%s" (substitute-command-keys
334                      "Type \\[describe-mode] for help")))))
335
336 (defun riece-shrink-buffer (buffer)
337   (save-excursion
338     (set-buffer buffer)
339     (goto-char (point-min))
340     (while (> (buffer-size) riece-max-buffer-size)
341       (let* ((inhibit-read-only t)
342              buffer-read-only
343              (end (progn
344                     (goto-char riece-shrink-buffer-remove-chars)
345                     (beginning-of-line 2)
346                     (point)))
347              (overlays (riece-overlays-in (point-min) end)))
348         (while overlays
349           (riece-delete-overlay (car overlays))
350           (setq overlays (cdr overlays)))
351         (delete-region (point-min) end)))))
352
353 (defun riece-exit ()
354   (if riece-save-variables-are-dirty
355       (riece-save-variables-files))
356   (while riece-buffer-list
357     (if (and (get-buffer (car riece-buffer-list))
358              (buffer-live-p (car riece-buffer-list)))
359         (funcall riece-buffer-dispose-function (car riece-buffer-list)))
360     (setq riece-buffer-list (cdr riece-buffer-list)))
361   (if riece-shrink-buffer-idle-timer
362       (riece-cancel-timer riece-shrink-buffer-idle-timer))
363   (riece-clear-signal-slots)
364   (setq riece-server nil
365         riece-current-channels nil
366         riece-current-channel nil
367         riece-channel-buffer nil
368         riece-channel-buffer-alist nil
369         riece-user-indicator nil
370         riece-long-channel-indicator "None"
371         riece-channel-list-indicator "No channel"
372         riece-away-indicator "-"
373         riece-operator-indicator "-"
374         riece-channel-status-indicator "-"
375         riece-freeze-indicator "-")
376   (modify-frame-parameters (selected-frame)
377                            (list (list 'riece-window-configuration)))
378   (delete-other-windows)
379   (run-hooks 'riece-exit-hook))
380
381 (defun riece-command-mode ()
382   "Major mode for Riece.  Normal edit function are available.
383 Typing Return or Linefeed enters the current line in the dialogue.
384 The following special commands are available:
385 For a list of the generic commands type \\[riece-command-generic] ? RET.
386 \\{riece-command-mode-map}"
387   (interactive)
388   (kill-all-local-variables)
389
390   ;; Make `truncate-partial-width-windows' buffer local and set it to
391   ;; nil.  This causes `truncate-lines' to directly control line
392   ;; truncation.
393   (make-local-variable 'truncate-partial-width-windows)
394   (setq truncate-partial-width-windows nil)
395
396   (make-local-variable 'riece-mode-line-buffer-identification)
397   (setq riece-away-indicator "-"
398         riece-operator-indicator "-"
399         riece-channel-status-indicator "-"
400         major-mode 'riece-command-mode
401         mode-name "Command"
402         riece-mode-line-buffer-identification
403         '("Riece: "
404           riece-away-indicator
405           riece-operator-indicator
406           riece-channel-status-indicator
407           " "
408           riece-user-indicator
409           " "
410           riece-channel-indicator)
411         mode-line-buffer-identification
412         (riece-mode-line-buffer-identification
413          riece-mode-line-buffer-identification)
414         truncate-lines nil)
415   (riece-simplify-mode-line-format)
416   (use-local-map riece-command-mode-map)
417
418   (unless riece-command-mode-syntax-table
419     (setq riece-command-mode-syntax-table
420           (copy-syntax-table (syntax-table)))
421     (set-syntax-table riece-command-mode-syntax-table)
422     (mapcar
423      (lambda (c) (modify-syntax-entry c "w"))
424      "^[]{}'`"))
425
426   (run-hooks 'riece-command-mode-hook))
427
428 (defun riece-dialogue-mode ()
429   "Major mode for displaying the IRC dialogue.
430 All normal editing commands are turned off.
431 Instead, these commands are available:
432 \\{riece-dialogue-mode-map}"
433   (kill-all-local-variables)
434   (make-local-variable 'riece-freeze)
435   (make-local-variable 'riece-freeze-indicator)
436
437   ;; Make `truncate-partial-width-windows' buffer local and set it to
438   ;; nil.  This causes `truncate-lines' to directly control line truncation.
439   (make-local-variable 'truncate-partial-width-windows)
440   (setq truncate-partial-width-windows nil)
441
442   (make-local-variable 'riece-mode-line-buffer-identification)
443   (setq riece-freeze riece-default-freeze
444         riece-away-indicator "-"
445         riece-operator-indicator "-"
446         riece-channel-status-indicator "-"
447         major-mode 'riece-dialogue-mode
448         mode-name "Dialogue"
449         riece-mode-line-buffer-identification
450         '("Riece: "
451           riece-away-indicator
452           riece-operator-indicator
453           riece-freeze-indicator
454           riece-channel-status-indicator
455           " "
456           riece-channel-list-indicator " ")
457         mode-line-buffer-identification
458         (riece-mode-line-buffer-identification
459          riece-mode-line-buffer-identification)
460         truncate-lines nil
461         buffer-read-only t)
462   (riece-simplify-mode-line-format)
463   (use-local-map riece-dialogue-mode-map)
464   (buffer-disable-undo)
465   (run-hooks 'riece-dialogue-mode-hook))
466
467 (define-derived-mode riece-others-mode riece-dialogue-mode
468   "Others"
469   "Major mode for displaying the IRC others message except current channel.
470 All normal editing commands are turned off.
471 Instead, these commands are available:
472 \\{riece-others-mode-map}")
473
474 (define-derived-mode riece-channel-mode riece-dialogue-mode
475   "Channel"
476   "Major mode for displaying the IRC current channel buffer.
477 All normal editing commands are turned off.
478 Instead, these commands are available:
479 \\{riece-channel-mode-map}"
480   (make-local-variable 'riece-channel-buffer-window-point)
481   (make-local-variable 'riece-mode-line-buffer-identification)
482   (setq riece-mode-line-buffer-identification
483         '("Riece: "
484           riece-away-indicator
485           riece-operator-indicator
486           riece-freeze-indicator
487           riece-channel-status-indicator
488           " "
489           riece-long-channel-indicator)
490         mode-line-buffer-identification
491         (riece-mode-line-buffer-identification
492          riece-mode-line-buffer-identification)))
493
494 (defun riece-channel-list-mode ()
495   "Major mode for displaying channel list.
496 All normal editing commands are turned off."
497   (kill-all-local-variables)
498   (buffer-disable-undo)
499
500   ;; Make `truncate-partial-width-windows' buffer local and set it to
501   ;; nil.  This causes `truncate-lines' to directly control line truncation.
502   (make-local-variable 'truncate-partial-width-windows)
503   (setq truncate-partial-width-windows nil)
504
505   (make-local-variable 'riece-mode-line-buffer-identification)
506   (setq major-mode 'riece-channel-list-mode
507         mode-name "Channels"
508         riece-mode-line-buffer-identification '("Riece: ")
509         mode-line-buffer-identification
510         (riece-mode-line-buffer-identification
511          riece-mode-line-buffer-identification)
512         truncate-lines t
513         buffer-read-only t)
514   (make-local-hook 'riece-update-buffer-functions)
515   (add-hook 'riece-update-buffer-functions
516             'riece-update-channel-list-buffer nil t)
517   (use-local-map riece-channel-list-mode-map)
518   (run-hooks 'riece-channel-list-mode-hook))
519
520 (defun riece-user-list-mode ()
521   "Major mode for displaying members in the IRC current channel buffer.
522 All normal editing commands are turned off.
523 Instead, these commands are available:
524 \\{riece-user-list-mode-map}"
525   (kill-all-local-variables)
526   (buffer-disable-undo)
527
528   ;; Make `truncate-partial-width-windows' buffer local and set it to
529   ;; nil.  This causes `truncate-lines' to directly control line truncation.
530   (make-local-variable 'truncate-partial-width-windows)
531   (setq truncate-partial-width-windows nil)
532
533   (make-local-variable 'riece-mode-line-buffer-identification)
534   (setq major-mode 'riece-user-list-mode
535         mode-name "Users"
536         riece-mode-line-buffer-identification
537         '("Riece: " riece-long-channel-indicator " ")
538         mode-line-buffer-identification
539         (riece-mode-line-buffer-identification
540          riece-mode-line-buffer-identification)
541         truncate-lines t
542         buffer-read-only t)
543   (if (boundp 'transient-mark-mode)
544       (set (make-local-variable 'transient-mark-mode) t))
545   (make-local-hook 'riece-update-buffer-functions)
546   (add-hook 'riece-update-buffer-functions
547             'riece-update-user-list-buffer nil t)
548   (use-local-map riece-user-list-mode-map)
549   (run-hooks 'riece-user-list-mode-hook))
550
551 (defun riece-create-buffers ()
552   (let ((alist riece-buffer-alist))
553     (while alist
554       (save-excursion
555         (set-buffer (apply #'riece-get-buffer-create
556                            (cdr (car alist))))
557         (set (car (car alist)) (current-buffer))
558         (unless (or (null (nth 2 (car alist)))
559                     (eq major-mode (nth 2 (car alist))))
560           (funcall (nth 2 (car alist))))
561         (setq alist (cdr alist))))))
562
563 (defvar reporter-prompt-for-summary-p)
564 (defun riece-submit-bug-report (&optional recent-messages recent-keys)
565   "Submit via mail a bug report on Riece."
566   ;; This strange form ensures that (recent-keys) is the value before
567   ;; the bug subject string is read.
568   (interactive (list (riece-recent-messages 20) (recent-keys)))
569   (message "Querying server version...")
570   (let ((pointer riece-server-process-alist)
571         nickname)
572     (while pointer
573       (when (riece-server-process-opened (cdr (car pointer)))
574         (process-send-string (cdr (car pointer)) "VERSION\r\n")
575         (if (setq nickname
576                   (with-current-buffer (process-buffer (cdr (car pointer)))
577                     riece-real-nickname))
578             (process-send-string
579              (cdr (car pointer))
580              (format "PRIVMSG %s :\1VERSION\1\r\n" nickname))))
581       (setq pointer (cdr pointer))))
582   (sit-for 3)
583   (message "Querying server version...done")
584   (require 'reporter)
585   (let ((reporter-prompt-for-summary-p t))
586     (unless riece-debug
587       (error "Please turn on riece-debug and restart Riece."))
588     (reporter-submit-bug-report
589      "liece@unixuser.org"
590      (riece-version)
591      '(riece-debug)
592      nil
593      nil
594      "This bug report will be sent to the Riece Development Team,
595 not to your local site managers!!
596
597 Please write in Japanese or English, because the Riece maintainers do
598 not have translators to read other languages for them.
599
600 Please describe as succinctly as possible:
601 \t- What happened.
602 \t- What you thought should have happened.
603 \t- Precisely what you were doing at the time.
604
605 Also include a reliable recipe for triggering the bug, as well as
606 any lisp back-traces that you may have.
607 \(setq stack-trace-on-error t\), or \(setq debug-on-error t\) if you
608 are familiar with the debugger, to get a lisp back-trace.")
609     (delete-other-windows)
610     (save-excursion
611       (goto-char (point-max))
612       (insert
613        "\nAdd-on state:\n"
614        "------------\n"
615        (save-window-excursion
616          (save-excursion
617            (riece-command-list-addons)
618            (search-forward "\n\n")
619            (buffer-substring (point-min) (point)))))
620       (insert "Recent messages from servers:\n"
621               "--------------------------")
622       (let ((pointer riece-server-process-alist))
623         (while pointer
624           (insert "\n- \"" (car (car pointer)) "\", \n"
625                   (format "%S" (if (equal (car (car pointer)) "")
626                                    riece-server
627                                  (cdr (assoc (car (car pointer))
628                                              riece-server-alist))))
629                   "\n"
630                   (if (riece-server-process-opened (cdr (car pointer)))
631                       (save-excursion
632                         (set-buffer (process-buffer (cdr (car pointer))))
633                         (goto-char (point-max))
634                         (beginning-of-line -60)
635                         (buffer-substring (point) (point-max)))
636                     "(closed server)"))
637           (setq pointer (cdr pointer))))
638       (insert "\n\nRecent debug messages:\n"
639               "-----------------------------------\n"
640               (with-current-buffer riece-debug-buffer
641                 (buffer-string)))
642       ;; Insert recent keystrokes.
643       (insert "\n\nRecent keystrokes:\n"
644               "-----------------\n\n")
645       (let ((before-keys (point)))
646         (insert (key-description recent-keys))
647         (save-restriction
648           (narrow-to-region before-keys (point))
649           (goto-char before-keys)
650           (while (progn (move-to-column 50) (not (eobp)))
651             (search-forward " " nil t)
652             (insert "\n"))))
653       ;; Insert recent minibuffer messages.
654       (insert "\n\nRecent messages (most recent first):\n"
655               "-----------------------------------\n"
656               recent-messages))))
657
658 (provide 'riece)
659
660 ;;; riece.el ends here