1 ;;; talk.el --- allow several users to talk to each other through Emacs
3 ;; Copyright (C) 1995, 2001-2013 Free Software Foundation, Inc.
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/>.
25 ;; This is a multi-user talk package that runs in Emacs.
26 ;; Use talk-connect to bring a new person into the conversation.
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).")
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))
48 "Connect to the Emacs talk group from the current X display or tty frame."
50 (let ((type (frame-live-p (selected-frame))))
51 (if (or (eq type t
) (eq type
'x
))
53 (terminal-name (frame-terminal)))
54 (error "Unknown frame type")))
55 (talk-update-buffers))
57 (defun talk-add-display (display)
58 (let* ((elt (assoc display talk-display-alist
))
59 (name (concat "*talk-" display
"*"))
61 (if (and elt
(frame-live-p (nth 1 elt
)))
62 (setq frame
(nth 1 elt
))
63 (setq frame
(make-frame-on-display display
(list (cons 'name name
)))))
64 (if (not (and elt
(buffer-name (get-buffer (setq buffer
(nth 2 elt
))))))
65 (setq buffer
(get-buffer-create name
)))
66 (add-to-list 'delete-frame-functions
'talk-handle-delete-frame
)
67 (setq talk-display-alist
68 (cons (list display frame buffer
) (delq elt talk-display-alist
)))))
70 (defun talk-handle-delete-frame (frame)
71 (dolist (d talk-display-alist
)
72 (when (eq (nth 1 d
) frame
)
73 (setq talk-display-alist
(delq d talk-display-alist
))
74 (talk-update-buffers))))
76 (defun talk-disconnect ()
77 "Disconnect this display from the Emacs talk group."
79 (let* ((mydisp (cdr (assq 'display
(frame-parameters (selected-frame)))))
80 (elt (assoc mydisp talk-display-alist
)))
81 (delete-frame (nth 1 elt
))
82 (kill-buffer (nth 2 elt
))
83 (setq talk-display-alist
(delq elt talk-display-alist
))
84 (talk-update-buffers)))
86 (defun talk-update-buffers ()
87 "Update all the talk frames so that each shows all the talk buffers."
88 (let ((tail talk-display-alist
))
90 (let ((frame (nth 1 (car tail
)))
91 (this-buffer (nth 2 (car tail
)))
93 (mapcar (function (lambda (elt) (nth 2 elt
)))
95 ;; Put this display's own talk buffer
96 ;; at the front of the list.
97 (setq buffers
(cons this-buffer
(delq this-buffer buffers
)))
98 (talk-split-up-frame frame buffers
))
99 (setq tail
(cdr tail
)))))
101 (defun talk-split-up-frame (frame buffers
)
102 "Split FRAME into equal-sized windows displaying the buffers in BUFFERS.
103 Select the first of these windows, displaying the first of the buffers."
104 (let ((lines-per-buffer (/ (frame-height frame
) (length buffers
)))
105 (old-frame (selected-frame)))
109 (select-window (frame-first-window frame
))
110 (delete-other-windows)
112 (switch-to-buffer (car buffers
))
113 (setq buffers
(cdr buffers
)))
114 (split-window-below lines-per-buffer
)
116 (select-window (frame-first-window frame
)))
117 (select-frame old-frame
))))
121 ;;; talk.el ends here