diff options
Diffstat (limited to 'lib/state.lisp')
-rw-r--r-- | lib/state.lisp | 70 |
1 files changed, 46 insertions, 24 deletions
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 |