[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/mines f11e546 41/43: * mines.el (mines-mode-map): Add m
From: |
Stefan Monnier |
Subject: |
[elpa] externals/mines f11e546 41/43: * mines.el (mines-mode-map): Add mouse bindings |
Date: |
Mon, 30 Nov 2020 18:44:20 -0500 (EST) |
branch: externals/mines
commit f11e54651d9bbbb8592006c69296e31702bd6d04
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* mines.el (mines-mode-map): Add mouse bindings
(mines--insert): Add mouse-face to the cells.
(mines-flag-cell): Make it work when bound to a mouse event.
(mines-dig): Make it work when bound to a mouse event.
Straighten out the control flow.
---
mines.el | 70 +++++++++++++++++++++++++++++++---------------------------------
1 file changed, 34 insertions(+), 36 deletions(-)
diff --git a/mines.el b/mines.el
index fce9f64..7ca2c65 100644
--- a/mines.el
+++ b/mines.el
@@ -327,6 +327,7 @@ Each cell can be either:
(pos (point))
(inhibit-read-only t))
(insert (format " %c " char))
+ (add-text-properties pos (point) `(mouse-face ,(list 'highlight)))
(when (= (cadr (mines-index-2-matrix idx)) (1- mines-number-cols))
(backward-delete-char 1)
(insert "\n"))
@@ -465,10 +466,11 @@ After sorting, games completed with shorter times appear
first."
(message (format "Well done %s, you have completed it in %s!"
user-login-name elapsed-time))))
-(defun mines-flag-cell ()
+(defun mines-flag-cell (&optional event)
"Flag current cell as having a mine.
If called again then unflag it."
- (interactive)
+ (interactive (list last-nonmenu-event))
+ (if event (posn-set-point (event-end event)))
(let* ((idx (mines-current-pos))
(state (aref mines-state idx)))
(if (null state)
@@ -518,45 +520,39 @@ If called again then unflag it."
;; Update the numbers on neighbour cells.
(mines-set-numbers))))
-(defun mines-dig ()
+(defun mines-dig (&optional event)
"Reveal the content of the cell at point."
- (interactive)
+ (interactive (list last-nonmenu-event))
+ (if event (posn-set-point (event-end event)))
(if mines-game-over
(user-error "Current game is over. Try `%s' to start a new one"
(substitute-command-keys "\\[mines]"))
(mines-goto (mines-current-pos)) ; Set point in the center of the cell.
- (cl-labels ((uncover-fn
- ()
- (let* ((idx (mines-current-pos))
- (inhibit-read-only t)
- (state (aref mines-state idx))
- (done (null state)))
- (cond (done (message "Nothing new here")) ; Already updated.
- (t
- (let ((elt (aref mines-grid idx)))
- (cl-flet ((game-end-fn
- ()
- ;; Check for end of game.
- (cond ((eq elt 'bomb)
- ;; We lost the game; show all
the mines.
- (mines-game-over))
- (t
- (when (mines-end-p)
- (mines-game-completed))))))
- ;; Don't end the game in the first trial when
- ;; `mines-protect-first-move' is non-nil.
- (when (and mines-protect-first-move
- (mines-first-move-p)
- elt)
- (mines--clear-first-move idx)
- (setq elt nil))
- (cond ((and (eq 'flag state)
- ;; If the cell is flagged ask for
confirmation.
- (not (yes-or-no-p "This cell is
flagged as having a bomb. Uncover it? ")))
- (message "OK, canceled"))
- (t
- (mines--update-cell idx nil)
- (game-end-fn))))))))))
+ (cl-flet ((uncover-fn
+ ()
+ (let* ((idx (mines-current-pos))
+ (inhibit-read-only t)
+ (state (aref mines-state idx)))
+ (cond ((null state)
+ (message "Nothing new here")) ; Already updated.
+ ((and (eq 'flag state)
+ ;; If the cell is flagged ask for confirmation.
+ ;; FIXME: I personally find this prompt annoying.
+ (not (yes-or-no-p "This cell is flagged as having
a bomb. Uncover it? ")))
+ (message "OK, canceled"))
+ (t
+ (let ((elt (aref mines-grid idx)))
+ ;; Don't end the game in the first trial when
+ ;; `mines-protect-first-move' is non-nil.
+ (when (and mines-protect-first-move
+ (mines-first-move-p)
+ elt)
+ (mines--clear-first-move idx)
+ (setq elt nil))
+ (mines--update-cell idx nil)
+ ;; Check for end of game.
+ (cond ((eq elt 'bomb) (mines-game-over))
+ ((mines-end-p) (mines-game-completed)))))))))
(uncover-fn)
(when mines-undone-neighbours
(while mines-undone-neighbours
@@ -638,6 +634,8 @@ Called with a prefix prompt for the difficulty level."
(define-key map "x" 'mines-dig)
;; FIXME: I think SPC would be a natural binding for `mines-dig'.
(define-key map "c" 'mines-dig)
+ (define-key map [mouse-1] 'mines-dig)
+ (define-key map [mouse-3] 'mines-flag-cell)
;; (define-key map "a" 'mines-flag-cell)
(define-key map "1" 'mines-flag-cell)
(define-key map "m" 'mines-flag-cell)
- [elpa] externals/mines bea3ad8 42/43: * packages/mines/mines.el (mines-auto-flag): New custom var, (continued)
- [elpa] externals/mines bea3ad8 42/43: * packages/mines/mines.el (mines-auto-flag): New custom var, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 97e0a05 43/43: * mines.el: Adjust docs for the @ => SPC change, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 92399df 29/43: * packages/mines/mines.el: Bump version to 1.2, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 868e9b9 35/43: * mines.el: Bump version to v1.6, Stefan Monnier, 2020/11/30
- [elpa] externals/mines e127c84 30/43: Add fallback function for read-multiple-choice, Stefan Monnier, 2020/11/30
- [elpa] externals/mines bf577b0 31/43: Sort the score file from better to worst results, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 179ed77 32/43: Dont prompt user when updating the score file, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 9b07cb6 33/43: Do not uncover flagged cells if the user dont want that, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 34d088c 34/43: Reimplement mines-end-p, Stefan Monnier, 2020/11/30
- [elpa] externals/mines 5920f2d 37/43: * mines/mines.el (mines-grid): Use `bomb` instead of t, Stefan Monnier, 2020/11/30
- [elpa] externals/mines f11e546 41/43: * mines.el (mines-mode-map): Add mouse bindings,
Stefan Monnier <=