Fork me on GitHub
#parinfer
<
2016-02-27
>
cfleming00:02:55

@sekao: This confused me as well at first. I don’t think paren mode is actually useful as an editing mode to expose to the user.

cfleming00:02:08

Indentation requires semantic knowledge:

cfleming00:02:24

(defn x []
  something)

cfleming00:02:02

(println a
         b
         c)

cfleming00:02:27

Paren mode just corrects the file so that it’s within the invariants required by indent mode.

cfleming00:02:38

I think it’s mostly useful for that that correction.

sekao01:02:58

@cfleming that makes sense, there is a lot of subtlety to indentation. it does however mean that this will be more challenging to integrate into my ide than I thought ;) it will be hard to post-process the output of paren mode, especially since indent mode may misinterpret it

sekao01:02:19

I don't actually expose paren mode to the user except for pre processing files and handling enter, btw

chrisoakman02:02:54

@sekao: I'm not sure about "running paren mode on enter"; I don't think other plugins are doing that

chrisoakman02:02:08

have you tried atom-parinfer at all?

sekao02:02:54

in the parinfer readme it recommends doing that, albeit specifically for repls

cfleming03:02:03

@sekao: I'm not convinced that paren mode will do a good enough job on enter for that purpose for the reasons above. I think you'll need some custom indentation code.

cfleming03:02:41

It'll work in a lot of cases but in some important ones it won't

mfikes03:02:39

@sekao: I use the “indent-on-enter” pattern in Replete and Planck, and I just live with the 1-space indent (and the lack of semantic indentation as @cfleming points out)

shaunlebron14:02:34

catching up from yesterday now

shaunlebron14:02:12

@sekao: paren mode only does one-space indentation because it clamps indentation to valid thresholds

shaunlebron14:02:01

for example, it will clamp:

(defn foo [a b]
             c)
to:
(defn foo [a b]
          c)

shaunlebron14:02:20

So the above example is not one-space indentation, because it clamped to max not min

shaunlebron14:02:22

For completeness, here’s one-space indentation responding to clamp min:

(defn foo [a b]
c)
to:
(defn foo [a b]
 c)

shaunlebron14:02:27

This has been a stopgap solution for setting indentation since auto-indent is something provided by most editors I thought

shaunlebron14:02:00

precise auto-indent inside thresholds becomes subjective in a few cases. for example, david nolen only ever uses two-space indentation:

(println a
  b
  c)
not:
(println a
         b
         c)

shaunlebron14:02:14

and the clojure style guide calls on one-space indentation if a newline comes directly after the first symbol of a call:

(println
 a
 b
 c)

shaunlebron14:02:39

which is something I’ve never done

shaunlebron14:02:46

my point is that Paren Mode allows ALL of the styles above since it only clamps to threshold. It's my intention to not destroy people’s preferred indentation as long as it fits in the threshold.

shaunlebron14:02:47

this means that auto-indentation length must be decided by a thing separate from Paren Mode

shaunlebron14:02:04

I have been working for the past couple days on adding auto-indent on enter for Indent Mode

shaunlebron14:02:27

so it’s coming @sekao

shaunlebron14:02:16

I thought it would be straight forward since mfikes has been doing the Paren Mode on enter thing

shaunlebron14:02:29

But this case caused me to reevaluate:

(foo|) bar
After pressing enter in Paren Mode:
(foo
 |) bar
Then re-enabling Indent Mode:
(foo)
 | bar
which is not what we want

shaunlebron14:02:08

My current opinion is that pressing enter below should produce the following output in Indent Mode.

(foo|) bar
(foo
 |)
bar

shaunlebron15:02:21

if the cursor were to move to another line above, then bar is not at risk of being reabsorbed into the foo expression

shaunlebron15:02:04

this is the first instance of an explicit action in Parinfer, whereas all other actions are implicit on the text inserted in respective modes.

shaunlebron15:02:04

@cfleming: your idea to run Paren Mode when inserting a ) could be a second explicit that may lead us to an Auto Mode

shaunlebron15:02:20

i’ve been spelunking on this issue pretty hard, you can read more if you really want to: https://github.com/shaunlebron/parinfer/issues/98

mfikes15:02:11

@shaunlebron: By the way, Planck and Replete with Parinfer will likely both be released within a week, so we may get good real-world feedback.

shaunlebron15:02:22

@mfikes: cool, thanks. I’ll ping you when this new enter stuff is implemented

sekao16:02:52

thanks @shaunlebron for the explanation. in the process of adding parinfer i removed the code which was providing me auto-indentation previously. i can try combining them, but my fear is that they will clash

sekao16:02:10

one example is multi-arity functions

sekao16:02:36

nightcode’s current auto-indentation code makes the inner functions indent with two spaces, so hitting enter at ([arg1 arg2]|) leads to ([arg1 arg2]\n |)

sekao16:02:12

but with parinfer’s indent mode this would mean anything i type at that point would be added to my arg list rather than the body of the function

shaunlebron17:02:04

clojure style guide recommends against that. bozhidar batsov was adamant about that convention stemming from a clojure-mode bug in emacs

shaunlebron17:02:11

I ran Paren Mode on many core clojure libraries to pickup on things that would be in conflict with Indent Mode

shaunlebron17:02:45

the only thing Indent Mode is in conflict with is the multi-arity convention you mentioned

shaunlebron17:02:29

@sekao, so if you modify nightcode's auto-indentation to not indent multi-arity bodies, auto-indent would be safe to use with Indent Mode

shaunlebron17:02:35

with the exception of the special line-splitting case I mentioned above, which I should have fixed next week

sekao17:02:50

interesting, if that’s the only one then i’ll look into combining them. it’s already usable enough that i’m editing nightcode with the latest master build of nightcode using parinfer 😃

shaunlebron17:02:01

nice! cant wait to play with it