Fork me on GitHub
#parinfer
<
2016-02-21
>
cfleming08:02:22

(sorry about the actual tweet there, I tried to just link the image but Slack is too clever)

cfleming22:02:40

@shaunlebron: There’s another interesting case related to maintaining the caret position - maintaining the selection.

cfleming22:02:08

If I have the following:

(println test)
:test
"test”

cfleming22:02:39

And I select the final two lines and indent them, then the selection gets messed up after running parinfer.

cfleming22:02:07

I’m wondering if some more general mechanism might not be required here.

cfleming22:02:27

It looks like Atom actually handles this correctly even though the file changes, but I’m not sure how.

cfleming22:02:58

@chrisoakman: Do you know how that works? Do you have to do anything explicit to maintain the selection?

chrisoakman22:02:17

I capture the selection before parinfer runs, then I re-apply that selection after it's finished

chrisoakman22:02:28

in Atom, a selection is just an array of points

chrisoakman22:02:59

I don't modify the selection at all, essentially

chrisoakman22:02:18

I'm not 100% sure if that is "correct", but it always seems to feel natural when I'm using it

chrisoakman22:02:20

if that makes sense

chrisoakman22:02:10

that function is the heart and soul of atom-parinfer

chrisoakman22:02:02

everything else is essentially plugin state management or interop / event glue code

cfleming22:02:10

But doesn’t the selection change when parinfer modifies the underlying file?

chrisoakman22:02:05

I guess it might just move it whatever characters have been added to the end of a line

chrisoakman22:02:07

I'm not 100% sure

chrisoakman22:02:39

when I was first setting up atom-parinfer it would lose the selection completely, then I just tried copying the old selection into the result text

chrisoakman22:02:43

and it seemed to work ok

chrisoakman23:02:11

I think most of the time when you're modifying the file and have a selection, you have multiple lines selected and are probably indenting / dedenting

chrisoakman23:02:18

that's my normal use case for it anyway

cfleming23:02:33

Ok, thanks - I’ll try that and see how it works.

chrisoakman23:02:56

yeah - give it try and see how it feels / performs

chrisoakman23:02:08

no one has complained about atom-parinfer selection

chrisoakman23:02:17

and I don't notice any problems with it

cfleming23:02:25

BTW I think it would be a good idea to have some perf tests where changes are actually made to the document.

cfleming23:02:47

Currently the really big file test, just runs parinfer but (presumably) doesn’t actually modify it.

chrisoakman23:02:18

yeah - I agree with that

cfleming23:02:20

That might actually change the perf a bit since it’ll have to copy more strings around.

chrisoakman23:02:24

real-world will be modifications

chrisoakman23:02:01

real-world will be lots of changes happening from parenMode()

cfleming23:02:47

Right. I’m going to modify the JVM version at least to create a set of diffs rather than return a new file, that should eliminate a lot of string copying, and I suspect that for most editors it will be more efficient to apply.

cfleming23:02:01

It’s hard to benchmark, though.

cfleming23:02:29

I’ll make that modification in my fork first, and then we can see if that’s something we might want in the official version or not.

chrisoakman23:02:34

sounds good; I haven't caught up with the last few days of Parinfer news

chrisoakman23:02:41

have been working on a different project

cfleming23:02:08

No worries. I’m going to port Shaun’s caret movement update over to the JVM version when I get a moment.