1 ;;; chess-chat.el --- Very much like kibitzing, but not saved.
3 ;; Copyright (C) 2002, 2014 Free Software Foundation, Inc.
5 ;; Author: John Wiegley <johnw@gnu.org>
6 ;; Maintainer: Mario Lang <mlang@delysid.org>
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
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
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/>.
24 ;; RET is used to send each chat line.
28 (require 'chess-module)
30 (defvar chess-chat-input-last nil)
32 (make-variable-buffer-local 'chess-chat-input-last)
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)))
42 (defun chess-chat-send ()
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))
50 (defun chess-chat-handler (_game event &rest args)
52 ((eq event 'initialize)
53 (kill-buffer (current-buffer))
54 (set-buffer (generate-new-buffer "*Chat*"))
58 ((eq event 'switch-to-chat)
59 (switch-to-buffer-other-window (current-buffer)))
62 (chess-chat-handler 'switch-to-chat)
64 (goto-char chess-chat-input-last)
65 (insert (car args))))))
69 ;;; chess-chat.el ends here