From 50df94fd2a0fce7a2499a8ceafd6034adc69779e Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sat, 12 Mar 2022 19:07:19 -0600 Subject: bugfix: s/defstruct/defplist. made defplist --- lib/client.lisp | 6 +++--- lib/oneliner.lisp | 37 +++++++++++++++++-------------------- lib/state.lisp | 9 +++------ lib/util.lisp | 22 ++++++++++++++++++++++ 4 files changed, 45 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/client.lisp b/lib/client.lisp index 7ee9ebc..fe29932 100644 --- a/lib/client.lisp +++ b/lib/client.lisp @@ -84,8 +84,8 @@ running the body. If such a oneliner can be found." (defun bind-vars-and-run-oneliner (ol args &optional force-clip) (let* ((oneliner (oneliner-oneliner ol)) (runstyle (oneliner-runstyle ol)) - (pos-args (get-positional-arguments oneliner)) - (named-args (get-named-arguments oneliner))) + (pos-args (get-positional-arguments ol)) + (named-args (get-named-arguments ol))) (when (or (not (oneliner-isflagged ol)) (y-or-n-p "This oneliner is flagged. Are you sure you want to run it?")) ;; substitute positional args @@ -113,7 +113,7 @@ running the body. If such a oneliner can be found." (princ ol) (princ #\newline) (princ #\newline) - (run-with-shell ol :shell-name (or (shell) "bash"))))) + (run-with-shell ol :shell-name (or (shell) "bash") :await-output-p *ol-output-timeout*)))) ;;; ADDING ONELINERS diff --git a/lib/oneliner.lisp b/lib/oneliner.lisp index 39aad0d..4828b2d 100644 --- a/lib/oneliner.lisp +++ b/lib/oneliner.lisp @@ -18,7 +18,7 @@ (in-package :oneliners.cli) -(defstruct oneliner +(defplist oneliner id name oneliner @@ -78,22 +78,19 @@ (concatenate 'string "~" (prin1-to-string *term-width*) "<~a~;by ~a~>~%"))) (loop repeat *term-width* do (princ #\_)) (terpri) - (with-slots - (id name isflagged islocked runstyle tags createdby brief oneliner) ol - - (format t title-line-format-str - id - (or name " ") - (format nil "~:[ ~;⚠~]~:[ ~;🔒~]~:[ ~;📋~]" - isflagged - islocked - (equalp "manual" runstyle))) - (format t tags-line-format-string - (format nil "tags: ~{~a~^ ~}" tags) - createdby) - (loop - for x from 0 to (length brief) by *term-width* - do (format t "~a~%" - (string-trim '(#\space) - (alexandria-2:subseq* brief x (+ x *term-width*))))) - (format t "~%~a~%~%" oneliner)))) + (format t title-line-format-str + (oneliner-id ol) + (or (oneliner-name ol) " ") + (format nil "~:[ ~;⚠~]~:[ ~;🔒~]~:[ ~;📋~]" + (oneliner-isflagged ol) + (oneliner-islocked ol) + (equalp "manual" (oneliner-runstyle ol)))) + (format t tags-line-format-string + (format nil "tags: ~{~a~^ ~}" (oneliner-tags ol)) + (oneliner-createdby ol)) + (loop + for x from 0 to (length (oneliner-brief ol)) by *term-width* + do (format t "~a~%" + (string-trim '(#\space) + (alexandria-2:subseq* (oneliner-brief ol) x (+ x *term-width*))))) + (format t "~%~a~%~%" (oneliner-oneliner ol)))) diff --git a/lib/state.lisp b/lib/state.lisp index 676ff10..0f69ff3 100644 --- a/lib/state.lisp +++ b/lib/state.lisp @@ -19,7 +19,7 @@ ;;; Config Struct -(defstruct config +(defplist config (handle "") (api-token "") (host "") @@ -69,8 +69,7 @@ (defun write-config-to-disk () (print-to-file - (with-slots (handle api-token host shell) *config* - (list :handle handle :api-token api-token :host host :shell shell)) + *config* (config-file))) (defun write-cache-to-disk () @@ -79,9 +78,7 @@ (defun read-config-file () "Read a configuration from the location returned by CONFIG-FILE. NIL if there is no such file" - (a:when-let ((conf - (read-from-file (config-file)))) - (apply 'make-config conf))) + (read-from-file (config-file))) (defun read-cache-file () "Read the cache from the location returned by diff --git a/lib/util.lisp b/lib/util.lisp index 27f389e..4b827f1 100644 --- a/lib/util.lisp +++ b/lib/util.lisp @@ -70,3 +70,25 @@ determined by EXECUTABLE-ON-SYSTEM-P." "Returns the strings \"true\" or \"false\" depending on whehter or not WHAT is null" (if what "true" "false")) + +(defmacro defplist (name &rest slots) + (let* ((slots-names + (loop for slot in slots + when (symbolp slot) + collect slot + when (consp slot) + collect (first slot))) + (slot-defuns + (loop for slot in slots-names + collect `(defun ,(intern (format nil "~a-~a" name slot)) (,name) + (getf ,name ,(a:make-keyword slot))) + collect `(defun (setf ,(intern (format nil "~a-~a" name slot))) (val ,name) + (setf (getf ,name ,(a:make-keyword slot)) val)))) + (make-name-defun + `(defun ,(intern (format nil "MAKE-~a" name)) (&key ,@slots) + (list ,@(loop for slot in slots-names + collect (a:make-keyword slot) + collect slot))))) + `(progn + ,make-name-defun + ,@slot-defuns))) -- cgit v1.2.3