Regenerate autotools stuff, grumble.
[emacs.git] / lisp / talk.el
blobfd845a7eee076d916a06231777472f442bb6a139
1 ;;; talk.el --- allow several users to talk to each other through Emacs
3 ;; Copyright (C) 1995, 2001-2011 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Keywords: comm, frames
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs 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 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs 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.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; This is a multi-user talk package that runs in Emacs.
26 ;; Use talk-connect to bring a new person into the conversation.
28 ;;; Code:
30 (defvar talk-display-alist nil
31 "Alist of displays on which Emacs talk is now running.
32 Each element has the form (DISPLAY FRAME BUFFER).")
34 ;;;###autoload
35 (defun talk-connect (display)
36 "Connect to display DISPLAY for the Emacs talk group."
37 (interactive "sTalk to display: ")
38 ;; Make sure we have an entry for the current display.
39 (let ((mydisp (cdr (assq 'display (frame-parameters (selected-frame))))))
40 (talk-add-display mydisp))
41 ;; Make sure we have an entry for the specified display.
42 (talk-add-display display)
43 ;; Add the new buffers to all talk frames.
44 (talk-update-buffers))
46 ;;;###autoload
47 (defun talk ()
48 "Connect to the Emacs talk group from the current X display or tty frame."
49 (interactive)
50 (let ((type (frame-live-p (selected-frame)))
51 (display (frame-terminal (selected-frame))))
52 (if (or (eq type t) (eq type 'x))
53 (talk-add-display
54 (terminal-name (frame-terminal (selected-frame))))
55 (error "Unknown frame type")))
56 (talk-update-buffers))
58 (defun talk-add-display (display)
59 (let* ((elt (assoc display talk-display-alist))
60 (name (concat "*talk-" display "*"))
61 frame buffer)
62 (if (and elt (frame-live-p (nth 1 elt)))
63 (setq frame (nth 1 elt))
64 (setq frame (make-frame-on-display display (list (cons 'name name)))))
65 (if (not (and elt (buffer-name (get-buffer (setq buffer (nth 2 elt))))))
66 (setq buffer (get-buffer-create name)))
67 (add-to-list 'delete-frame-functions 'talk-handle-delete-frame)
68 (setq talk-display-alist
69 (cons (list display frame buffer) (delq elt talk-display-alist)))))
71 (defun talk-handle-delete-frame (frame)
72 (dolist (d talk-display-alist)
73 (when (eq (nth 1 d) frame)
74 (setq talk-display-alist (delq d talk-display-alist))
75 (talk-update-buffers))))
77 (defun talk-disconnect ()
78 "Disconnect this display from the Emacs talk group."
79 (interactive)
80 (let* ((mydisp (cdr (assq 'display (frame-parameters (selected-frame)))))
81 (elt (assoc mydisp talk-display-alist)))
82 (delete-frame (nth 1 elt))
83 (kill-buffer (nth 2 elt))
84 (setq talk-display-alist (delq elt talk-display-alist))
85 (talk-update-buffers)))
87 (defun talk-update-buffers ()
88 "Update all the talk frames so that each shows all the talk buffers."
89 (let ((tail talk-display-alist))
90 (while tail
91 (let ((frame (nth 1 (car tail)))
92 (this-buffer (nth 2 (car tail)))
93 (buffers
94 (mapcar (function (lambda (elt) (nth 2 elt)))
95 talk-display-alist)))
96 ;; Put this display's own talk buffer
97 ;; at the front of the list.
98 (setq buffers (cons this-buffer (delq this-buffer buffers)))
99 (talk-split-up-frame frame buffers))
100 (setq tail (cdr tail)))))
102 (defun talk-split-up-frame (frame buffers)
103 "Split FRAME into equal-sized windows displaying the buffers in BUFFERS.
104 Select the first of these windows, displaying the first of the buffers."
105 (let ((lines-per-buffer (/ (frame-height frame) (length buffers)))
106 (old-frame (selected-frame)))
107 (unwind-protect
108 (progn
109 (select-frame frame)
110 (select-window (frame-first-window frame))
111 (delete-other-windows)
112 (while (progn
113 (switch-to-buffer (car buffers))
114 (setq buffers (cdr buffers)))
115 (split-window-vertically lines-per-buffer)
116 (other-window 1))
117 (select-window (frame-first-window frame)))
118 (select-frame old-frame))))
120 (provide 'talk)
122 ;;; talk.el ends here