emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/pacmacs 69d47fbb9a 075/472: Merge branch 'pacman-utils-ut-


From: ELPA Syncer
Subject: [nongnu] elpa/pacmacs 69d47fbb9a 075/472: Merge branch 'pacman-utils-ut-54'. Close #54
Date: Thu, 6 Jan 2022 21:59:14 -0500 (EST)

branch: elpa/pacmacs
commit 69d47fbb9a3ff5eca0b1283a848e97911d42b9c0
Merge: 07e18ca1e6 7f706e2159
Author: rexim <reximkut@gmail.com>
Commit: rexim <reximkut@gmail.com>

    Merge branch 'pacman-utils-ut-54'. Close #54
---
 pacman-anim.el            | 31 +++++++++++++++----------------
 pacman-utils.el           | 43 +++++++++++++++++++++++++++++++++++++++++++
 test/pacman-utils-test.el |  7 +++++++
 test/test-helper.el       |  1 +
 4 files changed, 66 insertions(+), 16 deletions(-)

diff --git a/pacman-anim.el b/pacman-anim.el
index 2664380ccc..de2f09a726 100644
--- a/pacman-anim.el
+++ b/pacman-anim.el
@@ -35,6 +35,7 @@
 (require 'json)
 
 (require 'pacman-image)
+(require 'pacman-utils)
 
 (defun pacman-make-anim (frames sprite-sheet)
   (list :frames frames
@@ -64,29 +65,27 @@
     (< order1 order2)))
 
 (defun pacman-convert-aseprite-frame (aseprite-frame)
-  (let* ((frame (cdr (assoc 'frame (cdr aseprite-frame))))
-         (x (cdr (assoc 'x frame)))
-         (y (cdr (assoc 'y frame)))
-         (w (cdr (assoc 'w frame)))
-         (h (cdr (assoc 'h frame))))
-    (list x y w h)))
+  (let* ((frame (cdr (assoc 'frame (cdr aseprite-frame)))))
+    (mapcar (lambda (n)
+              (cdr (assoc n frame)))
+            '(x y w h))))
 
 (defun pacman-anim-get-frame (anim)
-  (let ((frames (plist-get anim :frames))
-        (current-frame (plist-get anim :current-frame)))
+  (plist-bind ((frames :frames)
+               (current-frame :current-frame))
+      anim
     (nth current-frame frames)))
 
 (defun pacman-anim-next-frame (anim)
-  (let* ((frames (plist-get anim :frames))
-         (current-frame (plist-get anim :current-frame))
-         (new-current-frame (mod (+ current-frame 1)
-                                 (length frames))))
-    (plist-put anim :current-frame new-current-frame)))
+  (plist-bind ((frames :frames)
+               (current-frame :current-frame))
+      anim
+    (let ((new-current-frame (mod (+ current-frame 1)
+                                  (length frames))))
+      (plist-put anim :current-frame new-current-frame))))
 
 (defun pacman-anim-object-next-frame (anim-object)
-  (let ((anim (plist-get anim-object :animation)))
-    (plist-put anim-object :animation
-               (pacman-anim-next-frame anim))))
+  (plist-map anim-object :animation #'pacman-anim-next-frame))
 
 (provide 'pacman-anim)
 
diff --git a/pacman-utils.el b/pacman-utils.el
index 46ff4901d2..3ff2903462 100644
--- a/pacman-utils.el
+++ b/pacman-utils.el
@@ -1,3 +1,36 @@
+;;; pacman-utils.el --- Pacman for Emacs
+
+;; Copyright (C) 2015 Codingteam
+
+;; Author: Codingteam <codingteam@conference.jabber.ru>
+;; Maintainer: Alexey Kutepov <reximkut@gmail.com>
+;; URL: http://github.com/rexim/pacman.el
+
+;; Permission is hereby granted, free of charge, to any person
+;; obtaining a copy of this software and associated documentation
+;; files (the "Software"), to deal in the Software without
+;; restriction, including without limitation the rights to use, copy,
+;; modify, merge, publish, distribute, sublicense, and/or sell copies
+;; of the Software, and to permit persons to whom the Software is
+;; furnished to do so, subject to the following conditions:
+
+;; The above copyright notice and this permission notice shall be
+;; included in all copies or substantial portions of the Software.
+
+;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+;; SOFTWARE.
+
+;;; Commentary:
+
+;; Some common utils
+
+;;; Code:
 
 (defmacro plist-bind (keys expr &rest body)
   (declare (indent 2) (debug t))
@@ -9,4 +42,14 @@
                       keys))
        ,@body)))
 
+(defun plist-map (plist property transformer)
+  "Transform the value of PROPERTY in PLIST with TRANSFORMER.
+This function modifies plist with plist-put. So it does the same
+side-effects."
+  (plist-bind ((value property)) plist
+    (plist-put plist property
+               (funcall transformer value))))
+
 (provide 'pacman-utils)
+
+;;; pacman.el ends here
diff --git a/test/pacman-utils-test.el b/test/pacman-utils-test.el
new file mode 100644
index 0000000000..378045dce3
--- /dev/null
+++ b/test/pacman-utils-test.el
@@ -0,0 +1,7 @@
+(ert-deftest plist-map-test ()
+  (let ((plist (list :foo 1
+                     :bar 2)))
+    (plist-map plist :bar #'1+)
+    (should (equal (list :foo 1
+                         :bar 3)
+                   plist))))
diff --git a/test/test-helper.el b/test/test-helper.el
index 3cf0400ea4..55373381c1 100644
--- a/test/test-helper.el
+++ b/test/test-helper.el
@@ -8,3 +8,4 @@
 (add-to-list 'load-path ".")
 (load "pacman-anim.el")
 (load "pacman-image.el")
+(load "pacman-utils.el")



reply via email to

[Prev in Thread] Current Thread [Next in Thread]