Sublime Forum

Enable code folding for parentheses

#1

I’m primarily a Javascript developer, and I’ve increasingly embraced function composition as a means of keeping things SOLID, which means a great volume of my code takes the form of arguments passed to functions (often highly nested) – is there a way I can get Sublime Text (3) to recognise parentheses as foldable?

As an example of problem code, here’s a common structure I use for defining DOM templates (using Mithril):

module.exports = {
	controller : function(){
		this.toggleMenu = function(){
			model.menuExpanded( !model.menuExpanded() );
		}
	},
	view       : function( ctrl ){
		return m( 'div', {
			className : 'page' + ( model.menuExpanded() ? ' menuExpanded' : '' )
		}, 
			m( 'button.btn.btn-large', {
				onclick : ctrl.toggleMenu
			}, 
				m( 'span.glyphicon.glyphicon-th-list',
					m( 'span.text-hide', 'Toggle menu display' )
				)
			] )
		] );
	}
};

The majority of the code above is unfoldable as it stands. Is there a RegEx I can modify somewhere to allow multi-line parentheses content to be identified as a collapsible island?

1 Like

#2

In the same boat here… Any news on this?

Did you find a solution @barney ?

0 Likes

#3

currently the fold arrows in the gutter are indentation based, not syntax based, and only show if there is more than 1 indented line.

however, one can select code to fold it manually, or try the Edit menu -> Code Folding levels, or a plugin like https://packagecontrol.io/packages/BracketHighlighter which may offer additional folding support

0 Likes