[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 01/01: * chess-display.el (chess-display-draw-square): New functi
From: |
Mario Lang |
Subject: |
[elpa] 01/01: * chess-display.el (chess-display-draw-square): New function. (chess-display-paint-move, chess-display-set-piece): Use it. |
Date: |
Sun, 15 Jun 2014 01:46:26 +0000 |
mlang pushed a commit to branch externals/chess
in repository elpa.
commit 0a5389e92c0ba865048b7ef0f433b4f7f0e08e31
Author: Mario Lang <address@hidden>
Date: Sun Jun 15 03:44:40 2014 +0200
* chess-display.el (chess-display-draw-square): New function.
(chess-display-paint-move, chess-display-set-piece): Use it.
* chess-plain.el (chess-plain-handler): Fix error if unknown event
is received.
---
ChangeLog | 6 ++++++
chess-display.el | 41 ++++++++++++++++++++++-------------------
chess-plain.el | 3 ++-
3 files changed, 30 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9d7115d..2a89732 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2014-06-15 Mario Lang <address@hidden>
+ * chess-display.el (chess-display-draw-square): New function.
+ (chess-display-paint-move, chess-display-set-piece): Use it.
+
+ * chess-plain.el (chess-plain-handler): Fix error if unknown event
+ is received.
+
* chess-display.el (chess-display-select-piece): Redraw legal targets
if a move is either accepted or the same piece is selected again.
This fixes ...
diff --git a/chess-display.el b/chess-display.el
index a6e675e..61a3ca2 100644
--- a/chess-display.el
+++ b/chess-display.el
@@ -350,6 +350,14 @@ also view the same game."
(point-min))))))
(aref chess-display-index-positions index)))
+(defun chess-display-draw-square (display index piece &optional pos)
+ (cl-check-type display (or null buffer))
+ (cl-check-type index (integer 0 63))
+ (chess-with-current-buffer display
+ (cl-check-type pos (or null (number ((point-min)) ((point-max)))))
+ (funcall chess-display-event-handler 'draw-square
+ (or pos (chess-display-index-pos nil index)) piece index)))
+
(defun chess-display-paint-move (display ply)
(chess-with-current-buffer display
(if chess-display-highlight-last-move
@@ -361,20 +369,15 @@ also view the same game."
(setq ch nil)
(let ((from (car ch))
(to (cadr ch)))
- (funcall chess-display-event-handler 'draw-square
- (chess-display-index-pos nil from) ? from)
- (funcall chess-display-event-handler 'draw-square
- (chess-display-index-pos nil to)
- (or (let ((new-piece (chess-ply-keyword ply :promote)))
- (when new-piece
- (if (chess-pos-side-to-move position)
- new-piece (downcase new-piece))))
- (chess-pos-piece position from))
- to)
+ (chess-display-draw-square nil from ? )
+ (chess-display-draw-square
+ nil to (or (let ((new-piece (chess-ply-keyword ply :promote)))
+ (when new-piece
+ (if (chess-pos-side-to-move position)
+ new-piece (downcase new-piece))))
+ (chess-pos-piece position from)))
(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))))
+ (chess-display-draw-square nil (chess-pos-en-passant position) ?
)))
(setq ch (cddr ch)))))
(if chess-display-highlight-last-move
(chess-display-highlight-move display ply))))
@@ -1116,12 +1119,12 @@ to the end or beginning."
(defun chess-display-set-piece (&optional piece)
"Set the piece under point to command character, or space for clear."
(interactive)
- (if (or (null piece) (characterp piece))
- (let ((index (get-text-property (point) 'chess-coord)))
- (chess-pos-set-piece chess-display-edit-position index
- (or piece last-command-event))
- (funcall chess-display-event-handler 'draw-square
- (point) (or piece last-command-event) index))))
+ (when (or (null piece) (characterp piece))
+ (let ((index (get-text-property (point) 'chess-coord)))
+ (chess-pos-set-piece chess-display-edit-position index
+ (or piece last-command-event))
+ (chess-display-draw-square nil index
+ (or piece last-command-event) (point)))))
(unless (fboundp 'event-window)
(defalias 'event-point 'ignore))
diff --git a/chess-plain.el b/chess-plain.el
index d4cab93..e5e1412 100644
--- a/chess-plain.el
+++ b/chess-plain.el
@@ -245,7 +245,8 @@ modify `chess-plain-piece-chars' to avoid real confusion.)"
(cond
((eq event 'initialize) t)
((eq event 'popup) (funcall chess-plain-popup-function))
- (t (apply (intern-soft (concat "chess-plain-" (symbol-name event))) args))))
+ (t (let ((handler (intern-soft (concat "chess-plain-" (symbol-name
event)))))
+ (when handler (apply handler args))))))
(defun chess-plain-popup ()
(if chess-plain-separate-frame