<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ole Bakstad&#039;s blog &#187; snippets</title>
	<atom:link href="http://dibon.net/wordpress/tag/snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://dibon.net/wordpress</link>
	<description>About stuff that happens, when it happens, if it happens.</description>
	<lastBuildDate>Mon, 15 Jun 2009 20:08:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Bug when trying to edit existing snippets in gedit</title>
		<link>http://dibon.net/wordpress/bug-when-trying-to-edit-existing-snippets-in-gedit/</link>
		<comments>http://dibon.net/wordpress/bug-when-trying-to-edit-existing-snippets-in-gedit/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 00:10:56 +0000</pubDate>
		<dc:creator>Ole Bakstad</dc:creator>
				<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[problem]]></category>
		<category><![CDATA[save]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://dibon.net/wordpress/?p=27</guid>
		<description><![CDATA[When trying to edit the existing snippets in gedit the changes was  gone the next time I opened gedit. It turns out that the predefined snippets is located in /usr/share/gedit-2/plugins/snippets/ (I&#8217;m running Ubuntu 8.04). To edit these files you need root access, which gedit doesn&#8217;t have (unless you do &#8220;sudo gedit&#8221; or something). To fix [...]]]></description>
			<content:encoded><![CDATA[<p>When trying to edit the existing snippets in gedit the changes was  gone the next time I opened gedit. It turns out that the predefined snippets is located in /usr/share/gedit-2/plugins/snippets/ (I&#8217;m running Ubuntu 8.04). To edit these files you need root access, which gedit doesn&#8217;t have (unless you do &#8220;sudo gedit&#8221; or something). To fix this I moved the snippet files from /usr/share/gedit-2/plugins/snippets/ into ~/.gnome2/gedit/snippets/. Fix in terminal:</p>
<pre lang="">sudo cp /usr/share/gedit-2/plugins/snippets/* ~/.gnome2/gedit/snippets</pre>
<p>It&#8217;s probably possible to change the permission of the files too.</p>
]]></content:encoded>
			<wfw:commentRss>http://dibon.net/wordpress/bug-when-trying-to-edit-existing-snippets-in-gedit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use and write snippets</title>
		<link>http://dibon.net/wordpress/how-to-use-and-write-snippets/</link>
		<comments>http://dibon.net/wordpress/how-to-use-and-write-snippets/#comments</comments>
		<pubDate>Tue, 17 Jun 2008 16:27:26 +0000</pubDate>
		<dc:creator>Ole Bakstad</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips & Hints]]></category>
		<category><![CDATA[gedit]]></category>
		<category><![CDATA[saver]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://dibon.net/wordpress/?p=25</guid>
		<description><![CDATA[In TextMate and in gedit (probably more editors too) you have the option to use snippets. I love snippets, and they make my day much easier.
To make a snippet you have to define a tab-trigger which is a word or a random sequence of characters that you will remember. Then you have to write the [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://macromates.com/" target="_blank">TextMate</a> and in <a href="http://www.gnome.org/projects/gedit/" target="_blank">gedit</a> (probably more editors too) you have the option to use <a href="http://en.wikipedia.org/wiki/Code_snippets" target="_blank">snippets</a>. I love snippets, and they make my day much easier.</p>
<p>To make a snippet you have to define a tab-trigger which is a word or a random sequence of characters that you will remember. Then you have to write the snippet body.</p>
<p><strong>Easy example</strong>: If and else statements. When you write &#8220;ife&#8221; and press tab you want an if-else statement to pop up. We write the snippet:</p>
<div class="geshi no php">
<div class="head">if($1)</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $<span class="nu0">2</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $<span class="nu0">0</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>$0, $1 and $2 are where the cursor will be placed. When you first type &#8220;ife&#8221; and press the tab button the cursor will be where the $1 is. If you hit tab again the cursor moves to $2 and so on, but you always ends up at $0. Now you can use this snippet whenever you need it. Just write &#8220;ife&#8221; press tab and fill inn the code you need.</p>
<p><strong>More advanced example</strong>: Lets say you are getting tired of writing all the code for a for loop every time you need one. Make a snippet!. We set the tab-trigger to be the string &#8220;for&#8221; and write the snippet:</p>
<div class="geshi no php">
<div class="head">for (\$${1:i}=${2:0}; \$${1:i} &lt; $3; \$${1:i}++)</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; $<span class="nu0">0</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>What the ${1:i} does is that it sets the 1st cursor position <em>and</em> sets a default value (&#8220;i&#8221; in this case). The default value is marked, so when you tab to the position you can immediately overwrite the default text. And an other thing in this example worth mentioning is that we use ${1:i} more than once. This enables you to change the default at more than one place at once. Let&#8217;s say you don&#8217;t want your variable called &#8220;i&#8221;, but &#8220;index&#8221;. You still just write &#8220;for&#8221;, press tab, and &#8220;i&#8221; is marked. You now write &#8220;index&#8221;, and the &#8220;i&#8221; in all 3 places where it&#8217;s used will change to &#8220;index&#8221;. Then tab again to set the start value of the for loop, and yet again to set the max value for the loop. After choosing variable name, start value and max value you just have one tab left. The last tab brings to you $0 and you&#8217;re ready to write some code inside the for loop. If you tab one more time while the cursor is at $0 the tab sequence will start over.</p>
]]></content:encoded>
			<wfw:commentRss>http://dibon.net/wordpress/how-to-use-and-write-snippets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
