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

<channel>
	<title>Gregory Grubbs &#187; Mac OS X</title>
	<atom:link href="http://gregorygrubbs.com/tag/mac-os-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://gregorygrubbs.com</link>
	<description>Attention in software development</description>
	<lastBuildDate>Mon, 12 Jul 2010 17:35:34 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Snippets with Emacs Lisp Power</title>
		<link>http://gregorygrubbs.com/wordpress/snippets-with-emacs-lisp-power/</link>
		<comments>http://gregorygrubbs.com/wordpress/snippets-with-emacs-lisp-power/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 06:00:51 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[E Text Editor]]></category>
		<category><![CDATA[Emacs Lisp]]></category>
		<category><![CDATA[Functional languages]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[TextMate]]></category>
		<category><![CDATA[yasnippet]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=415</guid>
		<description><![CDATA[ 
The YASnippet package for Emacs has some pretty awesome power for the developer, especially when you utilize the power of Emacs Lisp.  

YASnippet was inspired by TextMate, which was inspired by Emacs, in a highly-out-of-equilibrium whirlwind of self-referential creativity.  
The screencast above uses a set of snippets I originally took from this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flickr.com/photos/26405526@N00/2188203168" title="As RAW as Winter"><img src="http://farm3.static.flickr.com/2165/2188203168_86a4d818f4.jpg" /></a> </p>
<p>The YASnippet package for Emacs has some pretty awesome power for the developer, especially when you utilize the power of Emacs Lisp.  </p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/HPT7pm8ot8M&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/HPT7pm8ot8M&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
<p>YASnippet was inspired by TextMate, which was inspired by Emacs, in a highly-out-of-equilibrium whirlwind of self-referential creativity.  </p>
<p>The screencast above uses a set of snippets I originally took from <a href="http://top-frog.com/projects/wordpress-textmate-bundle/">this WordPress TextMate bundle</a>, created by Shawn Parker and Gordon Brander</p>
<p>The first snippet in the screencast illustrates YASnippet&#8217;s mirrors with transformation, in a WordPress plugin template.  The snippet calls Emacs Lisp functions as the plugin name is filled in to create the plugin URI, the &#8220;namespace&#8221; (used here as a prefix for function and variable names), and the primary class name for the plugin. </p>
<p>The second snippet writes a function skeleton, then calls Emacs Lisp at the end to move the generated function outside the current scope into a correct position in the file.  This snippet uses YASnippet&#8217;s fields with transformations syntax, but to do a sneaky thing: not transform the field, but move a region of generated text!</p>
<p>Following is the code for the snippets shown in the screencast, with no commentary.  So pipe up in the comments if you&#8217;re curious about how something works!</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># -*- mode: snippet -*-
</span><span style="color: #666666; font-style: italic;"># name: WP Plugin
</span><span style="color: #666666; font-style: italic;"># key: plugin
</span><span style="color: #666666; font-style: italic;"># --
</span><span style="color: #666666; font-style: italic;">/*
Plugin Name: ${1:Plugin Name}
Plugin URI: http://${2:dynapse.com/plugins/}${1:$(gjg/sanitize text)}/
Description: ${3:Description}
Version: ${4:1.0}
Author: ${5:Gregory Grubbs}
Author URI: http://${6:gregorygrubbs.com/}
Namespace: ${1:$(gjg/acronyminize text)}_
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> $<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>whitespace<span style="color: #339933;">-</span>to<span style="color: #339933;">-</span>underscore text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * constructor for $1
	 *
	 * The constructor is responsible for registering all hooks used
	 * by this class as as WordPress plugin
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		 $<span style="color: #cc66cc;">0</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// constructor</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
$$<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>acronyminize text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> $<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">:</span>$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>whitespace<span style="color: #339933;">-</span>to<span style="color: #339933;">-</span>underscore text<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Next, the add_action snippet, which moves a generated function at the end:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># -*- mode: snippet -*-
</span><span style="color: #666666; font-style: italic;"># name: add_action
</span><span style="color: #666666; font-style: italic;"># key: add_action
</span><span style="color: #666666; font-style: italic;"># --
</span>add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'${1:init}'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_${2:$1}'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">:</span>$$<span style="color: #009900;">&#40;</span>gjg<span style="color: #339933;">/</span>move<span style="color: #339933;">-</span>next<span style="color: #339933;">-</span>sexp<span style="color: #339933;">-</span>past<span style="color: #339933;">-</span>current<span style="color: #339933;">-</span>scope<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> my_$<span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And finally, (some of) the Emacs Lisp functions that the snippets call:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> gjg/acronyminize <span style="color: #66cc66;">&#40;</span>text <span style="color: #66cc66;">&amp;</span>optional do-capitalize<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Make an acronym from the text 
do-capitalize: t means run text through capitalize function, nil will respect CamelCase
&quot;</span>
  <span style="color: #66cc66;">&#40;</span>save-excursion
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> case-fold-search <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>downcase
     <span style="color: #66cc66;">&#40;</span>replace-regexp-in-string
      <span style="color: #ff0000;">&quot;[^A-Z]&quot;</span> <span style="color: #ff0000;">&quot;&quot;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> do-capitalize <span style="color: #66cc66;">&#40;</span>capitalize text<span style="color: #66cc66;">&#41;</span> text<span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">nil</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> gjg/move-next-sexp-past-current-scope <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;kill sexp following point, move past current scope/sexp/function&quot;</span>
  <span style="color: #66cc66;">&#40;</span>beginning-of-line<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">let</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>beg <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>re-search-forward <span style="color: #ff0000;">&quot;^[ <span style="color: #000099; font-weight: bold;">\t</span>]*function[ <span style="color: #000099; font-weight: bold;">\t</span>]+[^}]+?}&quot;</span> <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>mark-<span style="color: #b1b100;">defun</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#40;</span>kill-region <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>mark<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>forward-line<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>yank<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>indent-region <span style="color: #66cc66;">&#40;</span>mark<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>point<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/wordpress/snippets-with-emacs-lisp-power/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
