<?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; Emacs Lisp</title>
	<atom:link href="http://gregorygrubbs.com/tag/emacs-lisp/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>10 Tips for Powerful Emacs on Windows</title>
		<link>http://gregorygrubbs.com/emacs/10-tips-emacs-windows/</link>
		<comments>http://gregorygrubbs.com/emacs/10-tips-emacs-windows/#comments</comments>
		<pubDate>Sun, 23 May 2010 18:24:14 +0000</pubDate>
		<dc:creator>Gregory Grubbs</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[Emacs Lisp]]></category>
		<category><![CDATA[Microsoft Windows]]></category>
		<category><![CDATA[Software download links]]></category>
		<category><![CDATA[System software]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://gregorygrubbs.com/?p=439</guid>
		<description><![CDATA[
I avoided using Microsoft Windows for almost 15 years, but with my
new job at a Microsoft-enthralled development shop, those idyllic
days have come to an abrupt end.  Because in the past I could always
use my trusty Linux and OS X machines, I never did push past the
hurdles of using Emacs on Windows.  My utter [...]]]></description>
			<content:encoded><![CDATA[<p><a title="Ladybug Liftoff" href="http://flickr.com/photos/23084352@N00/403926829"><img src="http://farm1.static.flickr.com/163/403926829_cc213ee88b.jpg" alt="" /></a></p>
<p>I avoided using Microsoft Windows for almost 15 years, but with my<br />
new job at a Microsoft-enthralled development shop, those idyllic<br />
days have come to an abrupt end.  Because in the past I could always<br />
use my trusty Linux and OS X machines, I never did push past the<br />
hurdles of using Emacs on Windows.  My utter reliance on Org-mode,<br />
TRAMP, and Ediff (to name a few) made it essential to get Emacs<br />
working on Windows if at all possible.</p>
<p>Now I am using Emacs on Windows XP and Windows 7 on a daily basis,<br />
and am quite happy with the results.  It was not easy to get to the<br />
point of full functionality, so I wanted to share the magic that<br />
makes it all work.<br />
<span id="more-439"></span></p>
<p>I have decided against using the Cygwin Emacs package for several reasons:</p>
<ul>
<li>Running a windowed/multi-frame/pretty version requires running<br />
Cygwin-X, which is quite a lot of overhead just to run Emacs. I<br />
have had a few interface and display problems lately with Cygwin-X<br />
also.</li>
<li>Cool-though-seldom-used features that work in the native port do<br />
not work in the Cygwin port: Window opacity control, for example</li>
<li>Using the native port means I can always be running the latest<br />
released version from gnu.org</li>
<li>The native port just runs faster</li>
</ul>
<p>On the other hand, Cygwin does play a crucial role in making the<br />
native Emacs port work properly.  I have tried and hated using PuTTY<br />
and Plink, and various one-off ports of standard Unix commands.<br />
Using Cygwin and its package management makes all this<br />
much simpler and more reliable.</p>
<p>So all the hints given here use the &#8220;official&#8221; Emacs for Windows<br />
(sometimes referred to as NTEmacs), as well as Cygwin (with no<br />
dependency on Cygwin-X).</p>
<p>I really hope this helps some poor beleaguered Linux/OS X Emacs user<br />
make the giant backwards leap. With these tips and little helpers like<br />
<a href="http://www.launchy.net/">Launchy</a>, you won&#8217;t even have to<br />
acknowledge that you&#8217;re running Windows!</p>
<h2>Software download links</h2>
<p>Here&#8217;s where you will find all the software referenced in the tips:</p>
<ul>
<li><a href="http://ftp.gnu.org/pub/gnu/emacs/windows/">Emacs for Windows</a></li>
<li><a href="http://www.cygwin.com/">Cygwin</a></li>
<li><a href="http://gnuwin32.sourceforge.net/">GnuWin32</a> for image libraries</li>
<li><a href="ftp://ftp.franken.de/pub/win32/develop/gnuwin32/cygwin/porters/Humblet_Pierre_A/V1.1/ispell-3.2.06-cygwin-1.3-bin.tar.gz">ISpell package</a></li>
<li><a href="http://files.emacsblog.org/ryan/elisp/maxframe.el">Maxframe.el</a></li>
<li><a href="http://mirror.cs.wisc.edu/pub/mirrors/ghost/ghostgum/gsv49w32.exe">GSView</a></li>
</ul>
<h2>Tip #1: General Usage</h2>
<ul>
<li>Execute runemacs.exe or emacsclientw.exe.  On your Linux and OS X<br />
systems, the binary names or emacs and emacsclient: just use the<br />
windows-specific wrappers included in the standard port when on MS Windows.</li>
<li>Add Cygwin /bin to exec-path.

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>file-directory-p <span style="color: #ff0000;">&quot;c:/cygwin/bin&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'exec-path <span style="color: #ff0000;">&quot;c:/cygwin/bin&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

</li>
</ul>
<h2>Tip #2: Make TRAMP work nicely &#8212; and without PuTTY</h2>
<p>There are people using PuTTY and Plink.exe to get this working, but<br />
I like using good old OpenSSH much better: no translation required<br />
for the keys I use, and I have it installed anyway in Cygwin.</p>
<ul>
<li>Install Cygwin, including the OpenSSH package</li>
<li>In your Emacs init, set shell to bash

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> shell-file-<span style="color: #b1b100;">name</span> <span style="color: #ff0000;">&quot;bash&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> explicit-shell-file-<span style="color: #b1b100;">name</span> shell-file-<span style="color: #b1b100;">name</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

</li>
<li>In Emacs init, set tramp-default-method to &#8220;sshx&#8221; or &#8220;scpx&#8221;

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span>  <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'w32<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> tramp-default-method <span style="color: #ff0000;">&quot;scpx&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>t
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> tramp-default-method <span style="color: #ff0000;">&quot;scpc&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

</li>
<li>Test: Try <code>M-x shell</code>, then visit a TRAMP site such as <code>/user@site:</code> and try <code>M-x shell</code> from there!</li>
</ul>
<h2>Tip #3: Use SVN and GIT without tears</h2>
<p>Version control should work out of the box &#8212; but SSH problems can<br />
interfere sometimes.  So once you get TRAMP working properly, you<br />
should have no problems with VC.</p>
<ul>
<li>Install subversion and git from Cygwin</li>
<li>Use built-in vc-dir, or psvn.el and magit.el</li>
</ul>
<h2>Tip #4: Display images in buffers, including doc-view</h2>
<p>You may have noticed that your Windows Emacs has no ability to<br />
display images.  This is simply due to the fact that the port is<br />
not distributed with the libraries necessary to display them.</p>
<p>The solution is to visit the GnuWin32 link above, download the<br />
packages relevant to the types of images you want to display<br />
(including zlib1 for compressed images), and copy the DLLs into the<br />
bin directory of your Emacs installation (e.g, C:\Program<br />
Files\emacs23-2\bin).</p>
<p>Images will only be displayed after restarting Emacs.</p>
<p>Here&#8217;s a list of DLLs that I now have in my installation:</p>
<ul>
<li>jpeg62.dll</li>
<li>libXpm.dll</li>
<li>libjpeg-62.dll</li>
<li>libpng-bcc.lib</li>
<li>libpng.dll.a</li>
<li>libpng.la</li>
<li>libpng.lib</li>
<li>libpng12-0.dll</li>
<li>libpng12.def</li>
<li>libpng12.dll</li>
<li>libpng12.dll.a</li>
<li>libpng12.la</li>
<li>libtiff3.dll</li>
<li>zlib1.dll (for compression, not images)</li>
</ul>
<h2>Tip #5: Use W3M</h2>
<p>The W3M web browser works fine once you install the w3m binary &#8211;<br />
and once the image display step above is working, you will be able<br />
to display images in the W3M buffers as well.</p>
<ul>
<li>Install w3m from Cygwin</li>
<li>Test image display by hitting <code>T</code> (w3m-toggle-inline-images)</li>
<li>Example screenshot:<br />
<a rel="attachment wp-att-450" href="http://gregorygrubbs.com/emacs/10-tips-emacs-windows/attachment/emacs_pacman_google/"><img class="alignnone size-medium wp-image-450" title="W3M Browser in Emacs" src="http://gregorygrubbs.com/wp-content/uploads/2010/05/emacs_pacman_google-300x127.jpg" alt="W3M Browser in Emacs" width="300" height="127" /></a></li>
</ul>
<h2>Tip #6: Bring back Ediff and Smerge</h2>
<p>Ediff is yet another thing which doesn&#8217;t work as it should.  You<br />
will get an error complaining about Dos-style versus Unix-style<br />
paths.  Fixing it is a simple matter of setting an environment variable.</p>
<ul>
<li>Assure you have Cygwin&#8217;s diff package installed</li>
<li>Set the Windows environment variable nodosfilewarning=1</li>
<li>Restart Emacs, and verify that the environment variable is set by executing <code>M-x shell</code>, then typing <code>env | grep dos</code>, for example</li>
<li><strong>Always, prior to running ediff</strong>, execute <code>M-x shell</code></li>
</ul>
<h2>Tip #7: Spell using ISpell or Aspell</h2>
<p>Fortunately very easy to get working by following <a href="http://bria.nwood.org/node/49">Brian Wood&#8217;s directions</a> using the ISpell package for Cygwin linked above.</p>
<p><strong>Note added later:</strong> </p>
<p>Aspell is even easier to use: just install aspell and the correct language(s) in Cygwin, then use the following in your emacs init:</p>

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>setq-default ispell-program-<span style="color: #b1b100;">name</span> <span style="color: #ff0000;">&quot;aspell&quot;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

<h2>Tip #8: Maximized frame works using maxframe.el</h2>
<p>Those of us who practice Distraction-Free Emacsing, or DFE, will<br />
lament the inability to maximize the frame as we can do on other<br />
systems (ie, a true maximized windows, with no OS window<br />
decoration).  The solution is provided by maxfame.el, linked above.</p>
<p>After loading maxframe.el, use <code>M-x maximize-frame</code> and <code>M-x restore-frame</code></p>
<h2>Tip #9: Print on PostScript printers</h2>
<p>And finally, printing.  Even this just didn&#8217;t work out of the box<br />
for me.  The solution was to use a nice little utility called<br />
GSPrint from the GSView package linked above.</p>
<ul>
<li>Install Ghostscript in Cygwin</li>
<li>Install GSView

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span>string<span style="color: #66cc66;">=</span> <span style="color: #66cc66;">&#40;</span>window-system<span style="color: #66cc66;">&#41;</span> <span style="color: #ff0000;">&quot;w32&quot;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>file-exists-p <span style="color: #ff0000;">&quot;c:/Program Files/Ghostgum/gsview/gsprint.exe&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">progn</span>
      <span style="color: #808080; font-style: italic;">;;  Windows printer</span>
      <span style="color: #66cc66;">&#40;</span>setq-default ps-lpr-command <span style="color: #66cc66;">&#40;</span>expand-file-<span style="color: #b1b100;">name</span> <span style="color: #ff0000;">&quot;c:/Program Files/Ghostgum/gsview/gsprint.exe&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>setq-default ps-printer-<span style="color: #b1b100;">name</span> t<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>setq-default ps-printer-name-option <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> ps-lpr-switches '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;-query&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #808080; font-style: italic;">; show printer dialog</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> ps-right-header '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;/pagenumberstring load&quot;</span> ps-time-stamp-mon-dd-yyyy<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;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'x<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> ps-lpr-command <span style="color: #ff0000;">&quot;gtklp&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

</li>
</ul>
<h2>Tip #10: Some things Just Work™: Nifty Emacs 23 features that work &#8220;out of the box&#8221;</h2>
<p>Bonus tip — some things work already, no fiddling required!</p>
<h3>Select any font you want</h3>
<ul>
<li>M-x menu-set-font (choose something lovely like Consolas or Inconsolata &#8230; or Comic Sans MS)</li>
<li>Example font selection, cross-OS

<div class="wp_syntax"><div class="code"><pre class="lisp" style="font-family:monospace;">      <span style="color: #808080; font-style: italic;">;;* Font selection</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cond</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">or</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'mac<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'ns<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>set-face-font 'default '<span style="color: #ff0000;">&quot;-apple-inconsolata-medium-r-normal--16-0-72-72-m-0-iso10646-1&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'w32<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>set-face-font 'default '<span style="color: #ff0000;">&quot;-outline-Inconsolata-normal-normal-normal-mono-16-*-*-*-c-*-iso8859-1&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">and</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'x<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> emacs-major-version <span style="color: #cc66cc;">23</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>set-face-font 'default '<span style="color: #ff0000;">&quot;-unknown-Inconsolata-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>add-to-<span style="color: #b1b100;">list</span> 'default-frame-alist '<span style="color: #66cc66;">&#40;</span>font <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;-unknown-Inconsolata-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1&quot;</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: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> window-system 'x<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>set-face-font 'default '<span style="color: #ff0000;">&quot;10x20&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
      <span style="color: #66cc66;">&#40;</span>add-hook 'before-make-frame-hook
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">lambda</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>set-frame-font <span style="color: #ff0000;">&quot;-unknown-Inconsolata-normal-normal-normal-*-16-*-*-*-m-0-iso10646-1&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

</li>
<li><code>M-x grep</code>, <code>M-x grep-find</code>, <code>M-x rgrep</code> and friends (as long as<br />
you have the <code>grep</code> and <code>find</code> commands installed!)</li>
<li><code>M-x tetris</code>, <code>M-x doctor</code>, <code>M-x yow</code>, <code>M-x butterfly</code></li>
</ul>
<h3>Frame transparency</h3>
<ul>
<li>Transparent windows are not my favorite thing, as they tend to<br />
hamper DFE (see above).  But there are occasions, like copying text from a<br />
web page into an Emacs buffer, where it can come in quite handy.</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> set-transparency <span style="color: #66cc66;">&#40;</span>alpha-level<span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>interactive <span style="color: #ff0000;">&quot;p&quot;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>message <span style="color: #66cc66;">&#40;</span>format <span style="color: #ff0000;">&quot;Alpha level passed in: %s&quot;</span> alpha-level<span style="color: #66cc66;">&#41;</span><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>alpha-level <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&amp;</span>lt<span style="color: #808080; font-style: italic;">; alpha-level 2)</span>
				<span style="color: #66cc66;">&#40;</span>read-number <span style="color: #ff0000;">&quot;Opacity percentage: &quot;</span> <span style="color: #cc66cc;">85</span><span style="color: #66cc66;">&#41;</span>
				alpha-level<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#40;</span>myalpha <span style="color: #66cc66;">&#40;</span>frame-parameter <span style="color: #b1b100;">nil</span> 'alpha<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#40;</span>set-frame-parameter <span style="color: #b1b100;">nil</span> 'alpha alpha-level<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
				<span style="color: #66cc66;">&#40;</span>message <span style="color: #66cc66;">&#40;</span>format <span style="color: #ff0000;">&quot;Alpha level is %d&quot;</span> <span style="color: #66cc66;">&#40;</span>frame-parameter <span style="color: #b1b100;">nil</span> 'alpha<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></div></div>

</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://gregorygrubbs.com/emacs/10-tips-emacs-windows/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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>
