1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3 ;; Implements chess kibitzing, stored as annotations to the game being
4 ;; viewed or played. C-c C-c is used to save a kibitzing comment.
7 (defvar chess-kibitz-input-last nil)
8 (defvar chess-kibitz-index nil)
10 (make-variable-buffer-local 'chess-kibitz-input-last)
11 (make-variable-buffer-local 'chess-kibitz-index)
13 (define-derived-mode chess-kibitz-mode text-mode "Kibitz"
14 "A mode for editing chess annotations."
15 (set-buffer-modified-p nil)
16 (setq chess-kibitz-input-last (copy-marker (point-max) t))
17 (let ((map (current-local-map)))
18 (define-key map [(control ?c) (control ?c)] 'chess-kibitz-save)))
20 (defun chess-kibitz-save ()
22 (let ((ann (buffer-substring-no-properties chess-kibitz-input-last
24 (chess-game-run-hooks chess-module-game 'kibitz ann)
25 (chess-pos-add-annotation (chess-game-pos chess-kibitz-index) ann))
26 (set-marker chess-kibitz-input-last (point-max))
27 (set-buffer-modified-p nil))
29 (defun chess-kibitz-show-annotations (index)
30 (setq chess-kibitz-index index)
32 (let ((position (chess-game-pos chess-module-game index))
34 (dolist (ann (chess-pos-annotations position))
39 (display-buffer (current-buffer)))))
41 (defun chess-kibitz-handler (game event &rest args)
43 ((eq event 'initialize)
44 (kill-buffer (current-buffer))
45 (set-buffer (generate-new-buffer "*Annotations*"))
49 ((eq event 'switch-to-annotations)
50 (switch-to-buffer-other-window (current-buffer)))
53 (chess-kibitz-handler 'switch-to-annotations)
55 (goto-char chess-kibitz-input-last)
58 ((eq event 'set-index)
59 (chess-kibitz-show-annotations (car args)))
61 ((memq event '(post-undo move))
62 (chess-kibitz-show-annotations (chess-game-index game)))))
64 (provide 'chess-kibitz)
66 ;;; chess-kibitz.el ends here