From 3222b53d942daa404852e5148ba9d3ebb8fe96d0 Mon Sep 17 00:00:00 2001 From: dickmao Date: Mon, 27 Aug 2018 17:00:35 -0400 Subject: Pre-moves To activate, look for Chess Display Allow Pre Moves in: M-x customize-group chess-display Tested via: make test make test24 (requires evim) --- chess-images.el | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'chess-images.el') diff --git a/chess-images.el b/chess-images.el index 1164c45..aacd153 100644 --- a/chess-images.el +++ b/chess-images.el @@ -305,22 +305,31 @@ chess board are light or dark depending on location." (goto-char pos))) (defun chess-images-highlight (index &optional mode) - "Highlight the piece on the board at INDEX, using the given MODE. -Common modes are: - `selected' show that the piece has been selected for movement. - `unselected' show that the piece has been unselected." + "Highlight the piece on the board at INDEX, using the given MODE, which +is often an arbitrary color or + :selected show that the piece has been selected for movement. + :unselected show that the piece has been unselected." (let* ((pos (chess-display-index-pos nil index)) - (highlight (copy-alist (get-text-property pos 'display)))) - (setcar (last highlight) - (list (cons "light_square" (if (eq mode :selected) - chess-images-highlight-color - mode)) - (cons "dark_square" (if (eq mode :selected) - chess-images-highlight-color - mode)) - (cons "background" (if (eq mode :selected) - chess-images-highlight-color - mode)))) + (highlight (copy-alist (get-text-property pos 'display))) + (light-color (if (eq mode :selected) + chess-images-highlight-color + (if (eq mode :unselected) chess-images-light-color mode))) + (dark-color (if (eq mode :selected) + chess-images-highlight-color + (if (eq mode :unselected) chess-images-dark-color mode))) + (square-color (% (+ (chess-index-file index) (chess-index-rank index)) 2)) + (background (if (eq mode :selected) + chess-images-highlight-color + (if (eq mode :unselected) + (if (= square-color 0) chess-images-light-color chess-images-dark-color) mode))) + (color-syms (car (last highlight)))) + (setcar (last highlight) + (mapcar (lambda (cp) + (cond ((string= (car cp) "light_square") (cons (car cp) light-color)) + ((string= (car cp) "dark_square") (cons (car cp) dark-color)) + ((string= (car cp) "background") (cons (car cp) background)) + (t cp))) + color-syms)) (put-text-property pos (1+ pos) 'display highlight))) (chess-message-catalog 'english -- cgit v1.2.3