Is there an easy way to pretty-print a clojure data structure in a similar way to json-pretty-print ?
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
@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.
I guess cider-eval-last-sexp-and-replace and pprint could be married in a clever way.
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.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.
That crossed my mind; I will, but please grab it while it's not in CIDER's master yet π
Just in case, there actually is a CIDER function for this already (kudos to @rrudakov for pointing this out) -- cider-format-edn-last-sexp
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.the version issue probably relates to this note: https://www.spacemacs.org/layers/+emacs/org/README.html#important-note
> 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.
someone else with the same issue: https://list.orgmode.org/orgmode/m2zg6irvfj.fsf@gmail.com/
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?
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.
the issue seems related to this function: org-babel-expand-body:clojure is a natively compiled function defined in ob-clojure.el.
oh, i guess i should cider jack-in inside the org file to fix this...
nope, i still get the nonsense.
Hey @drewverlee, sorry for the delay. Try setting :results output in the header.
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.
That fixed it! Your powers are greater then Chatgpt.
But also Whyyyyy are things like this. laughcry
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_srcI'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!
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
@escherize i believe you are hitting this bug in copilot https://github.com/copilot-emacs/copilot.el/issues/409
it is a bug that has been reintroduced at least twice π€¦ββοΈ as a maintainer tries to fix another issue
I am using copilot.el on aebf69c7e85396aa16b3826e8c8534ad596e78ec and it works
I just use gptel in a separate buffer and ask questions there
much safer than having an extension like copilot messing up with the code directly imho
@ramblurr that solved it, thanks a lot!!
@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.