branch: elpa/pacmacs commit c499aa4b31d97d9777da7ce267b37c34891e41df Author: Stefan Monnier <monn...@iro.umontreal.ca> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Remove dependency on `f` and fix some compilation issues * test/test-helper.el: Use lexical-binding. Mark as not to be compiled. * test/pacmacs-walls-test.el: Use lexical-binding. Require `el-mock`, `dash`, and `pacmacs-walls`. Mark as not to be compiled. * test/pacmacs-vector-test.el: Use lexical-binding. Require `pacmacs-vector`. * test/pacmacs-utils-test.el: Use lexical-binding. Require `pacmacs-utils`. * test/pacmacs-test.el: Use lexical-binding. Require `el-mock` and `pacmacs`. Mark as not to be compiled. * test/pacmacs-score-test.el: Use lexical-binding. Require `pacmacs-score`. * test/pacmacs-render-test.el: Use lexical-binding. Require `el-mock`. Mark as not to be compiled. * test/pacmacs-board-test.el: Use lexical-binding. Require `pacmacs-board`. * test/pacmacs-anim-test.el: Use lexical-binding. Require `el-mock`. Mark as not to be compiled. * pacmacs.el: Remove `f` and `cl-lib` from Package-Requires. `cl-lib` was redundant since it's included in Emacsā„24.4. Don't require `f` any more. (pacmacs-levels-folder): Remove redundant `:group`. (pacmacs-mode-map, pacmacs-game-over-mode-map): Define it once and for all so we don't overwrite user changes when the mode is called again. (pacmacs-scores-mode): Don't change the `q` binding in `pacmacs-game-over-mode-map`. (pacmacs-quit): Delete scrobe buffer if applicable, instead. * pacmacs-vector.el: Require `dash` to fix compilation errors. * pacmacs-score.el: Don't require `f`. (pacmacs--read-score-table): Read directly from a buffer rather than going through a string. * tools/pacmacs-rr.el: Don't require `f`. (pacmacs--load-test-case): Read directly from a buffer rather than going through a string. (pacmacs-it-recorder-mode-map): Define it once and for all so we don't overwrite user changes when the mode is called again. * tools/compile.el: Use lexical-binding and don't require `f`. Require `dash` at top-level so it's byte-compiled properly. Don't require `cask` during compilation of the file itself. * tools/att.el: Use lexical-binding and don't require `f`. (att-replayer-finished): Use `write-region` instead of `f-write`. * .gitignore: Add ELPA's generated files. * it-cases/it-case0*.el: Change extentions from `.el` to `.eld` to indicate that those files do not contain ELisp code but ELisp data (they should use `lisp-data-mode` rather than `emacs-lisp-mode` and they should not be byte-compiled). * tools/att.el (att-it-case-path): Adjust accordingly. --- .gitignore | 4 +++- it-cases/{it-case01.el => it-case01.eld} | 0 it-cases/{it-case02.el => it-case02.eld} | 0 it-cases/{it-case03.el => it-case03.eld} | 0 pacmacs-anim.el | 4 ++-- pacmacs-score.el | 10 ++++---- pacmacs-vector.el | 2 ++ pacmacs.el | 39 +++++++++++++++++++------------- test/pacmacs-anim-test.el | 10 +++++++- test/pacmacs-board-test.el | 4 +++- test/pacmacs-render-test.el | 10 +++++++- test/pacmacs-score-test.el | 4 +++- test/pacmacs-test.el | 11 ++++++++- test/pacmacs-utils-test.el | 4 +++- test/pacmacs-vector-test.el | 4 +++- test/pacmacs-walls-test.el | 12 +++++++++- test/test-helper.el | 14 +++++++++--- tools/att.el | 17 ++++++++++---- tools/compile.el | 25 +++++++++++--------- tools/pacmacs-rr.el | 21 +++++++++-------- 20 files changed, 134 insertions(+), 61 deletions(-) diff --git a/.gitignore b/.gitignore index 69eff93d41..385f65c5b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ .cask/ dist/ *.elc -att.txt \ No newline at end of file +att.txt +/pacmacs-autoloads.el +/pacmacs-pkg.el diff --git a/it-cases/it-case01.el b/it-cases/it-case01.eld similarity index 100% rename from it-cases/it-case01.el rename to it-cases/it-case01.eld diff --git a/it-cases/it-case02.el b/it-cases/it-case02.eld similarity index 100% rename from it-cases/it-case02.el rename to it-cases/it-case02.eld diff --git a/it-cases/it-case03.el b/it-cases/it-case03.eld similarity index 100% rename from it-cases/it-case03.el rename to it-cases/it-case03.eld diff --git a/pacmacs-anim.el b/pacmacs-anim.el index c46ddabd14..db7c44665a 100644 --- a/pacmacs-anim.el +++ b/pacmacs-anim.el @@ -60,9 +60,9 @@ (aseprite-frames (cdr (assoc 'frames aseprite-json))) (sprite-sheet (pacmacs-load-image sprite-sheet-file))) (pacmacs-make-anim - (mapcar 'pacmacs-convert-aseprite-frame + (mapcar #'pacmacs-convert-aseprite-frame (sort aseprite-frames - 'pacmacs-compare-aseprite-frames)) + #'pacmacs-compare-aseprite-frames)) sprite-sheet))) (defun pacmacs-aseprite-frame-get-order (aseprite-frame) diff --git a/pacmacs-score.el b/pacmacs-score.el index e7466af6bb..8e90373dec 100644 --- a/pacmacs-score.el +++ b/pacmacs-score.el @@ -32,7 +32,6 @@ ;;; Code: -(require 'f) (require 'dash) (defconst pacmacs--max-score-nick-size 8) @@ -42,11 +41,10 @@ (defun pacmacs--read-score-table () (when (file-exists-p pacmacs--score-file-name) - (->> pacmacs--score-file-name - (f-read-text) - (read-from-string) - (car) - (pacmacs--sort-score-table)))) + (pacmacs--sort-score-table + (with-temp-buffer + (insert-file-contents pacmacs--score-file-name) + (read (current-buffer)))))) (defun pacmacs--write-score-table (score-table) (with-temp-buffer diff --git a/pacmacs-vector.el b/pacmacs-vector.el index a86a606f29..b38faa0320 100644 --- a/pacmacs-vector.el +++ b/pacmacs-vector.el @@ -32,6 +32,8 @@ ;;; Code: +(eval-when-compile (require 'dash)) + (defun pacmacs--vector-components-operation (vector1 vector2 operation) (-let (((row1 . column1) vector1) ((row2 . column2) vector2)) diff --git a/pacmacs.el b/pacmacs.el index e5372aacf4..97db41582d 100644 --- a/pacmacs.el +++ b/pacmacs.el @@ -6,7 +6,7 @@ ;; Maintainer: Alexey Kutepov <rexim...@gmail.com> ;; URL: http://github.com/codingteam/pacmacs.el ;; Version: 0.1 -;; Package-Requires: ((emacs "24.4") (dash "2.18.0") (cl-lib "0.5") (f "0.18.0")) +;; Package-Requires: ((emacs "24.4") (dash "2.18.0")) ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -38,7 +38,6 @@ (require 'cl-lib) (require 'dash) -(require 'f) (require 'widget) (require 'wid-edit) @@ -91,30 +90,34 @@ (defcustom pacmacs-levels-folder nil "A folder from where the Pacmacs game loads its levels." - :group 'pacmacs :type '(radio (const :tag "Default path") (directory :tag "Custom path"))) +(defvar pacmacs-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "<up>") #'pacmacs-up) + (define-key map (kbd "<down>") #'pacmacs-down) + (define-key map (kbd "<left>") #'pacmacs-left) + (define-key map (kbd "<right>") #'pacmacs-right) + (define-key map (kbd "q") #'pacmacs-quit) + (define-key map (kbd "SPC") #'pacmacs-pause) + map)) + (define-derived-mode pacmacs-mode special-mode "Pacmacs" - (define-key pacmacs-mode-map (kbd "<up>") 'pacmacs-up) - (define-key pacmacs-mode-map (kbd "<down>") 'pacmacs-down) - (define-key pacmacs-mode-map (kbd "<left>") 'pacmacs-left) - (define-key pacmacs-mode-map (kbd "<right>") 'pacmacs-right) - (define-key pacmacs-mode-map (kbd "q") 'pacmacs-quit) - (define-key pacmacs-mode-map (kbd "SPC") 'pacmacs-pause) - (add-hook 'kill-buffer-hook 'pacmacs-destroy nil t) + (add-hook 'kill-buffer-hook #'pacmacs-destroy nil t) (setq cursor-type nil) (setq truncate-lines t)) +(defvar pacmacs-game-over-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "q") #'pacmacs-quit) + map)) + (define-derived-mode pacmacs-game-over-mode special-mode "Pacmacs-Game-Over" - (define-key pacmacs-game-over-mode-map (kbd "q") 'pacmacs-quit) (setq cursor-type nil) (setq truncate-lines t)) (define-derived-mode pacmacs-scores-mode special-mode "Pacmacs-Scores" - (define-key pacmacs-game-over-mode-map (kbd "q") - (-partial #'pacmacs--kill-buffer-and-its-window - pacmacs--score-buffer-name)) (setq cursor-type nil) (setq truncate-lines t)) @@ -300,6 +303,8 @@ (defun pacmacs-quit () (interactive) + (when (get-buffer pacmacs--score-buffer-name) + (pacmacs--kill-buffer-and-its-window pacmacs--score-buffer-name)) (when (get-buffer pacmacs-buffer-name) (pacmacs--kill-buffer-and-its-window pacmacs-buffer-name))) @@ -773,9 +778,11 @@ (pacmacs--load-map-file))) (defun pacmacs--load-map-file (map-file-name) - (let* ((lines (split-string (f-read-text map-file-name) + (let* ((lines (split-string (with-temp-buffer + (insert-file-contents map-file-name) + (buffer-string)) "\n" t)) - (board-width (apply 'max (mapcar #'length lines))) + (board-width (apply #'max (mapcar #'length lines))) (board-height (length lines))) (setq pacmacs--object-board (pacmacs--make-board board-width board-height)) diff --git a/test/pacmacs-anim-test.el b/test/pacmacs-anim-test.el index b43185bfeb..c408f52548 100644 --- a/test/pacmacs-anim-test.el +++ b/test/pacmacs-anim-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,8 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'el-mock) + (ert-deftest pacmacs-load-image-test () (with-mock (mock (create-image "pew" 'xpm nil :heuristic-mask t) => 42 :times 1) @@ -129,3 +131,9 @@ (with-mock (mock (pacmacs--anim-object-next-frame 42 43) :times 5) (pacmacs--anim-object-list-next-frame (make-list 5 42) 43))) + +;; FIXME: Can't be compiled without `el-mock', but we don't want a hard +;; dependency on `el-mock'. +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/test/pacmacs-board-test.el b/test/pacmacs-board-test.el index 6ef772f6b3..351714b5a8 100644 --- a/test/pacmacs-board-test.el +++ b/test/pacmacs-board-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,8 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'pacmacs-board) + (ert-deftest pacmacs--make-board-test () (let ((width 5) (height 4) diff --git a/test/pacmacs-render-test.el b/test/pacmacs-render-test.el index a7c5cd21c9..7131f167b2 100644 --- a/test/pacmacs-render-test.el +++ b/test/pacmacs-render-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,8 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'el-mock) + (ert-deftest pacmacs-insert-image-test () (let ((resource "khooy") (resource-vector "pew")) @@ -34,3 +36,9 @@ (pacmacs--render-track-board track-board) (should (equal "\t10\t.\n\t.\t.\n" (buffer-string)))))) + +;; FIXME: Can't be compiled without `el-mock', but we don't want a hard +;; dependency on `el-mock'. +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/test/pacmacs-score-test.el b/test/pacmacs-score-test.el index 285875b399..fbc30670f5 100644 --- a/test/pacmacs-score-test.el +++ b/test/pacmacs-score-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,8 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'pacmacs-score) + (ert-deftest pacmacs--sort-score-table-test () (let ((input-table '(("hello" . 30) ("world" . 20) diff --git a/test/pacmacs-test.el b/test/pacmacs-test.el index 77d794a23c..8bf9708897 100644 --- a/test/pacmacs-test.el +++ b/test/pacmacs-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,9 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'pacmacs) +(require 'el-mock) + (ert-deftest pacmacs--cell-tracked-p-test () (let ((pacmacs--track-board (list :width 2 :height 2 @@ -178,3 +181,9 @@ (mock (pacmacs--track-object-to-player 'ghost) :times 10) (mock (pacmacs--step-object 'ghost) :times 10) (pacmacs--step-ghosts)))) + +;; FIXME: Can't be compiled without `el-mock', but we don't want a hard +;; dependency on `el-mock'. +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/test/pacmacs-utils-test.el b/test/pacmacs-utils-test.el index 66d8c5efd0..42b7596f4a 100644 --- a/test/pacmacs-utils-test.el +++ b/test/pacmacs-utils-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,8 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'pacmacs-utils) + (ert-deftest plist-map-test () (let ((plist (list :foo 1 :bar 2))) diff --git a/test/pacmacs-vector-test.el b/test/pacmacs-vector-test.el index 334beaef94..87e883c771 100644 --- a/test/pacmacs-vector-test.el +++ b/test/pacmacs-vector-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,8 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'pacmacs-vector) + (ert-deftest pacmacs--squared-distance-test () (should (= (pacmacs--squared-distance 1 1 3 3) 8))) diff --git a/test/pacmacs-walls-test.el b/test/pacmacs-walls-test.el index 1307ec2127..359c8b02c1 100644 --- a/test/pacmacs-walls-test.el +++ b/test/pacmacs-walls-test.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,6 +20,10 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. +(require 'dash) +(require 'el-mock) +(require 'pacmacs-walls) + (ert-deftest pacmacs--put-wall-tile-corner-test () (let ((input-wall-tile [[nil nil nil] [nil nil nil] @@ -125,3 +129,9 @@ (with-mock (mock (clrhash 42) :times 1) (pacmacs--clear-wall-tiles-cache)))) + +;; FIXME: Can't be compiled without `el-mock', but we don't want a hard +;; dependency on `el-mock'. +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/test/test-helper.el b/test/test-helper.el index 1e9f9af06a..63bb1506ef 100644 --- a/test/test-helper.el +++ b/test/test-helper.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,8 +20,10 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. -(require 'cl) ;el-mock doesn't work without - ;this +;; If `el-mock' doesn't work without this, then it's a bug in `el-mock' +;; which should be trivial to fix. Also, `el-mock' migrated to cl-lib +;; back in 2017. +;;(require 'cl) ;el-mock doesn't work without this (require 'el-mock) (require 'undercover) (require 'dash) @@ -49,3 +51,9 @@ (add-to-list 'load-path ".") (load "pacmacs.el") + +;; FIXME: Can't be compiled without `el-mock', but we don't want a hard +;; dependency on `el-mock'. +;; Local Variables: +;; no-byte-compile: t +;; End: diff --git a/tools/att.el b/tools/att.el index 91b0d28b68..a962030ab4 100644 --- a/tools/att.el +++ b/tools/att.el @@ -1,18 +1,25 @@ +;; -*- lexical-binding: t; -*- + +;; FIXME: ELisp files should not make such changes to the state when they're +;; loaded, since Emacs feels free to load files from `load-path' without +;; the user requesting it explicitly (e.g. to look for possible completions). +;; IOW, move those side-effects to a function. (add-to-list 'load-path default-directory) (add-to-list 'load-path (concat default-directory "/tools/")) (require 'pacmacs-rr) -(require 'f) (toggle-debug-on-error) (defconst att-result-file-path "./att.txt") -(defvar att-it-case-path "./it-cases/it-case03.el") +(defvar att-it-case-path "./it-cases/it-case03.eld") (defun att-replayer-finished () - (f-write (format "Average Tick Time: %fms" (pacmacs--average-tick-time)) - 'utf-8 - att-result-file-path) + (let ((coding-system-for-write 'utf-8)) + (write-region (format "Average Tick Time: %fms" + (pacmacs--average-tick-time)) + nil + att-result-file-path nil 0)) (kill-emacs 0)) (add-hook 'pacmacs-replay-finished-hook #'att-replayer-finished) diff --git a/tools/compile.el b/tools/compile.el index ee658e0de0..7db26387ae 100755 --- a/tools/compile.el +++ b/tools/compile.el @@ -1,4 +1,4 @@ -;; Copyright (C) 2015-2016 Codingteam +;; Copyright (C) 2015-2016 Codingteam -*- lexical-binding: t; -*- ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation @@ -20,21 +20,24 @@ ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. -(require 'cask "~/.cask/cask.el") +(require 'dash) + +(if t (require 'cask "~/.cask/cask.el")) ;Don't load when compiling compile.el (let ((bundle (cask-initialize default-directory))) - (require 'dash) - (require 'f) (require 'bytecomp) (let* ((byte-compile-error-on-warn t) (load-path (cons (cask-path bundle) (cask-load-path bundle))) - (compilation-failed (->> (cask-files bundle) - (-filter (-lambda (path) - (and (f-file? path) - (f-ext? path "el")))) - (-map (-lambda (file) - (byte-compile-file file nil))) - (-any #'null)))) + (compilation-failed + (->> (cask-files bundle) + (-filter (-lambda (file) + (and (file-regular-p file) + (equal (file-name-extension file) "el")))) + ;; FIXME: Why not use #'byte-compile-file especially, since that + ;; function doesn't accept the second arg we pass to it! + (-map (-lambda (file) + (byte-compile-file file nil))) + (-any #'null)))) (cask-clean-elc bundle) (when compilation-failed (kill-emacs 1)))) diff --git a/tools/pacmacs-rr.el b/tools/pacmacs-rr.el index 0259ff5e61..05e8bbcecb 100644 --- a/tools/pacmacs-rr.el +++ b/tools/pacmacs-rr.el @@ -36,7 +36,6 @@ (require 'pacmacs) (require 'dash) -(require 'f) (require 'cl-lib) (defvar pacmacs--tick-counter 0) @@ -68,9 +67,9 @@ (write-file filename))) (defun pacmacs--load-test-case (filename) - (-> (f-read-text filename) - (read-from-string) - (car))) + (with-temp-buffer + (insert-file-contents filename) + (read (current-buffer)))) (defun pacmacs-record-up () (interactive) @@ -111,11 +110,15 @@ (pacmacs-quit) (run-hooks 'pacmacs-replay-finished-hook))) -(define-derived-mode pacmacs-it-recorder-mode pacmacs-mode "pacmacs-it-recorder-mode" - (define-key pacmacs-it-recorder-mode-map (kbd "<up>") 'pacmacs-record-up) - (define-key pacmacs-it-recorder-mode-map (kbd "<down>") 'pacmacs-record-down) - (define-key pacmacs-it-recorder-mode-map (kbd "<left>") 'pacmacs-record-left) - (define-key pacmacs-it-recorder-mode-map (kbd "<right>") 'pacmacs-record-right)) +(defvar pacmacs-it-recorder-mode-map + (let ((map (make-sparse-keymap))) + (define-key map (kbd "<up>") #'pacmacs-record-up) + (define-key map (kbd "<down>") #'pacmacs-record-down) + (define-key map (kbd "<left>") #'pacmacs-record-left) + (define-key map (kbd "<right>") #'pacmacs-record-right) + map)) + +(define-derived-mode pacmacs-it-recorder-mode pacmacs-mode "pacmacs-it-recorder-mode") (defun pacmacs--average-tick-time () (/ (-sum pacmacs--tick-times) (length pacmacs--tick-times)))