Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; talk.el --- allow several users to talk to each other through Emacs |
5abe8993 | 2 | |
73b0cd50 | 3 | ;; Copyright (C) 1995, 2001-2011 Free Software Foundation, Inc. |
b578f267 | 4 | |
30764597 | 5 | ;; Maintainer: FSF |
5abe8993 RS |
6 | ;; Keywords: comm, frames |
7 | ||
8 | ;; This file is part of GNU Emacs. | |
9 | ||
eb3fa2cf | 10 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
5abe8993 | 11 | ;; it under the terms of the GNU General Public License as published by |
eb3fa2cf GM |
12 | ;; the Free Software Foundation, either version 3 of the License, or |
13 | ;; (at your option) any later version. | |
5abe8993 RS |
14 | |
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. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
eb3fa2cf | 21 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
5abe8993 RS |
22 | |
23 | ;;; Commentary: | |
24 | ||
b578f267 EN |
25 | ;; This is a multi-user talk package that runs in Emacs. |
26 | ;; Use talk-connect to bring a new person into the conversation. | |
5abe8993 RS |
27 | |
28 | ;;; Code: | |
29 | ||
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).") | |
33 | ||
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)) | |
45 | ||
17086732 KL |
46 | ;;;###autoload |
47 | (defun talk () | |
48 | "Connect to the Emacs talk group from the current X display or tty frame." | |
49 | (interactive) | |
b6660415 | 50 | (let ((type (frame-live-p (selected-frame))) |
6ed8eeff | 51 | (display (frame-terminal (selected-frame)))) |
a1feed48 CY |
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"))) | |
17086732 KL |
56 | (talk-update-buffers)) |
57 | ||
a1feed48 CY |
58 | (defun talk-add-display (display) |
59 | (let* ((elt (assoc display talk-display-alist)) | |
60 | (name (concat "*talk-" display "*")) | |
61 | frame buffer) | |
b6660415 | 62 | (if (and elt (frame-live-p (nth 1 elt))) |
a1feed48 CY |
63 | (setq frame (nth 1 elt)) |
64 | (setq frame (make-frame-on-display display (list (cons 'name name))))) | |
17086732 KL |
65 | (if (not (and elt (buffer-name (get-buffer (setq buffer (nth 2 elt)))))) |
66 | (setq buffer (get-buffer-create name))) | |
b6660415 | 67 | (add-to-list 'delete-frame-functions 'talk-handle-delete-frame) |
17086732 | 68 | (setq talk-display-alist |
b6660415 | 69 | (cons (list display frame buffer) (delq elt talk-display-alist))))) |
17086732 | 70 | |
b6660415 KL |
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)))) | |
17086732 | 76 | |
5abe8993 RS |
77 | (defun talk-disconnect () |
78 | "Disconnect this display from the Emacs talk group." | |
c2bef985 | 79 | (interactive) |
5abe8993 RS |
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))) | |
86 | ||
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))))) | |
101 | ||
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)))) | |
119 | ||
896546cd RS |
120 | (provide 'talk) |
121 | ||
5abe8993 | 122 | ;;; talk.el ends here |