[TMP] enable load_prefer_newer
[bpt/emacs.git] / lisp / talk.el
CommitLineData
60370d40 1;;; talk.el --- allow several users to talk to each other through Emacs
5abe8993 2
ba318903 3;; Copyright (C) 1995, 2001-2014 Free Software Foundation, Inc.
b578f267 4
34dc21db 5;; Maintainer: emacs-devel@gnu.org
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.
32Each 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)
06b60517 50 (let ((type (frame-live-p (selected-frame))))
a1feed48 51 (if (or (eq type t) (eq type 'x))
06b60517 52 (talk-add-display
12b4c0ea 53 (terminal-name (frame-terminal)))
a1feed48 54 (error "Unknown frame type")))
17086732
KL
55 (talk-update-buffers))
56
a1feed48
CY
57(defun talk-add-display (display)
58 (let* ((elt (assoc display talk-display-alist))
59 (name (concat "*talk-" display "*"))
60 frame buffer)
b6660415 61 (if (and elt (frame-live-p (nth 1 elt)))
a1feed48
CY
62 (setq frame (nth 1 elt))
63 (setq frame (make-frame-on-display display (list (cons 'name name)))))
17086732
KL
64 (if (not (and elt (buffer-name (get-buffer (setq buffer (nth 2 elt))))))
65 (setq buffer (get-buffer-create name)))
b6660415 66 (add-to-list 'delete-frame-functions 'talk-handle-delete-frame)
17086732 67 (setq talk-display-alist
b6660415 68 (cons (list display frame buffer) (delq elt talk-display-alist)))))
17086732 69
b6660415
KL
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))))
17086732 75
5abe8993
RS
76(defun talk-disconnect ()
77 "Disconnect this display from the Emacs talk group."
c2bef985 78 (interactive)
5abe8993
RS
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)))
85
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))
89 (while tail
90 (let ((frame (nth 1 (car tail)))
91 (this-buffer (nth 2 (car tail)))
92 (buffers
93 (mapcar (function (lambda (elt) (nth 2 elt)))
94 talk-display-alist)))
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)))))
100
101(defun talk-split-up-frame (frame buffers)
102 "Split FRAME into equal-sized windows displaying the buffers in BUFFERS.
103Select 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)))
106 (unwind-protect
107 (progn
108 (select-frame frame)
109 (select-window (frame-first-window frame))
110 (delete-other-windows)
111 (while (progn
112 (switch-to-buffer (car buffers))
113 (setq buffers (cdr buffers)))
2d197ffb 114 (split-window-below lines-per-buffer)
5abe8993
RS
115 (other-window 1))
116 (select-window (frame-first-window frame)))
117 (select-frame old-frame))))
118
896546cd
RS
119(provide 'talk)
120
5abe8993 121;;; talk.el ends here