From 07183b5bbb4d2e65514e3ec3e7cdf7e421f97749 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 13 Mar 2022 11:57:06 -0500 Subject: added intial drafting code to new --- lib/state.lisp | 70 ++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 24 deletions(-) (limited to 'lib/state.lisp') diff --git a/lib/state.lisp b/lib/state.lisp index a156d59..123bd79 100644 --- a/lib/state.lisp +++ b/lib/state.lisp @@ -25,7 +25,7 @@ (host "") (shell "bash")) -;;; DYNAMIC VARS FOR CONFIG AND CACHE, AND SOME GETTERS +;;; CONFIG VAR AND OPERATIONS (defvar *config* nil "Holds a config struct instance.") @@ -50,9 +50,54 @@ (defun shell () (config-shell *config*)) + +;;; CACHE VAR AND OPERATIONS + (defvar *cache* nil "Holds cached oneliners as a list.") +(defun merge-oneliners (new) + "Modifies *CACHE*. Merge updated oneliners into the *cache*, ensuring to remove old versions." + (setf *cache* + (nconc + new + (delete-if + (lambda (old-oneliner) + (find (oneliner-id old-oneliner) + new + :key #'oneliner-id + :test #'equal)) + *cache*)))) + +(defun get-cached (id-or-name) + "Looks up a oneliner instance by ID-OR-NAME using the current binding of *cache*. " + (find id-or-name + *cache* + :key (etypecase id-or-name + (integer #'oneliner-id) + (string #'oneliner-name)) + :test #'equal)) + + +;;; DRAFTS VAR AND OPERATIONS + +(defvar *drafts* nil + "Holds a list of oneliner drafts yet to be sent to the server.") + +(defun fetch-draft (name) + "Fetch a draft by name form the *DRAFTS* association list." + (cdr (assoc name *drafts*))) + +(defun drop-draft (name) + "Drop a draft by NAME from the *DFRAFTS* association list." + (setf *DRAFTS* (delete (assoc name *DRAFTS*) *DRAFTS*))) + +(defun put-draft (name draft) + "Modifies *DRAFTS*, adding a new DRAFT associated with NAME. If NAME +is already associated, that old association is deleted." + (drop-draft name) + (push (cons name draft) *drafts*)) + ;;; LOADING AND SAVING STATE (defun config-file () @@ -105,29 +150,6 @@ user for some input if it does not." (read-config-file) (make-fresh-config))) -;;; GETTING AND SETTING STATE, DYNAMICALLY BOUND - -(defun merge-oneliners (new) - "Modifies *CACHE*. Merge updated oneliners into the *cache*, ensuring to remove old versions." - (setf *cache* - (nconc - new - (delete-if - (lambda (old-oneliner) - (find (oneliner-id old-oneliner) - new - :key #'oneliner-id - :test #'equal)) - *cache*)))) - -(defun get-cached (id-or-name) - "Looks up a oneliner instance by ID-OR-NAME using the current binding of *cache*. " - (find id-or-name - *cache* - :key (etypecase id-or-name - (integer #'oneliner-id) - (string #'oneliner-name)) - :test #'equal)) ;;; STATE LOADING MACRO -- cgit v1.2.3