A use for code folding

Here’s my tip on how to use the IDE’s code folding feature for good rather than evil.

Create a new LiveTemplate, call it “assert” and use this XML code for the template text.

<?xml version="1.0" encoding="utf-8" ?>
<codetemplate	xmlns="http://schemas.borland.com/Delphi/2005/codetemplates"
	<template name="assert" surround="false" invoke="auto">
		<point name="condition">
			{$REGION 'Assert'}Assert(...){$ENDREGION}
			Lachlan Gemmell
		<code language="Delphi" context="methodbody" delimiter="|">
			<![CDATA[{$REGION 'Assert'}Assert(|condition|);{$ENDREGION}]]>

Now trigger the template whenever you write an assert statement, which we all use liberally of course 😉

You’ll get an assert statement wrapped in a single line region. Sounds pointless but trust me there is a reason.

Fill in the assert condition and message parameters then collapse the region either with the mouse or the key combination Ctrl+Shift+K,E

Your distracting full length Assert statement will be reduced to a nice unobtrusive single word “Assert”. It makes code with lots of Assert statements much easier to read but doesn’t hide their existence from you.

I also do a similar thing with SmartInspect/CodeSite logging statements.

You’ll find an extended video walkthrough including the LiveTemplate creation process here.

Posted in IDE, Language