fvictorio / vim-extract-variable

Vim plugin to extract an expression to a variable
MIT License
26 stars 6 forks source link

Haskell support #9

Open dataO1 opened 4 years ago

dataO1 commented 4 years ago

Hi, is haskell support possible ?

fvictorio commented 4 years ago

Hmm, I believe it should be possible, although I'm not sure the best way to do it. Plus, given haskell's declarative nature, the simple approach used by this plugin (open a new line before the current one and put the variable there) won't probably work (except maybe inside a do?). Another approach would be to use a where, although I'm not sure what would happen if you already have a where in your function (are two wheres syntactically valid?).

Anyway, if there's an approach that you think can work, I'd be happy to add it, but I'm not sure how it would be.

cc @k0001 @gillchristian do you have an opinion on this?

k0001 commented 4 years ago

You can always replace an expression x with another expression let a = b in c in place, without having to worry about indentation, etc. That's probably the easiest way to support this.

fvictorio commented 4 years ago

Makes sense. The problem is recognizing the boundaries of c though. Maybe search backwards for some weird regex like ^\S+\s*= to get the start of the function, and then adding the let a = b in after that. Not sure how brittle that would be though.