<?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>Ashutosh Mehra's Blog &#187; Emacs</title>
	<atom:link href="http://ashutoshmehra.net/blog/category/emacs/feed/" rel="self" type="application/rss+xml" />
	<link>http://ashutoshmehra.net/blog</link>
	<description>Notes on Math, Computer Science &#38; Programming</description>
	<lastBuildDate>Sat, 27 Feb 2010 14:22:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Aha! Emacs 23!</title>
		<link>http://ashutoshmehra.net/blog/2009/04/aha-emacs-23/</link>
		<comments>http://ashutoshmehra.net/blog/2009/04/aha-emacs-23/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 00:23:20 +0000</pubDate>
		<dc:creator>Ashutosh</dc:creator>
				<category><![CDATA[Emacs]]></category>

		<guid isPermaLink="false">http://ashutoshmehra.net/blog/?p=327</guid>
		<description><![CDATA[
Some days ago I migrated to the emacs 23 pretest (23.0.92 Windows binaries and 23.0.91 Cocoa Mac binaries). In this post I&#8217;ll give brief notes of several of the cool features I found in emacs 23. 
First, the good news: My zillions of customizations, installed packages and hooks all worked without a glitch and my [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/emacs128x128icon.png" alt="Emacs Logo" title="Emacs Logo" width="128" height="128" class="alignleft size-full wp-image-360" /><br />
Some days ago I migrated to the <a href="http://alpha.gnu.org/gnu/emacs/pretest/">emacs 23 pretest</a> (<a href="http://alpha.gnu.org/gnu/emacs/pretest/windows/"><tt>23.0.92</tt> Windows binaries</a> and <a href="http://www.porkrind.org/emacs/"><tt>23.0.91</tt> Cocoa Mac binaries</a>). In this post I&#8217;ll give brief notes of several of the cool features I found in emacs 23. </p>
<p>First, the good news: My zillions of customizations, installed packages and hooks all worked without a glitch and my most frequently used modes have been working great <span id="more-327"></span> &#8212; <tt>c++</tt>, <tt>emacs-lisp</tt>, <tt>haskell</tt> (with <tt>ghci</tt> interaction), <tt>dired</tt>, <tt>eshell</tt> and the dear old <tt>text</tt>. Also there have been no crashes or freezes or (I shudder!) data corruptions. The pretest looks rock-solid. The only major thing that didn&#8217;t work for me was <tt>w3m</tt> (it asked me to try the development version; that might likely have worked).</p>
<p>So, what&#8217;s new?</p>
<h4>The <tt>C-n</tt> and <tt>C-p</tt> line-motion commands now move by screen lines</h4>
<p>Now <tt>next-line</tt>/<tt>previous-line</tt> go to the next/previous <i>visual</i> line as opposed to the <i>logical</i> line. In the words of StackOverflow poster Chris R, emacs navigation now <a href="http://stackoverflow.com/questions/515946/emacs-navigation-in-new-versions-acts-like-notepad">acts like notepad</a>.</p>
<p>While it&#8217;s just a change of defaults and one could revert to the earlier behavior by setting <tt>line-move-visual</tt> to <tt>nil</tt>, I still think, this is, by far, the biggest change in behavior of emacs 23. And I can safely bet that it would break many keyboard macros. In less than a week of use, this behavior bit me twice while calling some keyboard macros. Note that our friends <tt>C-a</tt> and <tt>C-e</tt> (<tt>move-beginning-of-line</tt> and <tt>move-end-of-line</tt>) still act on logical lines.</p>
<p>With this new default, the usual technique of jumping to the next/previous visual line (of a long logical line) via a quick isearch is no longer needed. But more keystrokes have to be pressed to go next/previous logical line.</p>
<p>There seems to have been a fair bit of discussion around <a href="http://www.opensubscriber.com/message/emacs-devel@gnu.org/11355250.html">the behavior of <tt>C-n</tt> and <tt>C-p</tt></a>.</p>
<h4>Emacs can start as a daemon (the <i>multi-tty</i> feature)</h4>
<p>With the <tt>--daemon</tt> command-line argument, emacs starts running in background (with no visible terminal session or <a href="http://emacsworld.blogspot.com/2008/08/emacs-frames-and-windows.html">frame</a>).  New terminal sessions or frames can be created using <tt>emacsclient</tt>: specify <tt>-c</tt> to <b>c</b>reate frames or <tt>-t</tt> for <b>t</b>erminal sessions; and optionally <tt>-n</tt> if you don&#8217;t wish <tt>emacsclient</tt> to wait for the editing to finish. And if you&#8217;re feeling all hackerish, there&#8217;s even a <tt>-e</tt> option to supply an expression to be eval&#8217;ed!</p>
<p><tt>emacsclient</tt> also worked way back with emacs 21, but only after a <tt>server-start</tt> had been done from a running emacs session. Then <tt>emacsclient</tt> would just create a new buffer in that existing session/frame.</p>
<p>With the new daemon support, distinct sessions/frames can be created, all connected with the same server. One thing I find cool with this setup is that different sessions opened simultaneously share buffers and other state. So if you make some changes (add text, delete paragraphs whatever) in a buffer in one session, you can see those changes get reflected in the view of that buffer in another session <i>in real time</i>. Finally, even if all sessions are closed, the buffers remain open.</p>
<p><center><div id="attachment_364" class="wp-caption alignnone" style="width: 410px"><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/emacs23_server_edit.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/emacs23_server_edit_ss.png" alt="Two sessions (terminal and frame) working on the same buffer" title="Two sessions (terminal and frame) working on the same buffer" width="400" height="305" class="size-full wp-image-364" /></a><p class="wp-caption-text">Two sessions (terminal and frame) working on the same buffer.</p></div></center></p>
<p>In emacs 21, <tt>emacsclient</tt> was already instantaneous because it didn&#8217;t have to load up a new copy of emacs and do all the startup initialization. Hence it could be safely set as the <tt>$EDITOR</tt> on Mac or Linux (See Jared&#8217;s post <a href="http://curiousprogrammer.wordpress.com/2009/01/29/what-is-your-dollar-editor/">What is your $EDITOR?</a>). The same is true with emacs 23 running in <tt>--daemon</tt> mode, and now we have the added flexibility to create new sessions/frames.</p>
<p><tt>--daemon</tt> worked great for me on the Mac but on Windows, emacs refused to launch in the daemon mode, giving the error &#8220;This platform does not support the -daemon flag.&#8221; I wonder if daemon support for Windows would be included in the final emacs 23.</p>
<p>Emacs sessions created via <tt>emacsclient</tt> have a special indicator <tt>@</tt> in the mode-line and the minor-mode indicator <tt>Server</tt>. <tt>C-x C-c</tt> is now mapped to <tt>save-buffers-kill-<i>terminal</i></tt> rather than <tt>save-buffers-kill-<i>emacs</i></tt>.</p>
<p>See <tt>djcb</tt>&#8217;s entries at <a href="http://emacs-fu.blogspot.com/">emacs-fu</a> (a good regular source of emacs tricks) on <a href="http://emacs-fu.blogspot.com/2009/02/emacs-daemon.html">emacs &#8211;daemon</a> and <a href="http://emacs-fu.blogspot.com/2009/03/windows-and-daemons.html">windows and daemons</a>.</p>
<h4>Directory-local Variables</h4>
<p>Directory-local variables are a great way to associate certain mode-specific variables to every file contained in a particular directory (or in its subdirectories).</p>
<p>As an example, say, you&#8217;re working on a <tt>C++</tt> project that has peculiar code indentation requirements (indents are to be real tab character worth 8-space) while your usual indentation style is quite different (always 2-space indents, never tabs). Using directory-local variables, you can emacs pick the project&#8217;s indent style for files in the project&#8217;s directory and otherwise use your regular style. Something like the following setup would do the trick.</p>
<p>First, as usual, in your <tt>.emacs</tt> define your own personal style, via, say:<br />
<script src="http://gist.github.com/93143.js"></script></p>
<p>Next, define variables like <tt>c-basic-offset</tt>, <tt>tab-width</tt>, <tt>indent-tabs-mode</tt> to match your project&#8217;s style and associate them to the root of your source repository. So if your projects root is at &#8220;d:/work/BeautifulCode/&#8221;, you do this in your <tt>.emacs</tt>:<br />
<script src="http://gist.github.com/93142.js"></script></p>
<p>Now, whenever you open any <tt>C++</tt> file under your project&#8217;s root, the project-specific formatting would get applied. You can work this way with many different projects, each having different formatting requirements, without having to write specific customizations via a magic first line at the top of each file like:</p>
<pre>
/* -*- c-basic-offset: 8; tab-width: 8; indent-tabs-mode: t; -*- */
</pre>
<p>Using directory-local variables, one could also define scm parameters (server/port, repository root, &#8230;) on a per root-directory basis. I think it&#8217;s a very powerful feature.</p>
<p>Similar to the above configuration via <tt>dir-locals-set-directory-class</tt> and <tt>dir-locals-set-class-variables</tt>, it is possible to define directory-local variables via a <tt>.dir-locals.el</tt> file (actually, the file defined by the <tt>dir-locals-file</tt> variable).</p>
<p>The idea is to place all project-related customizations in a <tt>.dir-locals.el</tt> file placed at the root of the project source tree. Then, when emacs opens any file under it, it applies these customizations. This way, uniform configurations can be shared across multiple developers using emacs.</p>
<p>Also see <a href="http://atomized.org/2009/01/emacs-23-directory-local-variables/">atomized&#8217;s post on directory local variables</a> where he brings up some problems he&#8217;s faced with the directory-local variables feature.</p>
<h4>Emacs can have transparent frames</h4>
<p>The transparency of the emacs frame can be now controlled via the <tt>alpha</tt> frame parameter. Try something like: <tt>(set-frame-parameter (selected-frame) 'alpha 70)</tt></p>
<p><center><div id="attachment_366" class="wp-caption alignnone" style="width: 410px"><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/emacs23_transparency_support.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/emacs23_transparency_support_sm.png" alt="A Transparent emacs frame" title="A Transparent emacs frame" width="400" height="284" class="size-full wp-image-366" /></a><p class="wp-caption-text">A Transparent emacs frame</p></div></center></p>
<p>This is undoubtedly cool (I bet XCode and Visual Studio can&#8217;t do that!) and maybe useful in one-off cases. But I don&#8217;t think anyone would have long emacs sessions with a transparent frame &#8212; it hinders visibility and is distracting.</p>
<h4>D-Bus and ZeroConf</h4>
<p><a href="http://en.wikipedia.org/wiki/D-Bus">D-Bus</a> is a Unix IPC system for applications to talk to each other. I&#8217;ve not had a chance to play with it, but for an example of using <tt>dbus</tt> in emacs, see <tt>djcb</tt>&#8217;s <a href="http://emacs-fu.blogspot.com/2009/01/using-d-bus-example.html">using D-Bus example</a>.</p>
<h4>Anti-aliased font on X11</h4>
<p>This will be a welcome enhancement for linux programmers. Being a Mac/Win user, I&#8217;ve enjoyed anti-aliased fonts for some time now. For details and screenshots on Linux, see <a href="http://www.emacswiki.org/cgi-bin/wiki/XftGnuEmacs">XftGnuEmacs</a> on EmacsWiki. Alexandre Vassalotti has a <a href="http://peadrop.com/blog/2007/09/17/pretty-emacs-reloaded/">Pretty Emacs Reloaded</a> package for Ubuntu. <a href="http://dagobart.wordpress.com/2009/04/08/for-purpose-of-reference-anti-alias-emacs/">Another page</a> describing how to set this up on Linux.</p>
<p>By the way, with anti-aliasing, I love the <a href="http://www.gnome.org/fonts/">Bitstream Vera Sans Mono</a> and <a href="http://www.webdevkungfu.com/textmate-envy-aka-monaco-font-for-windows/">Monaco</a> fonts for programming (in particular because they have nice distinct shapes for <tt>l</tt>/<tt>1</tt>).</p>
<h4>Recycle Bin/Trash can be used for file deletion</h4>
<p>If <tt>delete-by-moving-to-trash</tt> is non-nil, then deleted files are moved to the Recycle Bin/Trash. It&#8217;s surprising that this feature wasn&#8217;t already available.</p>
<h4>Search Enhancements</h4>
<p>Some neat search and highlight related enhancements I found:</p>
<ul>
<li><tt>M-s a C-s</tt> and <tt>M-s a M-C-s</tt> in dired runs multi-file isearch on the marked files. Should come in handy.</li>
<li>For incremental <i>word</i> search, there&#8217;s a new command <tt>isearch-forward-word</tt> globally bound to <tt>M-s w</tt>. While doing an isearch, the same key <tt>M-s w</tt> (now bound to another new command <tt>isearch-toggle-word</tt>) toggles word searching on/off.</li>
<li><tt>M-s h r</tt> (bound globally to the command <tt>highlight-regexp</tt>) can be used to highlight all occurances of a regexp in a buffer. The same key can be used when doing isearch to highlight all occurrances of the current search string (it calls <tt>isearch-highlight-regexp</tt> internally).</li>
<li><tt>occur</tt> can now be invoked using <tt>M-s o</tt>. The same key runs an <tt>isearch-occur</tt> when doing an isearch.</li>
<li>If an isearch is started in the minibuffer, it searches <i>in the minibuffer</i>!</li>
<li>You can now specify group numbers explicitly in the regexp via an extended form of &#8220;shy&#8221; groups: <tt>\(?<i>number</i>:<i>regexp</i>\)</tt>. Again a handy thing.</li>
</ul>
<h4>Some New Default Keybindings</h4>
<ul>
<li><tt>C-x C-+</tt> or <tt>C-x C-=</tt> increase the text face size (font size), while <tt>C-x C--</tt> decreases it (that is, zooming in/out). <tt>C-x C-0</tt> restores to the default size. These are mapped to <tt>text-scale-adjust</tt>. You can also do stuff like <tt>C-x C-+ C-+ C-+</tt>, that is, omit the <tt>C-x</tt> on repeated commands.</li>
<li><tt>C-l</tt> now does something more useful. On the first invocation, it moves the current line to center of the window (as it did earlier). But on the second successive invocation, it moves the current line to the top of the window; and then to the bottom on a third invocation. Subsequent invocations cycle through these three placements. <tt>C-l</tt> is now bound to the <tt>recenter-top-bottom</tt> (in previous versions, it was bound to <tt>recenter</tt>).</li>
</ul>
<h4>New Modes</h4>
<ul>
<li><tt>linum-mode</tt> is a minor-mode for line numbers in the left margin. This is like vi&#8217;s <tt>:set nu</tt> command. I have already had <a href="http://stud4.tuwien.ac.at/~e0225855/linum/linum.html">the linum package</a> installed for some years now, and had used it occasionally. It is nice to see it finally become a part of emacs.</li>
<li>There&#8217;s a new game called <tt>bubbles</tt> (somewhat like &#8220;bejeweled&#8221;)</li>
<li><tt>proced</tt> is a &#8220;process editor&#8221; and creates a buffer with a list of processes running on the system (much like <tt>ibuffer</tt> does for buffers, or <tt>dired</tt> for files). You can use commands like <tt>k</tt> to kill a process etc. <tt>proced</tt> was not available on the Mac, while on Windows, it didn&#8217;t allow me to kill processes.</li>
</ul>
<h4>New Behaviors</h4>
<ul>
<li>The <tt>shift-select-mode</tt> variable (<tt>t</tt> by default) enables Win/Mac style selection by pressing the shift key first, and then pressing the right/left arrow keys to grow/shrink selection.</li>
<li>Pressing <tt>TAB</tt> when transient mark mode is now on (the default now) causes certain commands like <tt>M-q</tt> (<tt>fill-paragraph</tt>), <tt>M-$</tt> (<tt>ispell-word</tt>) and <tt>TAB</tt> to operate on the region instead.</li>
<li>Completion now takes text after the point in minibuffer into account for filtering the remaining alternatives (that were generated by the text before the point). For instance, if I&#8217;m trying to open the emacs PROBLEMS file, and the minibuffer input is <tt>d:/progs/emacs/etc/</tt>, and I type <tt>oo</tt> and bring the point back to before the <tt>oo</tt>, so that the input now looks like:<br/>
<p><center><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/completion_pre.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/completion_pre.png" alt="Minibuffer input before completion" title="Minibuffer input before completion" width="513" height="32" class="size-full wp-image-362" /></a></center></p>
<p>If I then press <tt>TAB</tt>, emacs not only restricts the choices to the two files that have <tt>oo</tt> in them (<tt>COOKIES</tt> and <tt>spook.lines</tt>) but also updates the minibuffer input <tt>oo</tt> to <tt>ook</tt> (since both of these have a <tt>k</tt> following <tt>oo</tt>):<br/></p>
<p><center><a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/completion_post.png"><img src="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/completion_post.png" alt="Updated minibuffer input and suggestion completion changes" title="Updated minibuffer input and suggestion completion changes" width="499" height="302" class="size-full wp-image-361" /></a></center></p>
</li>
<li>Minibuffer input for shell commands (<tt>M-!</tt>) also allows completion.</li>
<li><tt>M-x butterfly</tt> flips the <a href="http://xkcd.com/378/">desired bit on the disk platter</a>. It is almost a cliché now &#8212; but somehow it&#8217;s still funny!</li>
</ul>
<p>That&#8217;s about it! More pleasant surprises will turn up as I play more with it.</p>
<p><i>A word on the emacs <tt>etc/NEWS</tt> file</i>. I would never have discovered some of the features mentioned above without digging through the <tt>NEWS</tt> file. It lists several other improvements and additions that I&#8217;ve not even had time to try! I couldn&#8217;t find a copy online, so here&#8217;s a link to a local copy of the <a href="http://ashutoshmehra.net/blog/wp-content/uploads/2009/04/news-230921.txt">emacs 23 NEWS file (build 23.0.92.1)</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ashutoshmehra.net/blog/2009/04/aha-emacs-23/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
