]> code.delx.au - gnu-emacs-elpa/blob - chess-chat.el
Release 2.0.4
[gnu-emacs-elpa] / chess-chat.el
1 ;;; chess-chat.el --- Very much like kibitzing, but not saved.
2
3 ;; Copyright (C) 2002, 2014 Free Software Foundation, Inc.
4
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Maintainer: Mario Lang <mlang@delysid.org>
7 ;; Keywords: games
8
9 ;; This is free software; you can redistribute it and/or modify it under
10 ;; the terms of the GNU General Public License as published by the Free
11 ;; Software Foundation; either version 3, or (at your option) any later
12 ;; version.
13 ;;
14 ;; This is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 ;; for more details.
18 ;;
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
21
22 ;;; Commentary:
23
24 ;; RET is used to send each chat line.
25
26 ;;; Code:
27
28 (require 'chess-module)
29
30 (defvar chess-chat-input-last nil)
31
32 (make-variable-buffer-local 'chess-chat-input-last)
33
34 (define-derived-mode chess-chat-mode text-mode "Chat"
35 "A mode for editing chess annotations."
36 (set-buffer-modified-p nil)
37 (setq chess-chat-input-last (copy-marker (point-max) t))
38 (let ((map (current-local-map)))
39 (define-key map [return] 'chess-chat-send)
40 (define-key map [(control ?m)] 'chess-chat-send)))
41
42 (defun chess-chat-send ()
43 (interactive)
44 (chess-game-run-hooks chess-module-game 'chat
45 (buffer-substring-no-properties
46 chess-chat-input-last (point-max)))
47 (set-marker chess-chat-input-last (point-max))
48 (set-buffer-modified-p nil))
49
50 (defun chess-chat-handler (_game event &rest args)
51 (cond
52 ((eq event 'initialize)
53 (kill-buffer (current-buffer))
54 (set-buffer (generate-new-buffer "*Chat*"))
55 (chess-chat-mode)
56 t)
57
58 ((eq event 'switch-to-chat)
59 (switch-to-buffer-other-window (current-buffer)))
60
61 ((eq event 'chat)
62 (chess-chat-handler 'switch-to-chat)
63 (save-excursion
64 (goto-char chess-chat-input-last)
65 (insert (car args))))))
66
67 (provide 'chess-chat)
68
69 ;;; chess-chat.el ends here