]> code.delx.au - gnu-emacs/blob - lisp/talk.el
[!__GNUC__] (C_SWITCH_MACHINE): Disable this; it seems to confuse cpp.
[gnu-emacs] / lisp / talk.el
1 ;;; talk.el --- Allow several users to talk to each other through Emacs.
2
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Keywords: comm, frames
5
6 ;; This file is part of GNU Emacs.
7
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
12
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to
20 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
21
22 ;;; Commentary:
23
24 ;;; This is a multi-user talk package that runs in Emacs.
25 ;;; Use talk-connect to bring a new person into the conversation.
26
27 ;;; Code:
28
29 (defvar talk-display-alist nil
30 "Alist of displays on which Emacs talk is now running.
31 Each element has the form (DISPLAY FRAME BUFFER).")
32
33 ;;;###autoload
34 (defun talk-connect (display)
35 "Connect to display DISPLAY for the Emacs talk group."
36 (interactive "sTalk to display: ")
37 ;; Make sure we have an entry for the current display.
38 (let ((mydisp (cdr (assq 'display (frame-parameters (selected-frame))))))
39 (talk-add-display mydisp))
40 ;; Make sure we have an entry for the specified display.
41 (talk-add-display display)
42 ;; Add the new buffers to all talk frames.
43 (talk-update-buffers))
44
45 (defun talk-add-display (display)
46 (or (assoc display talk-display-alist)
47 (let* ((name (concat "*talk-" display "*"))
48 (buffer (get-buffer-create name))
49 (frame (make-frame-on-display display
50 (list (cons 'name name)))))
51 (setq talk-display-alist
52 (cons (list display frame buffer)
53 talk-display-alist)))))
54
55 (defun talk-disconnect ()
56 "Disconnect this display from the Emacs talk group."
57 (let* ((mydisp (cdr (assq 'display (frame-parameters (selected-frame)))))
58 (elt (assoc mydisp talk-display-alist)))
59 (delete-frame (nth 1 elt))
60 (kill-buffer (nth 2 elt))
61 (setq talk-display-alist (delq elt talk-display-alist))
62 (talk-update-buffers)))
63
64 (defun talk-update-buffers ()
65 "Update all the talk frames so that each shows all the talk buffers."
66 (let ((tail talk-display-alist))
67 (while tail
68 (let ((frame (nth 1 (car tail)))
69 (this-buffer (nth 2 (car tail)))
70 (buffers
71 (mapcar (function (lambda (elt) (nth 2 elt)))
72 talk-display-alist)))
73 ;; Put this display's own talk buffer
74 ;; at the front of the list.
75 (setq buffers (cons this-buffer (delq this-buffer buffers)))
76 (talk-split-up-frame frame buffers))
77 (setq tail (cdr tail)))))
78
79 (defun talk-split-up-frame (frame buffers)
80 "Split FRAME into equal-sized windows displaying the buffers in BUFFERS.
81 Select the first of these windows, displaying the first of the buffers."
82 (let ((lines-per-buffer (/ (frame-height frame) (length buffers)))
83 (old-frame (selected-frame)))
84 (unwind-protect
85 (progn
86 (select-frame frame)
87 (select-window (frame-first-window frame))
88 (delete-other-windows)
89 (while (progn
90 (switch-to-buffer (car buffers))
91 (setq buffers (cdr buffers)))
92 (split-window-vertically lines-per-buffer)
93 (other-window 1))
94 (select-window (frame-first-window frame)))
95 (select-frame old-frame))))
96
97 ;;; talk.el ends here