parinfer

shaunlebron 2016-11-29T04:50:49.000196Z

> 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

shaunlebron 2016-11-29T04:52:54.000197Z

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

shaunlebron 2016-11-29T04:56:30.000202Z

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

tianshu 2016-11-29T05:03:36.000203Z

@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/

cfleming 2016-11-29T08:42:22.000205Z

@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.

cfleming 2016-11-29T08:43:20.000206Z

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.

cfleming 2016-11-29T08:44:05.000207Z

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

tianshu 2016-11-29T08:45:06.000208Z

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.

cfleming 2016-11-29T08:46:41.000209Z

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.

cfleming 2016-11-29T08:47:54.000210Z

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.

cfleming 2016-11-29T08:48:29.000211Z

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

tianshu 2016-11-29T08:50:48.000212Z

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.

cfleming 2016-11-29T08:51:52.000213Z

Yes, definitely.

cfleming 2016-11-29T08:53:00.000214Z

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

cfleming 2016-11-29T08:53:07.000215Z

It’s hard to do in IntelliJ, unfortunately.

tianshu 2016-11-29T08:53:22.000216Z

hybrid mode?

cfleming 2016-11-29T08:53:22.000217Z

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

tianshu 2016-11-29T08:54:17.000218Z

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

tianshu 2016-11-29T08:57:10.000221Z

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.

cfleming 2016-11-29T08:58:04.000222Z

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

cfleming 2016-11-29T08:58:21.000223Z

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

tianshu 2016-11-29T08:59:48.000224Z

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.

eraserhd 2016-11-29T15:27:25.000225Z

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

eraserhd 2016-11-29T15:27:31.000226Z

(when pasting)

eraserhd 2016-11-29T15:30:17.000227Z

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?

eraserhd 2016-11-29T15:31:32.000228Z

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?

shaunlebron 2016-11-29T15:38:39.000229Z

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

shaunlebron 2016-11-29T15:38:53.000230Z

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

shaunlebron 2016-11-29T15:39:33.000231Z

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

shaunlebron 2016-11-29T15:40:38.000232Z

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

eraserhd 2016-11-29T15:41:05.000233Z

Oh, the paste buffer itself?

shaunlebron 2016-11-29T15:41:26.000235Z

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

shaunlebron 2016-11-29T15:41:41.000236Z

I think so, not sure yet

eraserhd 2016-11-29T15:42:02.000237Z

Interesting

shaunlebron 2016-11-29T15:43:07.000238Z

it might work either way

shaunlebron 2016-11-29T15:46:07.000239Z

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

shaunlebron 2016-11-29T15:46:58.000240Z

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