]> code.delx.au - gnu-emacs-elpa/blobdiff - chess-display.el
Correctly indent `chess-with-current-buffer' in lisp-mode.
[gnu-emacs-elpa] / chess-display.el
index 7e70f31e2909afb9e44abe398cc06d647f7c2fd9..553de49b72e5f43bb7e8d950253c8bd5627350f3 100644 (file)
@@ -3,16 +3,19 @@
 ;; Code shared by all chess displays
 ;;
 
+(require 'chess-message)
 (require 'chess-module)
 (require 'chess-var)
 (require 'chess-input)
+(require 'chess-random)
 
 (defgroup chess-display nil
   "Common code used by chess displays."
   :group 'chess)
 
 (defcustom chess-display-popup t
-  "If non-nil, popup displays whenever a significant event occurs."
+  "If non-nil (the default), popup displays whenever a significant event
+occurs."
   :type 'boolean
   :group 'chess-display)
 
@@ -78,13 +81,14 @@ See `mode-line-format' for syntax details."
 (make-variable-buffer-local 'chess-display-index)
 (make-variable-buffer-local 'chess-display-move-text)
 (make-variable-buffer-local 'chess-display-side-to-move)
+(put 'chess-display-side-to-move 'risky-local-variable t)
 (make-variable-buffer-local 'chess-display-perspective)
 (make-variable-buffer-local 'chess-display-event-handler)
 (make-variable-buffer-local 'chess-display-edit-mode)
 (make-variable-buffer-local 'chess-display-index-positions)
 
 (defvar chess-display-handling-event nil
-  "If non-nil, chess-display is aleady handling the event.  This variable
+  "If non-nil, chess-display is already handling the event.  This variable
 is used to avoid reentrancy.")
 
 (defvar chess-display-style)
@@ -121,7 +125,7 @@ of the board, if non-nil, the board is viewed from White's perspective."
 (defalias 'chess-display-destroy 'chess-module-destroy)
 
 (defun chess-display-clone (display style perspective)
-  (let ((new-display (chess-display-create chess-module-game
+  (let ((new-display (chess-display-create (chess-display-game display)
                                           style perspective)))
     ;; the display will have already been updated by the `set-' calls,
     ;; it's just not visible yet
@@ -263,10 +267,11 @@ also view the same game."
                     (str (format " %s " (if color
                                             (chess-string 'mode-white)
                                           (chess-string 'mode-black)))))
-               (add-text-properties
-                0 (length str) (list 'face (if color
-                                               'chess-display-white-face
-                                             'chess-display-black-face)) str)
+               (add-text-properties 0 (length str)
+                                    (list 'face (if color
+                                                    'chess-display-white-face
+                                                  'chess-display-black-face))
+                                    str)
                str)))))
     (force-mode-line-update)))
 
@@ -334,7 +339,11 @@ also view the same game."
                             (downcase new-piece)) to)
                (funcall chess-display-event-handler 'draw-square
                         (chess-display-index-pos nil to)
-                        (chess-pos-piece position from) to))))
+                        (chess-pos-piece position from) to)))
+           (when (chess-ply-keyword ply :en-passant)
+             (funcall chess-display-event-handler 'draw-square
+                      (chess-display-index-pos nil (chess-pos-en-passant position))
+                      ?  (chess-pos-en-passant position))))
          (setq ch (cddr ch)))))))
 
 (chess-message-catalog 'english
@@ -358,8 +367,8 @@ If only START is given, it must be in algebraic move notation."
          (chess-error 'game-is-over)))
     (if (= chess-display-index (chess-game-index chess-module-game))
        (let ((chess-display-handling-event t))
-         (chess-display-paint-move nil ply)
          (chess-game-move chess-module-game ply)
+         (chess-display-paint-move nil ply)
          (chess-display-set-index* nil (chess-game-index chess-module-game)))
       ;; jww (2002-03-28): This should beget a variation within the
       ;; game, or alter the game, just as SCID allows
@@ -385,6 +394,14 @@ that is supported by most displays, and is the default mode."
       (chess-display-highlight nil "pale green"
                               (chess-ply-target ply)))))
 
+(defun chess-display-highlight-passed-pawns (&optional display)
+  (interactive)
+  (mapc
+   (lambda (index) (chess-display-highlight display index :selected))
+   (append
+    (chess-pos-passed-pawns (chess-display-position display) t)
+    (chess-pos-passed-pawns (chess-display-position display) nil))))
+
 (defun chess-display-popup (display)
   "Popup the given DISPLAY, so that it's visible to the user."
   (chess-with-current-buffer display
@@ -414,8 +431,8 @@ that is supported by most displays, and is the default mode."
        (fit-window-to-buffer (display-buffer (current-buffer)))
       (display-buffer (current-buffer)))))
 
-(defun chess-display-popup-in-frame (height width &optional
-                                           display no-minibuffer)
+(defun chess-display-popup-in-frame (height width font
+                                    &optional display no-minibuffer)
   "Popup the given DISPLAY, so that it's visible to the user."
   (let ((window (get-buffer-window (current-buffer) t)))
     (if window
@@ -427,6 +444,8 @@ that is supported by most displays, and is the default mode."
                          (cons 'width width))))
        (if display
            (push (cons 'display display) params))
+       (if font
+           (push (cons 'font font) params))
        (if no-minibuffer
            (push (cons 'minibuffer nil) params))
        (select-frame (make-frame params))
@@ -1068,6 +1087,9 @@ to the end or beginning."
        (funcall chess-display-event-handler 'draw-square
                 (point) (or piece last-command-char) index))))
 
+(unless (fboundp 'event-window)
+  (defalias 'event-point 'ignore))
+
 (defun chess-display-mouse-set-piece (event)
   "Select the piece the user clicked on."
   (interactive "e")