<?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>cmarcelo</title>
	<atom:link href="http://cmarcelo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://cmarcelo.wordpress.com</link>
	<description>Yet another tech blog</description>
	<lastBuildDate>Wed, 04 Nov 2009 03:45:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='cmarcelo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>cmarcelo</title>
		<link>http://cmarcelo.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://cmarcelo.wordpress.com/osd.xml" title="cmarcelo" />
	<atom:link rel='hub' href='http://cmarcelo.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Moved again</title>
		<link>http://cmarcelo.wordpress.com/2009/11/04/moved-again/</link>
		<comments>http://cmarcelo.wordpress.com/2009/11/04/moved-again/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 03:45:56 +0000</pubDate>
		<dc:creator>cmarcelo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://cmarcelo.wordpress.com/?p=9</guid>
		<description><![CDATA[This blog has moved again, reach it now at cmarcelo.org/blog. Thanks!<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cmarcelo.wordpress.com&amp;blog=2599603&amp;post=9&amp;subd=cmarcelo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This blog has moved again, reach it now at <a href="http://cmarcelo.org/blog">cmarcelo.org/blog</a>. Thanks!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cmarcelo.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cmarcelo.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cmarcelo.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cmarcelo.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cmarcelo.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cmarcelo.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cmarcelo.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cmarcelo.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cmarcelo.wordpress.com&amp;blog=2599603&amp;post=9&amp;subd=cmarcelo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cmarcelo.wordpress.com/2009/11/04/moved-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/623957ab28e5c4785a7fcb66932fa9c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cmarcelo</media:title>
		</media:content>
	</item>
		<item>
		<title>A little Emacs experiment</title>
		<link>http://cmarcelo.wordpress.com/2008/04/26/a-little-emacs-experiment/</link>
		<comments>http://cmarcelo.wordpress.com/2008/04/26/a-little-emacs-experiment/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 01:56:33 +0000</pubDate>
		<dc:creator>cmarcelo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[yasnippet]]></category>
		<category><![CDATA[yegge]]></category>

		<guid isPermaLink="false">http://cmarcelo.wordpress.com/?p=7</guid>
		<description><![CDATA[As I mentioned before, after starting out the new job, in a new city, with a new language, and a new computer, I started playing with GNU Emacs editor. I kind of staled with Vim, knew how to do stuff, but I wasn&#8217;t feeling very pleased by Vimscript. On the other hand I was reading [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cmarcelo.wordpress.com&amp;blog=2599603&amp;post=7&amp;subd=cmarcelo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As I mentioned before, after starting out the new job, in a new city, with a new language, and a new computer, I started playing with <a href="http://www.gnu.org/software/emacs/">GNU Emacs</a> editor. I kind of <em>staled</em> with Vim, knew how to do stuff, but I wasn&#8217;t feeling very pleased by Vimscript. On the other hand I was reading good things about Emacs (many of them in <a href="http://steve-yegge.blogspot.com/">Steve Yegge</a> blog and his <a href="http://steve.yegge.googlepages.com/blog-rants"><em>Drunken Rants</em></a>) and always had some curiosity about Elisp.</p>
<p>At first I was using it just for playing at home, and kept using Vim at work, since my project was running at high speed and I was a little bit insecure &#8212; specially because I wanted to use a version from CVS that supported fancy Truetype fonts in the X11 environment. After some time, I got confident enough to use it full-time, bootstrapped my <code>.emacs</code> file with <a href="http://code.google.com/p/barbieri-playground/source/browse/dot-files/emacs">Barbieri&#8217;s <code>.emacs</code></a> plus minor modifications &#8212; funny thing is, for some reason I kept using Vim to edit my <code>.emacs</code> file for a few weeks.</p>
<p>Inside Emacs&#8217; <code>M-x info</code> library, there is a nice document, also available on the web, <a href="http://www.gnu.org/software/emacs/emacs-lisp-intro/">Programming in Emacs Lisp</a>. Nice because it explains Elisp but also how Emacs works at the same time &#8212; strongly recommended for those who are starting. Another good resource is Yegge&#8217;s <a href="http://steve-yegge.blogspot.com/2008/01/emergency-elisp.html">Emergency Lisp</a>, which is a good practical summary of the language.</p>
<p>During this process I kept talking to my friends about the new editor (we were all Vim users) and trying to push Emacs into them, too. It worked for at least <a href="http://dropthenumbers.wordpress.com">one of them</a>. He tried a bit, but missed some features from the editor he used to work, Textmate. We both immediatly concluded: <em>hey, Emacs should be able to do everything that Textmate did, and more</em>.</p>
<p>So he <a href="http://obvio171.wordpress.com/2008/04/12/yak-shaving-optimizing-brain-usage-for-code-snippets/">found out about yasnippet</a> that allowed the creation of mini-templates that are triggered by short strings and then using <code>TAB</code> (yes, the guy has two blogs, don&#8217;t ask me why). I ended up trying to solve another problem, which is to automatically insert the closing parenthesis when you insert the opening (abstract this to use with other interesting pairs of characters). It was just using the existing <code>skeleton-pair</code> feature available in Emacs, with a few twists.</p>
<h3>Show me the code</h3>
<p>I&#8217;ll comment on my solution, but you can also grab the raw file <a href="http://littlechina.org/~cmarcelo/paren-experiment.el">here</a>. By the way, I&#8217;ve used <a href="http://www.emacswiki.org/cgi-bin/wiki/Htmlize"><code>M-x htmlize-buffer</code></a> to create colorized pieces of code.</p>
<p><code></p>
<pre><span style="color:#ff7f24;">;; </span><span style="color:#ff7f24;">Paren experiment
</span>(setq skeleton-pair t)
(<span style="color:#00ffff;">defvar</span> <span style="color:#eedd82;">my-skeleton-pair-alist</span>
  '((?\) . ?\()
    (?\] . ?\[)
    (?} . ?{)
    (?<span style="color:#ffa07a;">" . ?"</span>)))</pre>
<p></code></p>
<p>First we needed to activate <code>skeleton-pair</code>. It&#8217;s part of <a href="http://www.emacswiki.org/cgi-bin/wiki/SkeletonMode"><code>skeleton-mode</code></a>. It allows you to type <tt>(</tt> and get <tt>()</tt> with the point (also known as cursor) positioned inside the parens. Also allows you to selected a region and type <tt>(</tt>, and the region will be inside the parens. In this block we also create a helper association list, that we&#8217;ll be using later.</p>
<p><code></p>
<pre>(<span style="color:#00ffff;">defun</span> <span style="color:#87cefa;">my-skeleton-pair-end</span> (arg)
  <span style="color:#ffa07a;">"Skip the char if it is an ending, otherwise insert it."</span>
  (interactive <span style="color:#ffa07a;">"*p"</span>)
  (<span style="color:#00ffff;">let</span> ((char last-command-char))
    (<span style="color:#00ffff;">if</span> (and (assq char my-skeleton-pair-alist)
             (eq char (following-char)))
        (forward-char)
      (self-insert-command (prefix-numeric-value arg)))))</pre>
<p></code></p>
<p>First real thing is here. We defined a function that accepts one argument. The <code>interactive</code> tells us how we fill the arguments when the function is called via some key or key combination interactively.</p>
<p>At this moment it&#8217;s nice to know that everything you type in Emacs will end up <em>triggering</em> some function. Even simple characters. When you type <tt>a</tt>, Emacs will look in a table and see what function it should call. Normal letters like <tt>a</tt> are bound to the function <code>self-insert-command</code>.</p>
<p>Back to the function: it&#8217;s body is very simple, if the character we typed (given by the <em>global</em> <code>last-command-char</code>) is one <em>closing char</em> present in our association list and the next character is the same, we just <code>forward-char</code>, otherwise, we add the character as usual. The idea is to bind this function to the closing chars like <tt>)</tt> and <tt>}</tt>. That&#8217;s what we do next:</p>
<p><code>
<pre>
(<span style="color:#00ffff;">dolist</span> (pair my-skeleton-pair-alist)
  (global-set-key (char-to-string (first pair))
                  'my-skeleton-pair-end)
  <span style="color:#ff7f24;">;; </span><span style="color:#ff7f24;">If the char for begin and end is the same,
</span>  <span style="color:#ff7f24;">;; </span><span style="color:#ff7f24;">use the original skeleton
</span>  (global-set-key (char-to-string (rest pair))
                  'skeleton-pair-insert-maybe))
</pre>
<p></code></p>
<p>So when you type <tt>(</tt> the function <code>skeleton-pair-insert-maybe</code> takes care, when you type <tt>)</tt> our function will take care of the ending. This gives the first feature over pure skeleton-pair: when you type <tt>(</tt> and then <tt>)</tt> you&#8217;ll end up with the right thing <tt>()</tt> instead of <tt>())</tt> that the plain skeleton pair would give you.</p>
<p>After testing a bit, and showing to others, we realize: if I press <tt>(</tt> and then backspace I would still have the <tt>)</tt> hanging around. Solutions? Well, let&#8217;s rebind <code>Backspace</code> to be smart enough about that, right? Well, that&#8217;s what I did at first: do my thing and call the original bind for backspace <code>backward-delete-char-untabify</code>. It worked&#8230;</p>
<p>&#8230;except when some language mode rebinds backspace, like <code>python-mode</code> because it uses backspace also to walk thru the possible indentations in the code and we would break their binding. And guess what? Lately I was coding mostly in Python. After some research, a solution came up:</p>
<p><code>
<pre>
(<span style="color:#00ffff;">defadvice</span> <span style="color:#87cefa;">backward-delete-char-untabify</span>
  (before my-skeleton-backspace activate)
  <span style="color:#ffa07a;">"When deleting the beginning of a pair, and the ending is next char, delete it too."</span>
  (<span style="color:#00ffff;">let</span> ((pair (assq (following-char) my-skeleton-pair-alist)))
    (and pair
         (eq (preceding-char) (rest pair))
         (delete-char 1))))
</pre>
<p></code></p>
<p>Short explanation: we say that this piece of code will run <em>before</em> <code>backward-delete-char-untabify</code> runs. It does what we need: if we are calling backspace to delete an opening paren and the closing paren is right after, we delete the closing one. After we run, the normal function will run and delete the opening one. Now <code>python-mode</code> or any other mode can rebind backspace as they want, everytime they use the original function, our code will run.</p>
<p>And that&#8217;s how we got the second feature (smart backspace). And that&#8217;s it. Actually after that, experimenting with other modes, like the <code>cc-mode</code> (default for C/C++ files), I discovered that the opening paren (as other opening chars) are binded to <code>c-electric-paren</code> to do indentation as you type.</p>
<p>I didn&#8217;t found an easy way to workaround this like in backspace, because the original function for <tt>(</tt> is <code>self-insert-char</code> but making an <em>advice</em> for this function would make our code run lots and lots of times unnecessarily. The other solution would be to create advices for the <code>c-electric-*</code> functions. But since I&#8217;m not using this smart parens when using C, I didn&#8217;t investigate further, so if you discover another clean way to do this, please tell me.</p>
<h3>Conclusion</h3>
<p>I hope this post could teach you something about Emacs. The code I present here is not very important, but the <em>concepts</em> around it are, for example: the binding of keys to functions in Emacs, or how to improve functions by using <code>defadvice</code>. Just <em>knowing</em> these concepts is already useful: later when you need something similar, you&#8217;ll know where to look. Even better, when solving a problem, you&#8217;ll have new ideas on how to solve it.</p>
<p>I&#8217;m still using this code, not sure for how long. I can say it&#8217;s useful when I&#8217;m coding Python &#8212; with a few exception cases. In other modes &#8212; like when typing normal text &#8212; the <em>smart parens</em> are not very useful for me, and in <code>erc</code> (one way to use IRC inside Emacs) they are even annoying, but that&#8217;s just me. If you try it, comments are welcome. Also are welcome new ideas on how to deal with these problems.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/cmarcelo.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/cmarcelo.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cmarcelo.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cmarcelo.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cmarcelo.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cmarcelo.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cmarcelo.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cmarcelo.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cmarcelo.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cmarcelo.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cmarcelo.wordpress.com&amp;blog=2599603&amp;post=7&amp;subd=cmarcelo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cmarcelo.wordpress.com/2008/04/26/a-little-emacs-experiment/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/623957ab28e5c4785a7fcb66932fa9c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cmarcelo</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello (again?)</title>
		<link>http://cmarcelo.wordpress.com/2008/04/22/hello-again/</link>
		<comments>http://cmarcelo.wordpress.com/2008/04/22/hello-again/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 03:08:50 +0000</pubDate>
		<dc:creator>cmarcelo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[indt]]></category>
		<category><![CDATA[openbossa]]></category>
		<category><![CDATA[soc]]></category>

		<guid isPermaLink="false">http://cmarcelo.wordpress.com/?p=6</guid>
		<description><![CDATA[Hello, I am Caio Marcelo (in IRC the nickname is cmarcelo) and this is my brand new blog, mostly focused on technology, like many blogs I like to read. I had a previous attempt, at blogspot, started almost two years ago to talk about my Summer of Code project. And the last post is from [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cmarcelo.wordpress.com&amp;blog=2599603&amp;post=6&amp;subd=cmarcelo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hello, I am Caio Marcelo (in IRC the nickname is cmarcelo) and this is my brand new blog, mostly focused on technology, like many blogs I like to read.</p>
<p>I had a previous attempt, at <a href="http://cmarcelo.blogspot.com">blogspot</a>, started almost two years ago to talk about my Summer of Code project. And the last post is from one year ago. I was very excited about our Free Software group in Unicamp (my university).</p>
<p>Since then, a lot of changes have taken place. I was hired by <a href="http://www.indt.org.br">INdT</a> (Instituto Nokia de Tecnologia) to work as a researcher on the <a href="http://www.openbossa.org">OpenBossa</a> labs in Recife/PE. This was about 8 months ago, when I joined the amazing people in the <strong>Concepts</strong> team and with them helped build <a href="http://openbossa.indt.org.br/canola/index.html">Canola2</a> (and contributed to lots of open source libraries to make it work), a media center for Nokia&#8217;s Internet tablets. After much work we have a great product for the tablets.</p>
<p>Well, that&#8217;s it for now. I have some other posts still in draft about other changes &#8212; the most <em>dramatic</em> being the one about leaving Vim to use Emacs. Let&#8217;s see if this time I keep a good posting rate :-)</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/cmarcelo.wordpress.com/6/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/cmarcelo.wordpress.com/6/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/cmarcelo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/cmarcelo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/cmarcelo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/cmarcelo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/cmarcelo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/cmarcelo.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/cmarcelo.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/cmarcelo.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=cmarcelo.wordpress.com&amp;blog=2599603&amp;post=6&amp;subd=cmarcelo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://cmarcelo.wordpress.com/2008/04/22/hello-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/623957ab28e5c4785a7fcb66932fa9c1?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">cmarcelo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
