* riece.el (riece): Don't override riece-addons setting.
[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 riece-addons))
283     (let ((pointer riece-addon-dependencies))
284       (while pointer
285         (riece-insinuate-addon (car (car pointer)) riece-debug)
286         (setq pointer (cdr pointer))))
287     (if (or confirm (null riece-server))
288         (setq riece-server (completing-read "Server: " riece-server-alist)))
289     (if (stringp riece-server)
290         (setq riece-server (riece-server-name-to-server riece-server)))
291     (riece-create-buffers)
292     (if riece-max-buffer-size
293         (setq riece-shrink-buffer-idle-timer
294               (riece-run-with-idle-timer
295                riece-shrink-buffer-idle-time-delay t
296                (lambda ()
297                  (let ((buffers riece-buffer-list))
298                    (while buffers
299                      (if (buffer-live-p (car buffers))
300                          (if (eq (derived-mode-class
301                                   (with-current-buffer (car buffers)
302                                     major-mode))
303                                  'riece-dialogue-mode)
304                              (riece-shrink-buffer (car buffers)))
305                        (delq (car buffers) riece-buffer-list))
306                      (setq buffers (cdr buffers))))))))
307     (switch-to-buffer riece-command-buffer)
308     (riece-display-connect-signals)
309     (riece-redisplay-buffers)
310     (riece-open-server riece-server "")
311     ;; If no server process is available, exit.
312     (if (null riece-server-process-alist)
313         (riece-exit)
314       (let ((server-list riece-startup-server-list))
315         (while server-list
316           (riece-command-open-server (car server-list))
317           (setq server-list (cdr server-list))))
318       (let ((channel-list riece-startup-channel-list)
319             server)
320         (while channel-list
321           (setq server (riece-identity-server
322                         (riece-parse-identity (car channel-list))))
323           (unless (riece-server-opened server)
324             (riece-command-open-server server))
325           (setq channel-list (cdr channel-list))))
326       (let ((pointer riece-addon-dependencies))
327         (while pointer
328           (unless (get (car pointer) 'riece-addon-default-disabled)
329             (riece-enable-addon (car pointer) riece-debug))
330           (setq pointer (cdr pointer))))
331       (run-hooks 'riece-startup-hook)
332       (message "%s" (substitute-command-keys
333                      "Type \\[describe-mode] for help")))))
334
335 (defun riece-shrink-buffer (buffer)
336   (save-excursion
337     (set-buffer buffer)
338     (goto-char (point-min))
339     (while (> (buffer-size) riece-max-buffer-size)
340       (let* ((inhibit-read-only t)
341              buffer-read-only
342              (end (progn
343                     (goto-char riece-shrink-buffer-remove-chars)
344                     (beginning-of-line 2)
345                     (point)))
346              (overlays (riece-overlays-in (point-min) end)))
347         (while overlays
348           (riece-delete-overlay (car overlays))
349           (setq overlays (cdr overlays)))
350         (delete-region (point-min) end)))))
351
352 (defun riece-exit ()
353   (if riece-save-variables-are-dirty
354       (riece-save-variables-files))
355   (while riece-buffer-list
356     (if (and (get-buffer (car riece-buffer-list))
357              (buffer-live-p (car riece-buffer-list)))
358         (funcall riece-buffer-dispose-function (car riece-buffer-list)))
359     (setq riece-buffer-list (cdr riece-buffer-list)))
360   (if riece-shrink-buffer-idle-timer
361       (riece-cancel-timer riece-shrink-buffer-idle-timer))
362   (riece-clear-signal-slots)
363   (setq riece-server nil
364         riece-current-channels nil
365         riece-current-channel nil
366         riece-channel-buffer nil
367         riece-channel-buffer-alist nil
368         riece-user-indicator nil
369         riece-long-channel-indicator "None"
370         riece-channel-list-indicator "No channel"
371         riece-away-indicator "-"
372         riece-operator-indicator "-"
373         riece-channel-status-indicator "-"
374         riece-freeze-indicator "-")
375   (modify-frame-parameters (selected-frame)
376                            (list (list 'riece-window-configuration)))
377   (delete-other-windows)
378   (run-hooks 'riece-exit-hook))
379
380 (defun riece-command-mode ()
381   "Major mode for Riece.  Normal edit function are available.
382 Typing Return or Linefeed enters the current line in the dialogue.
383 The following special commands are available:
384 For a list of the generic commands type \\[riece-command-generic] ? RET.
385 \\{riece-command-mode-map}"
386   (interactive)
387   (kill-all-local-variables)
388
389   ;; Make `truncate-partial-width-windows' buffer local and set it to
390   ;; nil.  This causes `truncate-lines' to directly control line
391   ;; truncation.
392   (make-local-variable 'truncate-partial-width-windows)
393   (setq truncate-partial-width-windows nil)
394
395   (setq riece-away-indicator "-"
396         riece-operator-indicator "-"
397         riece-channel-status-indicator "-"
398         major-mode 'riece-command-mode
399         mode-name "Command"
400         mode-line-buffer-identification
401         (riece-mode-line-buffer-identification
402          '("Riece: "
403            riece-away-indicator
404            riece-operator-indicator
405            riece-channel-status-indicator
406            " "
407            riece-user-indicator
408            " "
409            riece-channel-indicator))
410         truncate-lines nil)
411   (riece-simplify-mode-line-format)
412   (use-local-map riece-command-mode-map)
413
414   (unless riece-command-mode-syntax-table
415     (setq riece-command-mode-syntax-table
416           (copy-syntax-table (syntax-table)))
417     (set-syntax-table riece-command-mode-syntax-table)
418     (mapcar
419      (lambda (c) (modify-syntax-entry c "w"))
420      "^[]{}'`"))
421
422   (run-hooks 'riece-command-mode-hook))
423
424 (defun riece-dialogue-mode ()
425   "Major mode for displaying the IRC dialogue.
426 All normal editing commands are turned off.
427 Instead, these commands are available:
428 \\{riece-dialogue-mode-map}"
429   (kill-all-local-variables)
430   (make-local-variable 'riece-freeze)
431   (make-local-variable 'riece-freeze-indicator)
432
433   ;; Make `truncate-partial-width-windows' buffer local and set it to
434   ;; nil.  This causes `truncate-lines' to directly control line truncation.
435   (make-local-variable 'truncate-partial-width-windows)
436   (setq truncate-partial-width-windows nil)
437
438   (setq riece-freeze riece-default-freeze
439         riece-away-indicator "-"
440         riece-operator-indicator "-"
441         riece-channel-status-indicator "-"
442         major-mode 'riece-dialogue-mode
443         mode-name "Dialogue"
444         mode-line-buffer-identification
445         (riece-mode-line-buffer-identification
446          '("Riece: "
447            riece-away-indicator
448            riece-operator-indicator
449            riece-freeze-indicator
450            riece-channel-status-indicator
451            " "
452            riece-channel-list-indicator " "))
453         truncate-lines nil
454         buffer-read-only t)
455   (riece-simplify-mode-line-format)
456   (use-local-map riece-dialogue-mode-map)
457   (buffer-disable-undo)
458   (run-hooks 'riece-dialogue-mode-hook))
459
460 (define-derived-mode riece-others-mode riece-dialogue-mode
461   "Others"
462   "Major mode for displaying the IRC others message except current channel.
463 All normal editing commands are turned off.
464 Instead, these commands are available:
465 \\{riece-others-mode-map}")
466
467 (define-derived-mode riece-channel-mode riece-dialogue-mode
468   "Channel"
469   "Major mode for displaying the IRC current channel buffer.
470 All normal editing commands are turned off.
471 Instead, these commands are available:
472 \\{riece-channel-mode-map}"
473   (make-local-variable 'riece-channel-buffer-window-point)
474   (setq mode-line-buffer-identification
475         (riece-mode-line-buffer-identification
476          '("Riece: "
477            riece-away-indicator
478            riece-operator-indicator
479            riece-freeze-indicator
480            riece-channel-status-indicator
481            " "
482            riece-long-channel-indicator))))
483
484 (defun riece-channel-list-mode ()
485   "Major mode for displaying channel list.
486 All normal editing commands are turned off."
487   (kill-all-local-variables)
488   (buffer-disable-undo)
489
490   ;; Make `truncate-partial-width-windows' buffer local and set it to
491   ;; nil.  This causes `truncate-lines' to directly control line truncation.
492   (make-local-variable 'truncate-partial-width-windows)
493   (setq truncate-partial-width-windows nil)
494
495   (setq major-mode 'riece-channel-list-mode
496         mode-name "Channels"
497         mode-line-buffer-identification
498         (riece-mode-line-buffer-identification '("Riece: "))
499         truncate-lines t
500         buffer-read-only t)
501   (make-local-hook 'riece-update-buffer-functions)
502   (add-hook 'riece-update-buffer-functions
503             'riece-update-channel-list-buffer nil t)
504   (use-local-map riece-channel-list-mode-map)
505   (run-hooks 'riece-channel-list-mode-hook))
506
507 (defun riece-user-list-mode ()
508   "Major mode for displaying members in the IRC current channel buffer.
509 All normal editing commands are turned off.
510 Instead, these commands are available:
511 \\{riece-user-list-mode-map}"
512   (kill-all-local-variables)
513   (buffer-disable-undo)
514
515   ;; Make `truncate-partial-width-windows' buffer local and set it to
516   ;; nil.  This causes `truncate-lines' to directly control line truncation.
517   (make-local-variable 'truncate-partial-width-windows)
518   (setq truncate-partial-width-windows nil)
519
520   (setq major-mode 'riece-user-list-mode
521         mode-name "Users"
522         mode-line-buffer-identification
523         (riece-mode-line-buffer-identification
524          '("Riece: " riece-long-channel-indicator " "))
525         truncate-lines t
526         buffer-read-only t)
527   (if (boundp 'transient-mark-mode)
528       (set (make-local-variable 'transient-mark-mode) t))
529   (make-local-hook 'riece-update-buffer-functions)
530   (add-hook 'riece-update-buffer-functions
531             'riece-update-user-list-buffer nil t)
532   (use-local-map riece-user-list-mode-map)
533   (run-hooks 'riece-user-list-mode-hook))
534
535 (defun riece-create-buffers ()
536   (let ((alist riece-buffer-alist))
537     (while alist
538       (save-excursion
539         (set-buffer (apply #'riece-get-buffer-create
540                            (cdr (car alist))))
541         (set (car (car alist)) (current-buffer))
542         (unless (or (null (nth 2 (car alist)))
543                     (eq major-mode (nth 2 (car alist))))
544           (funcall (nth 2 (car alist))))
545         (setq alist (cdr alist))))))
546
547 (defvar reporter-prompt-for-summary-p)
548 (defun riece-submit-bug-report (&optional recent-messages recent-keys)
549   "Submit via mail a bug report on Riece."
550   ;; This strange form ensures that (recent-keys) is the value before
551   ;; the bug subject string is read.
552   (interactive (list (riece-recent-messages 20) (recent-keys)))
553   (message "Querying server version...")
554   (let ((pointer riece-server-process-alist)
555         nickname)
556     (while pointer
557       (when (riece-server-process-opened (cdr (car pointer)))
558         (process-send-string (cdr (car pointer)) "VERSION\r\n")
559         (if (setq nickname
560                   (with-current-buffer (process-buffer (cdr (car pointer)))
561                     riece-real-nickname))
562             (process-send-string
563              (cdr (car pointer))
564              (format "PRIVMSG %s :\1VERSION\1\r\n" nickname))))
565       (setq pointer (cdr pointer))))
566   (sit-for 3)
567   (message "Querying server version...done")
568   (require 'reporter)
569   (let ((reporter-prompt-for-summary-p t))
570     (unless riece-debug
571       (error "Please turn on riece-debug and restart Riece."))
572     (reporter-submit-bug-report
573      "liece@unixuser.org"
574      (riece-version)
575      '(riece-debug)
576      nil
577      nil
578      "This bug report will be sent to the Riece Development Team,
579 not to your local site managers!!
580
581 Please write in Japanese or English, because the Riece maintainers do
582 not have translators to read other languages for them.
583
584 Please describe as succinctly as possible:
585 \t- What happened.
586 \t- What you thought should have happened.
587 \t- Precisely what you were doing at the time.
588
589 Also include a reliable recipe for triggering the bug, as well as
590 any lisp back-traces that you may have.
591 \(setq stack-trace-on-error t\), or \(setq debug-on-error t\) if you
592 are familiar with the debugger, to get a lisp back-trace.")
593     (delete-other-windows)
594     (save-excursion
595       (goto-char (point-max))
596       (insert
597        "\nAdd-on state:\n"
598        "------------\n"
599        (save-window-excursion
600          (save-excursion
601            (riece-command-list-addons)
602            (search-forward "\n\n")
603            (buffer-substring (point-min) (point)))))
604       (insert "Recent messages from servers:\n"
605               "--------------------------")
606       (let ((pointer riece-server-process-alist))
607         (while pointer
608           (insert "\n- \"" (car (car pointer)) "\", \n"
609                   (format "%S" (if (equal (car (car pointer)) "")
610                                    riece-server
611                                  (cdr (assoc (car (car pointer))
612                                              riece-server-alist))))
613                   "\n"
614                   (if (riece-server-process-opened (cdr (car pointer)))
615                       (save-excursion
616                         (set-buffer (process-buffer (cdr (car pointer))))
617                         (goto-char (point-max))
618                         (beginning-of-line -60)
619                         (buffer-substring (point) (point-max)))
620                     "(closed server)"))
621           (setq pointer (cdr pointer))))
622       (insert "\n\nRecent debug messages:\n"
623               "-----------------------------------\n"
624               (with-current-buffer riece-debug-buffer
625                 (buffer-string)))
626       ;; Insert recent keystrokes.
627       (insert "\n\nRecent keystrokes:\n"
628               "-----------------\n\n")
629       (let ((before-keys (point)))
630         (insert (key-description recent-keys))
631         (save-restriction
632           (narrow-to-region before-keys (point))
633           (goto-char before-keys)
634           (while (progn (move-to-column 50) (not (eobp)))
635             (search-forward " " nil t)
636             (insert "\n"))))
637       ;; Insert recent minibuffer messages.
638       (insert "\n\nRecent messages (most recent first):\n"
639               "-----------------------------------\n"
640               recent-messages))))
641
642 (provide 'riece)
643
644 ;;; riece.el ends here