Fork me on GitHub
#emacs
<
2022-12-16
>
TMac11:12:08

If I have

(foo
  (bar baz))
and I want
(bar
  (foo baz))
what's the best way of going about it? transpose-sexp isn't quite right, and neither is paredit-splice-sexp-killing-backward or paredit-raise-sexp (since both are destructive)

tomd11:12:19

convolute with cursor on baz ?

❤️ 1
TMac12:12:38

awesome, thanks. Strange to me that the point has to be on b specifically, e.g. if it's on the a of baz I get (bar b (foo az)). But I can totally work with that, thank you!

tomd12:12:14

ah, that doesn't happen with smartparens. I'm not sure which one is right. glad that's helpful

slipset12:12:23

Dear lazyweb. We have some macros which we’ve annotated with

{:style/indent 1}
Sometimes(TM) this is honored by my emacs, other times it is not. It seems to be honored when I manually use TAB to indent, but when eg slurping and barfing with paredit (which causes reindentation) the :style/indent seems not to be honored. I use Clojure mode and clojure-lsp. I’m not asking for a full debug of this, I’m just sort of curious if eg clojure-lsp doesn’t honor the :style/indent or something?

ericdallo12:12:40

Never heard about that 😅 even so, clojure-lsp delegates format to cljfmt, so it should be supported there (if it really makes sense)

slipset12:12:52

:style/indent is a super neat idea 🙂

slipset12:12:09

But thanks, I’ll have a look at cljfmt then to see if it lies there.

ericdallo12:12:46

Cool, sounds like a good addition

slipset12:12:10

Issue been open since 2015 🙂

😔 1
vemv13:12:47

@UKFSJSM38 just in case, :style/indent is a CIDER thing. But it's pretty easy to translate from its format (https://docs.cider.mx/cider/indent_spec.html) to cljfmt's. So it's something clojure-lsp could do by analyzing the defmacros in the codebase, fetching all this metadata and then invoking cljfmt with this dynamically-built config That way, both worlds would be bridged cider clojure-lsp

slipset13:12:13

I’d nuance it a bit. I believe style/indent originated with CIDER, but the hope/intent was that it would be a cross IDE/formatter/whatever way to express indentation needs.

👍 1
vemv13:12:49

> Issue been open since 2015 yeah I doubt it will be fixed from their side - analyzing var metadata surely exceeds cljfmt's intended scope so either cider or clojure-lsp would do it

slipset13:12:20

@U0BKWMG5B seemed positive to the idea, but was lacking time?

ericdallo13:12:01

the issue with that is that clojure-lsp just pass the string to cljfmt, if we need to parse it and check every call macro, get kondo analysis for that and check if has metadata would probably affect performance and since format is something that is called automatically in some editors it needs to be fast :/

ericdallo13:12:36

supporting that on cljfmt would probably be the best as it already parses the node

vemv13:12:47

> the issue with that is that clojure-lsp just pass the string to cljfmt, if we need to parse it and check every call macro, get kondo analysis for that and check if has metadata would probably affect performance and since format is something that is called automatically in some editors it needs to be fast :/ I'd assume this can be cached like various other things in lsp? In CIDER it's fast becase it's runtime-powered, but we also could/should cache it for offline invocation. ...The key insight is that if you believe that :style/indent is useful, generally you have to perform some analysis. Under the clojure-mode/cider/style-indent philosophy, formatting isn't something homogeneous/mechanical (a la Tonsky), but codebase-specific. So, yes, there's no speedy formatting without caching or some other 'cheating' (runtime introspection) - CIDER users have lived under this constraint/tradeoff for years and it has worked perfectly :)

vemv13:12:59

> supporting that on cljfmt would probably be the best as it already parses the node Sounds pretty neat, however it misses metadata mutation performed via other means

ericdallo13:12:32

caching does not help that much here as user keeps changing the code, so we need to re-analyze the clojure and invalidate the cache. I can see how convenient it is to support that for the final user, would be perfect to have that on cljfmt IMO, but we could start with a issue on clojure-lsp to discuss more about it, maybe we can find something in between that could work.

👍 1
vemv13:12:18

Will create it - good timing (just joined a lsp-heavy job with cljfmt also in the mix 😃)

😄 1
ericdallo13:12:31

TBH I'd like to support other formatters in the future, cljfmt seems to be a little bit stagnant

slipset13:12:02

You mean done 😉

😅 1