coffescript custom folding
For "standard" JavaScript, I have this custom folding function which I like a lot:
function! JavaScriptFold()
setl foldmethod=syntax
setl foldlevelstart=1
set fillchars=fold:\
syn region foldBraces start=/{/ end=/}/ transparent fold keepend extend
function! FoldText()
return substitute(getline(v:foldstart), '{.*', '{...}', '')
endfunction
setl foldtext=FoldText()
endfunction
Could a kind soul please show me a translation of this for CoffeeScript? So that
testFunction = (x) -&g开发者_运维技巧t;
x + x
would be folded like this into its first line only
testFunction = (x) ->
Bonus points for folding literal objects too, but functions would be great already!
PS: of course, I'm using the coffee-script plugin for Vim
As I don't know cofee, and I don't know what literal objects it support, I can't help with that. However what you want, can be achieved by this setting (which could be translated into a modeline):
:setl fdm=expr fde=getline(v:lnum)=~'->$'?'>1':getline(v:lnum)=~'^\\s*$'?0:'='
You didn't specify what to display on the fold, so I left this out. You can use the foldtext setting for that. See :h fold-foldtext
for that.
精彩评论