summaryrefslogtreecommitdiff
path: root/src/wasp-utils.el
diff options
context:
space:
mode:
authorLLLL Colonq <llll@colonq>2026-04-26 23:47:18 -0400
committerLLLL Colonq <llll@colonq>2026-04-26 23:47:18 -0400
commit75e005e81b73d8471f16dc5fad7bbdc312bdbfe7 (patch)
tree1ad7d61b04c44fc52b453aef44868a42012f3551 /src/wasp-utils.el
parentcf266a56f30daae8b9af7c9bc3267c61b1973192 (diff)
Diffstat (limited to 'src/wasp-utils.el')
-rw-r--r--src/wasp-utils.el66
1 files changed, 64 insertions, 2 deletions
diff --git a/src/wasp-utils.el b/src/wasp-utils.el
index 58040a60..14e4368d 100644
--- a/src/wasp-utils.el
+++ b/src/wasp-utils.el
@@ -4,6 +4,7 @@
(require 's)
(require 'f)
+(require 'ht)
(require 'rx)
(require 'cl-lib)
(require 'eieio)
@@ -23,7 +24,8 @@
(defun w/read-sexp (s)
"Read string S into a Lisp form.
Return nil on error."
- (condition-case nil (read s) (error nil)))
+ (when s
+ (condition-case nil (read s) (error nil))))
(defun w/write (text &optional face)
"Write TEXT to the current buffer and apply FACE."
@@ -61,6 +63,19 @@ BODY is passed directly to `cl-defstruct'."
"Lookup SLOT in the struct S."
`(eieio-oref ,s (quote ,slot)))
+(defun w/struct-fields (cl)
+ "Return a list of fields in CL."
+ (when-let* ((class (cl--find-class cl)))
+ (ht-keys (cl--class-index-table class))))
+
+(defun w/struct-get (s f)
+ "Get field F from S."
+ (eieio-oref s f))
+
+(defun w/aref (a i)
+ "Take element I from A."
+ (ignore-errors (aref a i)))
+
(defun w/pick-random (xs)
"Pick a random element of XS."
(and xs (nth (random (length xs)) xs)))
@@ -159,6 +174,20 @@ Optionally append EXT to the path."
(lambda (data)
(funcall k (json-parse-string data)))))
+(defun w/process (cmd k)
+ "Run CMD in the background and pass its output as a string to K."
+ (let ((buf (generate-new-buffer " *wasp-process-generic*" t)))
+ (make-process
+ :name "wasp-process-generic"
+ :command (if (listp cmd) cmd (list cmd))
+ :buffer buf
+ :coding 'utf-8
+ :sentinel
+ (lambda (_ _)
+ (let ((s (with-current-buffer buf (buffer-string))))
+ (kill-buffer buf)
+ (funcall k s))))))
+
(defun w/devour (start end)
"Delete and return the region from START to END."
;; (w/write-log (format "devouring: %s %s %s" start end (buffer-string)))
@@ -246,7 +275,8 @@ If TEXT is nil, use the empty string instead."
:foreground fg-main
:background bg-alt
:weight 'bold
- :extend t)))
+ :extend t))
+ )
(defun w/random-color ()
"Return a random color string."
@@ -327,5 +357,37 @@ Return a list of the width, height, and pixels of the image."
(let ((res (shell-command-to-string (format "df %s" disk))))
(string-to-number (s-chop-suffix "%" (nth 4 (s-split " " (cadr (s-lines res)) t))))))
+(defun w/show-frame (f vis)
+ "If VIS is non-nil, make the frame F visible.
+Otherwise make it invisible."
+ (when f
+ (if vis
+ (make-frame-visible f)
+ (make-frame-invisible f))))
+(defun w/move-frame (f x y)
+ "Move the frame F to X, Y."
+ (when f
+ (modify-frame-parameters
+ f
+ (list
+ (cons 'top y)
+ (cons 'left x)))))
+(defun w/resize-frame (f w h)
+ "Resize the frame F to W, H."
+ (when f
+ (modify-frame-parameters
+ f
+ (list
+ (cons 'width w)
+ (cons 'height h)))))
+
+(defun w/random-flymake-error ()
+ "Return a random Flymake error from the current buffer or nil."
+ (w/pick-random (flymake-diagnostics)))
+
+(defun w/uuid ()
+ "Generate a UUID."
+ (s-trim (shell-command-to-string "uuidgen")))
+
(provide 'wasp-utils)
;;; wasp-utils.el ends here