all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dieter Deyke <dieter.deyke@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: [PATCH] elpa/packages/sokoban/sokoban.el
Date: Sun, 16 Jul 2017 18:57:46 +0200	[thread overview]
Message-ID: <87bmok5ng5.fsf@deyke2> (raw)
In-Reply-To: jwvzic4wewz.fsf-monnier+gmane.emacs.devel@gnu.org

How about this:

Commit message:

Determine sokoban-width and sokoban-height dynamically

This avoids hard-coding sokoban-width and sokoban-height by scanning
the level file and finding the correct values dynamically.

Unrelated additional changes:

- remove unused variable 'sokoban-temp-buffer-name'

- change sokoban-next-level to use sokoban-goto-level in order to
  range-check new level number

- change sokoban-goto-level to produce a more readable error message
  when level is out of range

Patch:

--- ../elpa/packages/sokoban/sokoban.el	2017-07-11 05:53:25.013984603 +0200
+++ ./sokoban.el	2017-07-16 17:20:12.073045180 +0200
@@ -4,7 +4,7 @@

 ;; Author: Glynn Clements <glynn.clements@xemacs.org>
 ;; Maintainer: Dieter Deyke <dieter.deyke@gmail.com>
-;; Version: 1.4.2
+;; Version: 1.4.3
 ;; Created: 1997-09-11
 ;; Keywords: games
 ;; Package-Type: multi
@@ -71,8 +71,6 @@

 (defvar sokoban-buffer-name "*Sokoban*")

-(defvar sokoban-temp-buffer-name " Sokoban-tmp")
-
 (defvar sokoban-level-file
   (if (fboundp 'locate-data-file)
       (locate-data-file "sokoban.levels")
@@ -84,14 +82,14 @@
               (and (file-exists-p file) file))
 	(expand-file-name "sokoban.levels" data-directory))))

-(defvar sokoban-width 27)
-(defvar sokoban-height 20)
+(defvar sokoban-width)
+(defvar sokoban-height)

-(defvar sokoban-buffer-width sokoban-width)
-(defvar sokoban-buffer-height (+ 4 sokoban-height))
+(defvar sokoban-buffer-width)
+(defvar sokoban-buffer-height)

-(defvar sokoban-score-x 0)
-(defvar sokoban-score-y (1+ sokoban-height))
+(defvar sokoban-score-x)
+(defvar sokoban-score-y)

 (defvar sokoban-level-data nil)

@@ -542,6 +540,28 @@
     (if (fboundp 'read-only-mode)
         (read-only-mode 1)
       (setq buffer-read-only t))
+
+    (setq sokoban-width 1
+          sokoban-height 1)
+    (goto-char (point-min))
+    (re-search-forward sokoban-level-regexp nil t)
+    (forward-char)
+    (let (r)
+      (while (not (eobp))
+        (while (looking-at sokoban-comment-regexp)
+	  (forward-line))
+        (setq r 0)
+        (while (not (or (eobp)
+		        (looking-at sokoban-comment-regexp)))
+          (incf r)
+          (setq sokoban-height (max sokoban-height r)
+                sokoban-width (max sokoban-width (- (line-end-position) (line-beginning-position))))
+	  (forward-line))))
+    (setq sokoban-buffer-width sokoban-width
+          sokoban-buffer-height (+ 4 sokoban-height)
+          sokoban-score-x 0
+          sokoban-score-y (1+ sokoban-height))
+
     (goto-char (point-min))
     (re-search-forward sokoban-level-regexp nil t)
     (forward-char)
@@ -823,8 +843,7 @@
   (sokoban-draw-score))

 (defun sokoban-next-level ()
-  (incf sokoban-level)
-  (sokoban-restart-level))
+  (sokoban-goto-level (1+ sokoban-level)))

 (defun sokoban-goto-level (level)
   "Jump to a specified LEVEL."
@@ -832,8 +851,9 @@
   (when (or (< level 1)
             (> level (length sokoban-level-data)))
     (signal 'args-out-of-range
-            (list "No such level number"
-                  level 1 (> level (length sokoban-level-data)))))
+            (list
+             (format "No such level number %d, should be 1..%d"
+                     level (length sokoban-level-data)))))
   (setq sokoban-level level)
   (sokoban-restart-level))

@@ -915,4 +935,3 @@
 (provide 'sokoban)

 ;;; sokoban.el ends here
-

--
Dieter Deyke
mailto:dieter.deyke@gmail.com
Get my Gnupg key:
gpg --keyserver keys.gnupg.net --recv-keys B116EA20




  reply	other threads:[~2017-07-16 16:57 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-16 14:14 [PATCH] elpa/packages/sokoban/sokoban.el Dieter Deyke
2017-07-16 16:01 ` Stefan Monnier
2017-07-16 16:57   ` Dieter Deyke [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-02-12 12:30 Dieter Deyke
2019-02-07 10:51 Dieter Deyke
2019-02-07 12:53 ` Clément Pit-Claudel
2019-02-07 14:42   ` Eli Zaretskii
2019-02-07 15:57     ` Dieter Deyke
2019-02-07 16:08       ` Clément Pit-Claudel
2019-02-07 16:11         ` Dieter Deyke
2019-02-07 16:55       ` Andreas Schwab
2019-02-08  3:34         ` Stefan Monnier
2019-02-07 14:56 ` Stefan Monnier
2017-07-25 11:36 Dieter Deyke
2017-07-25 14:24 ` Stefan Monnier
2017-07-09 13:36 Dieter Deyke
2017-07-09 14:15 ` Eli Zaretskii
2017-07-09 14:34   ` Dieter Deyke
2017-07-09 14:52     ` Eli Zaretskii
2017-07-11 15:17       ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87bmok5ng5.fsf@deyke2 \
    --to=dieter.deyke@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.