diff options
| author | LLLL Colonq <llll@colonq> | 2024-03-26 23:34:28 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-03-26 23:34:28 -0400 |
| commit | 782c667e824d426b5443591afeefc37d0ae17785 (patch) | |
| tree | ae5d232d598e2008bc2cadf32157a4d937b01951 /src/wasp-utils.el | |
| parent | 8e9db9303fc5d72ddfdc9ab4a9adaa8299e6e21a (diff) | |
We streamed for 9 hours and (mostly) fixed everything.
Diffstat (limited to 'src/wasp-utils.el')
| -rw-r--r-- | src/wasp-utils.el | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/wasp-utils.el b/src/wasp-utils.el index 15148f74..875295b6 100644 --- a/src/wasp-utils.el +++ b/src/wasp-utils.el @@ -3,6 +3,7 @@ ;;; Code: (require 's) +(require 'f) (require 'cl-lib) (require 'eieio) (require 'request) @@ -12,6 +13,11 @@ :type '(string) :group 'wasp) +(defun w/read-sexp (s) + "Read string S into a Lisp form. +Return nil on error." + (condition-case nil (read s) (error nil))) + (defun w/write (text &optional face) "Write TEXT to the current buffer and apply FACE." (let ((text-final (if face (propertize text 'face face) text))) @@ -29,7 +35,7 @@ "Write LINE to the log buffer and apply FACE." (with-current-buffer (get-buffer-create w/log-buffer) (goto-char (point-max)) - (w/write-line (w/clean-string (format "%s" line)) face) + (w/write-line (format "%s" line) face) (goto-char (point-max)))) (defmacro w/defstruct (name &rest body) @@ -116,7 +122,8 @@ Optionally append EXT to the path." (defun w/devour (start end) "Delete and return the region from START to END." - (let ((ret (buffer-substring start end))) + (w/write-log (format "devouring: %s %s %s" start end (buffer-string))) + (let ((ret (decode-coding-string (buffer-substring start end) 'utf-8))) (delete-region start end) ret)) @@ -147,7 +154,39 @@ Otherwise, throw an error." (delete-char 1) t) (error (format "While parsing, expected %c but found %c" c char)))) - + +(defun w/get-stream-primary-window () + "Get the marked primary stream window." + (window-at-x-y 0 0)) + +(defun w/open-link () + "Open URL in the primary stream window." + (interactive) + (when-let ((url (thing-at-point 'url t))) + (select-window (w/get-stream-primary-window)) + (browse-url url))) + +(defun w/prevent-focus-frame (e) + "Prevent focus from reaching popup frame E." + (not (frame-parameter (cadr e) 'wasp-prevent-focus))) + +(defconst w/asset-base-path (f-canonical "./assets/")) +(defun w/asset (path) + "Return the absolute path given an asset path PATH." + (f-join w/asset-base-path path)) + +(defun w/image-text (path &optional text) + "Return TEXT propertized with the image at PATH. +If TEXT is nil, use the empty string instead." + (propertize + (or text "i") + 'display + (create-image path) + 'rear-nonsticky t)) + +(defsubst w/saget (k a) + "Retrieve the value for string key K in alist A." + (alist-get k a nil nil #'s-equals?)) (provide 'wasp-utils) ;;; wasp-utils.el ends here |
