From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Dieter Deyke Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] elpa/packages/sokoban/sokoban.el Date: Sun, 16 Jul 2017 18:57:46 +0200 Message-ID: <87bmok5ng5.fsf@deyke2> References: <87k2385v0g.fsf@deyke2> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1500224305 12855 195.159.176.226 (16 Jul 2017 16:58:25 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 16 Jul 2017 16:58:25 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jul 16 18:58:21 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dWms4-0002qa-Ag for ged-emacs-devel@m.gmane.org; Sun, 16 Jul 2017 18:58:16 +0200 Original-Received: from localhost ([::1]:46286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWms8-0004Wd-5c for ged-emacs-devel@m.gmane.org; Sun, 16 Jul 2017 12:58:20 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dWms1-0004WY-OI for emacs-devel@gnu.org; Sun, 16 Jul 2017 12:58:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dWmrx-0004U8-Aq for emacs-devel@gnu.org; Sun, 16 Jul 2017 12:58:13 -0400 Original-Received: from [195.159.176.226] (port=47187 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dWmrx-0004Tg-4Q for emacs-devel@gnu.org; Sun, 16 Jul 2017 12:58:09 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1dWmro-0002Av-KS for emacs-devel@gnu.org; Sun, 16 Jul 2017 18:58:00 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 124 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:M2VczLm/QtiFltrsZpICZISYyzE= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216738 Archived-At: 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 ;; Maintainer: Dieter Deyke -;; 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