diff options
author | William Carroll <wpcarro@gmail.com> | 2022-07-29T18·15-0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-07-30T00·35+0000 |
commit | 230c4bbb3e9f44875d6593a7c6cb0ca33bb63805 (patch) | |
tree | 55207bf03a894ffdd2b5687216081ee81e3fb195 /users/wpcarro/emacs | |
parent | 4a4f8f93583df81344dd1c91f033d8644028dc85 (diff) |
feat(wpcarro/emacs): Package maybe.el r/4344
(Temporarily) remove dependency on list.el in favor of dash, which I'm not thrilled about. Change-Id: Ic4348ee72582dee63ba07a183f3bda65baa7e2d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5999 Reviewed-by: wpcarro <wpcarro@gmail.com> Autosubmit: wpcarro <wpcarro@gmail.com> Tested-by: BuildkiteCI
Diffstat (limited to 'users/wpcarro/emacs')
-rw-r--r-- | users/wpcarro/emacs/.emacs.d/wpc/buffer.el | 1 | ||||
-rw-r--r-- | users/wpcarro/emacs/.emacs.d/wpc/math.el | 9 | ||||
-rw-r--r-- | users/wpcarro/emacs/default.nix | 1 | ||||
-rw-r--r-- | users/wpcarro/emacs/pkgs/maybe/default.nix | 24 | ||||
-rw-r--r-- | users/wpcarro/emacs/pkgs/maybe/maybe.el (renamed from users/wpcarro/emacs/.emacs.d/wpc/maybe.el) | 21 | ||||
-rw-r--r-- | users/wpcarro/emacs/pkgs/maybe/tests.el | 28 |
6 files changed, 59 insertions, 25 deletions
diff --git a/users/wpcarro/emacs/.emacs.d/wpc/buffer.el b/users/wpcarro/emacs/.emacs.d/wpc/buffer.el index fa98393df82f..ede3d3e68d05 100644 --- a/users/wpcarro/emacs/.emacs.d/wpc/buffer.el +++ b/users/wpcarro/emacs/.emacs.d/wpc/buffer.el @@ -33,6 +33,7 @@ (require 'struct) (require 'ts) (require 'general) +(require 'list) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Library diff --git a/users/wpcarro/emacs/.emacs.d/wpc/math.el b/users/wpcarro/emacs/.emacs.d/wpc/math.el index 4013ce3be21d..dbc527928a30 100644 --- a/users/wpcarro/emacs/.emacs.d/wpc/math.el +++ b/users/wpcarro/emacs/.emacs.d/wpc/math.el @@ -13,6 +13,7 @@ ;; Dependencies ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(require 'dash) (require 'maybe) (require 'cl-lib) @@ -31,13 +32,13 @@ ;; Int -> Int -> Int -> Boolean (cl-defun math-triangle-of-power (&key base power result) (cond - ((maybe-somes? base power result) + ((-all? #'maybe-some? (list base power result)) (error "All three arguments should not be set")) - ((maybe-somes? power result) + ((-all? #'maybe-some? (list power result)) (message "power and result")) - ((maybe-somes? base result) + ((-all? #'maybe-some? (list base result)) (log result base)) - ((maybe-somes? base power) + ((-all? #'maybe-some? (list base power)) (expt base power)) (t (error "Two of the three arguments must be set")))) diff --git a/users/wpcarro/emacs/default.nix b/users/wpcarro/emacs/default.nix index ea70006e6fc7..af8198d51cba 100644 --- a/users/wpcarro/emacs/default.nix +++ b/users/wpcarro/emacs/default.nix @@ -27,6 +27,7 @@ let (with wpcarro.emacs.pkgs; [ al list + maybe set struct zle diff --git a/users/wpcarro/emacs/pkgs/maybe/default.nix b/users/wpcarro/emacs/pkgs/maybe/default.nix new file mode 100644 index 000000000000..68e058b42b19 --- /dev/null +++ b/users/wpcarro/emacs/pkgs/maybe/default.nix @@ -0,0 +1,24 @@ +{ pkgs, depot, ... }: + +let + maybe = pkgs.callPackage + ({ emacsPackages }: + emacsPackages.trivialBuild { + pname = "maybe"; + version = "1.0.0"; + src = ./maybe.el; + packageRequires = [ ]; + }) + { }; + + emacs = (pkgs.emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ + maybe + ]); +in +maybe.overrideAttrs (_old: { + doCheck = true; + checkPhase = '' + ${emacs}/bin/emacs -batch \ + -l ert -l ${./tests.el} -f ert-run-tests-batch-and-exit + ''; +}) diff --git a/users/wpcarro/emacs/.emacs.d/wpc/maybe.el b/users/wpcarro/emacs/pkgs/maybe/maybe.el index ef92e5a4c15c..3c386b531865 100644 --- a/users/wpcarro/emacs/.emacs.d/wpc/maybe.el +++ b/users/wpcarro/emacs/pkgs/maybe/maybe.el @@ -32,19 +32,6 @@ ;;; Code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Dependencies -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(require 'list) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Constants -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defvar maybe--run-tests? t - "When t, run the test suite defined herein.") - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Library ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -56,14 +43,6 @@ "Return t when X is non-nil." (not (maybe-nil? x))) -(defun maybe-nils? (&rest xs) - "Return t if all XS are nil." - (list-all? #'maybe-nil? xs)) - -(defun maybe-somes? (&rest xs) - "Return t if all XS are non-nil." - (list-all? #'maybe-some? xs)) - (defun maybe-default (default x) "Return DEFAULT when X is nil." (if (maybe-nil? x) default x)) diff --git a/users/wpcarro/emacs/pkgs/maybe/tests.el b/users/wpcarro/emacs/pkgs/maybe/tests.el new file mode 100644 index 000000000000..775bb6b7ac80 --- /dev/null +++ b/users/wpcarro/emacs/pkgs/maybe/tests.el @@ -0,0 +1,28 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Dependencies +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(require 'maybe) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Tests +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(ert-deftest maybe-nil? () + (and + (maybe-nil? nil) + (not (maybe-nil? t)))) + +(ert-deftest maybe-some? () + (and + (maybe-some? '(1 2 3)) + (not (maybe-some? nil)))) + +(ert-deftest maybe-default () + (and + (string= "some" (maybe-default "some" nil)) + (= 10 (maybe-default 1 10)))) + +(ert-deftest maybe-map () + (eq nil (maybe-map (lambda (x) (* x 2)) nil)) + (= 4 (maybe-map (lambda (x) (* x 2)) 2))) |