Fork me on GitHub
Drew Verlee01:07:48

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.

😬 3
😄 2

I feel you! 😊😄😂


Yeah me too! How'd we get here fingers? And how do we get outta here?

😂 1

> hitting some keys by accident and having emacs take up 100% of my cpu pkill -SIGUSR2 Emacs


Does this just abort the execution of the current Emacs Lisp command?


it just forces Emacs to enter the debugger. See Info for debug-on-event

👍 1

I've been dreaming for someone (smarter than me) to port something like core.async to emacs-lisp.

Benjamin05:07:54 @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 ()
  (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!



(shell-command-on-region (point-min) (point-max) "echo lol" (current-buffer))


duckie 🐧🎉

(defun teod-play-xx ()
  (shell-command-on-region (point-min) (point-max) "bb '(assoc *input* :title \"Good afternoon\")'" (current-buffer)))

🚀 1
duckie 1

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 ()
   (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))

(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)


t-bb-shell-command might be a better name than the plain t-bb.


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)
    (shell-command-to-string (format "bb -e '%s'" (princ form))))))

(+ (eval-bb '(+ 1 2 3)) 10)
I'm currently thinking that the last function is just good enough

💯 1

for 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 ""))

💯 1
teodorlu18:07:39;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?


Yea its naive and expects elisp readable output. You could either drop the read string part or return a string from bb if you want a string. Eg for insert

👍 1