parinfer

cfleming 2018-02-09T02:27:03.000253Z

@shaunlebron What is the best place to point people to when they ask what smart mode is?

cfleming 2018-02-09T02:27:23.000299Z

The home page is still mostly about the dual modes.

cfleming 2018-02-09T02:27:44.000141Z

Is there a summary documented anywhere public?

shaunlebron 2018-02-09T02:29:04.000216Z

i was just about to record a quick video summary

shaunlebron 2018-02-09T02:29:16.000169Z

but I wanted to demonstrate it in cursive

cfleming 2018-02-09T02:29:23.000124Z

That would be great, a few people have asked about it.

shaunlebron 2018-02-09T02:29:29.000130Z

but it doesn’t work here yet

cfleming 2018-02-09T02:29:38.000119Z

In Cursive?

shaunlebron 2018-02-09T02:31:09.000300Z

@cfleming: https://www.youtube.com/watch?v=QGzilYhqsPc

shaunlebron 2018-02-09T02:32:01.000124Z

i probably just got the wrong version? intellij versions are confusing

cfleming 2018-02-09T02:33:00.000266Z

That’s weird, it sounds like what @dave.dixon was reporting.

cfleming 2018-02-09T02:34:06.000140Z

Versions look good, Cursive wouldn’t be enabled otherwise.

taylor 2018-02-09T02:34:43.000089Z

I think I’m seeing the same behavior, seemed like it was working for a while then ☝️

cfleming 2018-02-09T02:36:03.000178Z

I’m going to try with the repo that Dave said was failing for him

shaunlebron 2018-02-09T02:36:23.000206Z

hmm, i’ll try a new clojure project then

cfleming 2018-02-09T02:37:11.000045Z

@taylor So it was working for you, then it started failing on the same code, or you opened some new code and it didn’t work there?

taylor 2018-02-09T02:38:07.000025Z

I was editing a large CLJS file and it was definitely (maybe?) working when I started, but then eventually it ran into some issues with unmatched parens/brackets that I had to manually fix, and after that it seemed to have stopped working?

cfleming 2018-02-09T02:38:36.000221Z

Hmm, I wonder if the problem is that it’s not re-enabling after things break

taylor 2018-02-09T02:39:34.000254Z

ok so if I open said file, it doesn’t work. If I work on a new/trivial file, it works

cfleming 2018-02-09T02:39:43.000041Z

@shaunlebron Does it work if you’re editing the main code of that project rather than a test file?

shaunlebron 2018-02-09T02:39:58.000339Z

that was what I first tried

cfleming 2018-02-09T02:40:08.000028Z

@taylor Could you restart IntelliJ and see if it starts working on that same file?

shaunlebron 2018-02-09T02:40:10.000024Z

I tried it in a new clojure project generated by intellij, and it worked in the core.clj file

taylor 2018-02-09T02:40:19.000052Z

I just restarted before testing @cfleming

cfleming 2018-02-09T02:40:32.000271Z

Hmm

shaunlebron 2018-02-09T02:40:33.000020Z

then I pasted a long clojurescript file into a new cljs namespace in the project, and it didn’t work

taylor 2018-02-09T02:41:47.000125Z

oddly, it doesn’t seem to work on any CLJS files in my project at all now, not even a new blank one

taylor 2018-02-09T02:41:56.000147Z

it works for CLJ files in same project

cfleming 2018-02-09T02:42:10.000236Z

I wonder if CLJS is the problem for some reason, I’ll see if I can reproduce that.

cfleming 2018-02-09T02:42:17.000145Z

I only really work on CLJ.

shaunlebron 2018-02-09T02:42:20.000164Z

should we move this to #cursive?

1👍
cfleming 2018-02-09T02:42:27.000059Z

Probably, yeah.

shaunlebron 2018-02-09T06:06:34.000148Z

@cfleming can you review this 60 second video before I tweet it? https://www.youtube.com/watch?v=sl6d9M8jkvU

1👏
shaunlebron 2018-02-09T06:06:48.000115Z

or anyone awake in this channel wanna look at it?

cfleming 2018-02-09T06:08:48.000135Z

@shaunlebron Looks good to me!

shaunlebron 2018-02-09T06:09:07.000215Z

cool, thanks for checking

shaunlebron 2018-02-09T06:09:28.000020Z

wanted to make sure i wasn’t leaving anything out important

shaunlebron 2018-02-09T06:43:42.000027Z

@cfleming: looks good in cursive

shaunlebron 2018-02-09T06:44:26.000155Z

only thing I found missing was the last part of the video—selecting a line to correct indentation in isolation

shaunlebron 2018-02-09T06:52:42.000151Z

@cfleming: this is the line that just turns off smart mode when any line is selected: https://github.com/shaunlebron/parinfer/blob/3.12.0/lib/parinfer.js#L1543

cfleming 2018-02-09T07:28:24.000061Z

@shaunlebron Ok, I’ll check that.

cfleming 2018-02-09T07:28:41.000227Z

Cursive doesn’t currently do that, you’re right.

shaunlebron 2018-02-09T08:04:00.000126Z

@doglooksgood i was thinking about the performance problem with your elisp port

shaunlebron 2018-02-09T08:04:46.000301Z

180ms for 2k lines doesn’t sound too bad if we just process top-level forms only

shaunlebron 2018-02-09T08:05:26.000151Z

atom-parinfer still doesn’t process the whole file, despite it being able to

shaunlebron 2018-02-09T08:06:12.000060Z

it just assumes that lines starting with ( are top-level forms

shaunlebron 2018-02-09T08:06:32.000187Z

could be a quick workaround for now

tianshu 2018-02-09T08:08:32.000006Z

It currently does like this. so in the most cases, it's okay. but in a project.clj it may cause problem.

tianshu 2018-02-09T08:36:41.000404Z

I'm wondering the dynamic module feature of emacs, that allow it load .so or .dll. If port parinfer.js to C, the performance should be good enough.

tianshu 2018-02-09T15:35:00.000690Z

I believe that, parinfer should also work for XML or HTML

shaunlebron 2018-02-09T15:35:47.000182Z

ha, I don’t see how that would work. thoughts?

tianshu 2018-02-09T15:36:34.000069Z

I think they are same.

tianshu 2018-02-09T15:37:10.000846Z

for XML and HTML, the close tag can be inferred by the indentation and open tag.

tianshu 2018-02-09T15:38:09.000047Z

no theory to prove this.

tianshu 2018-02-09T15:40:20.000633Z

I saw people who write JSX are painful for the close things. especially when they in some scopes like

xxxlist.map(x -> {
  <div>
    <h1>{x}</h1>
  </div>
})

shaunlebron 2018-02-09T15:41:38.000804Z

maybe if html was written this way:

<div>
    <h1>{x}</h1></div>

tianshu 2018-02-09T15:42:54.000229Z

no, they won't:joy:

shaunlebron 2018-02-09T15:43:37.000246Z

haha, right

shaunlebron 2018-02-09T15:44:12.000062Z

I’m just saying if we want to extend parinfer to other syntaxes, the closing tags have to be consistently placed (according to my current understanding)

shaunlebron 2018-02-09T15:45:48.000094Z

maybe not though, i can already look at that and see how the closing tags can be correctly placed based on indentation, according to how people want it

shaunlebron 2018-02-09T15:46:18.000054Z

yeah, maybe you’re on to something

tianshu 2018-02-09T15:46:19.000493Z

I just think the close tag in xml can be inferred, no saying that parinfer should extended to do this stuff. but if we can determine where we put the closers, for most of the languages, this is the only difference I think.

tianshu 2018-02-09T15:47:31.000501Z

the truth is , for most of the language, the indentation and the code block is relevant.

shaunlebron 2018-02-09T15:47:54.000261Z

hmm

shaunlebron 2018-02-09T15:48:24.000611Z

we can mock out this idea by replacing <div> => ( and </div> => )

shaunlebron 2018-02-09T15:48:33.000586Z

assume divs for all tags

shaunlebron 2018-02-09T15:50:11.000605Z

so now:

<div>
  <h1>{x}
is equal to:
(
  ({x}
which should evaluate to:
(
  ({x})
)
and converting back:
<div>
  <h1>{x}</h1>
</div>

shaunlebron 2018-02-09T15:51:01.000731Z

that would be a fun experiment 🙂

shaunlebron 2018-02-09T15:51:18.000206Z

@doglooksgood cool idea, good insight

tianshu 2018-02-09T15:52:32.000232Z

{x} is just like the string in lisp

shaunlebron 2018-02-09T15:52:48.000852Z

right

shaunlebron 2018-02-09T15:53:01.000140Z

it could be anything, I didn’t mean its brackets would be inferred

tianshu 2018-02-09T15:55:44.000033Z

the code inside {} can have jsx tag too, so should wait { closed first. it's bit complex than lisp maybe

shaunlebron 2018-02-09T15:56:16.000539Z

haha, we should probably just do HTML first

shaunlebron 2018-02-09T15:57:04.000747Z

i wonder if it could work for JS too

shaunlebron 2018-02-09T15:57:29.000178Z

it wouldn’t need anything from Smart Mode to work

tianshu 2018-02-09T15:58:09.000850Z

1. determine where we put closer. 2. custom the opener and closer type. with these two enhancement, I think it will work for html at least.

1👍
shaunlebron 2018-02-09T15:59:24.001135Z

to clarify why JS wouldn’t need Smart Mode stuff, replacing if with for below wouldn’t require the body to shift, since the body is always fixed indentation regardless of the position of the curly:

if (true) {
  foo()
}

shaunlebron 2018-02-09T16:00:07.000411Z

yeah, i think you’re right, that could be pretty simple to make work for html

shaunlebron 2018-02-09T16:01:10.000897Z

parinfer-html could be a pretty quick project 🙂

tianshu 2018-02-09T16:01:11.000630Z

the smart-parens in emacs has these kind of work, it handle whatever thing you call them parens, not limited in normal parens.

shaunlebron 2018-02-09T16:01:25.000600Z

cool

tianshu 2018-02-09T16:01:56.000375Z

If parinfer work both in JS and HTML, it will help JSX a lot

tianshu 2018-02-09T16:02:12.001Z

I always think, write JSX is a pain.

shaunlebron 2018-02-09T16:03:22.000846Z

JSX is nicer than HTML in terms of closing tag consistency

shaunlebron 2018-02-09T16:03:49.000218Z

<input> vs <input /> and <div></div> vs <div />

tianshu 2018-02-09T16:04:48.000589Z

yes, it is

shaunlebron 2018-02-09T16:12:32.000595Z

honestly, I don’t struggle with writing JSX

shaunlebron 2018-02-09T16:13:08.000520Z

easy to align the tags vertically, people like that. it’s just a bit verbose

tianshu 2018-02-09T16:13:11.000295Z

but I struggle and a lot of my workmates struggled. I don't have to write JSX, we prefer clojurescript.

shaunlebron 2018-02-09T16:14:15.000060Z

because it’s too much to type? or the fact that it doesn’t compose well with JS?

shaunlebron 2018-02-09T16:14:31.000349Z

the JS interpolation is very awkward

tianshu 2018-02-09T16:15:48.000309Z

I think the reason why I don't like it, I have to move the cursor here and there, you have to edit both begin and end, just like edit lisp without parinfer or paredit.

tianshu 2018-02-09T16:16:47.000239Z

especially when you do wrap and raise from

<div>
  x
</div>
to
<div>
  <span>x</span>
</div>

shaunlebron 2018-02-09T16:18:23.000818Z

ah okay, so it’s just the tag manipulation that you don’t like

tianshu 2018-02-09T16:48:21.000255Z

another thing, i think why my parser in elisp is slow is that I try to save parse result in a vector

tianshu 2018-02-09T16:50:47.000662Z

I should combine parsing and processing. for now, if I save result, parsing will cost 140ms, If I don't, will cost 50ms.

1👍
tianshu 2018-02-09T16:50:59.000105Z

I think 50ms is good enough