emacs

true.neutral 2025-04-24T15:04:16.198819Z

Is there an easy way to pretty-print a clojure data structure in a similar way to json-pretty-print ?

Evan Bernard 2025-04-24T16:09:08.282499Z

one hacky way I occasionally do it is by just evaluating the data structure in a CIDER REPL - it’ll pretty-print by default, i believe. there’s also M-x cider-format-buffer, but that’s going to format the entire buffer

true.neutral 2025-04-24T16:18:25.006589Z

@ebernard thanks! A bit hacky, but works indeed. Also, found cider-pprint-eval-last-sexp -- evals it in a dedicated buffer, so some kill-yanking is needed, but achieves the same result effectively.

πŸ‘ 2
true.neutral 2025-04-24T16:20:33.099099Z

I guess cider-eval-last-sexp-and-replace and pprint could be married in a clever way.

true.neutral 2025-04-24T16:39:28.079829Z

Yay, this works:

(defun trueneu/cider-pprint-eval-last-sexp-and-replace ()
  (interactive)
  (let ((last-sexp (cider-last-sexp)))
   ;; we have to be sure the evaluation won't result in an error
   (cider-nrepl-sync-request:eval last-sexp)
   ;; seems like the sexp is valid, so we can safely kill it
   (let ((opoint (point)))
     (clojure-backward-logical-sexp)
     (kill-region (point) opoint))
   (cider-interactive-eval last-sexp
                           (cider-eval-print-handler)
                           nil
                           (cider--nrepl-print-request-plist fill-column))))
Basically the very same eval-last-sexp-and-replace but with different additional params I took from one of pprint'ing functions.

πŸ‘ 1
Drew Verlee 2025-04-24T17:19:46.909609Z

if thats a cider-eval-and-replace-pprint then you should submit it to the cider, i have wanted that for years, but i want a lot of things and usually when i spend an hour trying to build something i break something else :cry.

true.neutral 2025-04-24T17:24:47.320129Z

That crossed my mind; I will, but please grab it while it's not in CIDER's master yet πŸ™‚

πŸ‘ 1
valtteri 2025-04-25T18:22:02.506559Z

https://github.com/ericdallo/jet.el

πŸ‘ 1
true.neutral 2025-05-17T18:33:05.913989Z

Just in case, there actually is a CIDER function for this already (kudos to @rrudakov for pointing this out) -- cider-format-edn-last-sexp

πŸ‘€ 1
Drew Verlee 2025-04-24T17:17:44.666989Z

Any ideas why when i tangle this block:

#+begin_src clojure :tangle foo.clj
1
#+end_src
foo.clj ends up looking like this:
(prn (binding [*out* (java.io.StringWriter.)]1))
org-version returns: Org mode version is 9.6.15 (release_9.6.15 @ /home/drewverlee/emacs/spacemacs/elpa/29.2/develop/org-9.7.28/). Huh, 9.6.15 but it's in a folder called 9.7.28, that seems odd to me.

Drew Verlee 2025-04-24T17:24:39.033979Z

the version issue probably relates to this note: https://www.spacemacs.org/layers/+emacs/org/README.html#important-note

Drew Verlee 2025-04-24T17:24:55.075329Z

> Spacemacs uses the org version from the ELPA repository instead of the one shipped with emacs. Then, any org related code should not be loaded before dotspacemacs/user-config, otherwise both versions will be loaded and will conflict.

Drew Verlee 2025-04-25T18:57:37.954229Z

someone else with the same issue: https://list.orgmode.org/orgmode/m2zg6irvfj.fsf@gmail.com/

Drew Verlee 2025-04-25T19:01:53.168649Z

oh, the person with the same issue was @ag... two years ago. laughcry Ag, did you figure out a fix for this? How is this still a problem years later?

Drew Verlee 2025-04-25T19:02:41.750159Z

i'm baffled what the chain of events even could be here, why would tangle be doing anything other then writing the blocks contents verbatim.

Drew Verlee 2025-04-25T19:04:21.726749Z

the issue seems related to this function: org-babel-expand-body:clojure is a natively compiled function defined in ob-clojure.el.

Drew Verlee 2025-04-25T19:06:46.031939Z

oh, i guess i should cider jack-in inside the org file to fix this...

Drew Verlee 2025-04-25T19:08:03.351509Z

nope, i still get the nonsense.

ag 2025-04-25T21:00:03.865829Z

Hey @drewverlee, sorry for the delay. Try setting :results output in the header.

πŸ™ 1
Drew Verlee 2025-04-25T21:01:37.417379Z

Err no reason to be sorry! I probably shouldn't have pinged you at all. I appreciate all the emacs help, I'm trying to get more into using org mode and it's an adventure... So many things to adjust.

Drew Verlee 2025-04-25T21:13:02.323729Z

That fixed it! Your powers are greater then Chatgpt.

Drew Verlee 2025-04-25T21:13:59.521359Z

But also Whyyyyy are things like this. laughcry

ag 2025-04-25T21:17:08.404589Z

Yeah, that shit annoyed me back then, I had to figure it out. I've been looking at your messages on my phone, but for the love of god I just couldn't remember what the workaround was. I had to wait till I get home, find my dotfiles (that I manage in org-mode) and this snippet:

#+begin_src clojure :results output :tangle ~/.lsp/config.edn :mkdirp yes :tangle-mode (identity #o444)
{:show-docs-arity-on-same-line? true
 :hover {:hide-file-location? false}
 :semantic-tokens?true}
#+end_src

πŸ‘ 1
escherize 2025-04-24T17:57:57.258329Z

I've switched emacs installs lately, and I have an issue with github copilot, I think it's fighting with smartparens. with | as cursor position, when i type (+ 1| auto pilot fills in the 1 ) in grey like: (+ 1| 1). If I hit tab, i end up with: (+ 1 1)) of course it should be (+ 1 1). I have a workaround where I call copilot-accept-completion-by-word up to the final closing parens/brackets/braces instead of taking the entire copilot completion. but I think that it was working for me on the old install!

djm 2025-04-25T06:47:32.931729Z

There might be a better way, but one thing you could do is add advice to the function to delete the extra ) similar to this: https://www.emacswiki.org/emacs/HippieExpand#h5o-9

Casey 2025-04-25T08:16:45.961669Z

@escherize i believe you are hitting this bug in copilot https://github.com/copilot-emacs/copilot.el/issues/409

Casey 2025-04-25T08:17:15.470209Z

it is a bug that has been reintroduced at least twice πŸ€¦β€β™‚οΈ as a maintainer tries to fix another issue

🫠 1
Casey 2025-04-25T08:17:54.810869Z

I am using copilot.el on aebf69c7e85396aa16b3826e8c8534ad596e78ec and it works

πŸ™ 1
2025-04-25T09:11:20.600739Z

I just use gptel in a separate buffer and ask questions there

2025-04-25T09:11:41.814649Z

much safer than having an extension like copilot messing up with the code directly imho

escherize 2025-04-28T16:01:18.698589Z

@ramblurr that solved it, thanks a lot!!

escherize 2025-04-28T16:03:59.373889Z

@andrea.crotti I see it as a pyramid: llm chats -> agentic coding -> copilot Where llm chats are for the higher level ideas, agentic coding is for pretty simple fixes (it's great at fixing clj kondo linting errors, with some extra tooling and good instructions: I found out at my work's ai hackathon). copilot is good for simple docstrings or brain-dead completions like:

(prn ["req" req])
(prn |) ;; cursor at | 
then hit to do what's more-or less right.