alx741 / vim-hindent

Vim Haskell Hindent integration plugin
52 stars 8 forks source link

Restrict on range #7

Closed normenmueller closed 6 years ago

normenmueller commented 7 years ago

Hi, would it be possible to restrict hindent to the (visual) selected area?

alx741 commented 7 years ago

You could setlocal formatprg=hindent and then execute gq on your visual selected area... But that brings back the very problem this plugin aims to solve (your code will be replaced by a hindent error, if the code has a syntax error).

I will try to provide that feature in this plugin on its next version as soon as I can. In the mean time you might just setlocal formatprg=hindent and gq as I've described above.

normenmueller commented 7 years ago

👍 Will do. Looking forward to your next update :)

BTW, the approach formatprg works but on comments. Say, I select a code block and gq, then this code block is formatted nicely. But if I just select a comment block and gq, then the lines are not formatted according to the line length. Do you know a workaround?

alx741 commented 7 years ago

Oh that!. It's been a recurrent problem for me as well, the thing is, if you define your own formatprg you're effectively overwriting vim's default behavior on that (the internal format function). Whenever I need to format trough an external program, but also need to wrap up text nicely with gq on its default function, I use a custom function: https://github.com/alx741/dotfiles/blob/master/vim/.vimrc#L524-L553 And map it to g=. For Haskell, I use this plugin (also mapped to g=) so whenever I need hindent formating I just hit g= but as formatprg remains empty, I have gq on the default behavior (really handy for comments formatting)

normenmueller commented 7 years ago

Thanks! Just to get things right. You proposal is (not using your Format() function but your 'Hindent' function out of this plugin directly):

nmap g= :Hindent<CR>
setlocal formatprg=

But will you still work on the "range restriction" feature?

alx741 commented 7 years ago

Yep, that's what I'm using/doing right now. You get your code through hindent with g= and nice comments formatting with default gq.

Will try to fit the "pass this visual selected code to hindent safely" thing... don't know how yet, but there will be some trade off I guess

denibertovic commented 6 years ago

@alx741 any updates on this?

alx741 commented 6 years ago

Sorry about the delay on this. Now writing a range manually like :7,10Hindent or visually selecting some code and then invoking :Hindent should do the right thing.

denibertovic commented 6 years ago

Awesome! Thank you @alx741 :cake: