diff options
author | William Carroll <wpcarro@gmail.com> | 2020-08-31T13·59+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-08-31T13·59+0100 |
commit | a35f723d9271c081318fe463cd6fc51757d8cb0f (patch) | |
tree | ca57e41d3ec34a5b7be164793babd9f00c7d9c78 /emacs | |
parent | 1c87082648c6d265bddaf160f858f14240db739d (diff) |
Lint maybe.el
This change had rippling implications.
Diffstat (limited to 'emacs')
-rw-r--r-- | emacs/.emacs.d/wpc/alist.el | 6 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/buffer.el | 6 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/constants.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/cycle.el | 8 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/fonts.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/irc.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/laptop-battery.el | 2 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/math.el | 8 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/maybe.el | 54 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/prelude.el | 4 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/tree.el | 6 | ||||
-rw-r--r-- | emacs/.emacs.d/wpc/window.el | 2 |
12 files changed, 53 insertions, 49 deletions
diff --git a/emacs/.emacs.d/wpc/alist.el b/emacs/.emacs.d/wpc/alist.el index f23109ce6a38..439fb67b27ab 100644 --- a/emacs/.emacs.d/wpc/alist.el +++ b/emacs/.emacs.d/wpc/alist.el @@ -135,7 +135,7 @@ Returns the first occurrence of K in XS since alists support multiple entries." "Apply F to the value stored at K in XS. If `K' is not in `XS', this function errors. Use `alist/upsert' if you're interested in inserting a value when a key doesn't already exist." - (if (maybe/nil? (alist/get k xs)) + (if (maybe-nil? (alist/get k xs)) (error "Refusing to update: key does not exist in alist") (alist/set k (funcall f (alist/get k xs)) xs))) @@ -183,11 +183,11 @@ Mutative variant of `alist/delete'." (defun alist/has-key? (k xs) "Return t if XS has a key `equal' to K." - (maybe/some? (assoc k xs))) + (maybe-some? (assoc k xs))) (defun alist/has-value? (v xs) "Return t if XS has a value of V." - (maybe/some? (rassoc v xs))) + (maybe-some? (rassoc v xs))) (defun alist/count (xs) "Return the number of entries in XS." diff --git a/emacs/.emacs.d/wpc/buffer.el b/emacs/.emacs.d/wpc/buffer.el index 3e4d546fc8ca..31d23432ba7b 100644 --- a/emacs/.emacs.d/wpc/buffer.el +++ b/emacs/.emacs.d/wpc/buffer.el @@ -90,7 +90,7 @@ This will ignore Emacs-generated buffers, like *Messages*. It will also ignore (defun buffer/exists? (name) "Return t if buffer, NAME, exists." - (maybe/some? (buffer/find name))) + (maybe-some? (buffer/find name))) (defun buffer/new (name) "Return a newly created buffer NAME." @@ -100,7 +100,7 @@ This will ignore Emacs-generated buffers, like *Messages*. It will also ignore "Find or create buffer, NAME. Return a reference to that buffer." (let ((x (buffer/find name))) - (if (maybe/some? x) + (if (maybe-some? x) x (buffer/new name)))) @@ -163,7 +163,7 @@ This function ignores Emacs-generated buffers, i.e. the ones that look like (interactive) (let* ((xs (buffer/source-code-buffers)) (candidate (list/get 1 xs))) - (prelude/assert (maybe/some? candidate)) + (prelude/assert (maybe-some? candidate)) (switch-to-buffer candidate))) (when buffer/install-kbds? diff --git a/emacs/.emacs.d/wpc/constants.el b/emacs/.emacs.d/wpc/constants.el index 7ac49c01c627..2080e2c74866 100644 --- a/emacs/.emacs.d/wpc/constants.el +++ b/emacs/.emacs.d/wpc/constants.el @@ -21,7 +21,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defconst constants/ci? - (maybe/some? (getenv "CI")) + (maybe-some? (getenv "CI")) "True when Emacs is running in CI.") (defconst constants/briefcase diff --git a/emacs/.emacs.d/wpc/cycle.el b/emacs/.emacs.d/wpc/cycle.el index 9ec6ecd2fbc8..df9c49b5dc80 100644 --- a/emacs/.emacs.d/wpc/cycle.el +++ b/emacs/.emacs.d/wpc/cycle.el @@ -73,7 +73,7 @@ (defun cycle/previous-focus (cycle) "Return the previously focused entry in CYCLE." (let ((i (cycle-previous-index cycle))) - (if (maybe/some? i) + (if (maybe-some? i) (nth i (cycle-xs cycle)) nil))) @@ -84,7 +84,7 @@ This will error when previous-index is nil. This function mutates the underlying struct." (let ((i (cycle-previous-index xs))) - (if (maybe/some? i) + (if (maybe-some? i) (progn (cycle/jump i xs) (cycle/current xs)) @@ -148,7 +148,7 @@ ITEM is the first item in XS that t for `equal'." (defun cycle/focused? (xs) "Return t if cycle XS has a non-nil value for current-index." - (maybe/some? (cycle-current-index xs))) + (maybe-some? (cycle-current-index xs))) (defun cycle/append (x xs) "Add X to the left of the focused element in XS. @@ -196,7 +196,7 @@ If X is the currently focused value, after it's deleted, current-index will be (when cycle/enable-tests? (let ((xs (cycle/new 1 2 3))) - (prelude/assert (maybe/nil? (cycle/previous-focus xs))) + (prelude/assert (maybe-nil? (cycle/previous-focus xs))) (prelude/assert (= 1 (cycle/current xs))) (prelude/assert (= 2 (cycle/next xs))) (prelude/assert (= 1 (cycle/previous-focus xs))) diff --git a/emacs/.emacs.d/wpc/fonts.el b/emacs/.emacs.d/wpc/fonts.el index bf22a2ecc226..3b4a686bfab6 100644 --- a/emacs/.emacs.d/wpc/fonts.el +++ b/emacs/.emacs.d/wpc/fonts.el @@ -86,7 +86,7 @@ (defun fonts/set (font &optional size) "Change the font to `FONT' with option integer, SIZE, in pixels." - (if (maybe/some? size) + (if (maybe-some? size) (set-frame-font (string/format "%s %s" font size) nil t) (set-frame-font font nil t))) diff --git a/emacs/.emacs.d/wpc/irc.el b/emacs/.emacs.d/wpc/irc.el index b9a1e3131769..ce0e5ffcb952 100644 --- a/emacs/.emacs.d/wpc/irc.el +++ b/emacs/.emacs.d/wpc/irc.el @@ -59,7 +59,7 @@ "Resolve an IRC server from a given CHANNEL." (let ((result (alist/find (lambda (k v) (cycle/contains? channel v)) server->channels))) - (prelude/assert (maybe/some? result)) + (prelude/assert (maybe-some? result)) result)) (defun irc/channel->cycle (server->channels channel) diff --git a/emacs/.emacs.d/wpc/laptop-battery.el b/emacs/.emacs.d/wpc/laptop-battery.el index 3ec03553d2ca..418d66325586 100644 --- a/emacs/.emacs.d/wpc/laptop-battery.el +++ b/emacs/.emacs.d/wpc/laptop-battery.el @@ -32,7 +32,7 @@ (defun laptop-battery/available? () "Return t if battery information is available." - (maybe/some? battery-status-function)) + (maybe-some? battery-status-function)) (defun laptop-battery/percentage () "Return the current percentage of the battery." diff --git a/emacs/.emacs.d/wpc/math.el b/emacs/.emacs.d/wpc/math.el index 3176d906b466..82b501e2172e 100644 --- a/emacs/.emacs.d/wpc/math.el +++ b/emacs/.emacs.d/wpc/math.el @@ -28,13 +28,13 @@ (cl-defun math/triangle-of-power (&key base power result) ;; TODO: Assert two of three are set. (cond - ((maybe/somes? base power result) + ((maybe-somes? base power result) (error "All three arguments should not be set")) - ((maybe/somes? power result) + ((maybe-somes? power result) (message "power and result")) - ((maybe/somes? base result) + ((maybe-somes? base result) (log result base)) - ((maybe/somes? base power) + ((maybe-somes? base power) (expt base power)) (t (error "Two of the three arguments must be set")))) diff --git a/emacs/.emacs.d/wpc/maybe.el b/emacs/.emacs.d/wpc/maybe.el index 0973b1ed65f7..dc5e9332f701 100644 --- a/emacs/.emacs.d/wpc/maybe.el +++ b/emacs/.emacs.d/wpc/maybe.el @@ -1,5 +1,9 @@ ;;; maybe.el --- Library for dealing with nil values -*- lexical-binding: t -*- + ;; Author: William Carroll <wpcarro@gmail.com> +;; Version: 0.0.1 +;; Package-Requires: ((emacs "24")) +;; Homepage: https://user.git.corp.google.com/wpcarro/briefcase ;;; Commentary: ;; Inspired by Elm's Maybe library. @@ -39,36 +43,36 @@ ;; Constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defvar maybe/test? t +(defvar maybe--run-tests? t "When t, run the test suite defined herein.") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Library ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defun maybe/nil? (x) +(defun maybe-nil? (x) "Return t if X is nil." (eq nil x)) -(defun maybe/some? (x) +(defun maybe-some? (x) "Return t when X is non-nil." - (not (maybe/nil? x))) + (not (maybe-nil? x))) -(defun maybe/nils? (&rest xs) +(defun maybe-nils? (&rest xs) "Return t if all XS are nil." - (list/all? #'maybe/nil? xs)) + (list/all? #'maybe-nil? xs)) -(defun maybe/somes? (&rest xs) +(defun maybe-somes? (&rest xs) "Return t if all XS are non-nil." - (list/all? #'maybe/some? xs)) + (list/all? #'maybe-some? xs)) -(defun maybe/default (default x) +(defun maybe-default (default x) "Return DEFAULT when X is nil." - (if (maybe/nil? x) default x)) + (if (maybe-nil? x) default x)) -(defun maybe/map (f x) +(defun maybe-map (f x) "Apply F to X if X is not nil." - (if (maybe/some? x) + (if (maybe-some? x) (funcall f x) x)) @@ -76,27 +80,27 @@ ;; Tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(when maybe/test? +(when maybe--run-tests? ;; nil? - (prelude/assert (maybe/nil? nil)) - (prelude/refute (maybe/nil? t)) + (prelude/assert (maybe-nil? nil)) + (prelude/refute (maybe-nil? t)) ;; some? - (prelude/assert (maybe/some? 10)) - (prelude/refute (maybe/some? nil)) + (prelude/assert (maybe-some? 10)) + (prelude/refute (maybe-some? nil)) ;; nils? - (prelude/assert (maybe/nils? nil nil nil nil)) - (prelude/refute (maybe/nils? nil t nil t)) + (prelude/assert (maybe-nils? nil nil nil nil)) + (prelude/refute (maybe-nils? nil t nil t)) ;; somes? - (prelude/assert (maybe/somes? t 10 '(1 2 3) "some")) - (prelude/refute (maybe/somes? t nil '(1 2 3) "some")) + (prelude/assert (maybe-somes? t 10 '(1 2 3) "some")) + (prelude/refute (maybe-somes? t nil '(1 2 3) "some")) ;; default (prelude/assert - (and (= 0 (maybe/default 5 0)) - (= 5 (maybe/default 5 nil)))) + (and (= 0 (maybe-default 5 0)) + (= 5 (maybe-default 5 nil)))) ;; map (prelude/assert - (and (= 2 (maybe/map #'1+ 1)) - (eq nil (maybe/map #'1+ nil))))) + (and (= 2 (maybe-map #'1+ 1)) + (eq nil (maybe-map #'1+ nil))))) (provide 'maybe) ;;; maybe.el ends here diff --git a/emacs/.emacs.d/wpc/prelude.el b/emacs/.emacs.d/wpc/prelude.el index 6ef9e3ba7afb..ee7bcbbf2707 100644 --- a/emacs/.emacs.d/wpc/prelude.el +++ b/emacs/.emacs.d/wpc/prelude.el @@ -95,7 +95,7 @@ These are strict assertions and purposely do not rely on truthiness." (add-hook 'linum-mode-hook (lambda () (setq linum/safe? t) - (when (maybe/some? linum/mru-color) + (when (maybe-some? linum/mru-color) (set-face-foreground 'linum linum/mru-color)))) (defun prelude/set-line-number-color (color) @@ -137,7 +137,7 @@ This is a wrapper around `start-process' that has an API that resembles "Return t if CLI tool NAME exists according to `exec-path'." (let ((file (locate-file name exec-path))) (require 'maybe) - (if (maybe/some? file) + (if (maybe-some? file) (f-exists? file) nil))) diff --git a/emacs/.emacs.d/wpc/tree.el b/emacs/.emacs.d/wpc/tree.el index 9c35c8b3a33b..ddb1df7859e8 100644 --- a/emacs/.emacs.d/wpc/tree.el +++ b/emacs/.emacs.d/wpc/tree.el @@ -69,7 +69,7 @@ Depth-first traversals have the advantage of typically consuming less memory (cl-labels ((do-reduce-depth (acc f node depth) (let ((acc-new (funcall f node acc depth))) - (if (or (maybe/nil? node) + (if (or (maybe-nil? node) (tree-leaf? node)) acc-new (list/reduce @@ -98,7 +98,7 @@ Depth-first traversals have the advantage of typically consuming less memory (tree-reduce-depth '() (lambda (node acc depth) - (if (or (maybe/nil? node) + (if (or (maybe-nil? node) (tree-leaf? node)) (list/cons depth acc) acc)) @@ -139,7 +139,7 @@ generating test data. Warning this function can overflow the stack." (defun tree-leaf? (node) "Return t if NODE has no children." - (maybe/nil? (node-children node))) + (maybe-nil? (node-children node))) (defun tree-balanced? (n xs) "Return t if the tree, XS, is balanced. diff --git a/emacs/.emacs.d/wpc/window.el b/emacs/.emacs.d/wpc/window.el index 707641c6ff73..c0a4d5765694 100644 --- a/emacs/.emacs.d/wpc/window.el +++ b/emacs/.emacs.d/wpc/window.el @@ -25,7 +25,7 @@ (defun window-find (name) "Find a window by the NAME of the buffer it's hosting." (let ((buffer (get-buffer name))) - (if (maybe/some? buffer) + (if (maybe-some? buffer) (get-buffer-window buffer) nil))) |