This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-07-13
Channels
- # aleph (15)
- # announcements (4)
- # babashka (36)
- # babashka-sci-dev (1)
- # beginners (15)
- # biff (2)
- # calva (15)
- # cider (3)
- # clj-kondo (8)
- # clojure (149)
- # clojure-europe (14)
- # clojure-norway (13)
- # clojure-switzerland (1)
- # clojure-uk (1)
- # clojurescript (21)
- # community-development (5)
- # cursive (20)
- # data-science (2)
- # datomic (7)
- # duct (5)
- # emacs (19)
- # etaoin (3)
- # events (2)
- # fulcro (11)
- # introduce-yourself (2)
- # jobs (4)
- # jobs-discuss (19)
- # joyride (1)
- # leiningen (11)
- # malli (7)
- # membrane (131)
- # nbb (12)
- # nginx (1)
- # off-topic (33)
- # pathom (8)
- # polylith (28)
- # re-frame (8)
- # sci (7)
- # shadow-cljs (225)
- # spacemacs (10)
- # specter (1)
- # vim (10)
- # xtdb (8)
Things i like ~ how much functionality is jammed into emacs! things i don't like ~ hitting some keys by accident and having emacs take up 100% of my cpu trying to do i have no idea what.
> hitting some keys by accident and having emacs take up 100% of my cpu
pkill -SIGUSR2 Emacs
it just forces Emacs to enter the debugger. See Info for debug-on-event
https://www.gnu.org/software/emacs/manual/html_node/elisp/Error-Debugging.html#index-debug_002don_002devent
I've been dreaming for someone (smarter than me) to port something like core.async to emacs-lisp.
https://github.com/jwiegley/emacs-async @ag i guess you knew about this. I think the big draw back is you have to import code you want to use in the async process. So it isnt at all like core async. Consult for example uses it in searches
Oh I didn't know Consult uses emacs-async. I wanna dig through the source code when I get a chance. I'm curious.
Hey! Quick question. With #babashka it's easy to transform some EDN:
$ echo '{:title "Good morning"}' | bb '(assoc *input* :title "Good afternoon")'
{:title "Good afternoon"}
I want to write an Emacs Lisp function that mutates the current buffer containing some EDN, and change it to some other EDN. Something like this:
;; Current buffer contains:
;;
;; {:title "Good morning"}
(defun edn-good-afternoon ()
(interactive)
(shell-command-transform-buffer "bb" "(assoc *input* :title \"Good afternoon\")"))
;; run M-x edn-good-afternoon
;; Current buffer now contains:
;;
;; {:title "Good afternoon"}
Is there a function I can use that roughly the same as the imaginary shell-command-transform-buffer
?
---
If I were to try right now, I would:
1. Read the content of the current buffer
2. Construct the same echo {,,,} | bb ...
command above
3. Write that result back to the same buffer.
I'm suspecting there's a better way. Pointers much welcome!call-process might work https://www.gnu.org/software/emacs/manual/html_node/elisp/Synchronous-Processes.html
closer:
(shell-command-on-region (point-min) (point-max) "echo lol" (current-buffer))
🐧🎉
(defun teod-play-xx ()
"Play."
(interactive)
(shell-command-on-region (point-min) (point-max) "bb '(assoc *input* :title \"Good afternoon\")'" (current-buffer)))
I did a bit of more work. Problems with the solution above:
1. Can't edit structure inside text string easily
2. A bit of noise around point-min, point-max and current-buffer.
So I created t-bb
(macro) that takes an Emacs lisp form and turns it into a babashka shell invocation, and a simplified "run stuff on buffer.
Here's the example above -- revised:
(defun teod-play-xx ()
"Play."
(interactive)
(t-shell-command-buffer
(t-bb (assoc *input*
:title "Good afternoon"))))
Pasting the source of t-bb
and t-shell-comamnd-buffer
as well:
(defun t-str (&rest xs)
"Join XS into string."
(apply #'s-concat
(mapcar (lambda (s)
(format "%s" s))
xs)))
(defun t-bb-fun (form)
"Convert quoted FORM to Babashka shell invocation."
(t-str "bb " "'" form "'"))
;; Example:
;;
;; (t-bb-fun '(assoc *input* :message "Hello!"))
(defmacro t-bb (form)
"Convert FORM to babashka shell invocation."
(list 't-bb-fun (list 'quote form)))
;; Example:
;;
;; (t-bb (assoc *input* :message "Hello!"))
(defun t-shell-command-buffer (command)
"Run COMMAND on current buffer."
(shell-command-on-region (point-min) (point-max)
command
(current-buffer)))
I recently crafted something with princ
as the thing to pass into bb -e.
I wrote t-bb in terms of it
(shell-command-to-string (format "bb -e '%s'" (princ '(+ 1 2 3))))
(defmacro t-bb (form)
`(format "bb -e '%s'" (princ ',form)))
(shell-command-to-string (t-bb (+ 1 2 3)))
(defun eval-bb (form)
(car
(read-from-string
(shell-command-to-string (format "bb -e '%s'" (princ form))))))
(+ (eval-bb '(+ 1 2 3)) 10)
16
I'm currently thinking that the last function is just good enoughfor reference t-str
can be written in terms of mapconcat
(defun t-str (&rest xs)
"Join XS into string."
(mapconcat (lambda (s) (format "%s" s)) xs ""))
https://clojurians.slack.com/archives/C099W16KZ/p1657734204817869?thread_ts=1657721213.601949&cid=C099W16KZ Nice! That's bb directly in Emacs Lisp 😄 I guess it would crash if you tried to return a map or something though?