Fork me on GitHub
#cursive
<
2017-09-01
>
kenny00:09:42

I'm curious about that too ^

cfleming00:09:57

@rgdelato No, IntelliJ plugins have to use the formatting engine it provides, so it’s a custom algorithm.

cfleming00:09:30

It’s very powerful, but a bit tricky to get right.

kenny00:09:50

Dang, that's unfortunate. I'm finding it's very tricky to work with the way other people format their code.

cfleming00:09:12

I’m planning a mode to make Cursive conform to external standards such as cljfmt, but it’ll be hard to make other systems match what Cursive can do.

kenny00:09:23

I can use something like zprint to enforce a format but then Cursive always changes it back.

cfleming00:09:38

@kenny If you have specific examples feel free to send them over, or other things you’d like to be able to configure.

cfleming00:09:22

Would a flag in Cursive like “zprint mode” work for you?

kenny00:09:32

Which does what?

cfleming00:09:41

Although I think zprint is fairly configurable, right?

kenny00:09:47

Very 🙂

cfleming00:09:51

It would match what zprint would do when formatting in Cursive.

cfleming00:09:24

Hmm, if it’s very configurable, it might be easier to just expose more knobs in Cursive.

cfleming00:09:38

So that you can match however you have zprint configured.

kenny00:09:43

I think what would be cool is to take a zprint config and map it to IntelliJ algo.

cfleming00:09:01

Yeah, but that may be very difficult - lots of edge cases there.

kenny00:09:17

Oh yes, definitely not straightforward.

cfleming00:09:37

In the meantime, if you have particular problems, send them over and I’ll see if I can help.

cfleming00:09:52

Feel free to email if you’d rather not share code snippets here.

cfleming00:09:02

I really need an “anonymize this code snippet” function that replaces all the sensitive names with lorem ipsum or something.

kenny00:09:06

Sure. I'll compile a list. This is the first time I'll be working with several other devs using various formats and tools, so getting the format flow correct seems important. Not sure what others are doing to avoid the "formatting tag" that can occur.

cfleming00:09:47

Great, let me know. I’m definitely interested in supporting formatting better since it’s really important for mixed-editor tools.

cfleming00:09:57

And so far I haven’t managed complete world domination.

kenny00:09:19

git blame can ignore whitespace, which is helpful. But it's annoying to see basically every file change when changing a file.

kenny00:09:48

By change I mean turn blue indicating that there are changes that need to be committed.

cfleming00:09:07

But that should only happen when you actually change the file, right?

cfleming00:09:27

Or are you using parinfer?

kenny00:09:49

Yes but you may make several small changes in a number of files and having multiple formats in files seems wrong.

kenny00:09:18

So then you either deal with the wrong feeling or you auto-format the file using Cursive thus creating "format tag."

cfleming00:09:32

Yeah, that’s tricky. You don’t have to reformat the whole file though, you can just reformat something like the top-level form you’ve worked on, or even a smaller unit than that if required.

cfleming00:09:44

It requires care though, for sure.

kenny00:09:08

It's just not really something I want to think about. I want to solve problems, not worry about my code formatting 😆

cfleming00:09:32

Yeah. I’m now totally in favour of languages which enforce a code style (go, Elm).

cfleming00:09:47

It’s the sort of thing people think they will hate but in practice don’t.

cfleming00:09:54

And if they do they should just get over it.

cfleming00:09:05

It’s too late for Clojure, sadly.

kenny00:09:30

Totally agree. Anyway, I think the solution has to be some variant of zprint. While cljfmt is a very cool, succinct library, it does not come close to the amount of configuration zprint provides.

cfleming00:09:59

Yeah, but again I’d rather something opinionated and sensible, so that we can just get on with our lives 🙂

cfleming00:09:18

i.e. “just do it like this, already”

kenny00:09:22

Yep. And I don't think strict formatting matters as much in a lisp as it would in a traditional language (e.g. Java).

kenny00:09:28

That being said, the problem still isn't solved. I think part of the issue is Cursive's autoformatter is not opinionated.

kenny00:09:20

For example, running autoformat on this

(assoc {} :a
          "a"
          :b "b")
simply aligns all the chars but does not format the code.

kenny00:09:50

Cursive's autoformat is more of an auto-aligner.

cfleming01:09:15

Right, currently it doesn’t mess with newlines at all.

kenny01:09:09

Which is great for a number of cases. Really it seems like there should be two modes: align & format. Where format does deal with newlines.

cfleming01:09:51

Yeah, it’s very easy to end up with an exponential number of rules, though.

cfleming01:09:03

I’ll take a look at the sort of thing zprint allows you to configure.

kenny01:09:49

This could be an interesting solution: - Create your zprint config - Write a lumo script to run the formatting in your current project - Assign that script to an external tool - Map external tool to a keybinding

cfleming01:09:05

Sure, and you can already do that.

cfleming01:09:41

The issue is that the formatting engine in IntelliJ is also invoked in many other circumstances, such as pressing enter (to work out where to indent the new line) etc

cfleming01:09:20

I’m looking at zprint now - that’s just a silly amount of configuration IMO.

cfleming01:09:40

I’m not sure Cursive will ever allow that much control, just because I don’t think it’s sensible.

kenny01:09:16

Right but IntelliJ's formatting never does anything destructive (as far as I can tell). So as long as you never invoke the autoformatter I think you'd be good.

kenny01:09:22

And yeah, I totally agree.

kenny01:09:26

It's useful because it has a built in "style" for https://github.com/bbatsov/clojure-style-guide.

kenny01:09:56

No way I'm spending my time reading through the zprint doc and configuring everything I can.

cfleming01:09:32

It would take me an afternoon just to read this.

kenny01:09:30

Yep. But I think the lumo solution may work.

cfleming01:09:31

The problem is also competing standards - CIDER now has its own specification format in metadata

cfleming01:09:49

Which I think cljfmt can be made to respect.

kenny01:09:08

That is exactly what cljfmt can do. Wonder why they made their own.

cfleming01:09:46

Well, I think it was designed to be interoperable with cljfmt (I can’t remember if they were designed concurrently or not)

kenny01:09:12

Huh. cljfmt looks much different than that syntax.

cfleming01:09:16

Again, Emacs has its own formatting engine which they probably need to integrate with.

kenny01:09:23

Ah right.

cfleming01:09:42

Otherwise e.g. paredit wouldn’t use it when it’s reformatting after actions.

cfleming01:09:30

Man, I’m kind of in awe of the zprint doc. I can’t imagine how long it took to write that, let alone implement it.

kenny01:09:01

Haha yeah, very complex. Some documentation formatting would certainly stop scaring people away. Though what really makes me nervous is I recently ran into https://github.com/kkinnear/zprint/issues/23, which is nasty and makes me worried about how their parser is written such that the failing case is to just output nothing.

cfleming01:09:11

It also does things like convert maps to namespaced maps and so on.

cfleming01:09:18

Which IMO is way out of scope.

cfleming01:09:53

That’s a pretty bad bug.

kenny01:09:57

It just tried to do everything.

kenny01:09:22

And yes. I ran it on my code and things just broke.

kenny01:09:03

Latest version fixes it but still. I don't see how failing to parse something correctly should ever spit out nothing.

kenny01:09:35

Anyway, I'll try the lumo solution and see how that goes. I'm very curious how others are solving this problem.

cfleming02:09:44

@ikitommi There are a couple of solutions for that. One would be to enable stubs generation for compojure.api.api, however that might have some unexpected side effects with navigation.

cfleming02:09:24

The other solution would be for the doc lookup to use the open REPL if available, and fall back on the statically-determined one if not.

cfleming02:09:39

@wilkerlucio I’ll look into that. I’m planning a full namespace tidy, but that might be a good middle ground.

cfleming02:09:02

It’s tricky when people do crazy things like use prefix lists, though.

wilkerlucio02:09:54

you could keep it simple, just do it when it's all plain flat and simple, otherwise ignore it

cfleming02:09:58

Yeah, something like that is probably a good idea.

ikitommi06:09:44

@cfleming I can inline the docs for c-api. But wanted to know if there is something coming for this as the function specs contribute to docs too.

ikitommi06:09:22

and big thanks for making Cursive. It's awesome :)

ikitommi07:09:21

btw, feature idea: many clojure libs (including clojure.spec, re-frame) define things with qualified keywords. It would be great if there was a shortcut “goto definition” for those. You can now say “find occurances” and there is most likely one that matter s/def, reg-event-db, reg-event-fx etc. Would massively help on navigation.

cfleming07:09:43

@ikitommi Yeah, I’m planning to do that very soon - there’s an issue for it: https://github.com/cursive-ide/cursive/issues/1470

cfleming07:09:17

I’m planning to add better support for spec including the doc fixes, too.

cfleming07:09:27

Glad you’re still liking Cursive too 🙂