Lint prelude.el
This was a doozey because I use it everywhere. Is there a better way to globally rename things? Aye aye aye... computers, man!
This commit is contained in:
parent
5d3bb0b7ea
commit
ff8277625f
29 changed files with 163 additions and 164 deletions
|
@ -257,13 +257,13 @@ In this case, the last writer wins, which is B."
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(when alist/enable-tests?
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal '((2 . one)
|
||||
(3 . two))
|
||||
(alist/map-keys #'1+
|
||||
'((1 . one)
|
||||
(2 . two)))))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal '((one . 2)
|
||||
(two . 3))
|
||||
(alist/map-values #'1+
|
||||
|
|
|
@ -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?
|
||||
|
@ -183,7 +183,7 @@ This function ignores Emacs-generated buffers, i.e. the ones that look like
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(when buffer/enable-tests?
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(list/all? #'buffer/emacs-generated?
|
||||
'("*scratch*"
|
||||
"*Messages*"
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
(defun bytes/classify (x)
|
||||
"Return unit that closest fits byte count, X."
|
||||
(prelude/assert (number/whole? x))
|
||||
(prelude-assert (number/whole? x))
|
||||
(cond
|
||||
((and (>= x 0) (< x bytes/kb)) 'byte)
|
||||
((and (>= x bytes/kb) (< x bytes/mb)) 'kilobyte)
|
||||
|
@ -92,17 +92,17 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(progn
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal "1000B" (bytes/to-string 1000)))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal "2KB" (bytes/to-string (* 2 bytes/kb))))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal "17MB" (bytes/to-string (* 17 bytes/mb))))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal "419GB" (bytes/to-string (* 419 bytes/gb))))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal "999TB" (bytes/to-string (* 999 bytes/tb))))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal "2PB" (bytes/to-string (* 2 bytes/pb)))))
|
||||
|
||||
(provide 'bytes)
|
||||
|
|
|
@ -60,18 +60,18 @@ If X isn't in XS (using `equal'), insert it at the front."
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; contains?/2
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(cache/contains? "turkey" cache))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(cache/contains? "chicken" cache))
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; touch/2
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal
|
||||
(cache/touch "nugget" cache)
|
||||
(cache/from-list '("nugget" "chicken"))))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal
|
||||
(cache/touch "spicy" cache)
|
||||
(cache/from-list '("spicy" "chicken" "nugget"))))))
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
"Call `load-theme' with `THEME', ensuring that the line numbers are bright.
|
||||
There is no hook that I'm aware of to handle this more elegantly."
|
||||
(load-theme theme t)
|
||||
(prelude/set-line-number-color "#da5468"))
|
||||
(prelude-set-line-number-color "#da5468"))
|
||||
|
||||
(defun colorscheme/whitelist-set (colorscheme)
|
||||
"Focus the COLORSCHEME in the `colorscheme/whitelist' cycle."
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
(require 'f)
|
||||
(require 'maybe)
|
||||
|
||||
(prelude/assert (f-exists? (getenv "BRIEFCASE")))
|
||||
(prelude-assert (f-exists? (getenv "BRIEFCASE")))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Configuration
|
||||
|
|
|
@ -196,23 +196,23 @@ 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 (= 1 (cycle/current xs)))
|
||||
(prelude/assert (= 2 (cycle/next xs)))
|
||||
(prelude/assert (= 1 (cycle/previous-focus xs)))
|
||||
(prelude/assert (= 1 (->> xs (cycle/jump 0) cycle/current)))
|
||||
(prelude/assert (= 2 (->> xs (cycle/jump 1) cycle/current)))
|
||||
(prelude/assert (= 3 (->> xs (cycle/jump 2) cycle/current)))
|
||||
(prelude/assert (= 2 (cycle/previous-focus xs)))
|
||||
(prelude/assert (= 2 (cycle/focus-previous! xs)))
|
||||
(prelude/assert (equal '(1 4 2 3) (cycle-xs (cycle/append 4 xs))))
|
||||
(prelude/assert (equal '(1 2 3) (cycle-xs (cycle/remove 4 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)))
|
||||
(prelude-assert (= 1 (->> xs (cycle/jump 0) cycle/current)))
|
||||
(prelude-assert (= 2 (->> xs (cycle/jump 1) cycle/current)))
|
||||
(prelude-assert (= 3 (->> xs (cycle/jump 2) cycle/current)))
|
||||
(prelude-assert (= 2 (cycle/previous-focus xs)))
|
||||
(prelude-assert (= 2 (cycle/focus-previous! xs)))
|
||||
(prelude-assert (equal '(1 4 2 3) (cycle-xs (cycle/append 4 xs))))
|
||||
(prelude-assert (equal '(1 2 3) (cycle-xs (cycle/remove 4 xs))))
|
||||
(progn
|
||||
(cycle/focus-item 3 xs)
|
||||
(cycle/focus-item 2 xs)
|
||||
(cycle/remove 1 xs)
|
||||
(prelude/assert (= 2 (cycle/current xs)))
|
||||
(prelude/assert (= 3 (cycle/previous-focus xs))))))
|
||||
(prelude-assert (= 2 (cycle/current xs)))
|
||||
(prelude-assert (= 3 (cycle/previous-focus xs))))))
|
||||
|
||||
(provide 'cycle)
|
||||
;;; cycle.el ends here
|
||||
|
|
|
@ -46,7 +46,7 @@ The car models the enabled state of my laptop display; the cdr models the
|
|||
(defun display/enable-4k ()
|
||||
"Attempt to connect to my 4K monitor."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "display/enable-4k"
|
||||
:command (string/format
|
||||
"xrandr --output %s --above %s --primary --auto --size 3840x2160 --rate 30.00 --dpi 144"
|
||||
|
@ -56,7 +56,7 @@ The car models the enabled state of my laptop display; the cdr models the
|
|||
(defun display/disable-4k ()
|
||||
"Disconnect from the 4K monitor."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "display/disable-4k"
|
||||
:command (string/format "xrandr --output %s --off"
|
||||
display/4k-monitor)))
|
||||
|
@ -66,7 +66,7 @@ The car models the enabled state of my laptop display; the cdr models the
|
|||
Sometimes this is useful when I'm sharing my screen in a Google Hangout and I
|
||||
only want to present one of my monitors."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "display/disable-laptop"
|
||||
:command (string/format "xrandr --output %s --auto"
|
||||
display/laptop-monitor)))
|
||||
|
@ -76,7 +76,7 @@ Sometimes this is useful when I'm sharing my screen in a Google Hangout and I
|
|||
Sometimes this is useful when I'm sharing my screen in a Google Hangout and I
|
||||
only want to present one of my monitors."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "display/disable-laptop"
|
||||
:command (string/format "xrandr --output %s --off"
|
||||
display/laptop-monitor)))
|
||||
|
|
|
@ -38,11 +38,11 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(progn
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal '(fname . "Bob") (dotted/new 'fname "Bob")))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(dotted/instance? '(one . two)))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(dotted/instance? '(1 2 3))))
|
||||
|
||||
(provide 'dotted)
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
mail-envelope-from 'header)
|
||||
|
||||
;; Assert that no two saved searches share share a KBD
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(list/xs-distinct-by? (lambda (x) (plist-get x :key)) notmuch-saved-searches))
|
||||
|
||||
(provide 'email)
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
(defun fonts/whitelist-set (font)
|
||||
"Focuses the FONT in the `fonts/whitelist' cycle.
|
||||
The size of the font is determined by `fonts/size'."
|
||||
(prelude/assert (cycle/contains? font fonts/whitelist))
|
||||
(prelude-assert (cycle/contains? font fonts/whitelist))
|
||||
(cycle/focus (lambda (x) (equal x font)) fonts/whitelist)
|
||||
(fonts/set (fonts/current) fonts/size))
|
||||
|
||||
|
|
|
@ -64,11 +64,11 @@ The user must pass in a valid Neighbors Table since asserting on the shape of
|
|||
;; TODO: Model each of the mapping functions into an isomorphism.
|
||||
(defun graph/edges->neighbors (xs)
|
||||
"Map Edge List, XS, into a Neighbors Table."
|
||||
(prelude/assert (graph/instance? xs)))
|
||||
(prelude-assert (graph/instance? xs)))
|
||||
|
||||
(defun graph/neighbors->edges (xs)
|
||||
"Map Neighbors Table, XS, into an Edge List."
|
||||
(prelude/assert (graph/instance? xs)))
|
||||
(prelude-assert (graph/instance? xs)))
|
||||
|
||||
;; Below are three different models of the same unweighted, directed graph.
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
;; TODO: Assert that no two servers have a channel with the same name. We need
|
||||
;; this because that's the assumption that underpins the `irc/channel->server'
|
||||
;; function. This will probably be an O(n^2) operation.
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/distinct? (set/from-list
|
||||
(cycle/to-list
|
||||
(alist/get "irc.freenode.net"
|
||||
|
@ -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)
|
||||
|
@ -166,7 +166,7 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(when irc/enable-tests?
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(equal
|
||||
(irc/channel->server `(("irc.dairy.com" . ,(cycle/new "#cheese" "#milk"))
|
||||
("irc.color.com" . ,(cycle/new "#red" "#blue")))
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
"Mapping of functions to designated keybinding prefixes to stay organized.")
|
||||
|
||||
;; Assert that no keybindings are colliding.
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(= (alist/count kbd/prefixes)
|
||||
(->> kbd/prefixes
|
||||
alist/values
|
||||
|
@ -49,7 +49,7 @@
|
|||
Values for F include:
|
||||
- workspace
|
||||
- x11"
|
||||
(prelude/assert (alist/has-key? f kbd/prefixes))
|
||||
(prelude-assert (alist/has-key? f kbd/prefixes))
|
||||
(string/format
|
||||
"%s-%s"
|
||||
(alist/get f kbd/prefixes)
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
(rate keyboard/repeat-rate)
|
||||
(delay keyboard/repeat-delay))
|
||||
"Use xset to set the key-repeat RATE and DELAY."
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "keyboard/set-key-repeat"
|
||||
:command (string/format "xset r rate %s %s" delay rate)))
|
||||
|
||||
|
@ -65,7 +65,7 @@
|
|||
(defun keyboard/swap-caps-lock-and-escape ()
|
||||
"Swaps the caps lock and escape keys using xmodmap."
|
||||
(interactive)
|
||||
;; TODO: Ensure these work once the tokenizing in prelude/start-process works
|
||||
;; TODO: Ensure these work once the tokenizing in prelude-start-process works
|
||||
;; as expected.
|
||||
(start-process "keyboard/swap-caps-lock-and-escape" nil "/usr/bin/xmodmap" "-e"
|
||||
"remove Lock = Caps_Lock")
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
;; Dependencies
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; TODO: Move `prelude/assert' elsewhere so that I can require it without
|
||||
;; TODO: Move `prelude-assert' elsewhere so that I can require it without
|
||||
;; introducing the circular dependency of list.el -> prelude.el -> list.el.
|
||||
;;(require 'prelude)
|
||||
(require 'dash)
|
||||
|
@ -137,7 +137,7 @@
|
|||
;; (if (alist/has-key? k acc)
|
||||
;; (setf (alist-get k acc) (list v))
|
||||
;; (setf (alist-get k acc) (list v))))))))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (equal '(("John" . ("Cleese" "Malkovich"))
|
||||
;; ("Thomas" . ("Aquinas")))
|
||||
;; (list/index (lambda (x) (plist-get x :first-name))
|
||||
|
@ -210,7 +210,7 @@ Be leery of using this with things like alists. Many data structures in Elisp
|
|||
;; TODO: Add tests.
|
||||
(defun list/dedupe-adjacent (xs)
|
||||
"Return XS without adjacent duplicates."
|
||||
(prelude/assert (not (list/empty? xs)))
|
||||
(prelude-assert (not (list/empty? xs)))
|
||||
(list/reduce (list (list/first xs))
|
||||
(lambda (x acc)
|
||||
(if (equal x (list/first acc))
|
||||
|
@ -223,16 +223,16 @@ Be leery of using this with things like alists. Many data structures in Elisp
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; (when list/tests?
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (= 0
|
||||
;; (list/length '())))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (= 5
|
||||
;; (list/length '(1 2 3 4 5))))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (= 16
|
||||
;; (list/reduce 1 (lambda (x acc) (+ x acc)) '(1 2 3 4 5))))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (equal '(2 4 6 8 10)
|
||||
;; (list/map (lambda (x) (* x 2)) '(1 2 3 4 5)))))
|
||||
|
||||
|
|
|
@ -82,23 +82,23 @@
|
|||
|
||||
(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
|
||||
(prelude-assert
|
||||
(and (= 0 (maybe-default 5 0))
|
||||
(= 5 (maybe-default 5 nil))))
|
||||
;; map
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(and (= 2 (maybe-map #'1+ 1))
|
||||
(eq nil (maybe-map #'1+ nil)))))
|
||||
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
;;; number.el --- Functions for working with numbers -*- 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:
|
||||
;;
|
||||
|
@ -124,29 +128,29 @@ While this function is undeniably trivial, I have unintentionally done (- 1 x)
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(when number/test?
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(number/positive? 10))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(number/natural? 10))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(number/whole? 10))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(number/whole? 0))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(number/integer? 10))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (= 120 (number/factorial 5)))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(number/even? 6))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(number/odd? 6))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(number/positive? -10))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(number/natural? 10.0))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(number/natural? -10))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(number/natural? -10.0)))
|
||||
|
||||
(provide 'number)
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
;;; prelude.el --- My attempt at augmenting Elisp stdlib -*- lexical-binding: t -*-
|
||||
|
||||
;; Author: William Carroll <wpcarro@gmail.com>
|
||||
;; Version: 0.0.1
|
||||
;; Package-Requires: ((emacs "24.3"))
|
||||
;; Homepage: https://user.git.corp.google.com/wpcarro/briefcase
|
||||
|
||||
;;; Commentary:
|
||||
;; Some of these ideas are scattered across other modules like `fs',
|
||||
|
@ -13,38 +17,29 @@
|
|||
;;; Code:
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Third-party libraries
|
||||
;; Dependencies
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(require 's)
|
||||
(require 'dash)
|
||||
(require 's)
|
||||
(require 'f)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Libraries
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; TODO: Maybe don't globally import everything here. Disable these and attepmt
|
||||
;; to reload Emacs to assess damage.
|
||||
(require 'string)
|
||||
(require 'list)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Utilities
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun prelude/to-string (x)
|
||||
(defun prelude-to-string (x)
|
||||
"Convert X to a string."
|
||||
(format "%s" x))
|
||||
|
||||
(defun prelude/inspect (&rest args)
|
||||
"Message `ARGS' where ARGS are any type."
|
||||
(defun prelude-inspect (&rest args)
|
||||
"Message ARGS where ARGS are any type."
|
||||
(->> args
|
||||
(list/map #'prelude/to-string)
|
||||
(apply #'string/concat)
|
||||
(-map #'prelude-to-string)
|
||||
(apply #'s-concat)
|
||||
message))
|
||||
|
||||
(defmacro prelude/call-process-to-string (cmd &rest args)
|
||||
(defmacro prelude-call-process-to-string (cmd &rest args)
|
||||
"Return the string output of CMD called with ARGS."
|
||||
`(with-temp-buffer
|
||||
(call-process ,cmd nil (current-buffer) nil ,@args)
|
||||
|
@ -55,28 +50,28 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; TODO: Should I `throw' instead of `error' here?
|
||||
(defmacro prelude/assert (x)
|
||||
(defmacro prelude-assert (x)
|
||||
"Errors unless X is t.
|
||||
These are strict assertions and purposely do not rely on truthiness."
|
||||
(let ((as-string (prelude/to-string x)))
|
||||
(let ((as-string (prelude-to-string x)))
|
||||
`(unless (equal t ,x)
|
||||
(error (string/concat "Assertion failed: " ,as-string)))))
|
||||
(error (s-concat "Assertion failed: " ,as-string)))))
|
||||
|
||||
(defmacro prelude/refute (x)
|
||||
(defmacro prelude-refute (x)
|
||||
"Errors unless X is nil."
|
||||
(let ((as-string (prelude/to-string x)))
|
||||
(let ((as-string (prelude-to-string x)))
|
||||
`(unless (equal nil ,x)
|
||||
(error (string/concat "Refutation failed: " ,as-string)))))
|
||||
(error (s-concat "Refutation failed: " ,as-string)))))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Adapter functions
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(defun prelude/identity (x)
|
||||
(defun prelude-identity (x)
|
||||
"Return X unchanged."
|
||||
x)
|
||||
|
||||
(defun prelude/const (x)
|
||||
(defun prelude-const (x)
|
||||
"Return a variadic lambda that will return X."
|
||||
(lambda (&rest _) x))
|
||||
|
||||
|
@ -86,54 +81,54 @@ These are strict assertions and purposely do not rely on truthiness."
|
|||
|
||||
;; TODO: Consider packaging these into a linum-color.el package.
|
||||
;; TODO: Generate the color used here from the theme.
|
||||
(defvar linum/safe? nil
|
||||
"Flag indicating whether or not it is safe to work with `linum-mode'.")
|
||||
(defvar prelude--linum-safe? nil
|
||||
"Flag indicating whether it is safe to work with function `linum-mode'.")
|
||||
|
||||
(defvar linum/mru-color nil
|
||||
(defvar prelude--linum-mru-color nil
|
||||
"Stores the color most recently attempted to be applied.")
|
||||
|
||||
(add-hook 'linum-mode-hook
|
||||
(lambda ()
|
||||
(setq linum/safe? t)
|
||||
(when (maybe-some? linum/mru-color)
|
||||
(set-face-foreground 'linum linum/mru-color))))
|
||||
(setq prelude--linum-safe? t)
|
||||
(when (maybe-some? prelude--linum-mru-color)
|
||||
(set-face-foreground 'linum prelude--linum-mru-color))))
|
||||
|
||||
(defun prelude/set-line-number-color (color)
|
||||
(defun prelude-set-line-number-color (color)
|
||||
"Safely set linum color to `COLOR'.
|
||||
|
||||
If this is called before Emacs initializes, the color will be stored in
|
||||
`linum/mru-color' and applied once initialization completes.
|
||||
`prelude--linum-mru-color' and applied once initialization completes.
|
||||
|
||||
Why is this safe?
|
||||
If `(set-face-foreground 'linum)' is called before initialization completes,
|
||||
Emacs will silently fail. Without this function, it is easy to introduce
|
||||
difficult to troubleshoot bugs in your init files."
|
||||
(if linum/safe?
|
||||
(if prelude--linum-safe?
|
||||
(set-face-foreground 'linum color)
|
||||
(setq linum/mru-color color)))
|
||||
(setq prelude--linum-mru-color color)))
|
||||
|
||||
(defun prelude/prompt (prompt)
|
||||
(defun prelude-prompt (prompt)
|
||||
"Read input from user with PROMPT."
|
||||
(read-string prompt))
|
||||
|
||||
(cl-defun prelude/start-process (&key name command)
|
||||
(cl-defun prelude-start-process (&key name command)
|
||||
"Pass command string, COMMAND, and the function name, NAME.
|
||||
This is a wrapper around `start-process' that has an API that resembles
|
||||
`shell-command'."
|
||||
;; TODO: Fix the bug with tokenizing here, since it will split any whitespace
|
||||
;; character, even though it shouldn't in the case of quoted string in shell.
|
||||
;; e.g. - "xmodmap -e 'one two three'" => '("xmodmap" "-e" "'one two three'")
|
||||
(prelude/refute (string/contains? "'" command))
|
||||
(let* ((tokens (string/split " " command))
|
||||
(program-name (list/head tokens))
|
||||
(program-args (list/tail tokens)))
|
||||
(prelude-refute (s-contains? "'" command))
|
||||
(let* ((tokens (s-split " " command))
|
||||
(program-name (nth 0 tokens))
|
||||
(program-args (cdr tokens)))
|
||||
(apply #'start-process
|
||||
`(,(string/format "*%s<%s>*" program-name name)
|
||||
`(,(format "*%s<%s>*" program-name name)
|
||||
,nil
|
||||
,program-name
|
||||
,@program-args))))
|
||||
|
||||
(defun prelude/executable-exists? (name)
|
||||
(defun prelude-executable-exists? (name)
|
||||
"Return t if CLI tool NAME exists according to `exec-path'."
|
||||
(let ((file (locate-file name exec-path)))
|
||||
(require 'maybe)
|
||||
|
@ -141,7 +136,7 @@ This is a wrapper around `start-process' that has an API that resembles
|
|||
(f-exists? file)
|
||||
nil)))
|
||||
|
||||
(defmacro prelude/time (x)
|
||||
(defmacro prelude-time (x)
|
||||
"Print the time it takes to evaluate X."
|
||||
`(benchmark 1 ',x))
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
(defun pulse-audio-toggle-mute ()
|
||||
"Mute the default sink."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "pulse-audio-toggle-mute"
|
||||
:command "pactl set-sink-mute @DEFAULT_SINK@ toggle")
|
||||
(pulse-audio--message "Mute toggled."))
|
||||
|
@ -43,7 +43,7 @@
|
|||
(defun pulse-audio-toggle-microphone ()
|
||||
"Mute the default sink."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "pulse-audio-toggle-microphone"
|
||||
:command "pactl set-source-mute @DEFAULT_SOURCE@ toggle")
|
||||
(pulse-audio--message "Microphone toggled."))
|
||||
|
@ -51,7 +51,7 @@
|
|||
(defun pulse-audio-decrease-volume ()
|
||||
"Low the volume output of the default sink."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "pulse-audio-decrease-volume"
|
||||
:command (string/format "pactl set-sink-volume @DEFAULT_SINK@ -%s%%"
|
||||
pulse-audio--step-size))
|
||||
|
@ -60,7 +60,7 @@
|
|||
(defun pulse-audio-increase-volume ()
|
||||
"Raise the volume output of the default sink."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "pulse-audio-increase-volume"
|
||||
:command (string/format "pactl set-sink-volume @DEFAULT_SINK@ +%s%%"
|
||||
pulse-audio--step-size))
|
||||
|
|
|
@ -64,7 +64,7 @@
|
|||
;; TODO: Support random-sample
|
||||
;; (defun random-sample (n xs)
|
||||
;; "Return a randomly sample of list XS of size N."
|
||||
;; (prelude/assert (and (>= n 0) (< n (list/length xs))))
|
||||
;; (prelude-assert (and (>= n 0) (< n (list/length xs))))
|
||||
;; (cl-labels ((do-sample
|
||||
;; (n xs y ys)
|
||||
;; (if (= n (set/count ys))
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
(defun screen-brightness/increase ()
|
||||
"Increase the screen brightness."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "screen-brightness/increase"
|
||||
:command (string/format "xbacklight -inc %s" screen-brightness/step-size))
|
||||
(message "[screen-brightness.el] Increased screen brightness."))
|
||||
|
@ -36,7 +36,7 @@
|
|||
(defun screen-brightness/decrease ()
|
||||
"Decrease the screen brightness."
|
||||
(interactive)
|
||||
(prelude/start-process
|
||||
(prelude-start-process
|
||||
:name "screen-brightness/decrease"
|
||||
:command (string/format "xbacklight -dec %s" screen-brightness/step-size))
|
||||
(message "[screen-brightness.el] Decreased screen brightness."))
|
||||
|
|
|
@ -113,59 +113,59 @@
|
|||
|
||||
(when set/enable-testing?
|
||||
;; set/distinct?
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/distinct? (set/new 'one 'two 'three)
|
||||
(set/new 'a 'b 'c)))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(set/distinct? (set/new 1 2 3)
|
||||
(set/new 3 4 5)))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(set/distinct? (set/new 1 2 3)
|
||||
(set/new 1 2 3)))
|
||||
;; set/equal?
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(set/equal? (set/new 'a 'b 'c)
|
||||
(set/new 'x 'y 'z)))
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(set/equal? (set/new 'a 'b 'c)
|
||||
(set/new 'a 'b)))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/equal? (set/new 'a 'b 'c)
|
||||
(set/new 'a 'b 'c)))
|
||||
;; set/intersection
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/equal? (set/new 2 3)
|
||||
(set/intersection (set/new 1 2 3)
|
||||
(set/new 2 3 4))))
|
||||
;; set/{from,to}-list
|
||||
(prelude/assert (equal '(1 2 3)
|
||||
(prelude-assert (equal '(1 2 3)
|
||||
(->> '(1 1 2 2 3 3)
|
||||
set/from-list
|
||||
set/to-list)))
|
||||
(let ((primary-colors (set/new "red" "green" "blue")))
|
||||
;; set/subset?
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(set/subset? (set/new "black" "grey")
|
||||
primary-colors))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/subset? (set/new "red")
|
||||
primary-colors))
|
||||
;; set/superset?
|
||||
(prelude/refute
|
||||
(prelude-refute
|
||||
(set/superset? primary-colors
|
||||
(set/new "black" "grey")))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/superset? primary-colors
|
||||
(set/new "red" "green" "blue")))
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(set/superset? primary-colors
|
||||
(set/new "red" "blue"))))
|
||||
;; set/empty?
|
||||
(prelude/assert (set/empty? (set/new)))
|
||||
(prelude/refute (set/empty? (set/new 1 2 3)))
|
||||
(prelude-assert (set/empty? (set/new)))
|
||||
(prelude-refute (set/empty? (set/new 1 2 3)))
|
||||
;; set/count
|
||||
(prelude/assert (= 0 (set/count (set/new))))
|
||||
(prelude/assert (= 2 (set/count (set/new 1 1 2 2)))))
|
||||
(prelude-assert (= 0 (set/count (set/new))))
|
||||
(prelude-assert (= 2 (set/count (set/new 1 1 2 2)))))
|
||||
|
||||
(provide 'set)
|
||||
;;; set.el ends here
|
||||
|
|
|
@ -111,15 +111,15 @@
|
|||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
;; (when string/test?
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (string=
|
||||
;; (string/surround "-*-" "surround")
|
||||
;; "-*-surround-*-"))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (string=
|
||||
;; (string/caps->kebab "CAPS_CASE_STRING")
|
||||
;; "caps-case-string"))
|
||||
;; (prelude/assert
|
||||
;; (prelude-assert
|
||||
;; (string=
|
||||
;; (string/kebab->caps "kebab-case-string")
|
||||
;; "KEBAB_CASE_STRING")))
|
||||
|
|
|
@ -78,11 +78,11 @@ This is an adapter interface to `setf'."
|
|||
(cl-defstruct dummy name age)
|
||||
(defvar test-dummy (make-dummy :name "Roofus" :age 19))
|
||||
(struct/set! dummy name "Doofus" test-dummy)
|
||||
(prelude/assert (string= "Doofus" (dummy-name test-dummy)))
|
||||
(prelude-assert (string= "Doofus" (dummy-name test-dummy)))
|
||||
(let ((result (struct/set dummy name "Shoofus" test-dummy)))
|
||||
;; Test the immutability of `struct/set'
|
||||
(prelude/assert (string= "Doofus" (dummy-name test-dummy)))
|
||||
(prelude/assert (string= "Shoofus" (dummy-name result)))))
|
||||
(prelude-assert (string= "Doofus" (dummy-name test-dummy)))
|
||||
(prelude-assert (string= "Shoofus" (dummy-name result)))))
|
||||
|
||||
(provide 'struct)
|
||||
;;; struct.el ends here
|
||||
|
|
|
@ -184,13 +184,13 @@ A tree is balanced if none of the differences between any two depths of two leaf
|
|||
(list (tree-node 9)
|
||||
(tree-node 10)))))))
|
||||
;; instance?
|
||||
(prelude/assert (tree-instance? tree-a))
|
||||
(prelude/assert (tree-instance? tree-b))
|
||||
(prelude/refute (tree-instance? '(1 2 3)))
|
||||
(prelude/refute (tree-instance? "oak"))
|
||||
(prelude-assert (tree-instance? tree-a))
|
||||
(prelude-assert (tree-instance? tree-b))
|
||||
(prelude-refute (tree-instance? '(1 2 3)))
|
||||
(prelude-refute (tree-instance? "oak"))
|
||||
;; balanced?
|
||||
(prelude/assert (tree-balanced? 1 tree-a))
|
||||
(prelude/refute (tree-balanced? 1 tree-b))
|
||||
(prelude-assert (tree-balanced? 1 tree-a))
|
||||
(prelude-refute (tree-balanced? 1 tree-b))
|
||||
(message "Tests pass!")))
|
||||
|
||||
(provide 'tree)
|
||||
|
|
|
@ -69,12 +69,12 @@ This function mutates XS."
|
|||
(when vector-enable-tests?
|
||||
(let ((xs [1 2 3])
|
||||
(ys [1 2 3]))
|
||||
(prelude/assert (= 1 (vector-get 0 ys)))
|
||||
(prelude-assert (= 1 (vector-get 0 ys)))
|
||||
(vector-set 0 4 ys)
|
||||
(prelude/assert (= 1 (vector-get 0 ys)))
|
||||
(prelude/assert (= 1 (vector-get 0 xs)))
|
||||
(prelude-assert (= 1 (vector-get 0 ys)))
|
||||
(prelude-assert (= 1 (vector-get 0 xs)))
|
||||
(vector-set! 0 4 xs)
|
||||
(prelude/assert (= 4 (vector-get 0 xs)))))
|
||||
(prelude-assert (= 4 (vector-get 0 xs)))))
|
||||
|
||||
;; TODO: Decide between "remove" and "delete" as the appropriate verbs.
|
||||
;; TODO: Implement this.
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
(defmacro vterm-mgt--assert-vterm-buffer ()
|
||||
"Error when the `current-buffer' is not a vterm buffer."
|
||||
'(prelude/assert (vterm-mgt--instance? (current-buffer))))
|
||||
'(prelude-assert (vterm-mgt--instance? (current-buffer))))
|
||||
|
||||
(defun vterm-mgt-next ()
|
||||
"Replace the current buffer with the next item in `vterm-mgt--instances'.
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
"List of `window-manager--named-workspace' structs.")
|
||||
|
||||
;; Assert that no two workspaces share KBDs.
|
||||
(prelude/assert (= (list/length window-manager--named-workspaces)
|
||||
(prelude-assert (= (list/length window-manager--named-workspaces)
|
||||
(->> window-manager--named-workspaces
|
||||
(list/map #'window-manager--named-workspace-kbd)
|
||||
set/from-list
|
||||
|
@ -188,7 +188,7 @@
|
|||
cycle/from-list)
|
||||
"Cycle of the my EXWM workspaces.")
|
||||
|
||||
(prelude/assert
|
||||
(prelude-assert
|
||||
(= exwm-workspace-number
|
||||
(list/length window-manager--named-workspaces)))
|
||||
|
||||
|
|
Loading…
Reference in a new issue