chore(wpcarro/emacs): Delete unused packages
Elisp liposuction Change-Id: Id1940977afb33ae893264cfa388fd05c60b0ec9c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7399 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI Reviewed-by: wpcarro <wpcarro@gmail.com>
This commit is contained in:
		
							parent
							
								
									094f07ad9a
								
							
						
					
					
						commit
						8fd9b91d29
					
				
					 11 changed files with 13 additions and 906 deletions
				
			
		|  | @ -1,88 +0,0 @@ | |||
| ;;; cache.el --- Caching things -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "24.3")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; An immutable cache data structure. | ||||
| ;; | ||||
| ;; This is like a sideways stack, that you can pull values out from and re-push | ||||
| ;; to the top.  It'd be like a stack supporting push, pop, pull. | ||||
| ;; | ||||
| ;; This isn't a key-value data-structure like you might expect from a | ||||
| ;; traditional cache.  The name is subject to change, but the underlying idea of | ||||
| ;; a cache remains the same. | ||||
| ;; | ||||
| ;; Think about prescient.el, which uses essentially an LRU cache integrated into | ||||
| ;; counsel to help create a "clairovoyant", self-organizing list. | ||||
| ;; | ||||
| ;; Use-cases: | ||||
| ;; - Keeps an cache of workspaces sorted as MRU with an LRU eviction strategy. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'prelude) | ||||
| (require 'struct) | ||||
| (require '>) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (cl-defstruct cache xs) | ||||
| 
 | ||||
| ;; TODO: Prefer another KBD for yasnippet form completion than company-mode's | ||||
| ;; current KBD. | ||||
| 
 | ||||
| (defun cache-from-list (xs) | ||||
|   "Turn list, XS, into a cache." | ||||
|   (make-cache :xs xs)) | ||||
| 
 | ||||
| (defun cache-contains? (x xs) | ||||
|   "Return t if X in XS." | ||||
|   (->> xs | ||||
|        cache-xs | ||||
|        (list-contains? x))) | ||||
| 
 | ||||
| (defun cache-touch (x xs) | ||||
|   "Ensure value X in cache, XS, is front of the list. | ||||
| If X isn't in XS (using `equal'), insert it at the front." | ||||
|   (struct-update | ||||
|    cache | ||||
|    xs | ||||
|    (>-> (list-reject (lambda (y) (equal x y))) | ||||
|        (list-cons x)) | ||||
|    xs)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Tests | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (progn | ||||
|   (let ((cache (cache-from-list '("chicken" "nugget")))) | ||||
|     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
|     ;; contains?/2 | ||||
|     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
|     (prelude-refute | ||||
|      (cache-contains? "turkey" cache)) | ||||
|     (prelude-assert | ||||
|      (cache-contains? "chicken" cache)) | ||||
|     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
|     ;; touch/2 | ||||
|     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
|     (prelude-assert | ||||
|      (equal | ||||
|       (cache-touch "nugget" cache) | ||||
|       (cache-from-list '("nugget" "chicken")))) | ||||
|     (prelude-assert | ||||
|      (equal | ||||
|       (cache-touch "spicy" cache) | ||||
|       (cache-from-list '("spicy" "chicken" "nugget")))))) | ||||
| 
 | ||||
| (provide 'cache) | ||||
| ;;; cache.el ends here | ||||
|  | @ -1,57 +0,0 @@ | |||
| ;;; dotted.el --- Working with dotted pairs in Elisp -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "24.3")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; Part of my primitives library extensions in Elisp.  Contrast my primitives | ||||
| ;; with the wrapper extensions that I provide, which expose immutable variants | ||||
| ;; of data structures like an list, alist, tuple, as well as quasi-typeclasses | ||||
| ;; like sequence, etc. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'prelude) | ||||
| (require 'macros) | ||||
| (require 'cl-lib) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (cl-defun dotted-new (&optional a b) | ||||
|   "Create a new dotted pair of A and B." | ||||
|   (cons a b)) | ||||
| 
 | ||||
| (defun dotted-instance? (x) | ||||
|   "Return t if X is a dotted pair." | ||||
|   (let ((b (cdr x))) | ||||
|     (and b (atom b)))) | ||||
| 
 | ||||
| (defun dotted-first (x) | ||||
|   "Return the first element of X." | ||||
|   (car x)) | ||||
| 
 | ||||
| (defun dotted-second (x) | ||||
|   "Return the second element of X." | ||||
|   (cdr x)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Tests | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (progn | ||||
|   (prelude-assert | ||||
|    (equal '(fname . "Bob") (dotted-new 'fname "Bob"))) | ||||
|   (prelude-assert | ||||
|    (dotted-instance? '(one . two))) | ||||
|   (prelude-refute | ||||
|    (dotted-instance? '(1 2 3)))) | ||||
| 
 | ||||
| (provide 'dotted) | ||||
| ;;; dotted.el ends here | ||||
|  | @ -15,8 +15,6 @@ | |||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'string) | ||||
| (require 'number) | ||||
| (require 'cl-lib) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
|  | @ -46,7 +44,7 @@ | |||
| 
 | ||||
| (defun keyboard-message (x) | ||||
|   "Message X in a structured way." | ||||
|   (message (string-format "[keyboard.el] %s" x))) | ||||
|   (message (format "[keyboard.el] %s" x))) | ||||
| 
 | ||||
| (cl-defun keyboard-set-key-repeat (&key | ||||
|                                    (rate keyboard-repeat-rate) | ||||
|  | @ -54,7 +52,7 @@ | |||
|   "Use xset to set the key-repeat RATE and DELAY." | ||||
|   (prelude-start-process | ||||
|    :name "keyboard-set-key-repeat" | ||||
|    :command (string-format "xset r rate %s %s" delay rate))) | ||||
|    :command (format "xset r rate %s %s" delay rate))) | ||||
| 
 | ||||
| ;; NOTE: Settings like this are machine-dependent. For instance I only need to | ||||
| ;; do this on my laptop and other devices where I don't have access to my split | ||||
|  | @ -76,42 +74,42 @@ | |||
| (defun keyboard-inc-repeat-rate () | ||||
|   "Increment `keyboard-repeat-rate'." | ||||
|   (interactive) | ||||
|   (setq keyboard-repeat-rate (number-inc keyboard-repeat-rate)) | ||||
|   (setq keyboard-repeat-rate (1+ keyboard-repeat-rate)) | ||||
|   (keyboard-set-key-repeat :rate keyboard-repeat-rate) | ||||
|   (keyboard-message | ||||
|    (string-format "Rate: %s" keyboard-repeat-rate))) | ||||
|    (format "Rate: %s" keyboard-repeat-rate))) | ||||
| 
 | ||||
| (defun keyboard-dec-repeat-rate () | ||||
|   "Decrement `keyboard-repeat-rate'." | ||||
|   (interactive) | ||||
|   (setq keyboard-repeat-rate (number-dec keyboard-repeat-rate)) | ||||
|   (setq keyboard-repeat-rate (1- keyboard-repeat-rate)) | ||||
|   (keyboard-set-key-repeat :rate keyboard-repeat-rate) | ||||
|   (keyboard-message | ||||
|    (string-format "Rate: %s" keyboard-repeat-rate))) | ||||
|    (format "Rate: %s" keyboard-repeat-rate))) | ||||
| 
 | ||||
| (defun keyboard-inc-repeat-delay () | ||||
|   "Increment `keyboard-repeat-delay'." | ||||
|   (interactive) | ||||
|   (setq keyboard-repeat-delay (number-inc keyboard-repeat-delay)) | ||||
|   (setq keyboard-repeat-delay (1+ keyboard-repeat-delay)) | ||||
|   (keyboard-set-key-repeat :delay keyboard-repeat-delay) | ||||
|   (keyboard-message | ||||
|    (string-format "Delay: %s" keyboard-repeat-delay))) | ||||
|    (format "Delay: %s" keyboard-repeat-delay))) | ||||
| 
 | ||||
| (defun keyboard-dec-repeat-delay () | ||||
|   "Decrement `keyboard-repeat-delay'." | ||||
|   (interactive) | ||||
|   (setq keyboard-repeat-delay (number-dec keyboard-repeat-delay)) | ||||
|   (setq keyboard-repeat-delay (1- keyboard-repeat-delay)) | ||||
|   (keyboard-set-key-repeat :delay keyboard-repeat-delay) | ||||
|   (keyboard-message | ||||
|    (string-format "Delay: %s" keyboard-repeat-delay))) | ||||
|    (format "Delay: %s" keyboard-repeat-delay))) | ||||
| 
 | ||||
| (defun keyboard-print-key-repeat () | ||||
|   "Print the currently set values for key repeat." | ||||
|   (interactive) | ||||
|   (keyboard-message | ||||
|    (string-format "Rate: %s. Delay: %s" | ||||
|                   keyboard-repeat-rate | ||||
|                   keyboard-repeat-delay))) | ||||
|    (format "Rate: %s. Delay: %s" | ||||
|            keyboard-repeat-rate | ||||
|            keyboard-repeat-delay))) | ||||
| 
 | ||||
| (defun keyboard-set-preferences () | ||||
|   "Reset the keyboard preferences to their default values. | ||||
|  |  | |||
|  | @ -1,142 +0,0 @@ | |||
| ;;; 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: | ||||
| ;; | ||||
| ;; Classifications of numbers: | ||||
| ;; - Natural: (a.k.a positive integers, counting numbers); {1, 2, 3, ... } | ||||
| ;; | ||||
| ;; - Whole: Natural Numbers, plus zero; {0, 1, 2, 3, ...} | ||||
| ;; | ||||
| ;; - Integers: Whole numbers plus all the negatives of the natural numbers; | ||||
| ;;   {... , -2, -1, 0, 1, 2, ...} | ||||
| ;; | ||||
| ;; - Rational numbers: (a.k.a. fractions) where the top and bottom numbers are | ||||
| ;;   integers; e.g., 1/2, 3/4, 7/2, ⁻4/3, 4/1.  Note: The denominator cannot be | ||||
| ;;   0, but the numerator can be. | ||||
| ;; | ||||
| ;; - Real numbers: All numbers that can be written as a decimal.  This includes | ||||
| ;;   fractions written in decimal form e.g., 0.5, 0.75 2.35, ⁻0.073, 0.3333, or | ||||
| ;;   2.142857. It also includes all the irrational numbers such as π, √2 etc. | ||||
| ;;   Every real number corresponds to a point on the number line. | ||||
| ;; | ||||
| ;; The functions defined herein attempt to capture the mathematical definitions | ||||
| ;; of numbers and their classifications as defined above. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'prelude) | ||||
| (require 'dash) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defconst number-test? t | ||||
|   "When t, run the test suite defined herein.") | ||||
| 
 | ||||
| ;; TODO: What about int.el? | ||||
| 
 | ||||
| ;; TODO: How do we handle a number typeclass? | ||||
| 
 | ||||
| (defun number-positive? (x) | ||||
|   "Return t if `X' is a positive number." | ||||
|   (> x 0)) | ||||
| 
 | ||||
| (defun number-negative? (x) | ||||
|   "Return t if `X' is a positive number." | ||||
|   (< x 0)) | ||||
| 
 | ||||
| ;; TODO: Don't rely on this. Need to have 10.0 and 10 behave similarly. | ||||
| (defun number-float? (x) | ||||
|   "Return t if `X' is a floating point number." | ||||
|   (floatp x)) | ||||
| 
 | ||||
| (defun number-natural? (x) | ||||
|   "Return t if `X' is a natural number." | ||||
|   (and (number-positive? x) | ||||
|        (not (number-float? x)))) | ||||
| 
 | ||||
| (defun number-whole? (x) | ||||
|   "Return t if `X' is a whole number." | ||||
|   (or (= 0 x) | ||||
|       (number-natural? x))) | ||||
| 
 | ||||
| (defun number-integer? (x) | ||||
|   "Return t if `X' is an integer." | ||||
|   (or (number-whole? x) | ||||
|       (number-natural? (- x)))) | ||||
| 
 | ||||
| ;; TODO: How defensive should these guards be?  Should we assert that the inputs | ||||
| ;; are integers before checking evenness or oddness? | ||||
| 
 | ||||
| ;; TODO: Look up Runar (from Unison) definition of handling zero as even or odd. | ||||
| 
 | ||||
| ;; TODO: How should rational numbers be handled? Lisp is supposedly famous for | ||||
| ;; its handling of rational numbers. | ||||
| ;; TODO: `calc-mode' supports rational numbers as "1:2" meaning "1/2" | ||||
| ;; (defun number-rational? (x)) | ||||
| 
 | ||||
| ;; TODO: Can or should I support real numbers? | ||||
| ;; (defun number-real? (x)) | ||||
| 
 | ||||
| (defun number-even? (x) | ||||
|   "Return t if `X' is an even number." | ||||
|   (or (= 0 x) | ||||
|       (= 0 (mod x 2)))) | ||||
| 
 | ||||
| (defun number-odd? (x) | ||||
|   "Return t if `X' is an odd number." | ||||
|   (not (number-even? x))) | ||||
| 
 | ||||
| (defun number-dec (x) | ||||
|   "Subtract one from `X'. | ||||
| While this function is undeniably trivial, I have unintentionally done (- 1 x) | ||||
|   when in fact I meant to do (- x 1) that I figure it's better for this function | ||||
|   to exist, and for me to train myself to reach for it and its inc counterpart." | ||||
|   (- x 1)) | ||||
| 
 | ||||
| (defun number-inc (x) | ||||
|   "Add one to `X'." | ||||
|   (+ x 1)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Tests | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (when number-test? | ||||
|   (prelude-assert | ||||
|    (number-positive? 10)) | ||||
|   (prelude-assert | ||||
|    (number-natural? 10)) | ||||
|   (prelude-assert | ||||
|    (number-whole? 10)) | ||||
|   (prelude-assert | ||||
|    (number-whole? 0)) | ||||
|   (prelude-assert | ||||
|    (number-integer? 10)) | ||||
|   ;; (prelude-assert | ||||
|   ;;  (= 120 (number-factorial 5))) | ||||
|   (prelude-assert | ||||
|    (number-even? 6)) | ||||
|   (prelude-refute | ||||
|    (number-odd? 6)) | ||||
|   (prelude-refute | ||||
|    (number-positive? -10)) | ||||
|   (prelude-refute | ||||
|    (number-natural? 10.0)) | ||||
|   (prelude-refute | ||||
|    (number-natural? -10)) | ||||
|   (prelude-refute | ||||
|    (number-natural? -10.0))) | ||||
| 
 | ||||
| (provide 'number) | ||||
| ;;; number.el ends here | ||||
|  | @ -1,80 +0,0 @@ | |||
| ;;; random.el --- Functions for working with randomness -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "24")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; Functions for working with randomness.  Some of this code is not as | ||||
| ;; functional as I'd like from. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'prelude) | ||||
| (require 'number) | ||||
| (require 'math) | ||||
| (require 'series) | ||||
| (require 'list) | ||||
| (require 'set) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun random-int (x) | ||||
|   "Return a random integer from 0 to `X'." | ||||
|   (random x)) | ||||
| 
 | ||||
| ;; TODO: Make this work with sequences instead of lists. | ||||
| (defun random-choice (xs) | ||||
|   "Return a random element of `XS'." | ||||
|   (let ((ct (list-length xs))) | ||||
|     (list-get | ||||
|      (random-int ct) | ||||
|      xs))) | ||||
| 
 | ||||
| (defun random-boolean? () | ||||
|   "Randonly return t or nil." | ||||
|   (random-choice (list t nil))) | ||||
| 
 | ||||
| ;; TODO: This may not work if any of these generate numbers like 0, 1, etc. | ||||
| (defun random-uuid () | ||||
|   "Return a generated UUID string." | ||||
|   (let ((eight  (number-dec (math-triangle-of-power :base 16 :power 8))) | ||||
|         (four   (number-dec (math-triangle-of-power :base 16 :power 4))) | ||||
|         (twelve (number-dec (math-triangle-of-power :base 16 :power 12)))) | ||||
|     (format "%x-%x-%x-%x-%x" | ||||
|             (random-int eight) | ||||
|             (random-int four) | ||||
|             (random-int four) | ||||
|             (random-int four) | ||||
|             (random-int twelve)))) | ||||
| 
 | ||||
| (defun random-token (length) | ||||
|   "Return a randomly generated hexadecimal string of LENGTH." | ||||
|   (->> (series/range 0 (number-dec length)) | ||||
|        (list-map (lambda (_) (format "%x" (random-int 15)))) | ||||
|        (list-join ""))) | ||||
| 
 | ||||
| ;; 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)))) | ||||
| ;;   (cl-labels ((do-sample | ||||
| ;;                (n xs y ys) | ||||
| ;;                (if (= n (set-count ys)) | ||||
| ;;                    (->> ys | ||||
| ;;                         set-to-list | ||||
| ;;                         (list-map (lambda (i) | ||||
| ;;                                     (list-get i xs)))) | ||||
| ;;                  (if (set-contains? y ys) | ||||
| ;;                      (do-sample n xs (random-int (list-length xs)) ys) | ||||
| ;;                    (do-sample n xs y (set-add y ys)))))) | ||||
| ;;     (do-sample n xs (random-int (list-length xs)) (set-new)))) | ||||
| 
 | ||||
| (provide 'random) | ||||
| ;;; random.el ends here | ||||
|  | @ -1,106 +0,0 @@ | |||
| ;;; scope.el --- Work with a scope data structure -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "25.1")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; Exposing an API for working with a scope data structure in a non-mutative | ||||
| ;; way. | ||||
| ;; | ||||
| ;; What's a scope?  Think of a scope as a stack of key-value bindings. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'al) | ||||
| (require 'stack) | ||||
| (require 'struct) | ||||
| (require '>) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Create | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (cl-defstruct scope scopes) | ||||
| 
 | ||||
| (defun scope-new () | ||||
|   "Return an empty scope." | ||||
|   (make-scope :scopes (->> (stack-new) | ||||
|                            (stack-push (al-new))))) | ||||
| 
 | ||||
| (defun scope-flatten (xs) | ||||
|   "Return a flattened representation of the scope, XS. | ||||
| The newest bindings eclipse the oldest." | ||||
|   (->> xs | ||||
|        scope-scopes | ||||
|        stack-to-list | ||||
|        (list-reduce (al-new) | ||||
|                     (lambda (scope acc) | ||||
|                       (al-merge acc scope))))) | ||||
| 
 | ||||
| (defun scope-push-new (xs) | ||||
|   "Push a new, empty scope onto XS." | ||||
|   (struct-update scope | ||||
|                  scopes | ||||
|                  (>-> (stack-push (al-new))) | ||||
|                  xs)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Read | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun scope-get (k xs) | ||||
|   "Return K from XS if it's in scope." | ||||
|   (->> xs | ||||
|        scope-flatten | ||||
|        (al-get k))) | ||||
| 
 | ||||
| (defun scope-current (xs) | ||||
|   "Return the newest scope from XS." | ||||
|   (let ((xs-copy (copy-scope xs))) | ||||
|     (->> xs-copy | ||||
|          scope-scopes | ||||
|          stack-peek))) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Update | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun scope-set (k v xs) | ||||
|   "Set value, V, at key, K, in XS for the current scope." | ||||
|   (struct-update scope | ||||
|                  scopes | ||||
|                  (>-> (stack-map-top (>-> (al-set k v)))) | ||||
|                  xs)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Delete | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun scope-pop (xs) | ||||
|   "Return a new scope without the top element from XS." | ||||
|   (->> xs | ||||
|        scope-scopes | ||||
|        stack-pop)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Predicates | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun scope-defined? (k xs) | ||||
|   "Return t if K is in scope of XS." | ||||
|   (->> xs | ||||
|        scope-flatten | ||||
|        (al-has-key? k))) | ||||
| 
 | ||||
| ;; TODO: Find a faster way to write aliases like this. | ||||
| (defun scope-instance? (xs) | ||||
|   "Return t if XS is a scope struct." | ||||
|   (scope-p xs)) | ||||
| 
 | ||||
| (provide 'scope) | ||||
| ;;; scope.el ends here | ||||
|  | @ -1,108 +0,0 @@ | |||
| ;;; sequence.el --- Working with the "sequence" types -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "25.1")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; Elisp supports a typeclass none as "sequence" which covers the following | ||||
| ;; types: | ||||
| ;; - list: '(1 2 3 4 5) | ||||
| ;; - vector: ["John" 27 :blue] | ||||
| ;; - string: "To be or not to be..." | ||||
| 
 | ||||
| ;; TODO: Document the difference between a "reduce" and a "fold".  I.e. - reduce | ||||
| ;; has an initial value whereas fold uses the first element in the sequence as | ||||
| ;; the initial value. | ||||
| ;; | ||||
| ;; Note: This should be an approximation of Elixir's Enum protocol albeit | ||||
| ;; without streams. | ||||
| ;; | ||||
| ;; Elisp has done a lot of this work already and these are mostly wrapper | ||||
| ;; functions. | ||||
| ;; See the following list for reference: | ||||
| ;; - sequencep | ||||
| ;; - elt | ||||
| ;; - copy-sequence | ||||
| ;; - reverse | ||||
| ;; - nreverse | ||||
| ;; - sort | ||||
| ;; - seq-elt | ||||
| ;; - seq-length | ||||
| ;; - seqp | ||||
| ;; - seq-drop | ||||
| ;; - seq-take | ||||
| ;; - seq-take-while | ||||
| ;; - seq-drop-while | ||||
| ;; - seq-do | ||||
| ;; - seq-map | ||||
| ;; - seq-mapn | ||||
| ;; - seq-filter | ||||
| ;; - seq-remove | ||||
| ;; - seq-reduce | ||||
| ;; - seq-some | ||||
| ;; - seq-find | ||||
| ;; - seq-every-p | ||||
| ;; - seq-empty-p | ||||
| ;; - seq-count | ||||
| ;; - seq-sort | ||||
| ;; - seq-contains | ||||
| ;; - seq-position | ||||
| ;; - seq-uniq | ||||
| ;; - seq-subseq | ||||
| ;; - seq-concatenate | ||||
| ;; - seq-mapcat | ||||
| ;; - seq-partition | ||||
| ;; - seq-intersection | ||||
| ;; - seq-difference | ||||
| ;; - seq-group-by | ||||
| ;; - seq-into | ||||
| ;; - seq-min | ||||
| ;; - seq-max | ||||
| ;; - seq-doseq | ||||
| ;; - seq-let | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;; Perhaps we can provide default implementations for `filter' and `map' derived | ||||
| ;; from the `reduce' implementation. | ||||
| ;; (defprotocol sequence | ||||
| ;;   :functions (reduce)) | ||||
| ;; (definstance sequence list | ||||
| ;;   :reduce #'list-reduce | ||||
| ;;   :filter #'list-filter | ||||
| ;;   :map    #'list-map) | ||||
| ;; (definstance sequence vector | ||||
| ;;   :reduce #'vector/reduce) | ||||
| ;; (definstance sequence string | ||||
| ;;   :reduce #'string) | ||||
| 
 | ||||
| (defun sequence-classify (xs) | ||||
|   "Return the type of `XS'." | ||||
|   (cond | ||||
|    ((listp xs) 'list) | ||||
|    ((vectorp xs) 'vector) | ||||
|    ((stringp xs) 'string))) | ||||
| 
 | ||||
| (defun sequence-reduce (acc f xs) | ||||
|   "Reduce of `XS' calling `F' on x and `ACC'." | ||||
|   (seq-reduce | ||||
|    (lambda (acc x) | ||||
|      (funcall f x acc)) | ||||
|    xs | ||||
|    acc)) | ||||
| 
 | ||||
| ;; Elixir also turned everything into a list for efficiecy reasons. | ||||
| 
 | ||||
| (defun sequence-filter (p xs) | ||||
|   "Filter `XS' with predicate, `P'. | ||||
| Returns a list regardless of the type of `XS'." | ||||
|   (seq-filter p xs)) | ||||
| 
 | ||||
| (defun sequence-map (f xs) | ||||
|   "Maps `XS' calling `F' on each element. | ||||
| Returns a list regardless of the type of `XS'." | ||||
|   (seq-map f xs)) | ||||
| 
 | ||||
| (provide 'sequence) | ||||
| ;;; sequence.el ends here | ||||
|  | @ -1,92 +0,0 @@ | |||
| ;;; series.el --- Hosting common series of numbers -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "24")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; Encoding number series as I learn about them. | ||||
| ;; | ||||
| ;; These are the following series I'm interested in supporting: | ||||
| ;; - Fibonacci | ||||
| ;; - Catalan numbers | ||||
| ;; - Figurate number series | ||||
| ;;   - Triangular | ||||
| ;;   - Square | ||||
| ;;   - Pentagonal | ||||
| ;;   - Hexagonal | ||||
| ;;   - Lazy-caterer | ||||
| ;; - Magic square | ||||
| ;; - Look-and-say | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'number) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun series-range (beg end) | ||||
|   "Create a list of numbers from `BEG' to `END'. | ||||
| This is an inclusive number range." | ||||
|   (if (< end beg) | ||||
|       (list-reverse | ||||
|        (number-sequence end beg)) | ||||
|     (number-sequence beg end))) | ||||
| 
 | ||||
| (defun series-fibonacci-number (i) | ||||
|   "Return the number in the fibonacci series at `I'." | ||||
|   (cond | ||||
|    ((= 0 i) 0) | ||||
|    ((= 1 i) 1) | ||||
|    (t (+ (series-fibonacci-number (- i 1)) | ||||
|          (series-fibonacci-number (- i 2)))))) | ||||
| 
 | ||||
| (defun series-fibonacci (n) | ||||
|   "Return the first `N' numbers of the fibonaccci series starting at zero." | ||||
|   (if (= 0 n) | ||||
|       '() | ||||
|     (list-reverse | ||||
|      (list-cons (series-fibonacci-number (number-dec n)) | ||||
|                 (list-reverse | ||||
|                  (series-fibonacci (number-dec n))))))) | ||||
| 
 | ||||
| ;; TODO: Consider memoization. | ||||
| (defun series-triangular-number (i) | ||||
|   "Return the number in the triangular series at `I'." | ||||
|   (if (= 0 i) | ||||
|       0 | ||||
|     (+ i (series-triangular-number (number-dec i))))) | ||||
| 
 | ||||
| ;; TODO: Improve performance. | ||||
| ;; TODO: Consider creating a stream protocol with `stream/next' and implement | ||||
| ;; this using that. | ||||
| (defun series-triangular (n) | ||||
|   "Return the first `N' numbers of a triangular series starting at 0." | ||||
|   (if (= 0 n) | ||||
|       '() | ||||
|     (list-reverse | ||||
|      (list-cons (series-triangular-number (number-dec n)) | ||||
|                 (list-reverse | ||||
|                  (series-triangular (number-dec n))))))) | ||||
| 
 | ||||
| (defun series-catalan-number (i) | ||||
|   "Return the catalan number in the series at `I'." | ||||
|   (if (= 0 i) | ||||
|       1 | ||||
|     (/ (number-factorial (* 2 i)) | ||||
|        (* (number-factorial (number-inc i)) | ||||
|           (number-factorial i))))) | ||||
| 
 | ||||
| (defun series-catalan (n) | ||||
|   "Return the first `N' numbers in a catalan series." | ||||
|   (->> (series-range 0 (number-dec n)) | ||||
|        (list-map #'series-catalan-number))) | ||||
| 
 | ||||
| (provide 'series) | ||||
| ;;; series.el ends here | ||||
|  | @ -1,101 +0,0 @@ | |||
| ;;; stack.el --- Working with stacks in Elisp -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "25.1")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; A stack is a LIFO queue. | ||||
| ;; The design goal here is to expose an intuitive API for working with stacks in | ||||
| ;; non-mutative way. | ||||
| ;; | ||||
| ;; TODO: Consider naming a Functor instance "Mappable." | ||||
| ;; TODO: Consider naming a Foldable instance "Reduceable." | ||||
| ;; | ||||
| ;; TODO: Consider implementing an instance for Mappable. | ||||
| ;; TODO: Consider implementing an instance for Reduceable. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'list) | ||||
| (require '>) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Create | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (cl-defstruct stack xs) | ||||
| 
 | ||||
| (defun stack-new () | ||||
|   "Create an empty stack." | ||||
|   (make-stack :xs '())) | ||||
| 
 | ||||
| (defun stack-from-list (xs) | ||||
|   "Create a new stack from the list, `XS'." | ||||
|   (list-reduce (stack-new) #'stack-push xs)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Read | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun stack-peek (xs) | ||||
|   "Look at the top element of `XS' without popping it off." | ||||
|   (->> xs | ||||
|        stack-xs | ||||
|        list-first)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Update | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun stack-push (x xs) | ||||
|   "Push `X' on `XS'." | ||||
|   (struct-update stack | ||||
|                  xs | ||||
|                  (>-> (list-cons x)) | ||||
|                  xs)) | ||||
| 
 | ||||
| ;; TODO: How to return something like {(list-head xs), (list-tail xs)} in Elixir | ||||
| ;; TODO: How to handle popping from empty stacks? | ||||
| (defun stack-pop (xs) | ||||
|   "Return the stack, `XS', without the top element. | ||||
| Since I cannot figure out a nice way of return tuples in Elisp, if you want to | ||||
| look at the first element, use `stack-peek' before running `stack-pop'." | ||||
|   (struct-update stack | ||||
|                  xs | ||||
|                  (>-> list-tail) | ||||
|                  xs)) | ||||
| 
 | ||||
| (defun stack-map-top (f xs) | ||||
|   "Apply F to the top element of XS." | ||||
|   (->> xs | ||||
|        stack-pop | ||||
|        (stack-push (funcall f (stack-peek xs))))) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Miscellaneous | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defun stack-to-list (xs) | ||||
|   "Return XS as a list. | ||||
| The round-trip property of `stack-from-list' and `stack-to-list' should hold." | ||||
|   (->> xs | ||||
|        stack-xs | ||||
|        list-reverse)) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Predicates | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| ;; TODO: Create a macro that wraps `cl-defstruct' that automatically creates | ||||
| ;; things like `new', `instance?'. | ||||
| (defun stack-instance? (xs) | ||||
|   "Return t if XS is a stack." | ||||
|   (stack-p xs)) | ||||
| 
 | ||||
| (provide 'stack) | ||||
| ;;; stack.el ends here | ||||
|  | @ -1,77 +0,0 @@ | |||
| ;;; timestring.el --- Quickly access timestamps in different formats -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "25.1")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| 
 | ||||
| ;; I was making some API calls where a URL needed a `since` parameter that of an | ||||
| ;; RFC 3339 encoded string. | ||||
| ;; | ||||
| ;; Because I didn't know what a RFC 3339 encoded | ||||
| ;; string was at the time, and because I didn't know what its format was | ||||
| ;; according to strftime, and because I'm most likely to forget both of these | ||||
| ;; things by the next time that I need something similar, I decided to write | ||||
| ;; this package so that I can accumulate a list of common time encodings. | ||||
| ;; | ||||
| ;; Thank you, Emacs. | ||||
| ;; | ||||
| ;; p.s. - I may turn this into a proper module and publish it.  But not today. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'ts) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (defgroup timestring nil | ||||
|   "Customize group for timestring configuration.") | ||||
| 
 | ||||
| (defcustom timestring-supported-encodings | ||||
|   '(("RFC 3339" . "%Y-%m-%dT%H:%M:%SZ") | ||||
|     ;; Does anyone recognize this format? | ||||
|     ("IDK" . "%Y-%m-%d %H:%M:%S %z")) | ||||
|   "Mapping of encoding names to their format strings." | ||||
|   :group 'timestring) | ||||
| 
 | ||||
| (defcustom timestring-supported-times | ||||
|   '(("yesterday" . timestring--yesterday) | ||||
|     ("now" . ts-now) | ||||
|     ("tomorrow" . timestring--tomorrow)) | ||||
|   "Mapping of a labels to the functions that create those time objects." | ||||
|   :group 'timestring) | ||||
| 
 | ||||
| (defun timestring--yesterday () | ||||
|   "Return a time object for yesterday." | ||||
|   (ts-adjust 'day -1 (ts-now))) | ||||
| 
 | ||||
| (defun timestring--tomorrow () | ||||
|   "Return a time object for yesterday." | ||||
|   (ts-adjust 'day +1 (ts-now))) | ||||
| 
 | ||||
| (defun timestring--completing-read (label xs) | ||||
|   "Call `completing-read' with LABEL over the collection XS." | ||||
|   (alist-get (completing-read label xs) xs nil nil #'equal)) | ||||
| 
 | ||||
| (defun timestring-copy-encoded-time () | ||||
|   "Select a common time and an encoding. | ||||
| 
 | ||||
| The selected time will be encoded using the selected encoding and copied onto | ||||
| your clipboard." | ||||
|   (interactive) | ||||
|   (let ((time (funcall (timestring--completing-read | ||||
|                         "Time: " timestring-supported-times))) | ||||
|         (fmt (timestring--completing-read | ||||
|               "Encoding: " timestring-supported-encodings))) | ||||
|     (kill-new (ts-format fmt time)) | ||||
|     (message "Copied!"))) | ||||
| 
 | ||||
| (provide 'timestring) | ||||
| ;;; timestring.el ends here | ||||
|  | @ -1,40 +0,0 @@ | |||
| ;;; window.el --- Working with windows -*- lexical-binding: t -*- | ||||
| 
 | ||||
| ;; Author: William Carroll <wpcarro@gmail.com> | ||||
| ;; Version: 0.0.1 | ||||
| ;; Package-Requires: ((emacs "25.1")) | ||||
| 
 | ||||
| ;;; Commentary: | ||||
| ;; Utilities to make CRUDing windows in Emacs easier. | ||||
| 
 | ||||
| ;;; Code: | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Dependencies | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (require 'prelude) | ||||
| (require 'macros) | ||||
| (require 'maybe) | ||||
| 
 | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| ;; Library | ||||
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||||
| 
 | ||||
| (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) | ||||
|         (get-buffer-window buffer) | ||||
|       nil))) | ||||
| 
 | ||||
| ;; TODO: Find a way to incorporate these into function documentation. | ||||
| (macros-comment | ||||
|  (window-find "*scratch*")) | ||||
| 
 | ||||
| (defun window-delete (window) | ||||
|   "Delete the WINDOW reference." | ||||
|   (delete-window window)) | ||||
| 
 | ||||
| (provide 'window) | ||||
| ;;; window.el ends here | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue