From: Asher Gordon Date: Sat, 28 Mar 2020 18:32:25 +0000 (-0400) Subject: Fix movement commands in gomoku X-Git-Tag: emacs-28.0.90~7670 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1ded4a8b932eb377f5882e7b99ab7365dce43445;p=emacs.git Fix movement commands in gomoku * lisp/play/gomoku.el (gomoku-mode-map): Bind cursor motion keys to gomoku-specific commands. (gomoku-point-x, gomoku-move-right, gomoku-move-left): New commands. (gomoku--intangible, gomoku-move-ne, gomoku-move-se) (gomoku-move-nw, gomoku-move-sw): Call gomoku-move-left and gomoku-move-right instead of forward-char and backward-char. (Bug#40169) * etc/NEWS: Call out the changes. --- diff --git a/etc/NEWS b/etc/NEWS index 7e578f89dba..7588b418a40 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -93,6 +93,11 @@ line numbers that were previously jumped to. ** When 'suggest-key-bindings' is non-nil, the completion list of 'M-x' shows equivalent key bindings for all commands that have them. +--- +** Movement commands in 'gomoku-mode' are fixed. +'gomoku-move-sw' and 'gomoku-move-ne' now work correctly, and +horizontal movements now stop at the edge of the board. + * Changes in Specialized Modes and Packages in Emacs 28.1 diff --git a/lisp/play/gomoku.el b/lisp/play/gomoku.el index 6e0061d461a..403398672b1 100644 --- a/lisp/play/gomoku.el +++ b/lisp/play/gomoku.el @@ -110,8 +110,8 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces." (define-key map "u" 'gomoku-move-ne) ; u (define-key map "b" 'gomoku-move-sw) ; b (define-key map "n" 'gomoku-move-se) ; n - (define-key map "h" 'backward-char) ; h - (define-key map "l" 'forward-char) ; l + (define-key map "h" 'gomoku-move-left) ; h + (define-key map "l" 'gomoku-move-right) ; l (define-key map "j" 'gomoku-move-down) ; j (define-key map "k" 'gomoku-move-up) ; k @@ -119,11 +119,13 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces." (define-key map [kp-9] 'gomoku-move-ne) (define-key map [kp-1] 'gomoku-move-sw) (define-key map [kp-3] 'gomoku-move-se) - (define-key map [kp-4] 'backward-char) - (define-key map [kp-6] 'forward-char) + (define-key map [kp-4] 'gomoku-move-left) + (define-key map [kp-6] 'gomoku-move-right) (define-key map [kp-2] 'gomoku-move-down) (define-key map [kp-8] 'gomoku-move-up) + (define-key map "\C-b" 'gomoku-move-left) ; C-b + (define-key map "\C-f" 'gomoku-move-right) ; C-f (define-key map "\C-n" 'gomoku-move-down) ; C-n (define-key map "\C-p" 'gomoku-move-up) ; C-p @@ -146,6 +148,10 @@ One useful value to include is `turn-on-font-lock' to highlight the pieces." (define-key map [mouse-2] 'gomoku-mouse-play) (define-key map [drag-mouse-2] 'gomoku-mouse-play) + (define-key map [remap backward-char] 'gomoku-move-left) + (define-key map [remap left-char] 'gomoku-move-left) + (define-key map [remap forward-char] 'gomoku-move-right) + (define-key map [remap right-char] 'gomoku-move-right) (define-key map [remap previous-line] 'gomoku-move-up) (define-key map [remap next-line] 'gomoku-move-down) (define-key map [remap move-beginning-of-line] 'gomoku-beginning-of-line) @@ -954,6 +960,11 @@ If the game is finished, this command requests for another game." ;; 2 instead of 1 because WINDOW-HEIGHT includes the mode line ! gomoku-square-height))) +(defun gomoku-point-x () + "Return the board column where point is." + (1+ (/ (- (current-column) gomoku-x-offset) + gomoku-square-width))) + (defun gomoku-point-y () "Return the board row where point is." (1+ (/ (- (count-lines (point-min) (point)) @@ -1143,13 +1154,28 @@ If the game is finished, this command requests for another game." (skip-chars-forward gomoku--intangible-chars) (when (eobp) (skip-chars-backward gomoku--intangible-chars) - (forward-char -1))) + (gomoku-move-left))) (skip-chars-backward gomoku--intangible-chars) (if (bobp) (skip-chars-forward gomoku--intangible-chars) - (forward-char -1)))) + (gomoku-move-left)))) (setq gomoku--last-pos (point))) +;; forward-char and backward-char don't always move the right number +;; of characters. Also, these functions check if you're on the edge of +;; the screen. +(defun gomoku-move-right () + "Move point right one column on the Gomoku board." + (interactive) + (when (< (gomoku-point-x) gomoku-board-width) + (forward-char gomoku-square-width))) + +(defun gomoku-move-left () + "Move point left one column on the Gomoku board." + (interactive) + (when (> (gomoku-point-x) 1) + (backward-char gomoku-square-width))) + ;; previous-line and next-line don't work right with intangible newlines (defun gomoku-move-down () "Move point down one row on the Gomoku board." @@ -1171,25 +1197,25 @@ If the game is finished, this command requests for another game." "Move point North East on the Gomoku board." (interactive) (gomoku-move-up) - (forward-char)) + (gomoku-move-right)) (defun gomoku-move-se () "Move point South East on the Gomoku board." (interactive) (gomoku-move-down) - (forward-char)) + (gomoku-move-right)) (defun gomoku-move-nw () "Move point North West on the Gomoku board." (interactive) (gomoku-move-up) - (backward-char)) + (gomoku-move-left)) (defun gomoku-move-sw () "Move point South West on the Gomoku board." (interactive) (gomoku-move-down) - (backward-char)) + (gomoku-move-left)) (defun gomoku-beginning-of-line () "Move point to first square on the Gomoku board row."