1 ;;; talk.el --- Allow several users to talk to each other through Emacs.
3 ;; Copyright (C) 1995 Free Software Foundation, Inc.
4 ;; Keywords: comm, frames
6 ;; This file is part of GNU Emacs.
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)
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.
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.
24 ;;; This is a multi-user talk package that runs in Emacs.
25 ;;; Use talk-connect to bring a new person into the conversation.
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).")
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))
45 (defun talk-add-display (display)
46 (let* ((elt (assoc display talk-display-alist
))
47 (name (concat "*talk-" display
"*"))
49 (if (not (and elt
(frame-live-p (setq frame
(nth 1 elt
)))))
50 (setq frame
(make-frame-on-display display
(list (cons 'name name
)))))
51 (if (not (and elt
(buffer-name (get-buffer (setq buffer
(nth 2 elt
))))))
52 (setq buffer
(get-buffer-create name
)))
53 (setq talk-display-alist
54 (cons (list display frame buffer
) (delq elt talk-display-alist
)))))
56 (defun talk-disconnect ()
57 "Disconnect this display from the Emacs talk group."
59 (let* ((mydisp (cdr (assq 'display
(frame-parameters (selected-frame)))))
60 (elt (assoc mydisp talk-display-alist
)))
61 (delete-frame (nth 1 elt
))
62 (kill-buffer (nth 2 elt
))
63 (setq talk-display-alist
(delq elt talk-display-alist
))
64 (talk-update-buffers)))
66 (defun talk-update-buffers ()
67 "Update all the talk frames so that each shows all the talk buffers."
68 (let ((tail talk-display-alist
))
70 (let ((frame (nth 1 (car tail
)))
71 (this-buffer (nth 2 (car tail
)))
73 (mapcar (function (lambda (elt) (nth 2 elt
)))
75 ;; Put this display's own talk buffer
76 ;; at the front of the list.
77 (setq buffers
(cons this-buffer
(delq this-buffer buffers
)))
78 (talk-split-up-frame frame buffers
))
79 (setq tail
(cdr tail
)))))
81 (defun talk-split-up-frame (frame buffers
)
82 "Split FRAME into equal-sized windows displaying the buffers in BUFFERS.
83 Select the first of these windows, displaying the first of the buffers."
84 (let ((lines-per-buffer (/ (frame-height frame
) (length buffers
)))
85 (old-frame (selected-frame)))
89 (select-window (frame-first-window frame
))
90 (delete-other-windows)
92 (switch-to-buffer (car buffers
))
93 (setq buffers
(cdr buffers
)))
94 (split-window-vertically lines-per-buffer
)
96 (select-window (frame-first-window frame
)))
97 (select-frame old-frame
))))