<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">

    <title type="text">Espresso Wiki</title>
    <subtitle type="text">Espresso Wiki</subtitle>
    <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/" />
    <link rel="self" type="application/atom+xml" href="http://wiki.macrabbit.com/index/Special:Recentchanges_Atom" />
    <updated>2011-12-15T17:35:53Z</updated>
    <rights>Copyright (c) 2008, info@macrabbit.com</rights>
    <generator uri="http://expressionengine.com/" version="1.6.5">ExpressionEngine</generator>
    <id>tag:wiki.macrabbit.com,2011:12:15:wiki</id>


    <entry>
      <title>CodeSense</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/CodeSense/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:CodeSense/14.226</id>
      <published>2011-12-15T17:35:53Z</published>
      <updated>2011-12-15T17:35:53Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>CodeSense is the name of the auto-completion system in Espresso. CodeSense provides contextually-aware completions based on syntax zones.</p>

	<p>There are two components for CodeSense: <a href="#libraries">libraries</a> and <a href="#providers">providers</a>.</p>

	<h2 id="libraries">CodeSenseLibraries</h2>

	<p><span class="caps">XML</span> files within your CodeSenseLibraries folder define the possible completions for your Sugar, grouped into sets. Libraries contain no logic regarding when various sets should be shown to the user, but they do offer the ability to specify text snippets for use with specific sets or strings (see <a href="http://wiki.macrabbit.com/index/SnippetSyntax/" title="SnippetSyntax">SnippetSyntax</a> for more info about text snippets).</p>

	<p><span class="caps">XML</span> files within CodeSenseLibraries can be named anything you wish, and use this basic syntax:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?xml&nbsp;version</span><span style="color: #007700">=</span><span style="color: #DD0000">"1.0"&nbsp;</span><span style="color: #0000BB">encoding</span><span style="color: #007700">=</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #0000BB">?&gt;<br /></span><span style="color: #007700">&lt;</span><span style="color: #0000BB">codesense&nbsp;version</span><span style="color: #007700">=</span><span style="color: #DD0000">"1.0"</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">set&nbsp;name</span><span style="color: #007700">=</span><span style="color: #DD0000">"com.yourdomain.yoursugar.fruits"</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completion&nbsp;string</span><span style="color: #007700">=</span><span style="color: #DD0000">"apple"&nbsp;</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completion&nbsp;string</span><span style="color: #007700">=</span><span style="color: #DD0000">"pear"&nbsp;</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completion&nbsp;string</span><span style="color: #007700">=</span><span style="color: #DD0000">"orange"&nbsp;</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style="color: #0000BB">set</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">set&nbsp;name</span><span style="color: #007700">=</span><span style="color: #DD0000">"com.yourdomain.yoursugar.vegetables"</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completion&nbsp;string</span><span style="color: #007700">=</span><span style="color: #DD0000">"carrot"&nbsp;</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completion&nbsp;string</span><span style="color: #007700">=</span><span style="color: #DD0000">"cabbage"&nbsp;</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completion&nbsp;string</span><span style="color: #007700">=</span><span style="color: #DD0000">"potato"&nbsp;</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style="color: #0000BB">set</span><span style="color: #007700">&gt;<br /><br />&lt;/</span><span style="color: #0000BB">codesense</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>Each <strong>&lt;set&gt;</strong> has a name (which will be used in the <a href="#providers">CodeSenseProviders</a> to determine when to use these completions), and each <strong>&lt;completion&gt;</strong> element has a string attribute that will be suggested to the user.</p>

	<p>To use <strong>text snippets</strong>, you must add an additional <strong>&lt;behavior&gt;</strong> element. Behaviors cascade, so if you place a behavior in the root <strong>&lt;codesense&gt;</strong> element it will be used by default for all sets. If you have a behavior within a <strong>&lt;set&gt;</strong>, it will be used instead of the default behavior (if there is one) for all completion strings in the set. And if you nest a behavior within a <strong>&lt;completion&gt;</strong> it will be used only for that string instead of any behavior in the set or root element.</p>

	<p>There are two types of behaviors, but they use very similar syntax:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">behavior</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">append</span><span style="color: #007700">-static&nbsp;</span><span style="color: #0000BB">inserts&nbsp;the&nbsp;snippet&nbsp;immediately&nbsp;after&nbsp;the&nbsp;completion&nbsp;string&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">append</span><span style="color: #007700">-static&gt;</span><span style="color: #0000BB">snippet&nbsp;here</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">append</span><span style="color: #007700">-static&gt;<br />&lt;/</span><span style="color: #0000BB">behavior</span><span style="color: #007700">&gt;<br /><br />&lt;</span><span style="color: #0000BB">behavior</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">append</span><span style="color: #007700">-</span><span style="color: #0000BB">dynamic&nbsp;allows&nbsp;dynamically&nbsp;generated&nbsp;snippets&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">append</span><span style="color: #007700">-</span><span style="color: #0000BB">dynamic</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">matched</span><span style="color: #007700">-</span><span style="color: #0000BB">suffix&nbsp;captures&nbsp;information&nbsp;about&nbsp;following&nbsp;text&nbsp;via&nbsp;regex&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">matched</span><span style="color: #007700">-</span><span style="color: #0000BB">suffix</span><span style="color: #007700">&gt;(</span><span style="color: #0000BB">\s</span><span style="color: #007700">*</span><span style="color: #0000BB">\&#123;</span><span style="color: #007700">)|</span><span style="color: #0000BB">\s</span><span style="color: #007700">*</span><span style="color: #0000BB">&#91;</span><span style="color: #007700">^</span><span style="color: #0000BB">&#123;&#93;</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">matched</span><span style="color: #007700">-</span><span style="color: #0000BB">suffix</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">transform</span><span style="color: #007700">-</span><span style="color: #0000BB">into&nbsp;generates&nbsp;a&nbsp;snippet&nbsp;based&nbsp;on&nbsp;the&nbsp;groups&nbsp;in&nbsp;matched</span><span style="color: #007700">-</span><span style="color: #0000BB">suffix&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">transform</span><span style="color: #007700">-</span><span style="color: #0000BB">into</span><span style="color: #007700">&gt;(?</span><span style="color: #0000BB">1</span><span style="color: #007700">::&nbsp;</span><span style="color: #0000BB">&#123;</span><span style="color: #007700">$</span><span style="color: #0000BB">0&#125;</span><span style="color: #007700">)&lt;/</span><span style="color: #0000BB">transform</span><span style="color: #007700">-</span><span style="color: #0000BB">into</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style="color: #0000BB">append</span><span style="color: #007700">-</span><span style="color: #0000BB">dynamic</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">confirm&nbsp;is&nbsp;optional&nbsp;</span><span style="color: #007700">and&nbsp;</span><span style="color: #0000BB">can&nbsp;be&nbsp;used&nbsp;</span><span style="color: #007700">for&nbsp;</span><span style="color: #0000BB">any&nbsp;type&nbsp;of&nbsp;behavior&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">confirm&nbsp;characters</span><span style="color: #007700">=</span><span style="color: #DD0000">"&#123;"</span><span style="color: #007700">/&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">partial</span><span style="color: #007700">-</span><span style="color: #0000BB">confirm&nbsp;is&nbsp;optional&nbsp;</span><span style="color: #007700">and&nbsp;</span><span style="color: #0000BB">can&nbsp;be&nbsp;used&nbsp;</span><span style="color: #007700">for&nbsp;</span><span style="color: #0000BB">any&nbsp;type&nbsp;of&nbsp;behavior&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">partial</span><span style="color: #007700">-</span><span style="color: #0000BB">confirm&nbsp;characters</span><span style="color: #007700">=</span><span style="color: #DD0000">"_"</span><span style="color: #007700">/&gt;<br />&lt;/</span><span style="color: #0000BB">behavior</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p><strong>Static appends</strong> are straight-forward: if the user chooses the related CodeSense completion string, the snippet in <strong>&lt;append-static&gt;</strong> is inserted after the string no matter what.</p>

	<p><strong>Dynamic appends</strong> are more complicated. The <strong>&lt;matched-suffix&gt;</strong> element is a standard regular expression that can optionally contain capture groups, and it is tested on the characters immediately after the string the user is inserting via CodeSense. Like all regex in Sugars, <strong>&lt;matched-suffix&gt;</strong> is constrained to a single line.</p>

	<p>The <strong>&lt;transform-into&gt;</strong> element typically uses regex conditional logic based on the capture groups in the <strong>&lt;matched-suffix&gt;</strong> element. This uses this syntax:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">(?</span><span style="color: #0000BB">x</span><span style="color: #007700">:</span><span style="color: #0000BB">a</span><span style="color: #007700">:</span><span style="color: #0000BB">b</span><span style="color: #007700">)&nbsp;</span>
</span>
</code></div></p>

	<p>Which means: if capture group number &#8220;x&#8221; has contents, insert &#8220;a&#8221;. Otherwise, insert &#8220;b&#8221;.</p>

	<p>So in the example, if the string is followed by zero or more spaces and a curly brace, there will be something in capture group 1. Then <strong>&lt;transform-into&gt;</strong> specifies that if something is inside capture group 1, nothing is inserted (the location of &#8220;a&#8221; is blank). If the string is <em>not</em> followed by optional whitespace and a curly brace, though, a snippet with matched curly braces is inserted with a tab stop in between them (see <a href="http://wiki.macrabbit.com/index/SnippetSyntax/" title="SnippetSyntax">SnippetSyntax</a> for in-depth info about snippet syntax).</p>

	<p>This system can be tricky to get your head around. For real-world examples, make sure to open up the Sugars bundled with Espresso and see how they are using dynamic appends to insert different snippets based on context.</p>

	<p>The <strong>&lt;confirm&gt;</strong> and <strong>&lt;partial-confirm&gt;</strong> elements allow you to specify characters that will complete or advance the CodeSense completion in addition to tab and enter. For instance, in the built-in <span class="caps">CSS</span>.sugar hyphens (-) are used as a partial-comfirm character so that you can type something like &#8220;bo-t&#8221; and end up with &#8220;border-top&#8221;. Then the colon (:) is used to confirm CodeSense entries, so you could type &#8220;bo-t:&#8221; to insert &#8220;border-top&#8221;. In general, you should use confirm and partial-confirm characters sparingly. They work well for speeding up CodeSense in languages like <span class="caps">CSS</span> where the user is not defining their own properties, but for other languages where the user might have a custom variable or function that starts the same as a built-in CodeSense completion string, confirm characters can be maddening.</p>

	<h2 id="providers">CodeSenseProviders</h2>

	<p>The <span class="caps">XML</span> files in your CodeSenseProviders folder define the rules that tell Espresso when to display the sets you defined in your &#8220;CodeSenseLibraries&#8221;#libraries and use the following syntax:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?xml&nbsp;version</span><span style="color: #007700">=</span><span style="color: #DD0000">"1.0"&nbsp;</span><span style="color: #0000BB">encoding</span><span style="color: #007700">=</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #0000BB">?&gt;<br /></span><span style="color: #007700">&lt;</span><span style="color: #0000BB">codesense</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">provider</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">The&nbsp;selector&nbsp;when&nbsp;this&nbsp;provider&nbsp;is&nbsp;active&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">selector</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">js</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">js&nbsp;</span><span style="color: #007700">*:</span><span style="color: #0000BB">not</span><span style="color: #007700">(</span><span style="color: #0000BB">string</span><span style="color: #007700">,</span><span style="color: #0000BB">string&nbsp;</span><span style="color: #007700">*,</span><span style="color: #0000BB">comment</span><span style="color: #007700">)&lt;/</span><span style="color: #0000BB">selector</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">complete</span><span style="color: #007700">-</span><span style="color: #0000BB">match&nbsp;determines&nbsp;what&nbsp;characters&nbsp;are&nbsp;required&nbsp;</span><span style="color: #007700">for&nbsp;</span><span style="color: #0000BB">this&nbsp;provider&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">complete</span><span style="color: #007700">-</span><span style="color: #0000BB">match</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">\b&#91;a</span><span style="color: #007700">-</span><span style="color: #0000BB">zA</span><span style="color: #007700">-</span><span style="color: #0000BB">Z&#93;</span><span style="color: #007700">*&lt;/</span><span style="color: #0000BB">complete</span><span style="color: #007700">-</span><span style="color: #0000BB">match</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">completions&nbsp;</span><span style="color: #007700">use&nbsp;</span><span style="color: #0000BB">the&nbsp;set&nbsp;names&nbsp;you&nbsp;defined&nbsp;in&nbsp;your&nbsp;libraries&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completions</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">macrabbit</span><span style="color: #007700">.</span><span style="color: #0000BB">js</span><span style="color: #007700">.</span><span style="color: #0000BB">DOM</span><span style="color: #007700">-</span><span style="color: #0000BB">support</span><span style="color: #007700">.</span><span style="color: #0000BB">variables</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">completions</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completions</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">macrabbit</span><span style="color: #007700">.</span><span style="color: #0000BB">js</span><span style="color: #007700">.</span><span style="color: #0000BB">functions</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">completions</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style="color: #0000BB">provider</span><span style="color: #007700">&gt;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">Many&nbsp;providers&nbsp;can&nbsp;be&nbsp;defined&nbsp;in&nbsp;the&nbsp;same&nbsp;XML&nbsp;file&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">provider</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;(</span><span style="color: #0000BB">selector</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">completions</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">etc</span><span style="color: #007700">.&nbsp;</span><span style="color: #0000BB">here</span><span style="color: #007700">)&nbsp;--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style="color: #0000BB">provider</span><span style="color: #007700">&gt;<br />&lt;/</span><span style="color: #0000BB">codesense</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>In the example, zero or more letters are required and the syntax context must be JavaScript source code (but not a string or comment). If both of these requirements are met, the completions in the two sets listed will be displayed to the user.</p>

	<p>You can also use the <code>:capture()</code> pseudo-element in selectors to attach sets to a provider dynamically. For instance, in the <span class="caps">CSS</span>.sugar this is how attribute values are defined in the CodeSenseProviders:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">provider</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">selector</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">css&nbsp;</span><span style="color: #007700">&gt;&nbsp;</span><span style="color: #0000BB">property</span><span style="color: #007700">-</span><span style="color: #0000BB">name</span><span style="color: #007700">:</span><span style="color: #0000BB">capture</span><span style="color: #007700">(</span><span style="color: #0000BB">name</span><span style="color: #007700">)&nbsp;+&nbsp;</span><span style="color: #0000BB">property</span><span style="color: #007700">-</span><span style="color: #0000BB">value&nbsp;punctuation</span><span style="color: #007700">.</span><span style="color: #0000BB">separator</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">selector</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">The&nbsp;</span><span style="color: #DD0000">'name'&nbsp;</span><span style="color: #0000BB">variable&nbsp;is&nbsp;the&nbsp;textual&nbsp;contents&nbsp;of&nbsp;the&nbsp;captured&nbsp;zone&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;</span><span style="color: #0000BB">So&nbsp;in&nbsp;this&nbsp;</span><span style="color: #007700">case,&nbsp;</span><span style="color: #0000BB">it&nbsp;will&nbsp;be&nbsp;things&nbsp;like&nbsp;</span><span style="color: #DD0000">"display"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"float"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">etc</span><span style="color: #007700">.&nbsp;--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">completions</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">macrabbit</span><span style="color: #007700">.</span><span style="color: #0000BB">css</span><span style="color: #007700">.</span><span style="color: #0000BB">property</span><span style="color: #007700">.</span><span style="color: #0000BB">$&#123;name&#125;</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">completions</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">complete</span><span style="color: #007700">-</span><span style="color: #0000BB">match</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">&#91;a</span><span style="color: #007700">-</span><span style="color: #0000BB">zA</span><span style="color: #007700">-</span><span style="color: #0000BB">Z0</span><span style="color: #007700">-</span><span style="color: #0000BB">9</span><span style="color: #007700">-</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">*&lt;/</span><span style="color: #0000BB">complete</span><span style="color: #007700">-</span><span style="color: #0000BB">match</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--&nbsp;(</span><span style="color: #0000BB">Optional</span><span style="color: #007700">)&nbsp;require-</span><span style="color: #0000BB">suffix&nbsp;defines&nbsp;a&nbsp;regex&nbsp;text&nbsp;</span><span style="color: #007700">*</span><span style="color: #0000BB">after</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">completion&nbsp;has&nbsp;to&nbsp;match&nbsp;</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;require-</span><span style="color: #0000BB">suffix</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">&#91;</span><span style="color: #007700">^:</span><span style="color: #0000BB">&#93;</span><span style="color: #007700">|&lt;/require-</span><span style="color: #0000BB">suffix</span><span style="color: #007700">&gt;<br />&lt;/</span><span style="color: #0000BB">provider</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>A named capture is being used to map one provider onto an arbitrary number of set names. For instance, the <span class="caps">CSS</span> CodeSenseLibraries will contain sets named &#8220;com.macrabbit.css.property.display&#8221;, &#8220;com.macrabbit.css.property.float&#8221;, etc. to define completion strings for different <span class="caps">CSS</span> properties.</p>

	<p>The <strong>&lt;require-suffix&gt;</strong> element is an optional element that restricts CodeSense depending on whether or not the characters to the right of the cursor match the provided regex. In this instance, the rule will only be shown if the character to the cursor&#8217;s right is not a colon (:).</p>
      ]]></content>
    </entry>

    <entry>
      <title>SugarDev.sugar</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/SugarDev.sugar/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:SugarDev.sugar/39.224</id>
      <published>2011-12-05T22:32:04Z</published>
      <updated>2011-12-05T22:32:04Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>The SugarDev.sugar adds CodeSense for Sugar <span class="caps">XML</span> elements and the JavaScript <span class="caps">API</span> along with snippets for the base <span class="caps">XML</span> documents, making it easier to author Espresso Sugars.</p>

	<p><a href="http://wiki.macrabbit.com/downloads/SugarDev.sugar.zip">Download SugarDev.sugar</a></p>

	<p>Unzip the Sugar and double click it to install (as with any other Sugar), then relaunch Espresso to gain access to the new CodeSense and snippets.</p>
      ]]></content>
    </entry>

    <entry>
      <title>index</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/index/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:index/1.222</id>
      <published>2011-11-10T19:24:28Z</published>
      <updated>2011-11-10T19:24:28Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>Welcome! If you want to develop custom <strong>Sugars or themes</strong> for Espresso, you are in the right place!</p>

	<p>If you are <strong>using the program</strong> and need help, please choose <strong>Help&rarr;Send Feedback&#8230;</strong> in the app and ask us your questions directly.</p>

	<p>If you want to <strong>download</strong> custom Sugars or themes, please choose <strong>Help&rarr;Get Sugar Plug-Ins&#8230;</strong> in the app, or search GitHub (vast majority of Sugars and themes end up on GitHub).</p>

	<h2 id="getting-started">Getting started</h2>

	<p>If you are new to Sugar development, here are some good starting points:</p>

	<ul>
		<li>Introduce yourself to the <a href="http://wiki.macrabbit.com/index/SugarBasics/" title="SugarBasics">SugarBasics</a> and <a href="http://wiki.macrabbit.com/index/SugarStructure/" title="SugarStructure">SugarStructure</a></li>
		<li>Create custom <a href="http://wiki.macrabbit.com/index/SyntaxThemes/" title="SyntaxThemes">SyntaxThemes</a> to change the colors of your code</li>
		<li>Learn <a href="http://wiki.macrabbit.com/index/LanguageSugars/" title="LanguageSugars">LanguageSugars</a> so you can add support for a new language, or improve an existing one</li>
		<li>Craft new <a href="http://wiki.macrabbit.com/index/CodeSense/" title="CodeSense">CodeSense</a> to add auto-completion to new or existing languages</li>
		<li>Dive into <a href="http://wiki.macrabbit.com/index/JavaScriptActions/" title="JavaScriptActions">JavaScriptActions</a> and supercharge your code editing</li>
	</ul>

	<h2 id="reference">Reference</h2>

	<p>If you are already comfortable with Espresso Sugars and themes, here are some links to jump quickly to various info:</p>

	<ul>
		<li><a href="http://wiki.macrabbit.com/index/SugarBasics/" title="SugarBasics">SugarBasics</a> and <a href="http://wiki.macrabbit.com/index/SugarStructure/" title="SugarStructure">SugarStructure</a></li>
	</ul>

	<ul>
		<li><a href="http://wiki.macrabbit.com/index/Selectors/" title="Selectors">Selectors</a></li>
		<li><a href="http://wiki.macrabbit.com/index/SyntaxThemes/" title="SyntaxThemes">SyntaxThemes</a></li>
		<li><a href="http://wiki.macrabbit.com/index/Snippets/" title="Snippets">Snippets</a> and <a href="http://wiki.macrabbit.com/index/SnippetSyntax/" title="SnippetSyntax">SnippetSyntax</a></li>
	</ul>

	<ul>
		<li><a href="http://wiki.macrabbit.com/index/LanguageSugars/" title="LanguageSugars">LanguageSugars</a></li>
		<li><a href="http://wiki.macrabbit.com/index/CodeSense/" title="CodeSense">CodeSense</a></li>
		<li><a href="http://wiki.macrabbit.com/index/Syntaxes/" title="Syntaxes">Syntaxes</a> and <a href="http://wiki.macrabbit.com/index/LanguagesXML/" title="LanguagesXML">LanguagesXML</a></li>
		<li><a href="http://wiki.macrabbit.com/index/Itemizers/" title="Itemizers">Itemizers</a></li>
		<li><a href="http://wiki.macrabbit.com/index/ContextualSettings/" title="ContextualSettings">ContextualSettings</a></li>
	</ul>

	<ul>
		<li><a href="http://wiki.macrabbit.com/index/JavaScriptActions/" title="JavaScriptActions">JavaScriptActions</a></li>
		<li><a href="http://wiki.macrabbit.com/index/ActionXML/" title="ActionXML">ActionXML</a></li>
		<li><a href="http://wiki.macrabbit.com/index/Localizable.strings/" title="Localizable.strings">Localizable.strings</a></li>
		<li><a href="http://wiki.macrabbit.com/index/JavaScriptAPI/" title="JavaScriptAPI">JavaScriptAPI</a></li>
		<li><a href="http://wiki.macrabbit.com/index/CocoaAPI/" title="CocoaAPI">CocoaAPI</a></li>
	</ul>

	<p>If you&#8217;re an old hand with Espresso Sugars, you may be interested in the <a href="http://wiki.macrabbit.com/index/RecentChanges/" title="RecentChanges">RecentChanges</a>.</p>
      ]]></content>
    </entry>

    <entry>
      <title>SnippetSyntax</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/SnippetSyntax/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:SnippetSyntax/29.221</id>
      <published>2011-10-04T21:31:48Z</published>
      <updated>2011-10-04T21:31:48Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>Espresso snippets allow you to automatically fill in certain information, navigate through multiple tab stops, execute shell commands, and more.  However, because this functionality requires a special syntax you have to escape some characters (most notably the <code>$</code>, <code>\</code>, and <code>`</code> characters) with a backslash in order to have them output.  So for instance, if you want a literal <code>$</code> in your snippet you would enter <code>\$</code>.</p>

	<p>To create new snippets, see <a href="http://wiki.macrabbit.com/index/Snippets/" title="Snippets">Snippets</a>. Snippets offer the following features:</p>

	<ul>
		<li><a href="#tab-stops">Tab stops</a></li>
		<li><a href="#variables">Snippet variables</a></li>
		<li><a href="#shell-code">Shell code</a></li>
	</ul>

	<h2 id="tab-stops">Tab stops</h2>

	<p>A tab stop is a special area in your snippet that is automatically selected when your snippet is inserted.  Using tab stops you can quickly fill in the details for a snippet by hitting tab and shift-tab to move between them.  Tab stops come in three flavors: plain stops, placeholder text, and mirrored stops.</p>

	<p>A <strong>plain tab stop</strong> uses the format <code>$n</code>, and the cursor will advance in numeric order with $0 as a special final stop:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">p&nbsp;id</span><span style="color: #007700">=</span><span style="color: #DD0000">"$1"</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">2</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">p</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">0&nbsp;</span>
</span>
</code></div></p>

	<p>When you insert this snippet, your cursor will be inside the ID attribute. Then when you hit tab it will move between the paragraph tags, and when you hit tab a final time will move outside the paragraph.</p>

	<p>A tab stop with <strong>placeholder text</strong> uses the format <code>$&#123;n:placeholder&#125;</code>, and you can nest tab stops within one another:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">p$&#123;1</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">id</span><span style="color: #007700">=</span><span style="color: #DD0000">"$2"</span><span style="color: #0000BB">&#125;</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">$&#123;3</span><span style="color: #007700">:</span><span style="color: #0000BB">your&nbsp;text&nbsp;here&#125;</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">p</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">0&nbsp;</span>
</span>
</code></div></p>

	<p>When you insert this snippet, the text <code>id=&quot;&quot;</code> will be selected. If you hit tab, your cursor will be placed inside the ID attribute. A second tab will select the text &#8216;your text here&#8217; and a third will take the cursor outside the paragraph.  If you had decided you didn&#8217;t want an ID on this particular paragraph, you could hit delete to remove the first selected text, and then when you hit tab you would jump to the &#8216;your text here&#8217; stop.</p>

	<p>A <strong>mirrored</strong> tab stop outputs the text that you enter in one tab stop somewhere else in the snippet.  For instance, you could create a simple <span class="caps">HTML</span> tag like so:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">$&#123;1</span><span style="color: #007700">:</span><span style="color: #0000BB">p&#125;</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">2</span><span style="color: #007700">&lt;/$</span><span style="color: #0000BB">1</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">0&nbsp;</span>
</span>
</code></div></p>

	<p>Because tab stop #1 occurs in multiple places, it will be mirrored. So if you insert this snippet and type <code>li</code>, you will end up with an LI tag.</p>

	<p>A second type of mirrored tab stop is a <strong>transformation</strong>.  Transformations use the syntax <code>$&#123;n/regex/replacement/flags&#125;</code>.  For instance, here&#8217;s a more advanced version of the tag insertion snippet above:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">$&#123;1</span><span style="color: #007700">:</span><span style="color: #0000BB">p&#125;</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">2</span><span style="color: #007700">&gt;&lt;/</span><span style="color: #0000BB">$&#123;1</span><span style="color: #007700">/</span><span style="color: #0000BB">\s</span><span style="color: #007700">.*</span><span style="color: #FF8000">//&#125;&gt;$0&nbsp;</span>
</span>
</code></div></p>

	<p>This snippet will behave identically to the previous mirrored snippet, except that if you decide to enter any attributes in the opening tag they will not be mirrored to the closing tag.  This is because of the transformation in the closing tag which says &#8220;take the first tab stop, search for a whitespace character followed by any other characters, and replace that with nothing using no special flags&#8221;.</p>

	<p><em>Further documentation on the available flags and other advanced transformation techniques is forthcoming.</em></p>

	<h2 id="variables">Snippet variables</h2>

	<p>You can use several variables for snippets to do things like include selected text in a snippet.  Available placeholders include:</p>

	<ul>
		<li><strong><span class="caps">EDITOR</span>_SELECTION</strong>: the selected text, if any, when the snippet is invoked</li>
		<li><strong><span class="caps">EDITOR</span>_SELECTION_LINE</strong>: the contents of the first line of the selection when the snippet is invoked</li>
		<li><strong><span class="caps">EDITOR</span>_SELECTION_LINENUMBER</strong>: the number of the first selected line in the document when the snippet is invoked</li>
		<li><strong><span class="caps">EDITOR</span>_URL</strong>: the <span class="caps">URL</span> of the current file &#40;e.g. <code>file://localhost/Users/myaccount/myproject/dir/myfile.html</code>&#41;</li>
		<li><strong><span class="caps">EDITOR</span>_PATH</strong>: the absolute path to the file &#40;e.g. <code>/Users/myaccount/myproject/dir/myfile.html</code>&#41;</li>
		<li><strong><span class="caps">EDITOR</span>_DIRECTORY_PATH</strong>: the absolute path to the file&#8217;s parent directory (e.g. <code>/Users/myaccount/myproject/dir</code>)</li>
		<li><strong><span class="caps">EDITOR</span>_PROJECT_PATH</strong>: the absolute path to the project root directory (e.g. <code>/Users/myaccount/myproject</code>)</li>
	</ul>

	<p>To use a placeholder in a snippet, simply prepend a dollar sign to the variable name:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">p</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">This&nbsp;is&nbsp;the&nbsp;selected&nbsp;text</span><span style="color: #007700">:&nbsp;</span><span style="color: #0000BB">$EDITOR_SELECTION</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">p</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>You can also specify an alternative in case the variable is empty:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">$&#123;EDITOR_SELECTION</span><span style="color: #007700">:</span><span style="color: #0000BB">Sorry</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">no&nbsp;selection</span><span style="color: #007700">!</span><span style="color: #0000BB">&#125;&nbsp;</span>
</span>
</code></div></p>

	<p>By combining variable alternatives with tab stops, you can easily create snippets that will fill in the information if they have it and prompt you if not:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">a&nbsp;href</span><span style="color: #007700">=</span><span style="color: #DD0000">"$1"</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">$&#123;EDITOR_SELECTION</span><span style="color: #007700">:$</span><span style="color: #0000BB">2&#125;</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">a</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>Espresso also recognizes Textmate snippet variables for which there is a corresponding $EDITOR_* variable, and will fill them in intelligently.  For instance, if your snippet includes $TM_SELECTED_TEXT, Espresso will insert the contents of $EDITOR_SELECTION.</p>

	<h2 id="shell-code">Shell code</h2>

	<p>You can execute shell code directly within your snippet by surrounding it with backticks.  For instance, this will use the shell command <em>pbpaste</em> to insert the contents of the clipboard as the default contents of an href attribute:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">a&nbsp;href</span><span style="color: #007700">=</span><span style="color: #DD0000">"$&#123;1:`pbpaste`&#125;"</span><span style="color: #007700">&gt;$</span><span style="color: #0000BB">2</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">a</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>You can get much more complicated, as well, by including small shell programs within backticks.  The only character you have to escape to use properly within such shell code is the backtick character.</p>
      ]]></content>
    </entry>

    <entry>
      <title>SugarStructure</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/SugarStructure/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:SugarStructure/30.220</id>
      <published>2011-09-17T15:19:40Z</published>
      <updated>2011-09-17T15:19:40Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>A Sugar is a normal folder with a <code>.sugar</code> extension. Inside that folder, you will create specifically named folders and <span class="caps">XML</span> files depending on what you want your Sugar to do.</p>

	<h2 id="installation">Where to install Sugars</h2>

	<p>Sugars live here:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">~/</span><span style="color: #0000BB">Library</span><span style="color: #007700">/</span><span style="color: #0000BB">Application&nbsp;Support</span><span style="color: #007700">/</span><span style="color: #0000BB">Espresso</span><span style="color: #007700">/</span><span style="color: #0000BB">Sugars&nbsp;</span>
</span>
</code></div></p>

	<p>To access your Library folder in Lion, hold down <strong>option</strong> while you click the Go menu in the Finder, and then click the Library item. Alternatively, run this in Terminal to permanently unhide your Library folder:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">chflags&nbsp;nohidden&nbsp;</span><span style="color: #007700">~/</span><span style="color: #0000BB">Library</span><span style="color: #007700">/&nbsp;</span>
</span>
</code></div></p>

	<p>If the Sugars folder does not exist, create it. Inside create a folder named whatever you want your sugar to be called; for instance MySugar.sugar.</p>

	<p>To open your new Sugar, right click on it and choose <strong>Show Package Contents</strong>. A new window will open in the Finder. This is where you will need to create your Sugar files and folders; we will refer to it as the root Sugar folder throughout this wiki.</p>

	<h2 id="required-files">Required files</h2>

	<p>The <strong>Info.plist</strong> file is the only required file for a Sugar, and should live inside of a Contents folder. To get started with a new Sugar:</p>

	<ol>
		<li>Create your Sugar folder as per above</li>
		<li>Inside your root Sugar folder, create a folder called <strong>Contents</strong></li>
		<li>Inside the Contents folder, create a plain text file called <strong>Info.plist</strong></li>
	</ol>

	<p>Info.plist is a standard Mac OS X file. You can create it with a plist editor, or just edit it in Espresso. Here are example contents:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?xml&nbsp;version</span><span style="color: #007700">=</span><span style="color: #DD0000">"1.0"&nbsp;</span><span style="color: #0000BB">encoding</span><span style="color: #007700">=</span><span style="color: #DD0000">"UTF-8"</span><span style="color: #0000BB">?&gt;<br /></span><span style="color: #007700">&lt;!</span><span style="color: #0000BB">DOCTYPE&nbsp;plist&nbsp;</span><span style="color: #007700">PUBLIC&nbsp;</span><span style="color: #DD0000">"-//Apple//DTD&nbsp;PLIST&nbsp;1.0//EN"&nbsp;"http://www.apple.com/DTDs/PropertyList-1.0.dtd"</span><span style="color: #007700">&gt;<br />&lt;</span><span style="color: #0000BB">plist&nbsp;version</span><span style="color: #007700">=</span><span style="color: #DD0000">"1.0"</span><span style="color: #007700">&gt;<br />&lt;</span><span style="color: #0000BB">dict</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--</span><span style="color: #0000BB">Modify&nbsp;these&nbsp;</span><span style="color: #007700">for&nbsp;</span><span style="color: #0000BB">your&nbsp;Sugar</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">CFBundleName</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">MySugar</span><span style="color: #007700">.</span><span style="color: #0000BB">sugar</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">CFBundleIdentifier</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">com</span><span style="color: #007700">.</span><span style="color: #0000BB">mydomain</span><span style="color: #007700">.</span><span style="color: #0000BB">sugar</span><span style="color: #007700">.</span><span style="color: #0000BB">MySugar</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">CFBundleVersion</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">1.0</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;!--</span><span style="color: #0000BB">No&nbsp;need&nbsp;to&nbsp;modify&nbsp;these&nbsp;values</span><span style="color: #007700">--&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">CFBundleInfoDictionaryVersion</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">6.0</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">CFBundlePackageType</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">BNDL</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">CFBundleSignature</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;????&lt;/</span><span style="color: #0000BB">string</span><span style="color: #007700">&gt;<br />&lt;/</span><span style="color: #0000BB">dict</span><span style="color: #007700">&gt;<br />&lt;/</span><span style="color: #0000BB">plist</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p><a href="/downloads/BasicSugar.zip">Download basic Sugar template</a></p>

	<p>You now have a fully-functioning Sugar (albeit one that adds nothing to Espresso)! If you relaunch Espresso, your Sugar will be silently loaded. In order to add functionality, you now simply need to add <span class="caps">XML</span> files for <a href="http://wiki.macrabbit.com/index/LanguageSugars/" title="LanguageSugars">LanguageSugars</a>, <a href="http://wiki.macrabbit.com/index/CodeSense/" title="CodeSense">CodeSense</a>, <a href="http://wiki.macrabbit.com/index/JavaScriptActions/" title="JavaScriptActions">JavaScriptActions</a>, or similar.</p>

	<h2 id="structure">Full Sugar structure</h2>

	<p>The folders and files inside of a Sugar use the following names and structure. Directories are suffixed with a / character, * is a wildcard for filenames, and bold items are required for all Sugars:</p>

	<ul>
		<li><strong>MySugar.sugar</strong>/
	<ul>
		<li>CodeSenseLibraries/
	<ul>
		<li>*.xml</li>
	</ul></li>
		<li>CodeSenseProviders/
	<ul>
		<li>*.xml</li>
	</ul></li>
		<li><strong>Contents</strong>/
	<ul>
		<li><strong>Info.plist</strong></li>
		<li>Resources/
	<ul>
		<li>*.lproj/
	<ul>
		<li>Localizable.strings</li>
	</ul></li>
	</ul></li>
	</ul></li>
		<li>ContextualSettings/
	<ul>
		<li>*.xml</li>
	</ul></li>
		<li>FileActions/
	<ul>
		<li>*.xml</li>
		<li>*Categories.xml</li>
		<li>*Sorting.xml</li>
	</ul></li>
		<li>Itemizers/
	<ul>
		<li>*.xml</li>
	</ul></li>
		<li>Languages.xml</li>
		<li>PlaceholderThemes/
	<ul>
		<li>*.css</li>
	</ul></li>
		<li>ScriptLibraries/
	<ul>
		<li>*.js</li>
	</ul></li>
		<li>Scripts/
	<ul>
		<li>*.js</li>
	</ul></li>
		<li>Syntaxes/
	<ul>
		<li>*.xml</li>
	</ul></li>
		<li>SyntaxInjections/
	<ul>
		<li>*.xml</li>
	</ul></li>
		<li>TextActions/
	<ul>
		<li>*.xml</li>
		<li>*Categories.xml</li>
		<li>*Sorting.xml</li>
	</ul></li>
	</ul></li>
	</ul>

	<p>Languages.xml, Syntaxes, SyntaxInjections, Itemizers, PlaceholderThemes, and ContextualSettings are all used for <a href="http://wiki.macrabbit.com/index/LanguageSugars/" title="LanguageSugars">LanguageSugars</a>.</p>

	<p>CodeSenseLibraries and CodeSenseProviders are used to define new <a href="http://wiki.macrabbit.com/index/CodeSense/" title="CodeSense">CodeSense</a> auto-completions.</p>

	<p>Scripts, ScriptLibraries, and TextActions are used for <a href="http://wiki.macrabbit.com/index/JavaScriptActions/" title="JavaScriptActions">JavaScriptActions</a>.</p>

	<p>TextActions and FileActions can both be used to create custom actions with the <a href="http://wiki.macrabbit.com/index/CocoaAPI/" title="CocoaAPI">CocoaAPI</a>.</p>

	<p><a href="http://wiki.macrabbit.com/index/Localizable.strings/" title="Localizable.strings">Localizable.strings</a> files make it easy to translate your Sugar&#8217;s user-facing strings into multiple languages.</p>

	<h2 id="tips">Development tips</h2>

	<p>An easy way to work on Sugars without needing to be constantly right clicking them in the Finder is to name your Sugar folder without a .sugar extension, and then create a symlink to it in your Sugars folder. For instance, if you have created a sugar folder called MySugar-sugar in your Sugars folder, you could run this in Terminal to make sure Espresso recognizes it:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">cd&nbsp;</span><span style="color: #007700">~/</span><span style="color: #0000BB">Library</span><span style="color: #007700">/</span><span style="color: #0000BB">Application\&nbsp;Support</span><span style="color: #007700">/</span><span style="color: #0000BB">Espresso</span><span style="color: #007700">/</span><span style="color: #0000BB">Sugars<br />ln&nbsp;</span><span style="color: #007700">-</span><span style="color: #0000BB">s&nbsp;MySugar</span><span style="color: #007700">-</span><span style="color: #0000BB">sugar&nbsp;MySugar</span><span style="color: #007700">.</span><span style="color: #0000BB">sugar&nbsp;</span>
</span>
</code></div></p>

	<p>This also makes it easier to create an Espresso project for your Sugar folder.</p>

	<p>Although we try to keep this wiki up to date with documentation for all portions of the Espresso <span class="caps">API</span>, often the best way to figure out how to do things is to right click on an existing Sugar, choose Show Package Contents, and take a look at what&#8217;s inside. You can find the Sugars bundled with Espresso by right clicking on the application, choosing Show Package Contents, and navigating to Contents/SharedSupport/Sugars (make sure not to save anything in there, though, or it will be lost when you update Espresso!).</p>
      ]]></content>
    </entry>

    <entry>
      <title>Localizable.strings</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/Localizable.strings/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:Localizable.strings/36.219</id>
      <published>2011-09-17T15:18:48Z</published>
      <updated>2011-09-17T15:18:48Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>Your Localizable.strings file&#40;s&#41; allow you to easily translate your Sugar&#8217;s user-visible strings.</p>

	<p>Localizable.strings files live inside of *.lproj folders in the root-level Resources folder of your Sugar. For instance, your English strings will live here:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">MySugar</span><span style="color: #007700">.</span><span style="color: #0000BB">sugar</span><span style="color: #007700">/</span><span style="color: #0000BB">Contents</span><span style="color: #007700">/</span><span style="color: #0000BB">Resources</span><span style="color: #007700">/</span><span style="color: #0000BB">English</span><span style="color: #007700">.</span><span style="color: #0000BB">lproj</span><span style="color: #007700">/</span><span style="color: #0000BB">Localizable</span><span style="color: #007700">.</span><span style="color: #0000BB">strings&nbsp;</span>
</span>
</code></div></p>

	<h2 id="syntax">Syntax</h2>

	<p>Localizable.strings files are plain text files that use the following syntax:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #DD0000">"localizable.id.key"&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Localized&nbsp;string"</span><span style="color: #007700">;<br /></span><span style="color: #DD0000">"another.localizable.id.key"&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Another&nbsp;string"</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>

	<p>Most commonly, you will be localizing the titles for your <a href="http://wiki.macrabbit.com/index/ActionXML/" title="ActionXML">ActionXML</a> files. In this instance, if you have an action with the ID &#8220;com.mydomain.mysugar.text-actions.action-name&#8221; then you would have the following entry in your Localizable.strings file:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #DD0000">"com.mydomain.mysugar.text-actions.action-name.title"&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"My&nbsp;Custom&nbsp;Action"</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>

	<p>If you are localizing a different element, you will append something other than &#8220;title&#8221; to the action ID.</p>
      ]]></content>
    </entry>

    <entry>
      <title>JavaScriptActions</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/JavaScriptActions/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:JavaScriptActions/34.218</id>
      <published>2011-09-06T22:30:17Z</published>
      <updated>2011-09-06T22:30:17Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>Espresso provides a JavaScript <span class="caps">API</span> that allows you to easily script text actions to make Espresso even more useful for your particular workflow.</p>

	<h2 id="layout">Basic layout</h2>

	<p>JavaScript actions are made up of up to three parts:</p>

	<ol>
		<li>The <a href="#xml"><span class="caps">XML</span> definition</a> that tells Espresso how to present the action to the user</li>
		<li>The <a href="#syntax">JavaScript action file</a>, which lives in the Scripts folder</li>
		<li>Optional additional JavaScript files to share logic between multiple actions using <a href="#libraries">ScriptLibraries</a></li>
	</ol>

	<p>Most of the things you can do with the <a href="http://wiki.macrabbit.com/index/CocoaAPI/" title="CocoaAPI">CocoaAPI</a> are possible with JavaScript; notable exceptions are any actions that require custom <span class="caps">GUI</span> and FileActions. For an <span class="caps">API</span> reference, see the <a href="http://wiki.macrabbit.com/index/JavaScriptAPI/" title="JavaScriptAPI">JavaScriptAPI</a>.</p>

	<h2 id="xml"><span class="caps">XML</span> action definitions</h2>

	<p>JavaScript actions use the same <span class="caps">XML</span> syntax as <a href="http://wiki.macrabbit.com/index/ActionXML/" title="ActionXML">all other actions</a>, but instead of associating a <strong>&lt;class&gt;</strong> with the action, they have a <strong>&lt;script&gt;</strong> element:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">&lt;</span><span style="color: #0000BB">action&nbsp;id</span><span style="color: #007700">=</span><span style="color: #DD0000">"com.macrabbit.tea-for-two.text-actions.move-line-up"&nbsp;</span><span style="color: #0000BB">category</span><span style="color: #007700">=</span><span style="color: #DD0000">"menu.ids"</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">script</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">move_line</span><span style="color: #007700">.</span><span style="color: #0000BB">js&lt;/script&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">&lt;</span><span style="color: #0000BB">key</span><span style="color: #007700">-</span><span style="color: #0000BB">equivalent</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">command&nbsp;control&nbsp;arrow</span><span style="color: #007700">-</span><span style="color: #0000BB">up</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">key</span><span style="color: #007700">-</span><span style="color: #0000BB">equivalent</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">setup</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;</span><span style="color: #0000BB">direction</span><span style="color: #007700">&gt;</span><span style="color: #0000BB">up</span><span style="color: #007700">&lt;/</span><span style="color: #0000BB">direction</span><span style="color: #007700">&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&lt;/</span><span style="color: #0000BB">setup</span><span style="color: #007700">&gt;<br />&lt;/</span><span style="color: #0000BB">action</span><span style="color: #007700">&gt;&nbsp;</span>
</span>
</code></div></p>

	<p>The file referenced in the <strong>&lt;script&gt;</strong> element must be saved in the Scripts folder in your Sugar. Note that there are several elements you can use that are not shown in this example; see the <a href="http://wiki.macrabbit.com/index/ActionXML/" title="ActionXML">ActionXML</a> documentation for details.</p>

	<p>The contents of the <strong>&lt;setup&gt;</strong> element can be arbitrarily named elements that are strings, or other data formats using plist formatting.</p>

	<h2 id="syntax">JavaScript action syntax</h2>

	<p>Within your JavaScript action you will be provided with a root-level <code>action</code> object that you can use to create the logic for your action. The most basic actions will include a single function:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">action</span><span style="color: #007700">.</span><span style="color: #0000BB">performWithContext&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">context</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">outError</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Action&nbsp;logic&nbsp;here<br />&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;Return&nbsp;true&nbsp;or&nbsp;false<br /></span><span style="color: #0000BB">&#125;</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>

	<p>The <strong>context</strong> parameter will be a <a href="http://wiki.macrabbit.com/index/TextActionContext/" title="TextActionContext">TextActionContext</a> object provided by Espresso for the current document. The <strong>outError</strong> parameter is currently a placeholder, but will likely be used by the system in future updates.</p>

	<p>To access the contents of your action&#8217;s <strong>&lt;setup&gt;</strong> element, you will use the <code>action.setup</code> object. For instance, the JavaScript for the <a href="#xml">above <span class="caps">XML</span> example</a> might do something like this:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">action</span><span style="color: #007700">.</span><span style="color: #0000BB">setup</span><span style="color: #007700">.</span><span style="color: #0000BB">direction&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #DD0000">'up'</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Move&nbsp;line&nbsp;up<br /></span><span style="color: #0000BB">&#125;&nbsp;</span>
</span>
</code></div></p>

	<p>The <code>action.setup</code> object is <strong>read-only</strong>.</p>

	<p>In addition to performing your action with a given context, you can also specify custom logic to determine if your action applies to a particular context, or to give it a different title in different contexts. To do so, you will add two additional functions to your <code>action</code> object:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">action</span><span style="color: #007700">.</span><span style="color: #0000BB">titleWithContext&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">context</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">outError</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Return&nbsp;string&nbsp;representing&nbsp;new&nbsp;title,&nbsp;or&nbsp;null&nbsp;to&nbsp;use&nbsp;default<br /></span><span style="color: #0000BB">&#125;</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">action</span><span style="color: #007700">.</span><span style="color: #0000BB">canPerformWithContext&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">context</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">outError</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Return&nbsp;true&nbsp;or&nbsp;false<br /></span><span style="color: #0000BB">&#125;</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>

	<p>If you are using <code>titleWithContext</code>, you can additionally return a string formatted like <strong>@key</strong> to use the title associated with &#8220;key&#8221; in <a href="http://wiki.macrabbit.com/index/Localizable.strings/" title="Localizable.strings">Localizable.strings</a>. For instance, for the action above returning &#8220;@multiple&#8221; from the titleWithContext would use the *.title.multiple key:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #DD0000">"com.macrabbit.tea-for-two.text-actions.move-line-up.title"&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Move&nbsp;Line&nbsp;Up"</span><span style="color: #007700">;<br /></span><span style="color: #DD0000">"com.macrabbit.tea-for-two.text-actions.move-line-up.title.multiple"&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"Move&nbsp;Lines&nbsp;Up"</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>

	<h2 id="libraries">JavaScript Libraries</h2>

	<p>If you are coding more than one JavaScript action that shares similar logic, you can gather it all into a JavaScript library. To do so, create a new JS file in the top-level ScriptLibraries folder:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #0000BB">MySugar</span><span style="color: #007700">.</span><span style="color: #0000BB">sugar</span><span style="color: #007700">/</span><span style="color: #0000BB">ScriptLibraries</span><span style="color: #007700">/</span><span style="color: #0000BB">my_library</span><span style="color: #007700">.</span><span style="color: #0000BB">js&nbsp;</span>
</span>
</code></div></p>

	<p>Inside of your library, you can create whatever functions and variables that you need, and then assign the functions you need access to the global <code>library</code> object:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">var&nbsp;</span><span style="color: #0000BB">myFunction&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">text</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Do&nbsp;stuff&nbsp;to&nbsp;text<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">return&nbsp;</span><span style="color: #0000BB">text</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">&#125;</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">library</span><span style="color: #007700">.</span><span style="color: #0000BB">myFunction&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">myFunction</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>

	<p>Then in your JavaScript action code, load in your library and use it like so:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">var&nbsp;</span><span style="color: #0000BB">extras&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">loadLibrary</span><span style="color: #007700">(</span><span style="color: #DD0000">'my_library'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">action</span><span style="color: #007700">.</span><span style="color: #0000BB">performWithContext&nbsp;</span><span style="color: #007700">=&nbsp;function(</span><span style="color: #0000BB">context</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">outError</span><span style="color: #007700">)&nbsp;</span><span style="color: #0000BB">&#123;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">var&nbsp;</span><span style="color: #0000BB">selection&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">context</span><span style="color: #007700">.</span><span style="color: #0000BB">selectedRanges&#91;0&#93;</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span style="color: #0000BB">text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">context</span><span style="color: #007700">.</span><span style="color: #0000BB">string</span><span style="color: #007700">.</span><span style="color: #0000BB">substringWithRange</span><span style="color: #007700">(</span><span style="color: #0000BB">selection</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">text&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">extras</span><span style="color: #007700">.</span><span style="color: #0000BB">myFunction</span><span style="color: #007700">(</span><span style="color: #0000BB">text</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;Insert&nbsp;the&nbsp;modified&nbsp;text&nbsp;or&nbsp;similar<br /></span><span style="color: #0000BB">&#125;</span><span style="color: #007700">;&nbsp;</span>
</span>
</code></div></p>
      ]]></content>
    </entry>

    <entry>
      <title>CETextRecipe</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/CETextRecipe/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:CETextRecipe/44.217</id>
      <published>2011-09-06T22:27:24Z</published>
      <updated>2011-09-06T22:27:24Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p><a href="http://wiki.macrabbit.com/index/JavaScriptAPI/" title="JavaScriptAPI">JavaScriptAPI</a> : CETextRecipe</p>

	<p>CETextRecipe objects allow you to create recipes of changes to apply to a document via the <a href="http://wiki.macrabbit.com/index/TextActionContext/" title="TextActionContext">TextActionContext</a> object. By queuing up your changes in a recipe and applying them all at once, you do not have to worry about manually adjusting ranges to take into account previous insertions or deletions.</p>

	<h2 id="constructor">CETextRecipe()</h2>

	<p>The CETextSnippet constructor takes no arguments:</p>

	<p><div class="codeblock"><code><span style="color: #000000">
<span style="color: #007700">var&nbsp;</span><span style="color: #0000BB">recipe&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">CETextRecipe</span><span style="color: #007700">();&nbsp;</span>
</span>
</code></div></p>

	<h2 id="properties">Properties</h2>

	<p><strong>coalescesChanges</strong></p>

	<p>Returns <code>true</code> or <code>false</code>; whether or not this recipe groups its changes. Defaults to <code>true</code>.</p>

	<p>Set to <code>false</code> if you wish to have each change in the recipe applied individually (may decrease performance).</p>

	<p><strong>undoActionName</strong></p>

	<p>Returns the string that will be shown in the Edit menu&#8217;s Undo item.</p>

	<p>Most actions are automatically assigned an undo name, but if for some reason you need to change it you can set this to customize the undo name for the action.</p>

	<h2 id="methods">Methods</h2>

	<p><strong>replaceRange(range, string)</strong></p>

	<p>Returns void; replace the <a href="http://wiki.macrabbit.com/index/Range/" title="Range">Range</a> <strong>range</strong> with the string <strong>string</strong> when the recipe is applied.</p>

	<p><strong>insertAtIndex(index, string)</strong></p>

	<p>Returns void; insert the string <strong>string</strong> at the numerical character index <strong>index</strong> when the recipe is applied.</p>

	<p><strong>deleteRange(range)</strong></p>

	<p>Returns void; delete the <a href="http://wiki.macrabbit.com/index/Range/" title="Range">Range</a> <strong>range</strong> when the recipe is applied.</p>
      ]]></content>
    </entry>

    <entry>
      <title>IRC</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/IRC/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:IRC/17.216</id>
      <published>2011-09-06T22:02:42Z</published>
      <updated>2011-09-06T22:02:42Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>There is an unofficial <span class="caps">IRC</span> channel that has been established for discussion of Espresso-related topics on the <a href="http://freenode.net/">Freenode</a> <span class="caps">IRC</span> network. Anybody is free to join and chat with us, as well as ask questions or make suggestions.</p>

	<h2><a href="irc://chat.freenode.net/##Espresso">##Espresso</a></h2>

	<p>This channel is available for anybody to use, for general discussion, for requesting help from other Espresso users, or for quick help with Sugars.</p>

	<p>You can either download an <span class="caps">IRC</span> client (see below), or use the following link to open a web chat:</p>

	<p><strong><a href="http://webchat.freenode.net/?channels=##Espresso" target="_blank">http://webchat.freenode.net/?channels=##Espresso</a></strong></p>

	<h2>Clients</h2>

	<p>There are multiple viable <span class="caps">IRC</span> clients for Mac OS X. Here are a couple popular ones:</p>

	<ul>
		<li><a href="http://colloquy.info/">Colloquy</a></li>
		<li><a href="http://conceitedsoftware.com/linkinus">Linkinus</a></li>
	</ul>

	<h2>Who&#8217;s who</h2>

	<p>If you run across ianbeck in <span class="caps">IRC</span>, you are talking to the fellow responsible for QA and support for MacRabbit.</p>

	<p>Although sightings are extremely rare, if you find yourself talking to CaptainNeutrino, then you have discovered Jan Van Boghout, the head honcho of MacRabbit.</p>

	<p>We do not officially offer support through <span class="caps">IRC</span>, but time willing are happy to answer questions about Sugars or other aspects of Espresso. If you have something you definitely need a response to, you should email use using <strong>Help&rarr;Send Feedback</strong> in Espresso.</p>
      ]]></content>
    </entry>

    <entry>
      <title>Espresso Cocoa API</title>
      <link rel="alternate" type="text/html" href="http://wiki.macrabbit.com/index/Espresso_Cocoa_API/" />
      <id>tag:wiki.macrabbit.com,2011:wiki:Espresso Cocoa API/23.214</id>
      <published>2011-09-06T21:57:23Z</published>
      <updated>2011-09-06T21:57:23Z</updated>
      <author>
            <name>Ian Beck</name>
            <email></email>
      </author>
      <content type="html"><![CDATA[
        	<p>An up-to-date version of the Espresso Cocoa <span class="caps">API</span> is always available inside the Espresso application itself.  Simply navigate to Espresso, right click and choose Show Package Contents, and then go to Contents/Headers to view the <span class="caps">API</span> header files.</p>

	<p>However, the sheer number of files containing the <span class="caps">API</span> may be a bit daunting at first.  Here&#8217;s a breakdown of what files to look at based on types of actions you may wish to create.</p>

	<p><strong>EspressoActions.h</strong><br />
This file defines the protocol that your classes must support for text and file actions.</p>

	<p><strong>EspressoSDK.h</strong><br />
You can safely ignore this file; it doesn&#8217;t appear to actually define any <span class="caps">API</span> elements.</p>

	<h2>Text Actions</h2>

	<p><strong>EspressoTextActions.h</strong><br />
This file contains the definition of the text action context that is passed to your custom classes.  This class is your primary gateway to the other portions of the Espresso <span class="caps">API</span>; when looking through it you should make note of the types assigned to various objects and methods, as those will contain the main methods you&#8217;ll use to interact with the context object&#8217;s information.</p>

	<p><strong>EspressoTextCore.h</strong><br />
As of this writing, this contains four classes:</p>

	<ul>
		<li><strong>CETextRecipe</strong>: an interface for working with text recipes.  Text recipes allow you to queue up changes to the current document text without needing to worry about adjusting range offsets.  You will use text recipes whenever you need to insert or delete text, and you can initialize new text recipes in your code as needed.</li>
	</ul>

	<ul>
		<li><strong>CETextSnippet</strong>: a class for instantiating snippet objects (for use with <code>[context insertTextSnippet:snippet]</code>).</li>
	</ul>

	<ul>
		<li><strong>CELineStorage</strong>: a class for working with the lines in a text document.  You cannot instantiated a line storage element; it is purely there for reference when working with lineStorage.</li>
	</ul>

	<ul>
		<li><strong>CETextPreferences</strong>: a class for working with <code>[context textPreferences]</code>.  This is another that is there purely for reference.</li>
	</ul>

	<p><strong>EspressoSyntaxCore.h</strong><br />
This file contains all of the classes for working with Espresso syntax zones.  The Example Cocoa Sugar contains an example of using syntax zones to manipulate text.</p>

	<p><strong>EspressoDocumentActions.h</strong><br />
Similar to file action contexts below but only applying to a single document, this class contains methods for working with the <code>[context documentContext]</code>.  As of this writing, it does little more than provide a <span class="caps">URL</span> for accessing the file.</p>

	<p><strong>MRRangeSet.h</strong><br />
Contains the MRRangeSet class, which makes working with multiple ranges easier.  None of the Espress objects that I&#8217;ve found return a range set; the class is purely a convenience for use in your own code.</p>

	<p><strong><span class="caps">NSS</span>tring+MRFoundation.h</strong><br />
This contains convenience methods for working with strings, and is another example of useful utilities provided by MacRabbit for use in your own code.</p>

	<h2>File actions</h2>

	<p><strong>EspressoFileActions.h</strong><br />
This file defines the interface for file action contexts.  As of this writing, this provides little more than a list of <span class="caps">URL</span>s for selected files.</p>

	<h2>Itemizers</h2>

	<p><strong>EspressoItemizer.h</strong><br />
I am unfamiliar with how itemizers function, but this appears to be the class you need to override in order to create custom itemizer definitions.  <em>Note:</em> if Jan or someone else who is familiar with itemizers could expand on this, I&#8217;m sure folks would appreciate it.</p>

	<p><strong>EspressoItemizerCore.h</strong><br />
Again, I&#8217;m not familiar with itemizers, but as best I can tell this file defines useful classes for creating your custom itemizer definitions.  It also contains <span class="caps">CEI</span>temizer, which you can access from text action contexts.</p>
      ]]></content>
    </entry>


</feed>
