Fork me on GitHub
#parinfer
<
2016-11-29
>
shaunlebron04:11:49

> a js library for clojure indent spec? @doglooksgood: if you mean a spec based on the clojure style guide’s indent section, no— because a) there’s some disagreement about indentation length i.e. 2 spaces vs indent to second token b) i want to de-scope indentation preferences from leaking into parinfer’s options for now

shaunlebron04:11:54

plan is to use 1-space indentation to start, but match indentation of the previous or subsequent sibling line if found

shaunlebron04:11:30

much in the same way that Paren Mode will preserve whatever relative indentation you choose, the newline stuff will just use the current established indentation length you chose in the current scope

tianshu05:11:36

@shaunlebron I mean the cider-indent-spec, It doesn't care how many spaces will be used for indentation. Instead, it declare a expression syntax to define indentation rule for specific form/macro/function. here's a article for this: https://cider.readthedocs.io/en/latest/indent_spec/

cfleming08:11:22

@doglooksgood There are a couple of problems with that: 1) it ties parinfer to Clojure (I believe @shaunlebron wants it to be language agnostic) and 2) it requires parinfer to have access to metadata, which either means some sophisticated parsing, or access to a REPL.

cfleming08:11:20

I think that that degree of integration will have to be editor-specific. I could imagine a version which accepts a map of {head symbol -> indentation} which the editor supplies, though.

cfleming08:11:05

The problem is knowing ahead of time which symbols you will encounter. Editors could do a pre-pass, I guess, to collect that information.

tianshu08:11:06

I'm not sure about other dialects of Lisp, but elisp has the similar solution for indentation. IMO, indent spec can be used for other Lisp as well. And we do not have to access metadata or any thing Clojure specific, just provide a symbol list and let user customize that.

cfleming08:11:41

Sure, but the indent spec is currently supplied in metadata. The user could have the {symbol -> spec} map in their .emacs or whatever equivalent, but the point of the indent spec was to try to get away from that.

cfleming08:11:54

But right, I think from parinfer’s point of view, it could just receive a map like that. It’s still difficult though - parinfer is currently not aware of which forms represent metadata, and which are “significant” - the indent spec requires knowledge of that to apply it correctly.

cfleming08:11:29

None of it is insurmountable, but there are lots of tricky cases.

tianshu08:11:48

I think the indent spec can be implemented as a code formatter, separated from parinfer, since currently some editor for Clojure (Lighttable, Atom, VSCode, Nightlight) doesn't support complex indentation. There indent spec can help them a lot.

cfleming08:11:52

Yes, definitely.

cfleming08:11:00

@doglooksgood BTW I liked your experiments with the hybrid mode, I’ve been planning to try something like that myself.

cfleming08:11:07

It’s hard to do in IntelliJ, unfortunately.

tianshu08:11:22

hybrid mode?

cfleming08:11:22

Or at least, what I would like to do is difficult.

tianshu08:11:17

You mean combine Paren and Indent mode in parinfer-mode?

tianshu08:11:10

I use this for weeks and now I turn it off. This may be convenient for some cases, but not as good as I expected.

cfleming08:11:04

Interesting. I can imagine a lot of tricky cases around cut and paste

cfleming08:11:21

And around selecting a bunch of text including mixed parens, and then deleting it.

tianshu08:11:48

What I did for parinfer-mode is 1. before paste, fix parens 2. then, paste in Indent Mode will preserve indentation, paste in Paren Mode will preserve parens.

eraserhd15:11:25

Are there cases where we care about preserving indentation? I haven't paid to close attention, but it feels like there aren't.

eraserhd15:11:31

(when pasting)

eraserhd15:11:17

I'm wondering about cases like these for avi... e.g. should paste always be paren mode? Should inserting characters in the middle of a line always be paren mode?

eraserhd15:11:32

I'm not even sure how to go about answering them. Collect empiric data? Decide on what would make things work better if users adjusted to them?

shaunlebron15:11:39

@eraserhd: this is something I will have to write a guide on

shaunlebron15:11:53

i can say that there is a progress to make this safer

shaunlebron15:11:33

parinfer 2.0.0 (silent release) makes it safer to paste things in indent mode

shaunlebron15:11:38

pasting wrongly indented code could benefit from preprocessing with paren mode before pasting as doglooksgood said

eraserhd15:11:05

Oh, the paste buffer itself?

shaunlebron15:11:26

but sometimes there are partial unclosed expressions, which is one of the reasons why I’m considering making Paren Mode work for partial expressions

shaunlebron15:11:41

I think so, not sure yet

eraserhd15:11:02

Interesting

shaunlebron15:11:07

it might work either way

shaunlebron15:11:07

So yes, some major changes that will dial back parinfer’s aggression and will probably make it safer to copy/paste: 1. unmatched close-parens will suspend indent mode if they are not at the end of the line 2. paren mode should indent expressions even if for partial expressions

shaunlebron15:11:58

will be exploring number 2 after dealing with newline stuff, which protects expressions in Indent Mode when pressing enter