<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Magp.ie &#187; textwrangler</title>
	<atom:link href="http://magp.ie/tag/textwrangler/feed/" rel="self" type="application/rss+xml" />
	<link>http://magp.ie</link>
	<description>A nest for the random, shiny, online tidbits I stumble across...</description>
	<lastBuildDate>Wed, 16 May 2012 09:40:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='magp.ie' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/061e340c5da13b5a41ae8016bee03aa8?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Magp.ie &#187; textwrangler</title>
		<link>http://magp.ie</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://magp.ie/osd.xml" title="Magp.ie" />
	<atom:link rel='hub' href='http://magp.ie/?pushpress=hub'/>
		<item>
		<title>Tidy assignments in Coda and TextWrangler</title>
		<link>http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/</link>
		<comments>http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 08:40:28 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[assignments]]></category>
		<category><![CDATA[coda]]></category>
		<category><![CDATA[indentation]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[textwrangler]]></category>
		<category><![CDATA[tidy code]]></category>
		<category><![CDATA[Unix filter]]></category>
		<category><![CDATA[WordPress coding standards]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=529</guid>
		<description><![CDATA[I have written a simple tool to tidy assignments. It basically takes a group of assignments and uses spaces to make the code more readable. This tool will help code meet the indentation rules in the WordPress coding standards. If &#8230; <a href="http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=529&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have written a simple tool to tidy assignments. It basically takes a group of assignments and uses spaces to make the code more readable.</p>
<p>This tool will help code meet the indentation rules in the <a href="http://codex.wordpress.org/WordPress_Coding_Standards#Indentation"> WordPress coding standards</a>.<br />
<span id="more-529"></span><br />
If you have a group of basic assignments like&#8230;</p>
<p><pre class="brush: php;">
$variable1 = 0;
$long_variable2 = 123213123;
$short = 'test';
$s = 'test2';
</pre></p>
<p>This tool will space them so&#8230;</p>
<p><pre class="brush: php;">
$variable1      = 0;
$long_variable2 = 123213123;
$short          = 'test';
$s              = 'test2';
</pre></p>
<p>It will also work associative arrays&#8230;</p>
<p><pre class="brush: php;">
array(
'magpie' =&gt; 0,
'blog' =&gt; 1,
'random' =&gt; 2,
'too_long_string' =&gt; 3
);
</pre></p>
<p>&#8230; with spacing &#8230;</p>
<p><pre class="brush: php;">
array(
'magpie'          =&gt; 0,
'blog'            =&gt; 1,
'random'          =&gt; 2,
'too_long_string' =&gt; 3
);
</pre></p>
<p>The tool is available as a Coda plugin and a TextWrangler UNIX filter.</p>
<h4>For Coda</h4>
<ul>
<li><a href="http://dl.dropbox.com/u/5756988/tidy-assignment.codaplugin.zip">Download the Coda plugin</a></li>
<li>Extract the zip file and double-click the <strong>tidy-assignment.codaplugin</strong> file</li>
<li>Select code, right-click, goto Plug-ins-&gt;Tidy Assignment</li>
</ul>
<p><img src="http://blogalhost.files.wordpress.com/2011/03/highlight.png?w=450&h=261" alt="Highlight and select Tidy Assignment plugin" title="highlight-code" width="450" height="261" class="alignnone size-full wp-image-542" /></p>
<p>To remove/uninstall the plugin;</p>
<ul>
<li>Close Coda</li>
<li>Goto <code>[your_home_folder]/Library/Application Support/Coda/Plug-ins/</code></li>
<li>Delete the file tidy-assignment.codaplugin</li>
</ul>
<h4>For TextWrangler</h4>
<ul>
<li>Open TextWrangler and open a new text file.</li>
<li>Copy and paste the code below into this file.</li>
<p><pre class="brush: php;">
#!/usr/bin/php
&lt;?php

if ( !isset( $_SERVER['argv'] ) &amp;&amp; !isset( $_SERVER['argv'][1] ) )
	die();

$fc    = file_get_contents( $_SERVER['argv'][1] );
$lines = explode( &quot;\n&quot;, $fc );
$clean = array();
$assoc = false;

$longest_line_index  = 0;
$longest_line_length = 0;

foreach ( $lines as $key =&gt; $line ) {
	//remove whitspace
	$line = preg_replace( '/\s\s+/', ' ', trim( $line ) );
	$parts = array();
	
	if ( mb_stripos( $line, '=&gt;' ) !== FALSE ) {
		$parts = explode( &quot;=&gt;&quot;, $line );
		$assoc = true;
	}
	elseif ( mb_stripos( $line, '=' ) !== FALSE ) {
		$parts = explode( &quot;=&quot;, $line );
	}

	if ( !empty( $parts ) &amp;&amp; mb_strlen( $parts[0] ) &gt; $longest_line_length ) {
		$longest_line_index = $key;
		$longest_line_length = mb_strlen( $parts[0] );
	}
	
	if ( mb_strlen( $line ) &gt; 0 )
		$clean[$key] = $line;
}

$longest_line = $clean[$longest_line_index];
$operator = $assoc ? '=&gt;' : '=' ;

//add spaces to line
if ( mb_stripos( $longest_line, $operator ) !== FALSE ) {
	$parts = explode( $operator, $longest_line );
	$longest_line = sprintf( &quot;%s %s %s&quot;, trim( $parts[0] ), $operator, trim( $parts[1] ) );
}
else {
	$longest_line = sprintf( &quot;%s&quot;, trim( $longest_line ) );
}

//now get the position of equals
$pos = mb_stripos( $longest_line, $operator );
if ( $pos === FALSE )
	$pos = mb_strlen( $longest_line );

foreach ( $clean as $key =&gt; &amp;$line ) {
	if ( $key == $longest_line_index )
		$line = $longest_line;
	elseif ( mb_stripos( $line, $operator ) !== FALSE ) {
		$spaces = ' ';
		$parts = explode( $operator, $line );
		if ( !empty( $parts ) )
			while ( mb_stripos( $line, $operator ) &lt; $pos ) {
				$line = sprintf( &quot;%s%s%s %s&quot;, trim( $parts[0] ), $spaces, $operator, trim( $parts[1] ) );
				$spaces .= &quot; &quot;;
			}
	}
	else {
		$line = sprintf( &quot;%s&quot;, trim( $line ) );
	}
}

echo implode( &quot;\n&quot;, $clean );
</pre></p>
<li>Save the file, something like <strong>Tidy Assignment.php</strong>, in the Filters folder.</li>
<li>You can find the filters folder by going to the <em>#! menu</em> and go to the <em>Unix Filters</em> sub-menu, and select the <em>Open Filters Folder</em>, like below.<br />
<img class="alignnone size-full wp-image-98" title="Scripts menu" src="http://blogalhost.files.wordpress.com/2010/02/picture-7.png?w=450" alt=""   /></p>
<li>Now anytime you want to tidy assignments, just go to this menu and select the <strong>Tidy Assignment</strong> script.</li>
<p><img src="http://blogalhost.files.wordpress.com/2011/03/tidy-assignment-textwrangler.png?w=450&h=373" alt="Select tidy assignment script in TextWrangler" title="tidy-assignment-textwrangler" width="450" height="373" class="alignnone size-full wp-image-544" />
</ul>
<p>First time I <a href="http://www.panic.com/coda/developer/">created a coda plugin</a> and I am surprised how simple it is. I may experiment with this in the future if I can think of anything useful.</p>
<br />Filed under: <a href='http://magp.ie/category/code/'>Code</a> Tagged: <a href='http://magp.ie/tag/assignments/'>assignments</a>, <a href='http://magp.ie/tag/coda/'>coda</a>, <a href='http://magp.ie/tag/indentation/'>indentation</a>, <a href='http://magp.ie/tag/plugin/'>plugin</a>, <a href='http://magp.ie/tag/textwrangler/'>textwrangler</a>, <a href='http://magp.ie/tag/tidy-code/'>tidy code</a>, <a href='http://magp.ie/tag/unix-filter/'>Unix filter</a>, <a href='http://magp.ie/tag/wordpress-coding-standards/'>WordPress coding standards</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/529/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/529/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/529/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=529&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/03/16/tidy-assignments-in-coda-and-textwrangler/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>53.734700 -8.991280</georss:point>
		<geo:lat>53.734700</geo:lat>
		<geo:long>-8.991280</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2011/03/highlight.png" medium="image">
			<media:title type="html">highlight-code</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/02/picture-7.png" medium="image">
			<media:title type="html">Scripts menu</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2011/03/tidy-assignment-textwrangler.png" medium="image">
			<media:title type="html">tidy-assignment-textwrangler</media:title>
		</media:content>
	</item>
		<item>
		<title>Tidy and format your PHP and meet WordPress standards on Coda and TextWrangler</title>
		<link>http://magp.ie/2011/01/10/tidy-and-format-your-php-and-meet-wordpress-standards-on-coda-and-textwrangler/</link>
		<comments>http://magp.ie/2011/01/10/tidy-and-format-your-php-and-meet-wordpress-standards-on-coda-and-textwrangler/#comments</comments>
		<pubDate>Mon, 10 Jan 2011 21:08:13 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Shortcuts]]></category>
		<category><![CDATA[coda]]></category>
		<category><![CDATA[coding standards]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phptidy]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[textwrangler]]></category>
		<category><![CDATA[tidy]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=436</guid>
		<description><![CDATA[If you are working in a collaborative environment, coding standards are important. When you are reading through code that you haven&#8217;t written, it helps if it follows a standard. As I work with Automattic, the keepers of WordPress.com, I get &#8230; <a href="http://magp.ie/2011/01/10/tidy-and-format-your-php-and-meet-wordpress-standards-on-coda-and-textwrangler/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=436&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are working in a collaborative environment, coding standards are important. When you are reading through code that you haven&#8217;t written, it helps if it follows a standard.</p>
<p>As I work with <a href="http://automattic.com">Automattic</a>, the keepers of <a href="http://WordPress.com">WordPress.com</a>, I get the opportunity to work on the WordPress Platform. WordPress have their own <a href="http://codex.wordpress.org/WordPress_Coding_Standards">standards</a> that are sensible without being pedantic and are similar to the <a href="http://pear.php.net/manual/en/standards.php">PEAR standard</a>. The emphasis of the standard (in my opinion), is to present your code so collaboration is as easy as possible. It would prefer if you wrote code that is easier to read and understand, even if it is a little longer, than some compressed, <em>ubersmart</em> block of code that only you can follow.<br />
<span id="more-436"></span><br />
Sometimes I look back at old code I did, like when I first wrote a WordPress plugin, and see places where it is not consistent with the WordPress standards&#8230; and I&#8217;d to get the itch to fix it, line by line, which is time consuming and dull work.</p>
<p>So I looked into ways to automate this in my text editor but alas no feature or option existed. While its not really possible to automate for all the standards, it should be possible to correct the formatting.</p>
<p>What can be automated?, well&#8230;</p>
<ul>
<li><strong>Braces style</strong>. It should use <a href="http://en.wikipedia.org/wiki/Indent_style">K&amp;R style</a>.</li>
<li><strong>Indentation</strong>. Need to remove spacing and use tabs instead.</li>
<li><strong>Spacing</strong>. Add spacing to make code more readable.</li>
<li><strong>No shorthand PHP</strong>. So no <code>&lt;?</code> allowed.</li>
</ul>
<p>If you are using <a href="http://www.panic.com/coda/">Coda</a>, there is an excellent plugin called <a href="http://www.chipwreck.de/blog/software/coda-php/">Coda PHP &amp; Web Toolkit</a> written by Mario Fischer. This is easy to install, and all you have to do to tidy your HTML, PHP, Javascript and CSS is right click on your code and select the plugin&#8217;s Tidy option.</p>
<p><a href="http://blogalhost.files.wordpress.com/2011/01/screen-shot-2011-01-07-at-23-20-22.png"><img class="alignnone size-thumbnail wp-image-461" title="Tidy PHP with Coda Plugin" src="http://blogalhost.files.wordpress.com/2011/01/screen-shot-2011-01-07-at-23-20-22.png?w=300&h=38" alt="Tidy PHP with Coda Plugin" width="300" height="38" /></a></p>
<p>The best thing about this, it meets WordPress PHP formatting standards with only a couple of exceptions. To fix them, you need to locate the phptidy-coda.php file, usually found here&#8230;<br />
<code>/Users/[your user name]/Library/Application Support/Coda/Plug-ins/PhpPlugin.codaplugin/Contents/Resources/phptidy-coda.php</code></p>
<p>If you can&#8217;t locate it, go to root and use the following search command.<br />
<code>sudo find . -name "*.php" -exec grep -H "phptidy" {} \;</code></p>
<p>The first exception is, that for functions and classes, it pushes the opening curly bracket, <strong>{</strong>, to the next line.<br />
To fix this, open <strong>phptidy-coda.php</strong> in an editor and change the line</p>
<p><pre class="brush: php;">
// from
$curly_brace_newline = array(T_CLASS, T_FUNCTION);
// to...
$curly_brace_newline = false;
</pre></p>
<p>The other exception is, it does not add spacing after a start round bracket <strong>(</strong>, or before an end round bracket, <strong>)</strong>.</p>
<p>In <strong>phptidy-coda.php</strong>, find the phptidy function and add a default for this formatting with the other defaults&#8230;</p>
<p><pre class="brush: php;">
// Enable the single cleanup functions
$fix_token_case = true;
$fix_builtin_functions_case = true;
$replace_inline_tabs = true;
$replace_phptags = true;
$replace_shell_comments = true;
$fix_statement_brackets = true;
$fix_separation_whitespace = true;
$fix_comma_space = true;

//add new default in here
$fix_round_bracket_space = true;

$add_file_docblock = false;
$add_function_docblocks = false;
$add_doctags = false;
$fix_docblock_format = true;
$fix_docblock_space = false;
$add_blank_lines = false;
$indent = true;
</pre></p>
<p>Then look for the phptidy function and add a check for this default to format the spacing for round brackets.</p>
<p><pre class="brush: php;">
// Simple formatting
if ( $GLOBALS['fix_token_case'] ) fix_token_case( $tokens );
if ( $GLOBALS['fix_builtin_functions_case'] ) fix_builtin_functions_case( $tokens );
if ( $GLOBALS['replace_inline_tabs'] ) replace_inline_tabs( $tokens );
if ( $GLOBALS['replace_phptags'] ) replace_phptags( $tokens );
if ( $GLOBALS['replace_shell_comments'] ) replace_shell_comments( $tokens );
if ( $GLOBALS['fix_statement_brackets'] ) fix_statement_brackets( $tokens );
if ( $GLOBALS['fix_separation_whitespace'] ) fix_separation_whitespace( $tokens );
if ( $GLOBALS['fix_comma_space'] ) fix_comma_space( $tokens );
// Add in you call to new function here
if ( $GLOBALS['fix_round_bracket_space'] ) fix_round_bracket_space( $tokens );
</pre></p>
<p>Lastly, add in the function to format the code to add in spacing after the start round bracket and before the end round bracket where appropriate.</p>
<p><pre class="brush: php;">
/**
 * Adds one space after a start round bracket and before an end round bracket
 *
 * @param array   $tokens (reference)
 */
function fix_round_bracket_space( &amp;$tokens ) {

	foreach ( $tokens as $key =&gt; &amp;$token ) {
		if ( !is_string( $token ) ) continue;
		if (
			// If the current token is a start round bracket...
			$token === &quot;(&quot; and
			// ...and the next token is no whitespace
			!( isset( $tokens[$key+1][0] ) and $tokens[$key+1][0] === T_WHITESPACE ) and
			// ...and the next token is not an end round bracket
			!( isset( $tokens[$key+1][0] ) and $tokens[$key+1][0] === ')' )
		) {
			// Insert one space
			array_splice( $tokens, $key+1, 0, array(
					array( T_WHITESPACE, &quot; &quot; )
				) );
		}
		else if (
			// If the current token is an end round bracket...
			$token === &quot;)&quot; and
			// ...and the previous token is no whitespace
			!( isset( $tokens[$key-1][0] ) and $tokens[$key-1][0] === T_WHITESPACE ) and
			// ...and the previous token is a start round bracket
			!( isset( $tokens[$key-1][0] ) and $tokens[$key-1][0] === '(' )
		) {
			// Insert one space
			array_splice( $tokens, $key, 0, array(
					array( T_WHITESPACE, &quot; &quot; )
				) );
		}
	}
}
</pre></p>
<p>Then save the file. You may need to edit this file using sudo in order to change it.<br />
Restart Coda and tidy your PHP.</p>
<p><em><strong>UPDATE</strong>:: Mario has told me that he will include these changes in a future update But in case it is not in the next update, you should make a backup of the phptidy-coda.php file, as the next plugin update may overwrite it.</em></p>
<p><em><strong>UPDATE 2</strong>:: Mario has indeed included these changes into the lastest version of the plugin. He has also made the format configurable so if you don&#8217;t want your curly brackets on the same line, you can set it so.</em></p>
<p>Now that is all good and well if you have Coda, but what of the <a href="http://www.barebones.com/products/textwrangler/">TextWrangler</a> folk. Well the plugin for Coda uses an open sourced library called <a href="http://phptidy.berlios.de/">phptidy</a>, written by Magnus Rosenbaum, which is impressive not least for the brevity of the documentation.</p>
<p>To get it to work with TextWrangler is fairly straightforward. Follow these steps and if I have left any out place highlight them in the comments below.</p>
<p><strong>Note:</strong> I had to make some minor changes to the phptidy library to get it to work with TextWrangler. As well as the 2 changes above, I also had to suppress any text echo&#8217;d by the library.</p>
<ul>
<li>Download my <a href="http://dl.dropbox.com/u/5756988/phptidy.zip">phptidy</a> library.</li>
<li>Uncompress the zip file and copy the <strong>Tidy PHP.sh</strong> file to the Filters directory, you can find out how to do that <a href="http://magp.ie/2010/02/15/format-xml-with-textwrangler/">here</a></li>
<li>Open terminal and copy the <strong>phptidy.php</strong> file to your <code>/usr/bin</code> folder</li>
<li>Go to the <code>/usr/bin</code> folder and change the file permissions of the <strong>phptidy.php</strong> by typing, <code>sudo chmod 755 phptidy.php</code></li>
</ul>
<p>Now you should be ready to try out the filter in TextWrangler.</p>
<p>At a later date, I plan to use John Godley&#8217;s <a href="http://urbangiraffe.com/articles/wordpress-codesniffer-standard/">CodeSniffer code</a>, to validate the code and get a detailed explanation of where the code does not follow the WordPress standard.</p>
<br />Filed under: <a href='http://magp.ie/category/shortcuts/'>Shortcuts</a> Tagged: <a href='http://magp.ie/tag/coda/'>coda</a>, <a href='http://magp.ie/tag/coding-standards/'>coding standards</a>, <a href='http://magp.ie/tag/format/'>format</a>, <a href='http://magp.ie/tag/php/'>php</a>, <a href='http://magp.ie/tag/phptidy/'>phptidy</a>, <a href='http://magp.ie/tag/plugin/'>plugin</a>, <a href='http://magp.ie/tag/textwrangler/'>textwrangler</a>, <a href='http://magp.ie/tag/tidy/'>tidy</a>, <a href='http://magp.ie/tag/wordpress/'>wordpress</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/436/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/436/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/436/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=436&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2011/01/10/tidy-and-format-your-php-and-meet-wordpress-standards-on-coda-and-textwrangler/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2011/01/screen-shot-2011-01-07-at-23-20-22.png?w=300" medium="image">
			<media:title type="html">Tidy PHP with Coda Plugin</media:title>
		</media:content>
	</item>
		<item>
		<title>Textwrangler Tips &#8211; Compare files, keyboard shortcuts</title>
		<link>http://magp.ie/2010/06/16/textwrangler-tips-compare-files-keyboard-shortcuts/</link>
		<comments>http://magp.ie/2010/06/16/textwrangler-tips-compare-files-keyboard-shortcuts/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 17:10:30 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Shortcuts]]></category>
		<category><![CDATA[shortcuts]]></category>
		<category><![CDATA[text editor]]></category>
		<category><![CDATA[textwrangler]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://magp.ie/?p=195</guid>
		<description><![CDATA[A few quick TextWrangler tips. I never knew until recently that you can compare files in TextWrangler&#8230; and its easy. Simply highlight the 2 files you want to compare in the Documents drawer, right click on them and select the &#8230; <a href="http://magp.ie/2010/06/16/textwrangler-tips-compare-files-keyboard-shortcuts/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=195&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A few quick TextWrangler tips.</p>
<p>I never knew until recently that you can compare files in <a href="http://www.barebones.com/products/textwrangler/" target="_blank">TextWrangler</a>&#8230; and its easy.</p>
<p>Simply highlight the 2 files you want to compare in the Documents drawer, right click on them and select the option &#8216;<strong>Compare Selected Documents</strong>&#8216;.</p>
<p>Now the 2 files will open into 2 windows with a review of the differences below them. You can then apply the differences in either direction.</p>
<p>Another tip is adding keyboard shortcuts to TextWrangler&#8217;s menu options.<br />
<span id="more-195"></span><br />
I like to use the <strong>Search</strong> -&rsaquo; <strong>Jump Back/Forward</strong> option to navigate around a large body of code but alas it has no keyboard shortcut. So each time you wish to move from one Jump mark to another, you need to go up to the Search menu&#8230; which kinda defeats the handiness of the option in the first place.</p>
<p>Anyways, to add a keyboard shortcut to this (or some other useful menu) option, go to <strong>Textwrangler</strong> -&rsaquo; <strong>Preferences</strong>.</p>
<p>Select <strong>Menus</strong>&#8230;</p>
<p><img class="alignnone size-full wp-image-196" title="Menus option" src="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-39-03.png?w=450" alt=""   /></p>
<p>Find the menu heading for the option you want, in my case <strong>Search</strong>&#8230;</p>
<p><img class="alignnone size-full wp-image-197" title="Search Menu header" src="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-39-38.png?w=450" alt=""   /></p>
<p>In the menu header, find the option(s) you want to add a keyboard shortcut to.</p>
<p>Highlight an option and press the <strong>Set Key</strong> button.</p>
<p><img class="alignnone size-full wp-image-198" title="Set Key button" src="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-40-42.png?w=450" alt=""   /></p>
<p>Enter the keyboard shortcut and press the <strong>Set</strong> button.</p>
<p>Bingo.</p>
<p><img class="alignnone size-full wp-image-199" title="Shortcuts" src="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-41-49.png?w=450" alt=""   /></p>
<p>Lastly, a while back <a href="http://magp.ie/2010/02/15/format-xml-with-textwrangler/" target="_blank">I wrote a shell script to format my XML</a>. To add a shortcut to this, you need to select <strong>Window</strong> -&rsaquo; <strong>Palettes</strong> -&rsaquo; <strong>Unix Filters</strong></p>
<p>Select the script you want to shortcut and press the <strong>Set Key&#8230;</strong> button. Enter your keyboard shortcut and press the <strong>Set</strong> button and now when you want to format some messy XML, you have a keyboard shortcut to knock it into shape.</p>
<br />Filed under: <a href='http://magp.ie/category/shortcuts/'>Shortcuts</a> Tagged: <a href='http://magp.ie/tag/shortcuts-2/'>shortcuts</a>, <a href='http://magp.ie/tag/text-editor/'>text editor</a>, <a href='http://magp.ie/tag/textwrangler/'>textwrangler</a>, <a href='http://magp.ie/tag/tips/'>tips</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/195/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/195/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/195/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=195&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2010/06/16/textwrangler-tips-compare-files-keyboard-shortcuts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>53.734482 -8.990559</georss:point>
		<geo:lat>53.734482</geo:lat>
		<geo:long>-8.990559</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-39-03.png" medium="image">
			<media:title type="html">Menus option</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-39-38.png" medium="image">
			<media:title type="html">Search Menu header</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-40-42.png" medium="image">
			<media:title type="html">Set Key button</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/06/screen-shot-2010-06-16-at-17-41-49.png" medium="image">
			<media:title type="html">Shortcuts</media:title>
		</media:content>
	</item>
		<item>
		<title>Format XML with TextWrangler</title>
		<link>http://magp.ie/2010/02/15/format-xml-with-textwrangler/</link>
		<comments>http://magp.ie/2010/02/15/format-xml-with-textwrangler/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 20:47:06 +0000</pubDate>
		<dc:creator>Eoin</dc:creator>
				<category><![CDATA[Shortcuts]]></category>
		<category><![CDATA[format xml]]></category>
		<category><![CDATA[textwrangler]]></category>
		<category><![CDATA[UNIX Script]]></category>

		<guid isPermaLink="false">http://blogalhost.wordpress.com/?p=97</guid>
		<description><![CDATA[My text editor of choice on the Mac is TextWrangler. It&#8217;s lightweight and it has pretty much all you need from a text editor. In particular, I like that I can SFTP into my development server. One issue that bugged &#8230; <a href="http://magp.ie/2010/02/15/format-xml-with-textwrangler/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=97&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>My text editor of choice on the Mac is <a href="http://www.barebones.com/products/TextWrangler/" target="_blank">TextWrangler</a>. It&#8217;s lightweight and it has pretty much all you need from a text editor. In particular, I like that I can SFTP into my development server.</p>
<p>One issue that bugged me lately was when I opened an <em>unindented</em>, <em>unformatted</em> XML file. Basically, it looked a mess and there was no way to tidy the file up so that I could read it easily.</p>
<p>However, I found a simple way to do this today&#8230; <span id="more-97"></span>thanks to <a href="http://groups.google.com/group/textwrangler/browse_thread/thread/ea4d509c9266a6b1" target="_blank">this</a> and <a href="http://www.entropy.ch/blog/Developer/2008/04/23/XML-Pretty-Printing-in-BBEdit-and-vi-With-xmllint.html" target="_blank">this</a>.</p>
<p><strong>Simple guide</strong><br />
We want to add a UNIX script to TextWrangler so it can format an XML file&#8230; to do this, do this&#8230;</p>
<ul>
<li>Open TextWrangler and open a new text file.</li>
<li>Copy and paste the code below into this file.</li>
<p><pre class="brush: plain;">
#!/bin/sh
xmllint --c14n &quot;$*&quot; | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format -
</pre></p>
<li>Save the file, something like <strong>Tidy XML.sh</strong>, in the Filters folder.</li>
<li>You can find the filters folder by going to the <em>#! menu</em> and go to the <em>Unix Filters</em> sub-menu, and select the <em>Open Filters Folder</em>, like below.
<ul><img class="alignnone size-full wp-image-98" title="Scripts menu" src="http://blogalhost.files.wordpress.com/2010/02/picture-7.png?w=450" alt=""   /></p>
<li>Now anytime you want to format an XML file, just go to this menu and select the <strong>Tidy XML.sh</strong> script and BOOM, neat tidy XML.</li>
<p><img class="alignnone size-full wp-image-99" title="Select Script" src="http://blogalhost.files.wordpress.com/2010/02/picture-8.png?w=450" alt=""   /></ul>
</li>
</ul>
<p>This is an interesting facility to extend an already great text editor, and I will be looking into more cool scripts that can hopefully lessen my daily annoyances.</p>
<p><em><strong>UPDATED</strong>:: Added UTF8 encoding, thanks Rolan.</em><br />
<em><strong>UPDATED</strong>:: Added a post to <a href="http://wp.me/pN7Q4-72">format PHP code</a> in TextWrangler.</em></p>
<br />Filed under: <a href='http://magp.ie/category/shortcuts/'>Shortcuts</a> Tagged: <a href='http://magp.ie/tag/format-xml/'>format xml</a>, <a href='http://magp.ie/tag/textwrangler/'>textwrangler</a>, <a href='http://magp.ie/tag/unix-script/'>UNIX Script</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/blogalhost.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/blogalhost.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/blogalhost.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/blogalhost.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/blogalhost.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/blogalhost.wordpress.com/97/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/blogalhost.wordpress.com/97/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/blogalhost.wordpress.com/97/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=magp.ie&#038;blog=11708208&#038;post=97&#038;subd=blogalhost&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://magp.ie/2010/02/15/format-xml-with-textwrangler/feed/</wfw:commentRss>
		<slash:comments>50</slash:comments>
		<georss:point>53.734750 -8.989992</georss:point>
		<geo:lat>53.734750</geo:lat>
		<geo:long>-8.989992</geo:long>
		<media:content url="http://1.gravatar.com/avatar/72dd449e5e79e046c1c09ed8712b525a?s=96&#38;d=monsterid&#38;r=PG" medium="image">
			<media:title type="html">eoigal</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/02/picture-7.png" medium="image">
			<media:title type="html">Scripts menu</media:title>
		</media:content>

		<media:content url="http://blogalhost.files.wordpress.com/2010/02/picture-8.png" medium="image">
			<media:title type="html">Select Script</media:title>
		</media:content>
	</item>
	</channel>
</rss>
