]> code.delx.au - gnu-emacs-elpa/blob - chess-chat.el
reward passed pawns, and make the code a bit faster
[gnu-emacs-elpa] / chess-chat.el
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;
3 ;; Implements chess chat, which is very much like kibitzing, but not
4 ;; saved. RET is used to send each chat line.
5 ;;
6
7 (defvar chess-chat-input-last nil)
8
9 (make-variable-buffer-local 'chess-chat-input-last)
10
11 (define-derived-mode chess-chat-mode text-mode "Chat"
12 "A mode for editing chess annotations."
13 (set-buffer-modified-p nil)
14 (setq chess-chat-input-last (copy-marker (point-max) t))
15 (let ((map (current-local-map)))
16 (define-key map [return] 'chess-chat-send)
17 (define-key map [(control ?m)] 'chess-chat-send)))
18
19 (defun chess-chat-send ()
20 (interactive)
21 (chess-game-run-hooks chess-module-game 'chat
22 (buffer-substring-no-properties
23 chess-chat-input-last (point-max)))
24 (set-marker chess-chat-input-last (point-max))
25 (set-buffer-modified-p nil))
26
27 (defun chess-chat-handler (game event &rest args)
28 (cond
29 ((eq event 'initialize)
30 (kill-buffer (current-buffer))
31 (set-buffer (generate-new-buffer "*Chat*"))
32 (chess-chat-mode)
33 t)
34
35 ((eq event 'switch-to-chat)
36 (switch-to-buffer-other-window (current-buffer)))
37
38 ((eq event 'chat)
39 (chess-chat-handler 'switch-to-chat)
40 (save-excursion
41 (goto-char chess-chat-input-last)
42 (insert (car args))))))
43
44 (provide 'chess-chat)
45
46 ;;; chess-chat.el ends here