<?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>Mastering Emacs</title>
	<atom:link href="http://www.masteringemacs.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.masteringemacs.org</link>
	<description>a blog about mastering the world&#039;s best text editor</description>
	<lastBuildDate>Tue, 12 Mar 2013 09:59:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>What&#8217;s New in Emacs 24.3</title>
		<link>http://www.masteringemacs.org/articles/2013/03/11/whats-new-emacs-24-3/</link>
		<comments>http://www.masteringemacs.org/articles/2013/03/11/whats-new-emacs-24-3/#comments</comments>
		<pubDate>Mon, 11 Mar 2013 13:31:54 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=687</guid>
		<description><![CDATA[Emacs version 24.3 is now released to the public. This release, unlike 24.2, is chock full of goodies. I&#8217;ve taken the liberty of annotating things that&#8217;re relevant to me &#8212; and hopefully you, too, dear reader &#8212; but I&#8217;ve limited my commentary to things I&#8217;m familiar with. Always keen to hear what you think about [...]]]></description>
				<content:encoded><![CDATA[<p>Emacs version 24.3 is now released to the public. This release, unlike 24.2, is chock full of goodies. I&#8217;ve taken the liberty of annotating things that&#8217;re relevant to me &#8212; and hopefully you, too, dear reader &#8212; but I&#8217;ve limited my commentary to things I&#8217;m familiar with. Always keen to hear what you think about the changes in the comments.</p>
<p>You can retrieve Emacs 24.3 from one of these locations:</p>
<p><strong>Automatic mirror</strong><br />
<em>Note: As of 11 AM on 2013-03-11 I had issues with some mirrors not yet having the new version available.</em><br />
<a href="http://ftpmirror.gnu.org/emacs/emacs-24.3.tar.xz">http://ftpmirror.gnu.org/emacs/emacs-24.3.tar.xz</a><br />
<a href="http://ftpmirror.gnu.org/emacs/emacs-24.3.tar.gz">http://ftpmirror.gnu.org/emacs/emacs-24.3.tar.gz</a></p>
<h1>What&#8217;s New in Emacs 24.3</h1>
<h2>Installation Changes in Emacs 24.3</h2>
<blockquote><p>The default X toolkit is now Gtk+ version 3.<br />
If you don&#8217;t pass <code>--with-x-toolkit</code> to configure, or if you use<br />
<code>--with-x-toolkit=gtk</code> or <code>--with-x-toolkit=yes</code>, configure will try<br />
to build with Gtk+ version 3, and if that fails, try Gtk+ version 2.<br />
You can explicitly require a specific version by passing<br />
<code>--with-x-toolkit=gtk2</code> or <code>--with-x-toolkit=gtk3</code> to configure.
</p></blockquote>
<p>Although I always use Emacs in a window manager, and actively recommend that people who can do as well, this change is unlikely to affect me much at all. I don&#8217;t use scrollbars, toolbars or menubars.</p>
<blockquote><p>New configure option <code>--enable-link-time-optimization</code>, to utilize<br />
an appropriate feature provided by GCC since version 4.5.0.
</p></blockquote>
<p><br/></p>
<blockquote><p>New configure option <code>--without-all</code> to disable most of the optional<br />
features (image support, etc.) that are normally enabled by default.
</p></blockquote>
<p>For the luddites.</p>
<blockquote><p>New configure option <code>--enable-gcc-warnings</code> (for developing/debugging<br />
Emacs).  If building with GCC, this enables compile-time checks that<br />
warn/give errors about possibly-questionable C code.  On a recent GNU<br />
system there should be no warnings; on older and on non-GNU systems<br />
the results may be useful to developers.
</p></blockquote>
<blockquote><p>The configure option <code>--enable-use-lisp-union-type</code> has been<br />
renamed to <code>--enable-check-lisp-object-type</code>, as the resulting<br />
Lisp_Object type no longer uses a union to implement the compile time<br />
check that this option enables.
</p></blockquote>
<blockquote><p>The configure option <code>--disable-maintainer-mode</code> has been removed,<br />
as it was confusingly-named and rarely useful.
</p></blockquote>
<blockquote><p>The configure options <code>--program-prefix</code>, <code>--program-suffix</code>, and<br />
<code>--program-transform-name</code> apply to more than just the installed<br />
binaries.  Now they also affect the man pages, icons, and the<br />
etc/emacs.desktop file; but not the info pages, since this would break<br />
links between the various manuals.
</p></blockquote>
<blockquote><p>You can use <code>NO_BIN_LINK=t make install</code> to prevent the installation<br />
overwriting &#8220;emacs&#8221; in the installation bin/ directory with a link<br />
to &#8220;emacs-VERSION&#8221;.
</p></blockquote>
<blockquote><p>Emacs uses libtinfo in preference to libncurses, if available.
</p></blockquote>
<blockquote><p>On FreeBSD and NetBSD, configure no longer adds /usr/local/lib and<br />
/usr/pkg/lib to the linker search path.  You must add them yourself if<br />
you want them.
</p></blockquote>
<blockquote><p>The standalone scripts <code>rcs-checkin</code> and <code>vcdiff</code> have been removed<br />
(from the bin and libexec directories, respectively).  The former is<br />
no longer relevant, the latter is replaced by lisp (in vc-sccs.el).
</p></blockquote>
<h2>Startup Changes in Emacs 24.3</h2>
<blockquote><p>Emacs no longer searches for <code>leim-list.el</code> files beneath the standard<br />
lisp/ directory.  There should not be any there anyway.  If you have<br />
been adding them there, put them somewhere else; e.g., site-lisp.
</p></blockquote>
<blockquote><p>The <code>--no-site-lisp</code> command line option now works for Nextstep builds.
</p></blockquote>
<h2>Changes in Emacs 24.3</h2>
<h3>Help</h3>
<blockquote><p><code>C-h f</code> (<code>describe-function</code>) can now perform autoloading.<br />
When this command is called for an autoloaded function whose docstring<br />
contains a key substitution construct, that function&#8217;s library is<br />
automatically loaded, so that the documentation can be shown<br />
correctly.  To disable this, set <code>help-enable-auto-load</code> to nil.
</p></blockquote>
<p>That&#8217;s a potentially useful change, though I cannot offhand recall any instances where I&#8217;ve been bitten by this. This is not going to guard against unloaded libraries if you are <em>not</em> looking up autoloaded commands. In other words, if you&#8217;re looking up an obscure function or variable and the library isn&#8217;t loaded, this won&#8217;t help at all.</p>
<blockquote><p><code>C-h f</code> now reports previously-autoloaded functions as &#8220;autoloaded&#8221;,<br />
even after their associated libraries have been loaded (and the<br />
autoloads have been redefined as functions).
</p></blockquote>
<p>I would fill this under &#8220;Nice to know&#8221;.</p>
<h3>ImageMagick</h3>
<blockquote><p>Images displayed via ImageMagick now support transparency and the<br />
:background image specification property.
</p></blockquote>
<blockquote><p>When available, ImageMagick support is automatically enabled.<br />
It is no longer necessary to call <code>imagemagick-register-types</code><br />
explicitly to install ImageMagick image types; that function is called<br />
automatically at startup, or when customizing an imagemagick- option.
</p></blockquote>
<p>Most excellent. This should help encourage the use of Imagemagick now that it&#8217;s loaded by default.</p>
<blockquote><p>Setting <code>imagemagick-types-inhibit</code> to t now disables the use of<br />
ImageMagick to view images.  (You must call <code>imagemagick-register-types</code><br />
afterwards if you do not use customize to change this.)
</p></blockquote>
<p>&#8230; And this is how you disable it</p>
<blockquote><p>The new variable <code>imagemagick-enabled-types</code> also affects which<br />
ImageMagick types are treated as images.  The function<br />
<code>imagemagick-filter-types</code> returns the list of types that will be<br />
treated as images.
</p></blockquote>
<h3>Minibuffer</h3>
<blockquote><p>In minibuffer filename prompts, <code>C-M-f</code> and <code>C-M-b</code> now move to the<br />
next and previous path separator, respectively.
</p></blockquote>
<p>With the caveat, I suppose, that this is not likely to work if you use iswitchb or IDO.</p>
<blockquote><p><code>minibuffer-electric-default-mode</code> can shorten &#8220;(default &#8230;)&#8221; to &#8220;[...]&#8221;<br />
in minibuffer prompts.  Just set <code>minibuffer-eldef-shorten-default</code><br />
non-nil before enabling the mode.
</p></blockquote>
<h3>Mode line</h3>
<blockquote><p>New option <code>mode-line-default-help-echo</code> specifies the help text<br />
(shown in a tooltip or in the echo area) for any part of the mode line<br />
that does not have its own specialized help text.
</p></blockquote>
<blockquote><p>You can now click mouse-3 in the coding system indicator to invoke<br />
<code>set-buffer-file-coding-system</code>.
</p></blockquote>
<h3>Server and client</h3>
<blockquote><p>emacsclient now obeys string values for <code>initial-buffer-choice</code>,<br />
if it is told to open a new frame without specifying any file to visit<br />
or expression to evaluate.
</p></blockquote>
<blockquote><p>New option <code>server-auth-key</code> specifies a shared server key.
</p></blockquote>
<blockquote><p>Emacs now generates backtraces on fatal errors.<br />
On encountering a fatal error, Emacs now outputs a textual description<br />
of the fatal signal, and a short backtrace on platforms like glibc<br />
that support backtraces.
</p></blockquote>
<h3>Other</h3>
<blockquote><p><code>C-x C-q</code> is now bound to the new minor mode <code>read-only-mode</code>.<br />
This minor mode replaces <code>toggle-read-only</code>, which is now obsolete.
</p></blockquote>
<p>Interesting that they&#8217;ve moved it to a new minor mode. I imagine this change was effected to reduce the number of &#8220;magic states&#8221; a buffer could be in. As a mode, it also means you can customize it further like, say, adding hooks so you can gray out the text if it&#8217;s read only.</p>
<blockquote><p>Most <code>y-or-n</code> prompts now allow you to scroll the selected window.<br />
Typing <code>C-v</code> or <code>M-v</code> at a y-or-n prompt scrolls forward or backward<br />
respectively, without exiting from the prompt.
</p></blockquote>
<p>Very nice and welcome change.</p>
<blockquote><p>In the Package Menu, newly-available packages are listed as &#8220;new&#8221;,<br />
and sorted above the other &#8220;available&#8221; packages by default.
</p></blockquote>
<blockquote><p>If your Emacs was built from a bzr checkout, the new variable<br />
<code>emacs-bzr-version</code> contains information about the bzr revision used.
</p></blockquote>
<blockquote><p>New option <code>create-lockfiles</code> specifies usage of lockfiles.<br />
It defaults to t.  Changing it to nil inhibits the creation of lock<br />
files (use this with caution).
</p></blockquote>
<blockquote><p>New option <code>enable-remote-dir-locals</code>, if non-nil, allows directory-local<br />
variables on remote hosts.
</p></blockquote>
<p>This is useful if you use dir-local variables remotely, but there&#8217;s an obvious security risk if you enable it.</p>
<blockquote><p>The entry for PCL-CVS has been removed from the Tools menu.<br />
The PCL-CVS commands are still available via the keyboard.
</p></blockquote>
<blockquote><p>Using &#8220;unibyte: t&#8221; in Lisp source files is obsolete.<br />
Use &#8220;coding: raw-text&#8221; instead.
</p></blockquote>
<blockquote><p>In the buffer made by <code>M-x report-emacs-bug</code>, the <code>C-c m</code> binding<br />
has been changed to <code>C-c M-i</code> (<code>report-emacs-bug-insert-to-mailer</code>).<br />
The previous binding, introduced in Emacs 24.1, was a mistake, because<br />
<code>C-c LETTER</code> bindings are reserved for user customizations.
</p></blockquote>
<h3>Internationalization</h3>
<blockquote><p>New language environment: Persian.
</p></blockquote>
<blockquote><p>New input method <code>vietnamese-vni</code>.
</p></blockquote>
<h3>Nextstep (GNUstep / Mac OS X) port</h3>
<blockquote><p>Support for fullscreen and the frame parameter fullscreen.
</p></blockquote>
<p>A much longed-for feature.</p>
<blockquote><p>A file dialog is used for open/save operations initiated from the<br />
menu/toolbar.
</p></blockquote>
<h2>Editing Changes in Emacs 24.3</h2>
<h3>Search and Replace</h3>
<blockquote><p>Non-regexp Isearch now performs &#8220;lax&#8221; space matching.<br />
Each sequence of spaces in the supplied search string may match any<br />
sequence of one or more whitespace characters, as specified by the<br />
variable <code>search-whitespace-regexp</code>.  (This variable is also used by a<br />
similar existing feature for regexp Isearch.)
</p></blockquote>
<p>This is great as you can now find matches even though whitespacing may not be spot on.</p>
<blockquote><p>New Isearch command <code>M-s SPC</code> toggles lax space matching.<br />
This applies to both ordinary and regexp Isearch.
</p></blockquote>
<p>Handy if you don&#8217;t want fuzzy space matching.</p>
<blockquote><p>New option <code>replace-lax-whitespace</code>.<br />
If non-nil, <code>query-replace</code> uses flexible whitespace matching too.<br />
The default is nil.
</p></blockquote>
<blockquote><p>Global <code>M-s _</code> starts a symbol (identifier) incremental search,<br />
and <code>M-s _</code> in Isearch toggles symbol search mode.<br />
<code>M-s c</code> in Isearch toggles search case-sensitivity.
</p></blockquote>
<p>Very useful if you&#8217;re coding. It&#8217;s equivalent to wrapping an <code>isearch-forward-regexp</code> regexp query in <code>&#92_&lt;</code> and <code>&#92_&gt;</code>. Keep in mind that the definition of a symbol varies according to your major mode (and sometimes minor!). It&#8217;s usually set to rather sensible defaults in most programming major modes.</p>
<h2>Navigation commands</h2>
<blockquote><p>New binding <code>M-g c</code> for <code>goto-char</code>.
</p></blockquote>
<p>The word &#8220;char&#8221; here is rather misleading: it means the absolute position, as an integer, from the beginning of the buffer.</p>
<blockquote><p>New binding <code>M-g TAB</code> for <code>move-to-column</code>.
</p></blockquote>
<blockquote><p><code>M-g TAB</code> (<code>move-to-column</code>) prompts for a column number if called<br />
interactively with no prefix arg.  Previously, it moved to column 1.
</p></blockquote>
<blockquote><p>New option <code>yank-handled-properties</code> allows processing of text<br />
properties on yanked text, in ways that are more general than just<br />
removing them (as is done by <code>yank-excluded-properties</code>).
</p></blockquote>
<p>Useful if you want to strip out or alter properties on text when it&#8217;s yanked. This is unlikely to be of interest to anybody except module developers.</p>
<blockquote><p>New option <code>delete-trailing-lines</code> specifies whether<br />
M-x delete-trailing-whitespace should delete trailing lines at the end<br />
of the buffer.  It defaults to t.
</p></blockquote>
<p>A nice and useful addition, but be wary as it defaults to true.</p>
<blockquote><p><code>C-u M-=</code> now counts lines/words/characters in the entire buffer.
</p></blockquote>
<blockquote><p><code>C-x 8 RET</code> is now bound to <code>insert-char</code>, which is now a command.<br />
<code>ucs-insert</code> is now an obsolete alias for <code>insert-char</code>.
</p></blockquote>
<blockquote><p>The <code>z</code> key no longer has a binding in most special modes.<br />
It used to be bound to <code>kill-this-buffer</code>, but <code>z</code> is too easy to<br />
accidentally type.
</p></blockquote>
<p>Rejoice all who have accidentally killed your buffers.</p>
<blockquote><p>New command <code>C-x r M-w</code> (<code>copy-rectangle-as-kill</code>).<br />
It copies the region-rectangle as the last rectangle kill.
</p></blockquote>
<p>Very nice. This basically makes works exactly like <code>M-w</code> does except it operates on a rect. No more killing then yanking if you want to copy a rect.</p>
<h2>Registers</h2>
<blockquote><p><code>C-x r +</code> is now overloaded to invoke <code>append-to-register</code>.
</p></blockquote>
<p>This small change has rather wide ramifications for those of you who use registers in macros. You can now collect text and append it to the end of a register instead of shunting it to a different buffer. Groundbreaking? Not quite, but very useful indeed.</p>
<blockquote><p>New option <code>register-separator</code> specifies the register containing<br />
the text to put between collected texts for use with<br />
M-x append-to-register and M-x prepend-to-register.
</p></blockquote>
<p>Combined with the above, this enables you to collate appended texts with a separator symbol.</p>
<h2>Changes in Specialized Modes and Packages in Emacs 24.3</h2>
<h3>Common Lisp emulation (CL)</h3>
<blockquote><p>CL&#8217;s main entry is now (require &#8216;cl-lib).<br />
<code>cl-lib</code> is like the old <code>cl</code> except that it uses the namespace cleanly;<br />
i.e., all its definitions have the &#8220;cl-&#8221; prefix (and internal definitions<br />
use the &#8220;cl&#8211;&#8221; prefix).</p>
<p>If <code>cl</code> provided a feature under the name <code>foo</code>, then <code>cl-lib</code><br />
provides it under the name <code>cl-foo</code> instead; with the exceptions of the<br />
few <code>cl</code> definitions that had to use <code>foo*</code> to avoid conflicts with<br />
pre-existing Elisp entities.  These have been renamed to <code>cl-foo</code><br />
rather than <code>cl-foo*</code>.</p>
<p>The old <code>cl</code> is now deprecated and is mainly just a bunch of aliases that<br />
provide the old, non-prefixed names.  Some exceptions are listed below:
</p></blockquote>
<p>This is a good change but I doubt we will ever truly be rid of <code>cl</code>, not for a long tie anyway.</p>
<blockquote><p><code>cl-flet</code> is not like <code>flet</code> (which is deprecated).<br />
Instead it obeys the behavior of Common-Lisp&#8217;s <code>flet</code>.<br />
In particular, in cl-flet function definitions are lexically scoped,<br />
whereas in flet the scoping is dynamic.
</p></blockquote>
<blockquote><p><code>cl-labels</code> is slightly different from <code>labels</code>.<br />
The difference is that it relies on the <code>lexical-binding</code> machinery<br />
(as opposed to the <code>lexical-let</code> machinery used previously) to capture<br />
definitions in closures, so such closures will only work if <code>lexical-binding</code><br />
is in use.
</p></blockquote>
<blockquote><p><code>cl-letf</code> is not exactly like <code>letf</code>.<br />
The only difference is in details that relate to some deprecated usage<br />
of <code>symbol-function</code> in place forms.
</p></blockquote>
<blockquote><p><code>progv</code> was rewritten to use the <code>let</code> machinery.<br />
A side effect is that variables without corresponding values are bound<br />
to nil rather than being made unbound.
</p></blockquote>
<blockquote><p>The following methods of extending <code>setf</code> are obsolete<br />
(use features from gv.el instead):<br />
<code>define-modify-macro</code> (use <code>gv-letplace</code>)<br />
<code>defsetf</code> (use <code>gv-define-simple-setter</code> or <code>gv-define-setter</code>)<br />
<code>define-setf-expander</code> (use <code>gv-define-setter</code> or <code>gv-define-expander</code>)<br />
<code>get-setf-method</code> no longer exists (see &#8220;Incompatible Lisp Changes&#8221;)
</p></blockquote>
<h2>Diff mode</h2>
<blockquote><p>Changes are now highlighted using the same color scheme as in<br />
modern VCSes.  Deletions are displayed in red (new faces<br />
<code>diff-refine-removed</code> and <code>smerge-refined-removed</code>, and new definition<br />
of <code>diff-removed</code>), insertions in green (new faces <code>diff-refine-added</code><br />
and <code>smerge-refined-added</code>, and new definition of <code>diff-added</code>).
</p></blockquote>
<p>More standardization. Good.</p>
<blockquote><p>The variable <code>diff-use-changed-face</code> defines whether to use the<br />
face <code>diff-changed</code>, or <code>diff-removed</code> and <code>diff-added</code> to highlight<br />
changes in context diffs.
</p></blockquote>
<blockquote><p>The new command <code>diff-delete-trailing-whitespace</code> removes trailing<br />
whitespace introduced by a diff.
</p></blockquote>
<blockquote><p>Ediff now uses the same color scheme as Diff mode.
</p></blockquote>
<h2>Python mode</h2>
<blockquote><p>A new version of python.el, which provides several new features, including:<br />
per-buffer shells, better indentation, Python 3 support, and improved<br />
shell-interaction compatible with iPython (and virtually any other<br />
text based shell).
</p></blockquote>
<p>I blogged about a new python mode a long time ago and it seems it&#8217;s made it into trunk. That&#8217;s probably good news for most Python users, but as I haven&#8217;t yet explored the new python.el mode yet, I will cover this in much greater detail in another post.</p>
<blockquote><p>
Some user options have been replaced/renamed, including (old -> new):</p>
<p>python-indent -> python-indent-offset</p>
<p>python-guess-indent -> python-indent-guess-indent-offset</p>
<p>python-pdbtrack-do-tracking-p -> python-pdbtrack-activate</p>
<p>python-use-skeletons -> python-skeleton-autoinsert</p>
<p>Some user options have been removed, including:</p>
<p><code>python-indent-string-contents</code>: Strings are never indented.</p>
<p><code>python-honour-comment-indentation</code>:<br />
Comments are always considered as indentation markers.</p>
<p><code>python-continuation-offset</code>: Indentation is automatically<br />
calculated in a pep8 compliant way depending on the context.</p>
<p><code>python-shell-prompt-alist</code>, <code>python-shell-continuation-prompt-alist</code>:<br />
Have no direct mapping as the shell interaction is completely different.</p>
<p><code>python-python-command</code>, <code>python-jython-command</code>:<br />
Replaced by <code>python-shell-interpreter</code>.</p>
<p><code>inferior-python-filter-regexp</code>, <code>python-remove-cwd-from-path</code>,<br />
<code>python-pdbtrack-minor-mode-string</code>, <code>python-source-modes</code>:<br />
No longer relevant.</p>
<p>Some commands have been replaced (old -> new):<br />
python-insert-class -> python-skeleton-class<br />
python-insert-def -> python-skeleton-def<br />
python-insert-for -> python-skeleton-for<br />
python-insert-if -> python-skeleton-if<br />
python-insert-try/except -> python-skeleton-try<br />
python-insert-try/finally -> python-skeleton-try<br />
python-insert-while -> python-skeleton-while<br />
python-find-function -> python-nav-jump-to-defun<br />
python-next-statement -> python-nav-forward-sentence<br />
python-previous-statement -> python-nav-backward-sentence<br />
python-beginning-of-defun-function -> python-nav-beginning-of-defun<br />
python-end-of-defun-function -> python-nav-end-of-defun<br />
python-send-buffer -> python-shell-send-buffer<br />
python-send-defun -> python-shell-send-defun<br />
python-send-region -> python-shell-send-region<br />
python-send-region-and-go -> emulate with python-shell-send-region<br />
and python-shell-switch-to-shell<br />
python-send-string -> python-shell-send-string<br />
python-switch-to-python -> python-shell-switch-to-shell<br />
python-describe-symbol -> python-eldoc-at-point
</p></blockquote>
<p>Needless to say, the changes here are likely to break a lot of my custom Python code I&#8217;ve written over the years. If you&#8217;re relying on customizations to Python or modes that interact with it, I would probably ensure you can fix or live with broken modules until they&#8217;re fixed.</p>
<h2>D-Bus</h2>
<blockquote><p>New variables <code>dbus-compiled-version</code> and <code>dbus-runtime-version</code>.
</p></blockquote>
<blockquote><p>The D-Bus object manager interface is implemented.
</p></blockquote>
<blockquote><p>Variables of type <img src='http://www.masteringemacs.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> u)int32 and <img src='http://www.masteringemacs.org/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> u)int64 accept floating points,<br />
if their value does not fit into Emacs&#8217;s integer range.
</p></blockquote>
<blockquote><p>The function <code>dbus-call-method</code> is now non-blocking.<br />
It can be interrupted by <code>C-g</code>.  <code>dbus-call-method-non-blocking</code> is obsolete.
</p></blockquote>
<blockquote><p>Signals can also be sent as unicast messages.
</p></blockquote>
<blockquote><p>The argument list of <code>dbus-register-signal</code> has been extended,<br />
according to the new match rule types of D-Bus.
</p></blockquote>
<blockquote><p><code>dbus-init-bus</code> supports private connections.
</p></blockquote>
<blockquote><p>There is a new function <code>dbus-setenv</code>.
</p></blockquote>
<blockquote><p><code>desktop-path</code> no longer includes the &#8220;.&#8221; directory.<br />
Desktop files are now located in ~/.emacs.d by default.
</p></blockquote>
<h2>Dired</h2>
<blockquote><p><code>dired-do-async-shell-command</code> executes each file sequentially<br />
if the command ends in <code>;</code> (when operating on multiple files).<br />
Otherwise, it executes the command on each file in parallel.
</p></blockquote>
<p>Very useful and good for people working with commands on many files.</p>
<blockquote><p>Typing <code>M-n</code> in the minibuffer of <code>dired-do-chmod</code>, <code>dired-do-chgrp</code>,<br />
<code>dired-do-chown</code>, and <code>dired-do-touch</code> yanks the attributes of the<br />
file at point.
</p></blockquote>
<p>Hah! This is superb. I really like this change. Now you&#8217;re probably thinking the command, <code>M-n</code>, is arbitrary, but not so: in minibuffer prompts that command would go to the last used element in the minibuffer history; by re-using that command here, it achieves the same effect. </p>
<blockquote><p>When the region is active, <code>m</code> (<code>dired-mark</code>), <code>u</code> (<code>dired-unmark</code>),<br />
<CODE>DEL</CODE> (<code>dired-unmark-backward</code>), and <code>d</code> (<code>dired-flag-file-deletion</code>)<br />
mark/unmark/flag all files in the active region.
</p></blockquote>
<p>Can i hear a hallelujah? this is a most welcome change and one that should&#8217;ve been in dired since day one.</p>
<blockquote><p>The minibuffer default for <code>=</code> (<code>dired-diff</code>) has changed.<br />
it is now the backup file for the file at point, if one exists.<br />
in transient mark mode the default is the file at the active mark.
</p></blockquote>
<p>great idea but for most serious files you&#8217;re probably using <code>c-x v =</code>, the vcs diff command.</p>
<blockquote><p><code>M-=</code> is no longer bound to <code>dired-backup-diff</code> in Dired buffers.<br />
The global binding for <code>M-=</code>, <code>count-words-region</code> is in effect.
</p></blockquote>
<h2>ERC</h2>
<blockquote><p>New module &#8220;notifications&#8221;, which can send a notification when you<br />
receive a private message or your nickname is mentioned.
</p></blockquote>
<blockquote><p>ERC will look up server/channel names via auth-source and use any<br />
channel keys found.
</p></blockquote>
<blockquote><p>New option <code>erc-lurker-hide-list</code>, similar to <code>erc-hide-list</code>, but<br />
only applies to messages sent by lurkers.
</p></blockquote>
<h2>reStructuredText mode</h2>
<blockquote><p>Keybindings (see <code>C-c C-h</code>), TAB indentation, filling and auto-filling,<br />
fontification, comment handling, and customization have all been revised<br />
and improved.
</p></blockquote>
<p>That&#8217;s good. rST mode always did seem a bit&#8230; underdeveloped.</p>
<blockquote><p>Support for <code>imenu</code> and <code>which-function-mode</code>.
</p></blockquote>
<p>Great!</p>
<blockquote><p>The reStructuredText syntax is more closely covered.<br />
Sphinx support has been improved.
</p></blockquote>
<p>Sphinx support is very good news for Python docs writers and other fans of Sphinx.</p>
<blockquote><p><code>rst-insert-list</code> inserts new list or continues existing lists.
</p></blockquote>
<blockquote><p>A negative prefix argument always works for <code>rst-adjust</code>.
</p></blockquote>
<blockquote><p>The window configuration is reset after displaying a TOC.
</p></blockquote>
<blockquote><p>The constant <code>rst-version</code> describes the rst.el package version.
</p></blockquote>
<h2>Ruby mode</h2>
<blockquote><p>Support for percent literals and recognition of regular expressions<br />
in method calls without parentheses with more methods, including Cucumber<br />
steps definitions.
</p></blockquote>
<blockquote><p>Improved syntax highlighting and indentation.
</p></blockquote>
<blockquote><p>New command <code>ruby-toggle-block</code>, bound to <code>C-c {</code>.
</p></blockquote>
<blockquote><p>Some non-standard keybindings/commands have been removed:
</p></blockquote>
<blockquote><p><code>ruby-electric-brace</code>; use <code>electric-indent-mode</code> instead.
</p></blockquote>
<blockquote><p><code>ruby-mark-defun</code>; use <code>mark-defun</code>.
</p></blockquote>
<blockquote><p><code>ruby-beginning-of-defun</code> and <code>ruby-end-of-defun</code> are replaced by<br />
appropriate settings for the variables <code>beginning-of-defun-function</code><br />
and <code>end-of-defun-function</code>.
</p></blockquote>
<p>These three changes are all part of a larger drive in Emacs to remove major mode-specific functions that&#8217;re better served with the built-in Emacs equivalents.</p>
<blockquote><p>Non-standard keybindings for <code>backward-kill-word</code>, <code>comment-region</code>,<br />
<code>reindent-then-newline-and-indent</code> and <code>newline</code> have been removed.
</p></blockquote>
<h2>Shell Script mode</h2>
<blockquote><p>Pairing of parens/quotes uses <code>electric-pair-mode</code> instead of skeleton-pair.
</p></blockquote>
<p>More duplicate cruft removed and standardized.</p>
<blockquote><p><code>sh-electric-here-document-mode</code> now controls auto-insertion of here-docs.
</p></blockquote>
<blockquote><p><code>sh-use-smie</code> lets you choose a new indentation and navigation code.
</p></blockquote>
<h2>VHDL mode</h2>
<blockquote><p>The free software compiler GHDL is supported (and now the default).
</p></blockquote>
<blockquote><p>Support for the VHDL-AMS packages has been added/updated.
</p></blockquote>
<blockquote><p>Updated to the 2002 revision of the VHDL standard.
</p></blockquote>
<blockquote><p>Accepts \r and \f as whitespace.
</p></blockquote>
<h2>Apropos</h2>
<blockquote><p>The faces used by Apropos are now directly customizable.<br />
These faces are named <code>apropos-symbol</code>, <code>apropos-keybinding</code>, and so on;<br />
see the <code>apropos</code> Custom group for details.
</p></blockquote>
<blockquote><p>The old options whose values specified faces to use have been removed<br />
(i.e. <code>apropos-symbol-face</code>, <code>apropos-keybinding-face</code>, etc.).
</p></blockquote>
<h2>Buffer Menu</h2>
<blockquote><p>This package has been rewritten to use Tabulated List mode.
</p></blockquote>
<blockquote><p>Option <code>Buffer-menu-buffer+size-width</code> is now obsolete.<br />
Use <code>Buffer-menu-name-width</code> and <code>Buffer-menu-size-width</code> instead.
</p></blockquote>
<h2>Calendar</h2>
<blockquote><p>You can customize the header text that appears above each calendar month.<br />
See the variable <code>calendar-month-header</code>.
</p></blockquote>
<blockquote><p>New LaTeX calendar style, produced by <code>cal-tex-cursor-week2-summary</code>.
</p></blockquote>
<blockquote><p>The calendars produced by cal-html include holidays.<br />
Customize <code>cal-html-holidays</code> to change this.
</p></blockquote>
<h2>CEDET</h2>
<blockquote><p>The major modes from the parser generators &#8220;Bovine&#8221; and &#8220;Wisent&#8221;<br />
are now properly integrated in Emacs.  The file suffixes &#8220;.by&#8221; and &#8220;.wy&#8221;<br />
are in <code>auto-mode-alist</code>, and the corresponding manuals are included.
</p></blockquote>
<h3>EDE</h3>
<blockquote><p>Menu support for the &#8220;Configuration&#8221; feature.  This allows users to<br />
choose the active configuration (such as debug or install) from the menu.
</p></blockquote>
<blockquote><p>New command <code>ede-set</code> to interactively set project-local variables.
</p></blockquote>
<blockquote><p>Support for compiling, debugging, and running in &#8220;generic&#8221; projects.
</p></blockquote>
<blockquote><p>Autoconf editing support for M4 macros with complex arguments.
</p></blockquote>
<blockquote><p>Compilation support for the &#8220;linux&#8221; project type.
</p></blockquote>
<blockquote><p>&#8220;simple&#8221; projects have been removed; use &#8220;generic&#8221; projects instead.
</p></blockquote>
<h3>Semantic</h3>
<blockquote><p>Support for parsing #include statements inside a namespace in C/C++.
</p></blockquote>
<blockquote><p>Improved support for &#8216;extern &#8220;C&#8221;&#8216; declarations in C/C++.
</p></blockquote>
<blockquote><p>The ability to ignore more common special C/C++ preprocessor symbols,<br />
such as &#8216;__nonnull&#8217; and &#8216;__asm&#8217;.  Add &#8216;__cplusplus&#8217; macro when parsing C++.<br />
If available, include cdefs.h as an additional source of preprocessor symbols.
</p></blockquote>
<blockquote><p>Improved C/C++ function pointer parsing.
</p></blockquote>
<blockquote><p>In Python, support for converting imports to include file names.
</p></blockquote>
<blockquote><p>Ability to dynamically determine the Python load path.
</p></blockquote>
<blockquote><p>Support for the Python &#8216;WITH&#8217; and &#8216;AT&#8217; keywords.
</p></blockquote>
<blockquote><p>Improved tooltip completion.
</p></blockquote>
<h3>SRecode</h3>
<blockquote><p>The SRecode manual is now included.
</p></blockquote>
<blockquote><p>Tag generation supports constructor/destructor settings and system<br />
include differentiation.
</p></blockquote>
<blockquote><p>Addition of &#8216;Framework&#8217; support: Frameworks are specified when a<br />
particular kind of library (such as Android) is needed in a common language<br />
mode (like Java).
</p></blockquote>
<blockquote><p>Support for nested templates and let variables override based on priority.
</p></blockquote>
<blockquote><p>Support for merging tables from multiple related modes, such as<br />
default -> c++ -> arduino.
</p></blockquote>
<h2>Compile</h2>
<blockquote><p>Compile has a new option <code>compilation-always-kill</code>.
</p></blockquote>
<h2>Customize</h2>
<blockquote><p><code>custom-reset-button-menu</code> now defaults to t.
</p></blockquote>
<blockquote><p>Non-option variables are never matched in <code>customize-apropos</code> and<br />
<code>customize-apropos-options</code> (i.e., the prefix argument does nothing for<br />
these commands now).
</p></blockquote>
<h2>Term</h2>
<blockquote><p>The variables <code>term-default-fg-color</code> and <code>term-default-bg-color</code><br />
are now deprecated in favor of the customizable face <code>term</code>.
</p></blockquote>
<p>A pre-<em>customization</em> anachronism removed at last. Make sure you migrate your term color settings!</p>
<blockquote><p>You can customize how to display ANSI terminal colors and styles<br />
by customizing the corresponding <code>term-color-COLOR</code>,<br />
<code>term-color-underline</code> and <code>term-color-bold</code> faces.
</p></blockquote>
<p>If, like me, you customized <code>ansi-color-names-vector</code> to change the default term colours I suggest you switch to using the faces now. The good news here is you can, should desire to, change more than <em>just</em> the colours for each ANSI Color: there&#8217;s nothing stopping you from forcing a different font for certain colours.</p>
<h2>Tramp</h2>
<blockquote><p>The syntax has been extended in order to allow ad-hoc proxy definitions.
</p></blockquote>
<p>This is a great change and a most needed one if you want to <code>su</code> to a different user once you&#8217;ve connected to a another host and you can&#8217;t be bothered figuring out how TRAMP proxies work. <del>Typically I can&#8217;t find any information about the new syntax anywhere&#8230; I&#8217;ll have to dig into the source code and write a post about it later.</del> Despite my best attempts it seems I completely missed the new chapter, here <code>(info "(tramp)Ad-hoc multi-hops")</code>.</p>
<blockquote><p>Remote processes are now also supported on remote MS-Windows hosts.
</p></blockquote>
<h2>URL</h2>
<blockquote><p>Structs made by <code>url-generic-parse-url</code> have nil <code>attributes</code> slot.<br />
Previously, this slot stored semicolon-separated attribute-value pairs<br />
appended to some imap URLs, but this is not compatible with RFC 3986.<br />
So now the <code>filename</code> slot stores the entire path and query components,<br />
and the <code>attributes</code> slot is always nil.
</p></blockquote>
<blockquote><p>New function <code>url-encode-url</code> for encoding a URI string.<br />
The <code>url-retrieve</code> function now uses this to encode its URL argument,<br />
in case that is not properly encoded.
</p></blockquote>
<blockquote><p>notifications.el supports now version 1.2 of the Notifications API.<br />
The function <code>notifications-get-capabilities</code> returns the supported<br />
server properties.
</p></blockquote>
<h2>More misc changes</h2>
<blockquote><p>Flymake uses fringe bitmaps to indicate errors and warnings.<br />
See <code>flymake-fringe-indicator-position</code>, <code>flymake-error-bitmap</code> and<br />
<code>flymake-warning-bitmap</code>.
</p></blockquote>
<blockquote><p>The FFAP option <code>ffap-url-unwrap-remote</code> can now be a list of strings,<br />
specifying URL types that should be converted to remote file names at<br />
the FFAP prompt.  The default is now &#8216;(&#8220;ftp&#8221;).
</p></blockquote>
<blockquote><p>New Ibuffer <code>derived-mode</code> filter, bound to <code>/ M</code>.<br />
The old binding for <code>/ M</code> (filter by used-mode) is now bound to <code>/ m</code>.
</p></blockquote>
<blockquote><p>New option <code>mouse-avoidance-banish-position</code> specifies where the<br />
<code>banish</code> mouse avoidance setting moves the mouse.
</p></blockquote>
<blockquote><p>In Perl mode, new option <code>perl-indent-parens-as-block</code> causes non-block<br />
closing brackets to be aligned with the line of the opening bracket.
</p></blockquote>
<blockquote><p>In Proced mode, new command <code>proced-renice</code> renices marked processes.
</p></blockquote>
<blockquote><p>New option <code>async-shell-command-buffer</code> specifies the buffer to use<br />
for a new asynchronous <code>shell-command</code> when the default output buffer<br />
<code>*Async Shell Command*</code> is already in use.
</p></blockquote>
<p>Handy if you don&#8217;t want your shell output buffer overwritten when you run more than one asynchronous command. </p>
<blockquote><p>SQL mode has a new option <code>sql-db2-escape-newlines</code>.<br />
If non-nil, newlines sent to the command interpreter will be escaped<br />
by a backslash.  The default does not escape the newlines and assumes<br />
that the sql statement will be terminated by a semicolon.
</p></blockquote>
<blockquote><p>New command <code>tabulated-list-sort</code>, bound to <code>S</code> in Tabulated List mode<br />
(and modes that derive from it), sorts the column at point, or the Nth<br />
column if a numeric prefix argument is given.
</p></blockquote>
<p>Its use should be pretty straight forward but I find that mode a bit buggy. Probably better if you stick to using the one in org mode.</p>
<blockquote><p><code>which-func-modes</code> now defaults to t, so Which Function mode, when<br />
enabled, applies to all applicable major modes.
</p></blockquote>
<p>A nice change as Which Function mode worked in more buffers than the <code>which-func-modes</code> gave it credit for.</p>
<blockquote><p><code>winner-mode-hook</code> now runs when the mode is disabled, as well as when<br />
it is enabled.
</p></blockquote>
<blockquote><p>Follow mode no longer works by using advice.<br />
The option <code>follow-intercept-processes</code> has been removed.
</p></blockquote>
<blockquote><p><code>javascript-generic-mode</code> is now an obsolete alias for <code>js-mode</code>.
</p></blockquote>
<blockquote><p>
Hooks renamed to avoid obsolete &#8220;-hooks&#8221; suffix:<br />
semantic-lex-reset-hooks -> semantic-lex-reset-functions<br />
semantic-change-hooks -> semantic-change-functions<br />
semantic-edits-new-change-hooks -> semantic-edits-new-change-functions<br />
semantic-edits-delete-change-hooks -> semantic-edits-delete-change-functions<br />
semantic-edits-reparse-change-hooks -> semantic-edits-reparse-change-functions<br />
semanticdb-save-database-hooks -> semanticdb-save-database-functions<br />
c-prepare-bug-report-hooks -> c-prepare-bug-report-hook<br />
rcirc-sentinel-hooks -> rcirc-sentinel-functions<br />
rcirc-receive-message-hooks -> rcirc-receive-message-functions<br />
rcirc-activity-hooks -> rcirc-activity-functions<br />
rcirc-print-hooks -> rcirc-print-functions<br />
dbus-event-error-hooks -> dbus-event-error-functions<br />
eieio-pre-method-execution-hooks -> eieio-pre-method-execution-functions<br />
checkdoc-style-hooks -> checkdoc-style-functions<br />
checkdoc-comment-style-hooks -> checkdoc-comment-style-functions<br />
archive-extract-hooks -> archive-extract-hook<br />
filesets-cache-fill-content-hooks -> filesets-cache-fill-content-hook<br />
hfy-post-html-hooks -> hfy-post-html-hook<br />
nndiary-request-create-group-hooks -> nndiary-request-create-group-functions<br />
nndiary-request-update-info-hooks -> nndiary-request-update-info-functions<br />
nndiary-request-accept-article-hooks -> nndiary-request-accept-article-functions<br />
gnus-subscribe-newsgroup-hooks -> gnus-subscribe-newsgroup-functions
</p></blockquote>
<h2>Obsolete packages</h2>
<blockquote><p>assoc.el<br />
In most cases, assoc+member+push+delq work just as well.<br />
And in any case it&#8217;s just a terrible package: ugly semantics, terrible<br />
inefficiency, and not namespace-clean.<br />
*** bruce.el<br />
*** cust-print.el<br />
*** ledit.el<br />
*** mailpost.el<br />
*** mouse-sel.el<br />
*** patcomp.el
</p></blockquote>
<h2>Incompatible Lisp Changes in Emacs 24.3</h2>
<blockquote><p>Docstrings starting with <code>*</code> no longer indicate user options.<br />
Only variables defined using <code>defcustom</code> are considered user options.<br />
The function <code>user-variable-p</code> is now an obsolete alias for<br />
<code>custom-variable-p</code>.
</p></blockquote>
<blockquote><p>The return values of <code>defalias</code>, <code>defun</code> and <code>defmacro</code> have changed,<br />
and are now undefined.  For backwards compatibility, <code>defun</code> and<br />
<code>defmacro</code> currently return the name of the newly defined<br />
function/macro, but this should not be relied upon.
</p></blockquote>
<blockquote><p><code>random</code> by default now returns a different random sequence in<br />
every Emacs run.  Use <code>(random S)</code>, where S is a string, to set the<br />
random seed to a value based on S, in order to get a repeatable<br />
sequence in later calls.
</p></blockquote>
<blockquote><p>If the NEWTEXT arg to <code>replace-match</code> contains a substring &#8220;\?&#8221;,<br />
that substring is inserted literally even if the LITERAL arg is<br />
non-nil, instead of causing an error to be signaled.
</p></blockquote>
<blockquote><p><code>select-window</code> now always makes the window&#8217;s buffer current.<br />
It does so even if the window was selected before.
</p></blockquote>
<blockquote><p>The function <code>x-select-font</code> can return a font spec, instead of a<br />
font name as a string.  Whether it returns a font spec or a font name<br />
depends on the graphical library.
</p></blockquote>
<blockquote><p><code>face-spec-set</code> no longer sets frame-specific attributes when the<br />
third argument is a frame (that usage was obsolete since Emacs 22.2).
</p></blockquote>
<blockquote><p><code>set-buffer-multibyte</code> now signals an error in narrowed buffers.
</p></blockquote>
<blockquote><p>The CL package&#8217;s <code>get-setf-method</code> function no longer exists.<br />
Generalized variables are now part of core Emacs Lisp, and implemented<br />
differently to the way cl.el used to do it.  It is not possible to<br />
define a compatible replacement for <code>get-setf-method</code>.  See the file<br />
gv.el for internal details of the new implementation.
</p></blockquote>
<blockquote><p>The arguments of <code>dbus-register-signal</code> are no longer just strings,<br />
but keywords or keyword-string pairs.  The old argument list will<br />
still be supported for Emacs 24.x.
</p></blockquote>
<blockquote><p>Miscellaneous name changes<br />
Some Lisp symbols have been renamed to correct their spelling,<br />
or to be more consistent with standard Emacs terminology.
</p></blockquote>
<blockquote><p>Renamed functions<br />
hangul-input-method-inactivate -> hangul-input-method-deactivate<br />
inactivate-input-method -> deactivate-input-method<br />
quail-inactivate -> quail-deactivate<br />
robin-inactivate -> robin-deactivate<br />
viper-inactivate-input-method -> viper-deactivate-input-method<br />
viper-inactivate-input-method-action -><br />
     viper-deactivate-input-method-action<br />
ucs-input-inactivate -> ucs-input-deactivate
</p></blockquote>
<blockquote><p>Renamed hooks<br />
The old hooks are still supported for backward compatibility, but they<br />
are deprecated and will be removed eventually.<br />
input-method-inactivate-hook -> input-method-deactivate-hook<br />
robin-inactivate-hook -> robin-deactivate-hook<br />
quail-inactivate-hook -> quail-deactivate-hook
</p></blockquote>
<blockquote><p>Renamed variables<br />
follow-deactive-menu -> follow-inactive-menu<br />
inactivate-current-input-method-function -><br />
     deactivate-current-input-method-function
</p></blockquote>
<blockquote><p>Some obsolete functions, variables, and faces have been removed:<br />
<code>last-input-char</code>, <code>last-command-char</code>, <code>unread-command-char</code><br />
<code>facemenu-unlisted-faces</code><br />
<code>rmail-decode-mime-charset</code><br />
<code>iswitchb-read-buffer</code><br />
<code>sc-version</code>, <code>sc-submit-bug-report</code><br />
<code>set-char-table-default</code><br />
<code>string-to-sequence</code> (use <code>string-to-list</code> or <code>string-to-vector</code>)<br />
<code>compile-internal</code><br />
<code>modeline</code><br />
<code>mode-line-inverse-video</code><br />
<code>follow-mode-off-hook</code><br />
<code>cvs-commit-buffer-require-final-newline</code><br />
(use <code>log-edit-require-final-newline</code> instead)<br />
<code>cvs-changelog-full-paragraphs</code><br />
(use <code>log-edit-changelog-full-paragraphs</code> instead)<br />
<code>cvs-diff-ignore-marks</code>, <code>cvs-diff-buffer-name</code><br />
<code>vc-ignore-vc-files</code> (use <code>vc-handled-backends</code> instead)<br />
<code>vc-master-templates</code> (use <code>vc-handled-backends</code> instead)<br />
<code>vc-checkout-carefully</code>
</p></blockquote>
<h2>Lisp Changes in Emacs 24.3</h2>
<blockquote><p>CL-style generalized variables are now in core Elisp.<br />
<code>setf</code> is autoloaded; <code>push</code> and <code>pop</code> accept generalized variables.<br />
You can define your own generalized variables using <code>gv-define-simple-setter</code>,<br />
<code>gv-define-setter</code>, etc.
</p></blockquote>
<blockquote><p>Emacs tries to macroexpand interpreted (non-compiled) files during load.<br />
This can significantly speed up execution of non-byte-compiled code,<br />
but can also bump into previously unnoticed cyclic dependencies.<br />
These are generally harmless: they will simply cause the macro calls<br />
to be left for later expansion (as before), but will result in a<br />
warning (&#8220;Eager macro-expansion skipped due to cycle&#8221;) describing the cycle.<br />
You may wish to restructure your code so this does not happen.
</p></blockquote>
<blockquote><p>New sampling-based Elisp profiler.<br />
Try M-x profiler-start, do some work, and then call M-x profiler-report.<br />
When finished, use M-x profiler-stop.  The sampling rate can be based on<br />
CPU time or memory allocations.
</p></blockquote>
<blockquote><p><code>defun</code> also accepts a (declare DECLS) form, like <code>defmacro</code>.<br />
The interpretation of the DECLS is determined by <code>defun-declarations-alist</code>.
</p></blockquote>
<blockquote><p>New macros <code>setq-local</code> and <code>defvar-local</code>.
</p></blockquote>
<blockquote><p>Face underlining can now use a wave.
</p></blockquote>
<p>Now you can finally make misspelled words in <code>ispell-minor-mode</code> look like Microsoft Word with squiggly underlines!</p>
<blockquote><p><code>read-regexp</code> has a new argument HISTORY; the first argument PROMPT<br />
of <code>read-regexp</code> accepts a string ending with a colon and space, and its<br />
second argument DEFAULTS can be a list of strings accessible via <code>M-n</code><br />
in the minibuffer ahead of other hard-coded useful regexp-related values.<br />
More commands use <code>read-regexp</code> now to read their regexp arguments.
</p></blockquote>
<p>Very useful change for those of us who use readers and often find ourselves reinventing the history wheel.</p>
<blockquote><p>Completion
</p></blockquote>
<blockquote><p>New function <code>completion-table-with-quoting</code> to handle completion<br />
in the presence of quoting, such as file completion in shell buffers.
</p></blockquote>
<blockquote><p>New function <code>completion-table-subvert</code> to use an existing completion<br />
table, but with a different prefix.
</p></blockquote>
<h2>Debugger</h2>
<blockquote><p>New error type and new function <code>user-error</code>.<br />
These do not trigger the debugger.
</p></blockquote>
<blockquote><p>New option <code>debugger-bury-or-kill</code>, saying what to do with the<br />
debugger buffer when exiting debug.
</p></blockquote>
<blockquote><p>Set <code>debug-on-message</code> to enter the debugger when a certain<br />
message is displayed in the echo area.  This can be useful when trying<br />
to work out which code is doing something.
</p></blockquote>
<blockquote><p>New var <code>inhibit-debugger</code>, automatically set to prevent accidental<br />
recursive invocations.
</p></blockquote>
<h2>Window handling</h2>
<blockquote><p>New command <code>fit-frame-to-buffer</code> adjusts the frame height to<br />
fit the contents.
</p></blockquote>
<blockquote><p>The command <code>fit-window-to-buffer</code> can adjust the frame height<br />
if the new option <code>fit-frame-to-buffer</code> is non-nil.
</p></blockquote>
<blockquote><p>New macro <code>with-temp-buffer-window</code>, similar to<br />
<code>with-output-to-temp-buffer</code>.
</p></blockquote>
<p>This is a useful command if you want to generate output with <code>prin1</code>, etc. or print output from an external command in a separate window. I&#8217;m personally very happy to see this macro make an appearance.</p>
<blockquote><p><code>temp-buffer-resize-mode</code> no longer resizes windows that have been<br />
reused.
</p></blockquote>
<blockquote><p>New option <code>switch-to-buffer-preserve-window-point</code> to restore a<br />
window&#8217;s point when switching buffers.
</p></blockquote>
<blockquote><p>New display action alist entries <code>window-height</code> and <code>window-width</code><br />
specify the size of new windows created by <code>display-buffer</code>.
</p></blockquote>
<blockquote><p>New display action alist entry <code>pop-up-frame-parameters</code>, if<br />
non-nil, specifies frame parameters to give any newly-created frame.
</p></blockquote>
<blockquote><p>New display action alist entry <code>inhibit-switch-frame</code>, if non-nil,<br />
tells display action functions to avoid changing which frame is<br />
selected.
</p></blockquote>
<blockquote><p>New display action alist entry <code>previous-window</code>, if non-nil,<br />
specifies window to reuse in <code>display-buffer-in-previous-window</code>.
</p></blockquote>
<blockquote><p>New display action functions <code>display-buffer-below-selected</code>,<br />
and <code>display-buffer-in-previous-window</code>.
</p></blockquote>
<blockquote><p>The functions <code>get-lru-window</code>, <code>get-mru-window</code> and <code>get-largest-window</code><br />
now accept a third argument to avoid choosing the selected window.
</p></blockquote>
<blockquote><p>Additional values recognized for option <code>window-combination-limit</code>.
</p></blockquote>
<blockquote><p>The following variables are obsolete, as they can be replaced by<br />
appropriate entries in the <code>display-buffer-alist</code> function introduced<br />
in Emacs 24.1:<br />
<code>dired-shrink-to-fit</code><br />
<code>display-buffer-reuse-frames</code><br />
<code>display-buffer-function</code><br />
<code>special-display-buffer-names</code><br />
<code>special-display-frame-alist</code><br />
<code>special-display-function</code><br />
<code>special-display-regexps</code>
</p></blockquote>
<h2>Time</h2>
<blockquote><p><code>current-time-string</code> no longer requires that its argument&#8217;s year<br />
must be in the range 1000..9999.  It now works with any year supported<br />
by the underlying C implementation.
</p></blockquote>
<blockquote><p><code>current-time</code> now returns extended-format time stamps<br />
(HIGH LOW USEC PSEC), where the new PSEC slot specifies picoseconds.<br />
PSEC is typically a multiple of 1000 on current machines.  Other<br />
functions that use this format, such as <code>file-attributes</code> and<br />
<code>format-time-string</code>, have been changed accordingly.  Old-format time<br />
stamps are still accepted.
</p></blockquote>
<blockquote><p>The format of timers in <code>timer-list</code> and <code>timer-idle-list</code> is now<br />
[TRIGGERED-P HI-SECS LO-SECS USECS REPEAT-DELAY FUNCTION ARGS IDLE-DELAY PSECS].<br />
The PSECS slot is new, and uses picosecond resolution.  It can be<br />
accessed via the new <code>timer--psecs</code> accessor.
</p></blockquote>
<blockquote><p>Last-modified time stamps in undo lists now are of the form<br />
(t HI-SECS LO-SECS USECS PSECS) instead of (t HI-SECS . LO-SECS).
</p></blockquote>
<h2>(Old MacDonald had a farm) EIEIO</h2>
<blockquote><p>Improved security when handling persistent objects:
</p></blockquote>
<blockquote><p><code>eieio-persistent-read</code> now features optional arguments for specifying<br />
the class to load, as well as a flag stating whether subclasses are allowed;<br />
if provided, other classes will be rejected by the reader.  For<br />
compatibility with existing code, if the class is omitted only a<br />
warning is issued.
</p></blockquote>
<blockquote><p>New specialized reader for pulling in classes and signaling errors<br />
without evaluation of suspicious code.
</p></blockquote>
<blockquote><p>All slots that contain objects must have a :type.  Slots with lists<br />
of objects must use a new type predicate for a list of an object type.
</p></blockquote>
<blockquote><p>Support for <code>find-function</code> and similar utilities, through the addition<br />
of filename support to generated symbols.
</p></blockquote>
<h2>Even more misc stuff</h2>
<blockquote><p>Floating point functions now always return special values like NaN,<br />
instead of signaling errors, if given invalid args; e.g., (log -1.0).<br />
Previously, they returned NaNs on some platforms but signaled errors<br />
on others.  The affected functions are acos, asin, tan, exp, expt,<br />
log, log10, sqrt, and mod.
</p></blockquote>
<blockquote><p>New fringe bitmap <code>exclamation-mark</code>.
</p></blockquote>
<p>Seems like flymake&#8217;s using it for errors. Neat.</p>
<blockquote><p>Miscellaneous changes to special forms and macros
</p></blockquote>
<blockquote><p><code>defun</code> and <code>defmacro</code> are now macros rather than special forms.
</p></blockquote>
<p>If you ever wanted to know how a function is created in Emacs, now you can look at the lisp code in <code>byte-run.el</code>. Ditto for <code>defmacro</code>.</p>
<blockquote><p><code>kbd</code> is now a function rather than a macro.
</p></blockquote>
<h2>Miscellaneous new functions</h2>
<blockquote><p><code>set-temporary-overlay-map</code> sets up a temporary keymap that<br />
takes precedence over most other maps for a short while (normally one key).
</p></blockquote>
<blockquote><p><code>autoloadp</code> tests if its argument is an autoloaded object.
</p></blockquote>
<blockquote><p><code>autoload-do-load</code> performs the autoloading operation.
</p></blockquote>
<blockquote><p><code>buffer-narrowed-p</code> tests if the buffer is narrowed.
</p></blockquote>
<blockquote><p><code>file-name-base</code> returns a file name sans directory and extension.
</p></blockquote>
<blockquote><p><code>function-get</code> fetches a function property, following aliases.
</p></blockquote>
<blockquote><p><code>posnp</code> tests if an object is a <code>posn</code>.
</p></blockquote>
<blockquote><p><code>system-users</code> returns the user names on the system.
</p></blockquote>
<blockquote><p><code>system-groups</code> returns the group names on the system.
</p></blockquote>
<blockquote><p><code>tty-top-frame</code> returns the topmost frame of a text terminal.
</p></blockquote>
<h2>The following functions and variables are obsolete:</h2>
<blockquote><p>
<code>automount-dir-prefix</code> (use <code>directory-abbrev-alist</code>)<br />
<code>buffer-has-markers-at</code><br />
<code>macro-declaration-function</code> (use <code>macro-declarations-alist</code>)<br />
<code>window-system-version</code> (provides no useful information)<br />
<code>dired-pop-to-buffer</code> (use <code>dired-mark-pop-up</code>)<br />
<code>query-replace-interactive</code><br />
<code>font-list-limit</code> (has had no effect since Emacs < 23)
</p></blockquote>
<h2>Changes in Emacs 24.3 on Non-Free Operating Systems</h2>
<blockquote><p>Cygwin builds can use the native MS Windows user interface.<br />
Pass <code>--with-w32</code> to configure.  The default remains the X11 interface.
</p></blockquote>
<blockquote><p>Two new functions are available in Cygwin builds:<br />
<code>cygwin-convert-file-name-from-windows</code> and<br />
<code>cygwin-convert-file-name-to-windows</code>.  These functions allow Lisp<br />
code to access the Cygwin file-name mapping machinery to convert<br />
between Cygwin and Windows-native file and directory names.
</p></blockquote>
<blockquote><p>When invoked with the -nw switch to run on the Windows text-mode terminal,<br />
Emacs now supports <code>mouse-highlight</code>, help-echo (in the echo area), and<br />
<code>mouse-autoselect-window</code>.
</p></blockquote>
<blockquote><p>On MS Windows Vista and later Emacs now supports symbolic links.
</p></blockquote>
<blockquote><p>On MS Windows, you can pass <code>--without-libxml2</code> to configure.bat to omit<br />
support for libxml2, even if its presence is detected.
</p></blockquote>
<blockquote><p>On Mac OS X, the Nextstep port requires OS X 10.4 or later.
</p></blockquote>
<blockquote><p>On Mac OS X, configure no longer automatically adds the Fink &#8220;/sw&#8221;<br />
directories to the search path.  You must add them yourself if you want them.
</p></blockquote>
<h1>The End!</h1>
<p>Phew. That was a lot of changes and I&#8217;ve barely explained 10% of them. Let me know if I glossed over some cool new stuff.</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2013/03/11/whats-new-emacs-24-3/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2013/03/11/whats-new-emacs-24-3/" data-text="What&#8217;s New in Emacs 24.3"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2013%2F03%2F11%2Fwhats-new-emacs-24-3%2F&amp;title=What%E2%80%99s%20New%20in%20Emacs%2024.3" id="wpa2a_4">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2013/03/11/whats-new-emacs-24-3/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Evaluating Lisp Forms in Regular Expressions</title>
		<link>http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/</link>
		<comments>http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/#comments</comments>
		<pubDate>Fri, 25 Jan 2013 08:00:52 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=650</guid>
		<description><![CDATA[One of the oft-repeated complaints about Emacs is its antiquated regular expression engine: that it cannot compete with Vims&#8217;; that it&#8217;s GNU-style regex and not PCRE; and that you have to quote everything in triplicates and write your regular expression on carbon copied paper or something. There is some truth to this, but its detractors [...]]]></description>
				<content:encoded><![CDATA[<p>One of the oft-repeated complaints about Emacs is its antiquated regular expression engine: that it cannot compete with Vims&#8217;; that it&#8217;s GNU-style regex and not PCRE; and that you have to quote everything in triplicates and write your regular expression on carbon copied paper or something. There is some truth to this, but its detractors overlook the features it <em>adds</em> that you won&#8217;t find in most other editors or regexp implementations.</p>
<p>I recently did a <a href="http://www.masteringemacs.org/articles/2013/01/14/fun-vimgolf-3-swapping-words-sorting/">VimGolf challenge</a> where I abused <code>sort-regexp-fields</code> so I could swap two different words. I decided to do it in the most obtuse way possible so I could demonstrate the flexibility of Emacs&#8217;s sort commands, and solve what would be a banal challenge in any editor &#8212; swapping exactly two elements, once, in a two-line file &#8212; using an &#8220;eclectic&#8221; feature.</p>
<p>But there&#8217;s a better way: a &#8220;scalable&#8221; way that works with an arbitrary number of elements to swap, and it uses.. regular expressions! </p>
<h2>Evaluating Forms</h2>
<p>Due to the pervasive nature of Elisp in Emacs, you can invoke elisp from within a call to <code>replace-regexp</code>. That is to say, in the <code>Replace with:</code> portion of the call, you can tell Emacs to evaluate a form and return <em>its</em> output in lieu of (or in combination with) normal strings. The syntax is <code>&#92;,(FORM)</code>.</p>
<p>Let&#8217;s say you have the following file:</p>
<pre>
       INITECH.TXT
----------------------------
Peter Gibbons	$15000
Milton Waddams	$12500
Bill Lumbergh	$90000
</pre>
<p>And you want to give everybody a raise; well, you don&#8217;t <em>reaally</em> want to give Lumbergh a raise, but ho hum, right?</p>
<p>The simplest method is to use <code>[query-]replace-regexp</code> with the following parameters.</p>
<pre>
Replace regexp: &#92;$&#92;([0-9]+&#92;)
</pre>
<p>Here we search for the salary; we store the dollar amount in a capturing group.</p>
<pre>
Replace regexp with: $&#92;,(* &#92;#1 2)
</pre>
<p>And here we replace the salary with the output from an elisp form that multiplies the result from capturing group <code>&#92;1</code> &#8212; but in this case represented as <code>&#92;#1</code>, as we want Emacs to convert the result to an integer first &#8212; by two.</p>
<p>And now the output looks like:</p>
<pre>
       INITECH.TXT
----------------------------
Peter Gibbons	$30000
Milton Waddams	$25000
Bill Lumbergh	$180000
</pre>
<p>Neat.</p>
<h2>Conditional Replace</h2>
<p>Let&#8217;s refactor some random Java code into CamelCase:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> application_runner <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> Application<span style="color: #009900;">&#40;</span>create_os_specific_factory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> GUIFactory create_os_specific_factory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> sys <span style="color: #339933;">=</span> read_from_config_file<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OS_TYPE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sys <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WinFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> OSXFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<pre>
Replace regexp: _&#92;([[:lower:]]+&#92;)
</pre>
<p>Replace underscore and all lowercase characters, which we capture for use later.</p>
<pre>
Replace regexp with: &#92;,(capitalize &#92;1)
</pre>
<p>Here I use an elisp form to capitalize each match from capturing group <code>&#92;1</code>. The underscore is removed also, so <code>create_os_specific_factory</code> becomes <code>createOsSpecificFactory</code>, and so on.</p>
<p>And now it looks like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> applicationRunner <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">new</span> Application<span style="color: #009900;">&#40;</span>createOsSpecificFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> GUIFactory createOsSpecificFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000066; font-weight: bold;">int</span> sys <span style="color: #339933;">=</span> readFromConfigFile<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;OS_TYPE&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>sys <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> WinFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> OSXFactory<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Unfortunately, the word <code>Os</code> should probably be written like this, <code>OS</code>. Let&#8217;s change the form so that certain words are treated differently.</p>
<pre>
Replace regexp: _&#92;([[:lower:]]+&#92;)
</pre>
<p>Same as before.</p>
<pre>
Replace regexp with: &#92;,(cond ((member &#92;1 '("os")) (upcase &#92;1)) (t (capitalize &#92;1)))
</pre>
<p>This time I&#8217;ve use a <code>cond</code> form &#8212; basically a case statement &#8212; to check that <em>if</em> the capturing group is a member of the list <code>("os")</code>, we call the function <code>upcase</code> which, you guessed it, uppercases <code>&#92;1</code>; if that condition fails, fall through to the second clause which, because its conditional is <code>t</code>, always returns true and, therefore, we call <code>capitalize</code> on <code>&#92;1</code>. I could&#8217;ve used an <code>if</code> statement and saved a bit of typing, but <code>cond</code> is more flexible if you want more than one or two conditionals.</p>
<p>The end result is that we now uppercase <code>OS</code> and leave the rest capitalized.</p>
<h2>Swapping Elements</h2>
<p>Going back to what I said in the beginning about swapping text. It is perfectly possible, as I&#8217;m sure you can imagine now, to swap two items &#8212; you don&#8217;t even need a cond element for that!</p>
<p>Consider this trivial Python function.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> foobar<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    x <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">10</span>
    y <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">42</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> x <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">10</span> <span style="color: #ff7700;font-weight:bold;">and</span> y <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">40</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> y + y
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> x + x</pre></td></tr></table></div>

<p>Let&#8217;s say we want to swap <code>x</code> and <code>y</code>. That is, of course, a <em>no-op</em>, but there&#8217;s nothing stopping you from extending the example here and using it for something more meaningful, such as reversing <code>&gt;</code> and <code>&lt;</code>.</p>
<pre>
Replace: &#92;(x&#92;)&#92;|y
</pre>
<p>This is the most simple way of swapping two values. You only need one capturing group, because we only need to compare against one capturing group, hence why <code>y</code> isn&#8217;t captured.</p>
<pre>
Replace with: &#92;,(if &#92;1 "y" "x")
</pre>
<p>Next, we test for existence; if <code>&#92;1</code> is not <code>nil</code> &#8212; that is to say, we actually have something IN the capturing group, which would only happen if we encounter <code>x</code> &#8212; we fall through to the <code>THEN</code> clause (<code>"y"</code>) in the <code>if</code> form; if it is <code>nil</code>, we fall through to the <code>ELSE</code> clause (<code>"x"</code>).</p>
<p>The result is what you would expect:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">def</span> foobar<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    y <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">10</span>
    x <span style="color: #66cc66;">=</span> <span style="color: #ff4500;">42</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> y <span style="color: #66cc66;">&gt;</span> <span style="color: #ff4500;">10</span> <span style="color: #ff7700;font-weight:bold;">and</span> x <span style="color: #66cc66;">&lt;</span> <span style="color: #ff4500;">40</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> x + x
    <span style="color: #ff7700;font-weight:bold;">else</span>:
        <span style="color: #ff7700;font-weight:bold;">return</span> y + y</pre></td></tr></table></div>

<p>The variables are swapped. But let&#8217;s say you want to swap more than two elements: you&#8217;d need to nest <code>if</code> statements (ugly) or use <code>cond</code> (less ugly, but equally verbose.)</p>
<h3>More Cond Magic</h3>
<p>Consider the string <code>1 2 3</code>. To turn it into <code>One Two Three</code> you have two ways of doing it:</p>
<p>One, you can use <code>N</code> capturing groups like so: <code>&#92;(1&#92;)&#92;|...&#92;|&#92;(N&#92;)</code> and in a <code>cond</code> check for the existence of each capturing group to determine if it is the &#8220;matched&#8221; one. There&#8217;s no reason why you couldn&#8217;t use just one capturing group and then string match for each item, but it&#8217;s swings and roundabouts: you&#8217;re either grouping each match you care about in the <em>search</em> bit, or you&#8217;re checking for the existence of the elements you care about in a form in the <em>replace</em> bit.</p>
<p>Let&#8217;s go with the first option.</p>
<pre>
Replace: &#92;(1&#92;)&#92;|&#92;(2&#92;)&#92;|&#92;(3&#92;)
</pre>
<p>Look for, and capture, the three integers.</p>
<pre>
Replace with: &#92;,(cond (&#92;1 "One") (&#92;2 "Two") (&#92;3 "Three"))
</pre>
<p>Using <code>cond</code>, if any of the three capturing groups are non-<code>nil</code>, the body of that conditional is returned.</p>
<p>Not unsurprisingly, the result is <code>One Two Three</code>.</p>
<p>If you change the capturing groups to this <code>&#92;(1&#92;|2&#92;)&#92;|3</code> and if you then change the replacement string to <code>&#92;,(cond (&#92;1 "One") (&#92;2 "Two"))</code>, you end up with <code>One One Two</code>. So as you can see, it&#8217;s very easy to create rules that merge multiple different strings into one using <code>cond</code>.</p>
<h2>More ideas?</h2>
<p>I think I&#8217;ve amply demonstrated the power of mixing regular expressions and lisp. I know a few more tricks, but I&#8217;m always keen to find more, so if you have a novel application I&#8217;d love to hear about it.</p>
<p>There&#8217;s nothing stopping you from invoking elisp functions that <em>don&#8217;t</em> return anything useful; that is, you&#8217;re free to call functions just for their side effects, if that is what you want. For instance, if you want to open a list of files in a buffer, use <code>&#92;,(find-file-noselect &#92;1)</code>. Another useful application is formatting strings using <code>format</code>. Check out the help file (<code>C-h f format RET</code>) for more information. And lastly, you can use Lisp lists to gather matches for use programmatically later: <code>M-: (setq my-storage-variable '())</code> then <code>&#92;,(add-to-list 'my-storage-variable &#92;1)</code>.</p>
<p>Know any useful regexp hacks? Post a comment!</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/" data-text="Evaluating Lisp Forms in Regular Expressions"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2013%2F01%2F25%2Fevaluating-lisp-forms-regular-expressions%2F&amp;title=Evaluating%20Lisp%20Forms%20in%20Regular%20Expressions" id="wpa2a_8">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2013/01/25/evaluating-lisp-forms-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fun with Vimgolf 4: Transpositioning text with Tables</title>
		<link>http://www.masteringemacs.org/articles/2013/01/17/fun-vimgolf-4-transpositioning-text-tables/</link>
		<comments>http://www.masteringemacs.org/articles/2013/01/17/fun-vimgolf-4-transpositioning-text-tables/#comments</comments>
		<pubDate>Thu, 17 Jan 2013 10:00:14 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[mark]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[orgmode]]></category>
		<category><![CDATA[regexp]]></category>
		<category><![CDATA[vimgolf]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=627</guid>
		<description><![CDATA[Here&#8217;s another vim challenge, and one you might actually encounter frequently in real life. Transpose the original lines in separate columns, one for each line. Link to challenge. Simple, really; a transposition here, some alignment there&#8230; but can we do better than the good ole&#8217; brute force approach the Vim guys will invariably use? Can [...]]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s another vim challenge, and one you might actually encounter frequently in real life.</p>
<blockquote><p>
  Transpose the original lines in separate columns, one for each line.
</p></blockquote>
<p><a href="http://vimgolf.com/challenges/50d76e775539af000200006f">Link to challenge.</a></p>
<p>Simple, really; a transposition here, some alignment there&#8230; but can we do better than the good ole&#8217; brute force approach the Vim guys will invariably use? Can we do it without a call to a shell commands like <code>column</code> and <code>paste</code>? (Psst.. yes we can! It&#8217;s Emacs!)</p>
<p>Here&#8217;s the original data:</p>
<pre>
ultricies, vehicula, felis, sed, auctor, aenean, euismod, semper, quam, dapibus
nibh, consequat, consequat, maecenas, sit, amet, mauris, justo, quis, porttitor
curabitur, pharetra, euismod, orci, sit, amet, ullamcorper, mi, tincidunt, et
vitae, lorem, at, mi, feugiat, convallis, ac, eget, dui, fusce
blandit, iaculis, nulla, sit, amet, dolor, nec, est, ornare, volutpat
</pre>
<p>&#8230; Standard comma-, and newline-delimited data, and we must turn it into this:</p>
<pre>
ultricies  nibh       curabitur    vitae      blandit
vehicula   consequat  pharetra     lorem      iaculis
felis      consequat  euismod      at         nulla
sed        maecenas   orci         mi         sit
auctor     sit        sit          feugiat    amet
aenean     amet       amet         convallis  dolor
euismod    mauris     ullamcorper  ac         nec
semper     justo      mi           eget       est
quam       quis       tincidunt    dui        ornare
dapibus    porttitor  et           fusce      volutpat
</pre>
<p>Looking into the challenge, I was already thinking &#8220;tables&#8221; &#8212; Emacs tables. Transposition is a common operation in tables (spreadsheets) and mathematics, and Emacs can do both very well indeed.</p>
<p>So here&#8217;s what I did, utilizing our old friend <code>org-mode</code>; or rather, one of its subsidiary libraries. You don&#8217;t have to be in <code>org-mode</code> for this trick to work. It echoes an earlier VimGolf challenge I did where I used its hierarchical &#8220;sort&#8221; function to sort an address book: Fun with Vimgolf 1: Alphabetize the Directory.</p>
<table>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
<tr>
<td><code>C-x h</code></td>
<td>Mark the whole buffer</td>
</tr>
<tr>
<td><code>M-x org-table-convert-region</code></td>
<td>Converts a region into an org table. The defaults use comma and new line separators by default. Bonus.</td>
</tr>
<tr>
<td><code>M-x org-table-transpose-table-at-point</code></td>
<td>As the name implies this will transpose our table as required by the Vimgolf challenge.</td>
</tr>
<tr>
<td><code>C-x C-x</code></td>
<td>Exchange point and mark.</td>
</tr>
<tr>
<td><code>M-x replace-regexp</code></td>
<td><code>Replace: ^| \\||</code><br />
  <code>With: RET</code></p>
<p>  Replace the pipe at the beginning of the line and a whitespace, <em>or</em> any pipe.</td>
</tr>
<tr>
<td><code>M-x delete-trailing-whitespace</code></td>
<td>Delete trailing whitespace. Could also be done with a more sophisticated regexp in the penultimate step.</td>
</tr>
</table>
<p>Done right, and it should look like this:</p>
<pre>
ultricies nibh      curabitur   vitae     blandit
vehicula  consequat pharetra    lorem     iaculis
felis     consequat euismod     at        nulla
sed       maecenas  orci        mi        sit
auctor    sit       sit         feugiat   amet
aenean    amet      amet        convallis dolor
euismod   mauris    ullamcorper ac        nec
semper    justo     mi          eget      est
quam      quis      tincidunt   dui       ornare
dapibus   porttitor et          fusce     volutpat
</pre>
<p>Six &#8220;keystrokes&#8221; (for an arbitrarily large definition of &#8220;keystroke&#8221;&#8230;), but done the Emacs way. The best score on VimGolf is currently <strong>31</strong> (characters). Very impressive, but would it work on a 20&#215;20 or with variable-length rows? &#8220;Think Abstract,&#8221; the developer cried.</p>
<p>The result above should be identical to that of the Vimgolf output, but done without the hyper-specialized and brittle solutions (most?) of the VimGolfers employ.</p>
<p>I didn&#8217;t tweak the cell width (whitespacing between each word) for each column; that it aligns perfectly with VimGolf&#8217;s output is dumb luck. Maybe they generated the resultant output in Emacs? <img src='http://www.masteringemacs.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Nevertheless, the solution is &#8220;typical Emacs&#8221; and would scale well to very large datasets, and you don&#8217;t have to worry about things like unusually long cells; uneven number of rows and columns; etc.</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2013/01/17/fun-vimgolf-4-transpositioning-text-tables/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2013/01/17/fun-vimgolf-4-transpositioning-text-tables/" data-text="Fun with Vimgolf 4: Transpositioning text with Tables"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2013%2F01%2F17%2Ffun-vimgolf-4-transpositioning-text-tables%2F&amp;title=Fun%20with%20Vimgolf%204%3A%20Transpositioning%20text%20with%20Tables" id="wpa2a_12">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2013/01/17/fun-vimgolf-4-transpositioning-text-tables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fun with Vimgolf 3: Swapping Words by Sorting</title>
		<link>http://www.masteringemacs.org/articles/2013/01/14/fun-vimgolf-3-swapping-words-sorting/</link>
		<comments>http://www.masteringemacs.org/articles/2013/01/14/fun-vimgolf-3-swapping-words-sorting/#comments</comments>
		<pubDate>Mon, 14 Jan 2013 10:00:07 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[vimgolf]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=614</guid>
		<description><![CDATA[Jon over at Irreal&#8217;s been busy with VimGolf challenges, and I figured I&#8217;d throw in my two pieces of eight. The &#8220;challenge&#8221; is a simple. Take this text: app.config['CHALLENGE_FOLDER'] = SOLUTIONS_FOLDER app.config['SOLUTIONS_FOLDER'] = CHALLENGE_FOLDER And turn it into app.config['CHALLENGE_FOLDER'] = CHALLENGE_FOLDER app.config['SOLUTIONS_FOLDER'] = SOLUTIONS_FOLDER As you can see, a simple transposition between two words on [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://irreal.org/blog/?p=1546">Jon over at Irreal&#8217;s</a> been busy with VimGolf challenges, and I figured I&#8217;d throw in my two pieces of eight.</p>
<p>The &#8220;challenge&#8221; is a simple. Take this text:</p>
<pre>
app.config['CHALLENGE_FOLDER'] = SOLUTIONS_FOLDER
app.config['SOLUTIONS_FOLDER'] = CHALLENGE_FOLDER
</pre>
<p>And turn it into</p>
<pre>
app.config['CHALLENGE_FOLDER'] = CHALLENGE_FOLDER
app.config['SOLUTIONS_FOLDER'] = SOLUTIONS_FOLDER
</pre>
<p>As you can see, a simple transposition between two words on a line is all that we need, and Jon&#8217;s come up with a solution that solves it in 8 keystrokes. Arguably something like his solution is what <em>I</em> would do were I to do it in real life. </p>
<p>I&#8217;m not sure if the Vim guys count typing out strings of text as one atomic operation or if they count each character; in Emacs, arguably, each character is in itself a command as each key stroke will invoke <code>self-insert-command</code> but it&#8217;s more fun to think of strings of text as a single keystroke, for simplicity&#8217;s sake, and to give ourselves a sporting chance against our Vim nemeses.</p>
<p>So here&#8217;s my solution. It only solves this particular challenge and nothing more. It relies on the good ole sort order &#8212; that <code>C</code> come before <code>S</code>.</p>
<table>
<tr>
<th>Command</th>
<th>Description</th>
</tr>
<tr>
<td><code>C-x h</code></td>
<td>Mark whole buffer</td>
</tr>
<tr>
<td><code>M-x sort-regexp-fields</td>
<td>Run sort-regexp-fields. See Sorting Text by Line, Field and Regexp in Emacs for more information</td>
</tr>
<tr>
<td><code>Regexp specifying records to sort: <code>\\([a-z_]+\\)$</code></code></td>
<td>We want each record -- that's the part of the line we want Emacs to use for sorting -- to be the last word on each line<code</td>
</tr>
<tr>
<td><code>Regexp specifying key within record: <code>\\1</code></code></td>
<td>The key -- that's the part inside the capturing group from above -- we want to sort by is the entire capturing group.<code</td>
</tr>
</table>
<p>And we're done. So how does it work? Well, we rely on the side effect that the word <code>CHALLENGE_FOLDER</code> is less than, lexicographically, <code>SOLUTIONS_FOLDER</code>, because <code>C</code> comes before <code>S</code>.</p>
<p>It boils down to this: <code>sort-regexp-fields</code> is <strong>pure magic</strong>. As my article on the subject talks about at length, you can tell Emacs to only sort by <em>parts</em> of a line -- the part that matches the regular expression -- and using <em>that</em> match, you can then tell Emacs how you want to sort that data. We tell Emacs to sort by the last word on each line and leave the rest untouched. Simple <img src='http://www.masteringemacs.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So how many keystrokes is that? Good question. I don't know: it depends on how you count it. Two if you count the commands only; four if you count the commands and the prompts; and many more if you count each character.</p>
<p>As always, these challenges are pointless (though fun!) but they do force you to think on your feet.</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2013/01/14/fun-vimgolf-3-swapping-words-sorting/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2013/01/14/fun-vimgolf-3-swapping-words-sorting/" data-text="Fun with Vimgolf 3: Swapping Words by Sorting"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2013%2F01%2F14%2Ffun-vimgolf-3-swapping-words-sorting%2F&amp;title=Fun%20with%20Vimgolf%203%3A%20Swapping%20Words%20by%20Sorting" id="wpa2a_16">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2013/01/14/fun-vimgolf-3-swapping-words-sorting/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Jedi: A completion library for Python</title>
		<link>http://www.masteringemacs.org/articles/2013/01/10/jedi-completion-library-python/</link>
		<comments>http://www.masteringemacs.org/articles/2013/01/10/jedi-completion-library-python/#comments</comments>
		<pubDate>Thu, 10 Jan 2013 09:26:02 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=602</guid>
		<description><![CDATA[If you&#8217;re using Python with Emacs (using one of several competing, incompatible, and slightly different modes) you are used to a pretty&#8230; bare-bones experience: no completion; semi-functional dynamic docstring support; and little in the way of two-way communication between Python and Emacs. Enter Jedi, a completion library. Yes, Jedi, an editor-agnostic library that publishes auto [...]]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re using Python with Emacs (using one of several competing, incompatible, and slightly different modes) you are used to a pretty&#8230; bare-bones experience: no completion; semi-functional dynamic docstring support; and little in the way of two-way communication between Python and Emacs.</p>
<p>Enter <a href="https://github.com/davidhalter/jedi">Jedi, a completion library</a>. Yes, <em>Jedi</em>, an editor-agnostic library that publishes auto completion, docstring support, and more. Excellent.</p>
<p>I&#8217;ve experimented with Pymacs &#8212; an interesting science project that adds &#8220;Python-like&#8221; support Emacs, so you can avoid interacting with Elisp, except not really &#8212; rope, and ropemacs and they were&#8230; disappointing. Slow, crash-prone, obtuse and impossible to extend. So I never really used them, and lived without completion or, well, much of anything beyond the REPL and my own handcrafted modifications.</p>
<p>The other alternative is the 600 lbs gorilla, CEDET, and its incomplete Python support, but that&#8217;s no good either.</p>
<p>Imagine my surprise, after fidgeting with the dependencies for both Jedi and <a href="https://github.com/tkf/emacs-jedi">Jedi.el, the Emacs library for Jedi</a>, that it&#8230; works! And it&#8217;s good! It&#8217;s up-and-coming, I should say, but perfectly usable; it doesn&#8217;t get in my way, it&#8217;s got some crazy deferreds library it depends on for asynchronous, non-blocking querying of Jedi, but that bit works great &#8212; no input lag at all.</p>
<p>It seems to resolve, simplistically (which is good), as many assignments and method calls as one can reasonably expect from a non-evaluating, statically analyzing Python completion library. </p>
<p><a href="http://www.masteringemacs.org/articles/2013/01/10/jedi-completion-library-python/screenshot-at-2013-01-07-101353/" rel="attachment wp-att-610"><img src="http://www.masteringemacs.org/wp-content/uploads/Screenshot-at-2013-01-07-101353.png" alt="Functioning Auto Complete in a Python buffer" title="Functioning Auto Complete in a Python buffer" width="752" height="360" class="alignnone size-full wp-image-610" /></a></p>
<p>The Jedi.el module also Just Works with the excellent <a href="https://github.com/auto-complete/auto-complete">auto-complete</a> library, as you can see in the picture above.</p>
<p>Aside from completion, it also offers &#8220;find symbol definition at point&#8221; (a la <em>TAGS</em>, but not crap) and Jedi.el sensibly binds it to <code>C-.</code> by default. It also has a &#8220;related names&#8221; functionality, tracking down same-named identifiers in other modules; it uses <em>Anything</em> (now <em>Helm</em>) to display the results, and it is bound to <code>C-c r</code>. And finally, it can show the documentation for the identifier at point (be it a class or function) with <code>C-c d</code>. Useful.</p>
<p>I haven&#8217;t used Jedi and Jedi.el long enough to really get to know it, but I&#8217;m probably going to extend Jedi.el so it uses <code>eldoc-mode</code> for displaying the function parameters; it&#8217;s also a bit rough around the edges, and I may want to tweak certain things to my liking, but overall: huge success!</p>
<p>I highly recommend you give Jedi and Jedi.el a try!</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2013/01/10/jedi-completion-library-python/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2013/01/10/jedi-completion-library-python/" data-text="Jedi: A completion library for Python"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2013%2F01%2F10%2Fjedi-completion-library-python%2F&amp;title=Jedi%3A%20A%20completion%20library%20for%20Python" id="wpa2a_20">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2013/01/10/jedi-completion-library-python/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>IEdit: Interactive, multi-occurrence editing in your buffer</title>
		<link>http://www.masteringemacs.org/articles/2012/10/02/iedit-interactive-multi-occurrence-editing-in-your-buffer/</link>
		<comments>http://www.masteringemacs.org/articles/2012/10/02/iedit-interactive-multi-occurrence-editing-in-your-buffer/#comments</comments>
		<pubDate>Tue, 02 Oct 2012 13:55:10 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[beginner]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=580</guid>
		<description><![CDATA[Have you ever heard of iedit for Emacs by Victor Ren (Update:Seems the github link I posted earlier was way out of date)? Me neither, until recently, and that&#8217;s a terrible shame as it is a cornerstone of my programming workflow now that I&#8217;ve learned about it. So what does it do, then? Well, quite [...]]]></description>
				<content:encoded><![CDATA[<p>Have you ever heard of <a href="https://github.com/victorhge/iedit">iedit for Emacs</a> by Victor Ren (<strong>Update:</strong>Seems the github link I posted earlier was way out of date)? Me neither, until recently, and that&#8217;s a terrible shame as it is a cornerstone of my programming workflow now that I&#8217;ve learned about it. So what does it do, then? Well, quite simply, you can edit multiple, identical string occurrences at the same time. The twist here is it uses in-buffer editing without disrupting your workflow with prompts, windows or any of that stuff: you plonk your point down on a word you want to change; you run <code>iedit-mode</code>; and now all the occurrences of that word is highlighted on your screen, like <code>isearch</code>, and when you alter a highlighted word, the other highlighted words change also. How cool is that? Modern IDEs have it already &#8212; usually hidden away in the &#8220;Refactoring&#8221; section &#8212; and does exactly the same thing, but iedit is a lot dumber as it cannot infer context beyond <em>I want to iedit all occurrences of <em>word</em> point is on.</em></p>
<p>If you regularly replace variables or words with <code>M-%</code> or <code>C-M-%</code> &#8212; well, you can retire that workflow now, as iedit will handle it for you. Sure, go ahead; use the older way if you have complex, partial replacements you want to do, but if you&#8217;re renaming a variable in a buffer&#8230; Why not use iedit?</p>
<p>Here&#8217;s a sample demonstration showing what exactly it is I&#8217;m talking about, in brilliant technicolor:</p>
<p><a href="http://www.masteringemacs.org/wp-content/uploads/2012/10/iedit.png"><img src="http://www.masteringemacs.org/wp-content/uploads/2012/10/iedit.png" alt="Emacs with IEdit active" title="IEdit" width="772" height="514" class="alignnone size-full wp-image-581" /></a></p>
<h2>Improving iedit</h2>
<p>So iedit&#8217;s pretty great and all that, but I don&#8217;t replace words across a whole buffer very often; sure, I hear you say: &#8220;just <code>narrow-to-defun</code> with <code>C-x n d</code>!&#8221; Indeed, narrowing&#8217;s great, but this blog is all about half-baked, half-inventions and cobbled-together scripts, and this post is no exception!</p>
<p>I prefer a workflow that minimizes the use of commands to do routine tasks &#8212; a fairly common goal for most Emacs hackers. The code below aim to do just that: when invoked, it will take the word at point and only <em>iedit</em> occurrences in the local <em>defun</em> (Note: don&#8217;t forget that although <em>defun</em> is Lisp-speak, most modes automatically support commands like <code>mark-defun</code> or <code>narrow-to-defun</code>.) If you pass an argument to the function, it will <em>iedit</em> all occurrences in the entire buffer.</p>
<p>The <em>iedit</em> author suggest that you bind <code>iedit-mode</code> &#8212; the default command for entering <em>iedit</em> &#8212; to <code>C-;</code> and I agree: it&#8217;s rarely used and easy to type. </p>
<p><strong>Update: </strong><em>Le Wang</em> pointed out that I was using an older version of iedit; the code has been updated to reflect the API changes.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>require 'iedit<span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> iedit-dwim <span style="color: #66cc66;">&#40;</span>arg<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Starts iedit but uses <span style="color: #000099; font-weight: bold;">\\</span>[narrow-to-defun] to limit its scope.&quot;</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><span style="color: #b1b100;">if</span> arg
      <span style="color: #66cc66;">&#40;</span>iedit-mode<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>save-excursion
      <span style="color: #66cc66;">&#40;</span>save-restriction
        <span style="color: #66cc66;">&#40;</span>widen<span style="color: #66cc66;">&#41;</span>
        <span style="color: #808080; font-style: italic;">;; this function determines the scope of `iedit-start'.</span>
        <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> iedit-mode
            <span style="color: #66cc66;">&#40;</span>iedit-done<span style="color: #66cc66;">&#41;</span>
          <span style="color: #808080; font-style: italic;">;; `current-word' can of course be replaced by other</span>
          <span style="color: #808080; font-style: italic;">;; functions.</span>
          <span style="color: #66cc66;">&#40;</span>narrow-to-<span style="color: #b1b100;">defun</span><span style="color: #66cc66;">&#41;</span>
          <span style="color: #66cc66;">&#40;</span>iedit-start <span style="color: #66cc66;">&#40;</span>current-word<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">min</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">max</span><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;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span>global-set-key <span style="color: #66cc66;">&#40;</span>kbd <span style="color: #ff0000;">&quot;C-;&quot;</span><span style="color: #66cc66;">&#41;</span> 'iedit-dwim<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2012/10/02/iedit-interactive-multi-occurrence-editing-in-your-buffer/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2012/10/02/iedit-interactive-multi-occurrence-editing-in-your-buffer/" data-text="IEdit: Interactive, multi-occurrence editing in your buffer"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2012%2F10%2F02%2Fiedit-interactive-multi-occurrence-editing-in-your-buffer%2F&amp;title=IEdit%3A%20Interactive%2C%20multi-occurrence%20editing%20in%20your%20buffer" id="wpa2a_24">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2012/10/02/iedit-interactive-multi-occurrence-editing-in-your-buffer/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Hiding and replacing modeline strings with clean-mode-line</title>
		<link>http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/</link>
		<comments>http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/#comments</comments>
		<pubDate>Mon, 10 Sep 2012 15:58:20 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[Quick Tips]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[modeline]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[readability]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=561</guid>
		<description><![CDATA[If you are like me, you are probably using one or more minor modes, and most of them add their own lighter to the modeline to tell you that they are running. Common examples include &#8220;Abbrev&#8221; for Abbrev mode; &#8220;yas&#8221; for Yasnippet mode and so on. Unfortunately, modeline real estate is expensive, and if you [...]]]></description>
				<content:encoded><![CDATA[<p>If you are like me, you are probably using one or more minor modes, and most of them add their own <em>lighter</em> to the modeline to tell you that they are running. Common examples include &#8220;Abbrev&#8221; for <em>Abbrev mode</em>; &#8220;yas&#8221; for <em>Yasnippet mode</em> and so on. Unfortunately, modeline real estate is expensive, and if you are stuck on a small screen &#8212; or if you split your Emacs windows a lot &#8212; you will find that it is often truncated, possibly hiding useful information that you <em>actually</em> care about, such as <a href="http://www.masteringemacs.org/articles/2011/11/19/which-function-mode/">Which Function Mode</a>.</p>
<p>There is no feature in Emacs to selectively hide or compress modeline flotsam, so I have hacked together some code to do the job for you.</p>
<p>For instance, in my Emacs I can collapse the following modeline string <code>(Python Hi AC yas Eldoc Flymake:0/12 Abbrev)</code> into <code>(Py α υ Φ:0/12)</code>. I&#8217;ve chosen to completely obscure <code>hi-lock-mode</code>, <code>abbrev-mode</code>, and <code>eldoc-mode</code> but &#8220;compress&#8221; <code>auto-complete-mode</code>, <code>yas/minor-mode</code>, <code>python-mode</code> and <code>flymake-mode</code>. </p>
<p>I used Greek characters (How? <code>C-u C-&#92; greek RET</code> then <code>C-&#92;</code> to write Greek characters; see <a href="http://www.masteringemacs.org/articles/2010/10/13/diacritics-in-emacs/">Diacritics in Emacs</a>) because they look cool.</p>
<p>The code works rather well, and I have yet to experience any major issues with it, but do let me know if it breaks something! One important caveat is that a lot of minor modes that reach out and call other functions, like <em>ERC</em> or <em>Flymake</em>, often use functions in lieu of strings in <code>mode-line-format</code> and <code>mode-line-modes</code>, so replacing them with a string might break the minor mode, or cause it to not update properly! Please keep that in mind and experiment in a separate Emacs instance unless you know what you&#8217;re doing. Case in point: <em>Flymake</em>. I&#8217;ve replaced its own modeline updater function with one of my own with the &#8220;Flymake&#8221; string replaced; you could probably rejiggle it by advising the original function, then tweaking the modeline string <em>post facto</em>, blah, blah, blah &#8212; but I always opt for the simpler solution, which is what I&#8217;ve used below!</p>
<p>Here&#8217;s the code. Stick it in your emacs file, evaluate it, and you&#8217;re done. You can also force a refresh by running <code>M-x clean-mode-line</code>. Flymake will have to be turned off and back on for the changes to take effect in a buffer!</p>
<p><strong>9:17pm update:</strong> Fixed a small bug in <code>clean-mode-line</code> !</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>defvar mode-line-cleaner-alist
  `<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>auto-complete-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot; α&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>yas/minor-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot; υ&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>paredit-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot; π&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>eldoc-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>abbrev-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #808080; font-style: italic;">;; Major modes</span>
    <span style="color: #66cc66;">&#40;</span>lisp-interaction-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;λ&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>hi-lock-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>python-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;Py&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>emacs-lisp-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;EL&quot;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>nxhtml-mode <span style="color: #66cc66;">.</span> <span style="color: #ff0000;">&quot;nx&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Alist for `clean-mode-line'.
&nbsp;
When you add a new element to the alist, keep in mind that you
must pass the correct minor/major mode symbol and a string you
want to use in the modeline *in lieu of* the original.&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> clean-mode-line <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>interactive<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>loop for cleaner in mode-line-cleaner-alist
        <span style="color: #b1b100;">do</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>mode <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">car</span> cleaner<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#40;</span>mode-str <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> cleaner<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
                 <span style="color: #66cc66;">&#40;</span>old-mode-str <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">cdr</span> <span style="color: #66cc66;">&#40;</span>assq mode minor-mode-alist<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;">when</span> old-mode-str
                 <span style="color: #66cc66;">&#40;</span>setcar old-mode-str mode-str<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
               <span style="color: #808080; font-style: italic;">;; major mode</span>
             <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">eq</span> mode major-mode<span style="color: #66cc66;">&#41;</span>
               <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> mode-<span style="color: #b1b100;">name</span> mode-str<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;">&#41;</span>
&nbsp;
&nbsp;
<span style="color: #66cc66;">&#40;</span>add-hook 'after-change-major-mode-hook 'clean-mode-line<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;;; alias the new `flymake-report-status-slim' to</span>
<span style="color: #808080; font-style: italic;">;;; `flymake-report-status'</span>
<span style="color: #66cc66;">&#40;</span>defalias 'flymake-report-status 'flymake-report-status-slim<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> flymake-report-status-slim <span style="color: #66cc66;">&#40;</span>e-w <span style="color: #66cc66;">&amp;</span>optional status<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Show <span style="color: #000099; font-weight: bold;">\&quot;</span>slim<span style="color: #000099; font-weight: bold;">\&quot;</span> flymake status in mode line.&quot;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> e-w
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> flymake-mode-line-e-w e-w<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> status
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> flymake-mode-line-status status<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>mode-line <span style="color: #ff0000;">&quot; Φ&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">length</span> flymake-mode-line-e-w<span style="color: #66cc66;">&#41;</span> <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> mode-line <span style="color: #66cc66;">&#40;</span>concat mode-line <span style="color: #ff0000;">&quot;:&quot;</span> flymake-mode-line-e-w<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;">setq</span> mode-line <span style="color: #66cc66;">&#40;</span>concat mode-line flymake-mode-line-status<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> flymake-mode-line mode-line<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>force-mode-line-update<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/" data-text="Hiding and replacing modeline strings with clean-mode-line"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2012%2F09%2F10%2Fhiding-replacing-modeline-strings%2F&amp;title=Hiding%20and%20replacing%20modeline%20strings%20with%20clean-mode-line" id="wpa2a_28">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Working with Coding Systems and Unicode in Emacs</title>
		<link>http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/</link>
		<comments>http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/#comments</comments>
		<pubDate>Thu, 09 Aug 2012 10:23:34 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[coding system]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=556</guid>
		<description><![CDATA[Dealing with unicode in Emacs is a daily task for me. Unfortunately, I don&#8217;t have the luxury of sticking to just UTF-8 or iso-8859-1; my work involves a lot of fidgeting with a lot of coding systems local to particular regions, so I need a flexible editor that has the right defaults that will cover [...]]]></description>
				<content:encoded><![CDATA[<p>Dealing with unicode in Emacs is a daily task for me. Unfortunately, I don&#8217;t have the luxury of sticking to <em>just</em> <code>UTF-8</code> or <code>iso-8859-1</code>; my work involves a lot of fidgeting with a lot of coding systems local to particular regions, so I need a flexible editor that has the right defaults that will cover my most common use-cases. Unsurprisingly, Emacs is more than capable of fulfilling that role.</p>
<p>Emacs has facilities in place for changing the coding system for a variety of things, such as processes, buffers and files. You can also force Emacs to invoke a command with a certain coding system, a concept I will get to in a moment.</p>
<p>The most important change (for me, anyway) is to force Emacs to default to <code>UTF-8</code>. It&#8217;s practically a standard, at least in the West, as it is dominant on the Web; has a one-to-one mapping with ASCII; and is flexible enough to represent any unicode character, making it a world-readable format. But enough nattering about that. The biggest issue is convincing Emacs to treat files as UTF-8 <em>by default</em>, when no information in the file explicitly says it is.</p>
<p>I use the following code snippet to enforce UTF-8 as the default coding system for all files, comint processes and buffers. You&#8217;re free to replace <code>utf-8</code> below with your own preferred coding system.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>prefer-coding-system 'utf-<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>set-default-coding-systems 'utf-<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>set-terminal-coding-system 'utf-<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>set-keyboard-coding-system 'utf-<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">;; backwards compatibility as default-buffer-file-coding-system</span>
<span style="color: #808080; font-style: italic;">;; is deprecated in 23.2.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">boundp</span> 'buffer-file-coding-system<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>setq-default buffer-file-coding-system 'utf-<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> default-buffer-file-coding-system 'utf-<span style="color: #cc66cc;">8</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">;; Treat clipboard input as UTF-8 string first; compound text next, etc.</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> x-select-request-type '<span style="color: #66cc66;">&#40;</span>UTF8_STRING COMPOUND_TEXT TEXT STRING<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Once evaluated, Emacs will treat new files, buffers, processes, and so on as though they are UTF-8. Emacs will <strong>still</strong> use a different coding system if the file has a file-local variable like this <code>-*- coding: euc-tw -*-</code> near the top of the file. (See <code>48.2.4 Local Variables in Files</code> in the Emacs manual.)</p>
<p>OK, so Emacs will default to UTF-8 for everything. That&#8217;s great, but not everything is in UTF-8; how do you deal with cases where it isn&#8217;t? How do you make an exception to the proverbial rule? Well, Emacs has got it covered. The command <code>M-x universal-coding-system-argument</code>, bound to the handy <code>C-x RET c</code>, takes as an argument the coding system you want to use, and a command to execute it with. That makes it possible to open files, shells or run Emacs commands as though you were using a different coding system. Very, very useful. This command is a must-have if you have to deal with stuff encoded in strange coding systems.</p>
<p>One problem with the universal coding system argument is that it only cares about Emacs&#8217;s settings, not those of your shell or system. That&#8217;s a problem, because tools like Python use the environment variable <code>PYTHONIOENCODING</code> to set the coding system for the Python interpreter.</p>
<p>I have written the following code that advises the <code>universal-coding-system-argument</code> function so it also, temporarily for just that command, sets a user-supplied list of environment variables to the coding system.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>defvar universal-coding-system-env-<span style="color: #b1b100;">list</span> '<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;PYTHONIOENCODING&quot;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;List of environment variables <span style="color: #000099; font-weight: bold;">\\</span>[universal-coding-system-argument] should set&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defadvice universal-coding-system-argument <span style="color: #66cc66;">&#40;</span>around provide-env-handler activate<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Augments <span style="color: #000099; font-weight: bold;">\\</span>[universal-coding-system-argument] so it also sets environment variables
&nbsp;
Naively sets all environment variables specified in
`universal-coding-system-env-list' to the literal string
representation of the argument `coding-system'.
&nbsp;
No guarantees are made that the environment variables set by this advice support
the same coding systems as Emacs.&quot;</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>process-environment <span style="color: #66cc66;">&#40;</span>copy-alist process-environment<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;">dolist</span> <span style="color: #66cc66;">&#40;</span>extra-env universal-coding-system-env-<span style="color: #b1b100;">list</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span>setenv extra-env <span style="color: #66cc66;">&#40;</span>symbol-<span style="color: #b1b100;">name</span> <span style="color: #66cc66;">&#40;</span>ad-get-arg <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    ad-do-it<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Insert the code into your emacs file and evaluate it, and now Emacs will also set the environment variables listed in <code>universal-coding-system-env-list</code>. One important thing to keep in mind is that Python and Emacs do not share a one-to-one correspondence of coding systems. There will probably be instances where obscure coding systems exist in one and not the other, or that the spelling or punctuation differ; the mapping of such names is left as an exercise to the reader.</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/" data-text="Working with Coding Systems and Unicode in Emacs"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2012%2F08%2F09%2Fworking-coding-systems-unicode-emacs%2F&amp;title=Working%20with%20Coding%20Systems%20and%20Unicode%20in%20Emacs" id="wpa2a_32">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2012/08/09/working-coding-systems-unicode-emacs/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Compiling and running scripts in Emacs</title>
		<link>http://www.masteringemacs.org/articles/2012/05/29/compiling-running-scripts-emacs/</link>
		<comments>http://www.masteringemacs.org/articles/2012/05/29/compiling-running-scripts-emacs/#comments</comments>
		<pubDate>Tue, 29 May 2012 15:27:48 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[For Beginners]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[buffer]]></category>
		<category><![CDATA[compile]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=551</guid>
		<description><![CDATA[I&#8217;ve talked about running shells and executing shell commands in Emacs before, but that&#8217;s mostly used for ad hoc commands or spelunking; what if you want to compile or run your scripts, code or unit tests? There&#8217;s a command for that&#8230; Not surprisingly, Emacs has its own compilation feature, complete with an error message parser [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve talked about <a href="http://www.masteringemacs.org/articles/2010/11/01/running-shells-in-emacs-overview/">running shells</a> and <a href="http://www.masteringemacs.org/articles/2011/10/19/executing-shell-commands-emacs/">executing shell commands</a> in Emacs before, but that&#8217;s mostly used for <em>ad hoc</em> commands or spelunking; what if you want to compile or run your scripts, code or unit tests?</p>
<h2>There&#8217;s a command for that&#8230;</h2>
<p>Not surprisingly, Emacs has its own compilation feature, complete with an error message parser that adds syntax highlighting and &#8220;go to next/prev error&#8221; so you can walk up and down a traceback in Python, or jump to a syntax error, warning or hint in GCC.</p>
<p>There are two ways of using the compilation feature in Emacs: the easiest is invoking <code>M-x compile</code> followed by the compile command you want Emacs to run. So, for Python, you can type <code>M-x compile RET python myfile.py RET</code> and a new <code>*compilation*</code> buffer will appear with the output of the command. Emacs will parse the output and look for certain patterns &#8212; stored in the variables <code>compilation-error-regexp-alist[-alist]</code> &#8212; and then highlight the output in the compilation buffer with &#8220;hyperlinks&#8221; that jump to the file and line (and column, if the tool outputs it) where the error occurred.</p>
<p>One annoying thing about <code>compile</code> is its insistence on wanting to save every. single. unsaved buffer before continuing. It&#8217;s there to keep you from accidentally compiling a mix of newly saved and old, stale files, which would lead to unexpected behavior, and the only reason it&#8217;s <em>still</em> there &#8212; and why it insists on saving files unrelated to what you are compiling &#8212; is the complete lack of a proper, <em>integrated</em> project management suite in Emacs. But I&#8217;ll save that rant for later.</p>
<p>Anyway, if it offends you as much as it offends me, you can add this to your emacs file to shut it up:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">;;; Shut up compile saves</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> compilation-ask-about-save <span style="color: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #808080; font-style: italic;">;;; Don't save *anything*</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">setq</span> compilation-save-buffers-predicate '<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: #b1b100;">nil</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>There is nothing stopping you from customizing <code>compilation-save-buffers-predicate</code> to take into account the files or directories so its save mechanism is cleverer, but I personally never bothered.</p>
<p>If compilation is successful &#8212; and like most things in the UNIX world, this is governed by the exit code &#8212; the modeline and compilation buffer will say so; likewise, if an error occurred, this is also displayed.</p>
<p>You can jump to the next or previous error (<code>[next/previous]-error</code>) with <code>M-g M-n</code> and <code>M-g M-p</code> &#8212; they&#8217;re bound to more keys, but I think those are the easiest ones to use. Similarly, in the compilation buffer itself (only), you can go to the next/previous file (<code>compilation-[next/previous]-file</code>) with <code>M-g M-}</code> and <code>M-g M-{</code>, respectively, and <code>RET</code> jumps to the location of the error point is on.</p>
<p>There is an undocumented convention in Emacs that commands like <code>dired</code>, <code>grep</code>, and <code>compile</code> can be rerun, reverted or redisplayed by typing <code>g</code> in the buffer.</p>
<p>By default the compilation buffer is just a dumb display and you cannot communicate with the background process. If you pass the universal argument (<code>C-u</code>) you can; the buffer is switched to comint mode, and you can converse with the process as though you were running it in the shell.</p>
<h3>Python Debugging with Compile</h3>
<p>I work mostly in Python, and quite often I have to debug the script I am writing with pdb, the Python debugger. I use breakpoints a lot, and I have a command bound to <code>F5</code> that imports pdb and calls <code>pdb.set_trace()</code> &#8212; a standard Python debugging idiom. What it also does is highlight the line in bright red so I don&#8217;t miss it. And if I call <code>compile</code> from a Python buffer, it checks if there is a breakpoint present in the file: if there is, it switches to the interactive comint mode automagically; if there isn&#8217;t, it defaults to the &#8220;dumb&#8221; display mode. Having it switch automagically is perhaps a slightly pointless flourish, but screw it I&#8217;m using Emacs, not vim <img src='http://www.masteringemacs.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This is the code I use. Feel free to adapt it for other languages. Send me an e-mail if you do something neat with it.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>require 'python<span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> python--add-debug-highlight <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Adds a highlighter for use by `python--pdb-breakpoint-string'&quot;</span>
  <span style="color: #66cc66;">&#40;</span>highlight-lines-matching-regexp <span style="color: #ff0000;">&quot;## DEBUG ##<span style="color: #000099; font-weight: bold;">\\</span>s-*$&quot;</span> 'hi-red-b<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>add-hook 'python-mode-hook 'python--add-debug-highlight<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defvar python--pdb-breakpoint-string <span style="color: #ff0000;">&quot;import pdb; pdb.set_trace() ## DEBUG ##&quot;</span>
  <span style="color: #ff0000;">&quot;Python breakpoint string used by `python-insert-breakpoint'&quot;</span><span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> python-insert-breakpoint <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Inserts a python breakpoint using `pdb'&quot;</span>
  <span style="color: #66cc66;">&#40;</span>interactive<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>back-to-indentation<span style="color: #66cc66;">&#41;</span>
  <span style="color: #808080; font-style: italic;">;; this preserves the correct indentation in case the line above</span>
  <span style="color: #808080; font-style: italic;">;; point is a nested block</span>
  <span style="color: #66cc66;">&#40;</span>split-line<span style="color: #66cc66;">&#41;</span>
  <span style="color: #66cc66;">&#40;</span>insert python--pdb-breakpoint-string<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span>define-key python-mode-map <span style="color: #66cc66;">&#40;</span>kbd <span style="color: #ff0000;">&quot;&lt;f5&gt;&quot;</span><span style="color: #66cc66;">&#41;</span> 'python-insert-breakpoint<span style="color: #66cc66;">&#41;</span>
&nbsp;
<span style="color: #66cc66;">&#40;</span>defadvice compile <span style="color: #66cc66;">&#40;</span>before ad-compile-smart activate<span style="color: #66cc66;">&#41;</span>
  <span style="color: #ff0000;">&quot;Advises `compile' so it sets the argument COMINT to t
if breakpoints are present in `python-mode' files&quot;</span>
  <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">when</span> <span style="color: #66cc66;">&#40;</span>derived-mode-p major-mode 'python-mode<span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>save-excursion
      <span style="color: #66cc66;">&#40;</span>save-match-data
        <span style="color: #66cc66;">&#40;</span>goto-char <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">min</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>re-search-forward <span style="color: #66cc66;">&#40;</span>concat <span style="color: #ff0000;">&quot;^<span style="color: #000099; font-weight: bold;">\\</span>s-*&quot;</span> python--pdb-breakpoint-string <span style="color: #ff0000;">&quot;$&quot;</span><span style="color: #66cc66;">&#41;</span>
                               <span style="color: #66cc66;">&#40;</span>point-<span style="color: #b1b100;">max</span><span style="color: #66cc66;">&#41;</span> t<span style="color: #66cc66;">&#41;</span>
            <span style="color: #808080; font-style: italic;">;; set COMINT argument to `t'.</span>
            <span style="color: #66cc66;">&#40;</span>ad-set-arg <span style="color: #cc66cc;">1</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;">&#41;</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<h2>There&#8217;s a Minor Mode for that&#8230;</h2>
<p>The <code>compile</code> workflow isn&#8217;t for everyone; some people want everything in one place: their shell. Well, good news then &#8212; you can have your cake and eat it. The minor mode <code>M-x compilation-shell-minor-mode</code> is designed for comint buffers of all sizes and works well with <code>M-x shell</code> and most modes that use comint. You get the same benefits offered by <code>compile</code> without altering your workflow. If you compile or run interpreted stuff in your Emacs shell you&#8217;ll feel like a modern-day Prometheus with this minor mode enabled!</p>
<p>Add this to your emacs file and the compilation minor mode will start when <code>shell</code> does.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span>add-hook 'shell-mode-hook 'compilation-shell-minor-mode<span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2012/05/29/compiling-running-scripts-emacs/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2012/05/29/compiling-running-scripts-emacs/" data-text="Compiling and running scripts in Emacs"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2012%2F05%2F29%2Fcompiling-running-scripts-emacs%2F&amp;title=Compiling%20and%20running%20scripts%20in%20Emacs" id="wpa2a_36">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2012/05/29/compiling-running-scripts-emacs/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Fun with Emacs Calc</title>
		<link>http://www.masteringemacs.org/articles/2012/04/25/fun-emacs-calc/</link>
		<comments>http://www.masteringemacs.org/articles/2012/04/25/fun-emacs-calc/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 12:57:35 +0000</pubDate>
		<dc:creator>mickey</dc:creator>
				<category><![CDATA[All Articles]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[calc]]></category>
		<category><![CDATA[elisp]]></category>
		<category><![CDATA[ielm]]></category>
		<category><![CDATA[info]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.masteringemacs.org/?p=544</guid>
		<description><![CDATA[The Challenge Jon over at Irreal&#8217;s Emacs blog posted an interesting solution to a challenge raised by Xah Lee: How do you convert a string like this 37°26′36.42″N 06°15′14.28″W into a decimal answer like this 37.44345 -6.25396. First off, I&#8217;m not sure Xah&#8217;s example answer is entirely correct; my understanding of latitude and longitude is [...]]]></description>
				<content:encoded><![CDATA[<h2>The Challenge</h2>
<p>Jon over at <a href="http://irreal.org/blog/?p=795">Irreal&#8217;s Emacs blog</a> posted an interesting solution to a challenge raised by <a href="http://xahlee.blogspot.com/2012/04/programing-problem-decimalize-latitude.html">Xah Lee</a>:</p>
<blockquote><p>How do you convert a string like this <code>37°26′36.42″N 06°15′14.28″W</code> into a decimal answer like this <code>37.44345 -6.25396</code>.</p></blockquote>
<p>First off, I&#8217;m not sure Xah&#8217;s example answer is entirely correct; my understanding of latitude and longitude is limited to what I can google, and if I type the original degrees, minutes and seconds into <a href="http://transition.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html">this tool by the U.S. FCC</a> it returns <code>37.44345 6.25396</code>.</p>
<p>Anyway, on with the challenge. Jon&#8217;s solution is very interesting, but it got me thinking: surely Emacs has the facility in place to do this already? It&#8217;s <em>Emacs</em>, right? Right.</p>
<h2>Fun with Emacs Calc</h2>
<p>Emacs is equipped with a really, really awesome and spiffy RPN calculator (HP calculator fans, rejoice) capable of manifold things like algebraic and symbolic manipulation; matrix manipulation; conversion routines and much, much more. It&#8217;s truly wonderful but really complex, but it does come with a really nice Info manual (type <code>C-h i g (calc)</code> and check it out.) It&#8217;s a shame so few people know about its potential, as it&#8217;s basically a much simpler version of Mathematica, or even Wolfram Alpha (arguably you&#8217;ll have as much trouble telling <em>Calc</em> what you want as you would <em>Wolfram Alpha</em>&#8230;)</p>
<p><em>Anyway</em>, I figured the Emacs calculator would have a facility in place for converting Deg-Min-Sec to decimal form, and sure enough, it does.</p>
<p>To try it out, type <code>C-x * *</code> and the calculator will open. Two windows will appear: the calculator mode and the trail containing a trail &#8212; a history &#8212; of commands and actions. The first thing we need to do is switch the calculator to &#8220;HMS&#8221; mode so we can try it out. To do this, type <code>m h</code> in the mode (the left) window and the modeline will change and say something like <code>Calc: 12 Hms</code>. The <code>12</code> is the floating point precision.</p>
<p>Next, type in the expression, replacing the unicode symbols above with <code>@</code> for degrees; <code>'</code> for minutes; and <code>&quot;</code> for seconds. If you typed it in correctly, it will appear in the calculator window.</p>
<p>All we have to do now is convert it. Calc can convert between a wide range of units and systems, but we only care about decimals. Type <code>c d</code> and Calc will convert it to a decimal number. If you entered <code>37@26'36.42&quot;</code> you should see <code>37.44345</code> appear in its place.</p>
<p>OK, so we know it can do it, but how do we weaponize it? It so happens that Calc comes with a neat, little (though underdocumented) command called <code>calc-eval</code>.</p>
<p>Entering IELM, <code>M-x ielm</code>, we can query the calculator in real time:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;">ELISP<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>calc-<span style="color: #b1b100;">eval</span> <span style="color: #ff0000;">&quot;1+2&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #ff0000;">&quot;3&quot;</span></pre></td></tr></table></div>

<p>Yep. It does work. The hardest part about using it is mapping the &#8220;algebraic&#8221; notation used above with the indirect, keybinding-based input you use in the RPN calculator. Thankfully, the manual and (often) the trail will tell you the name of the function you are calling.</p>
<p>Let&#8217;s digress a little so I can show you how neat this calculator actually is: solving the elementary equation <code>2x+5=10</code>. In the calculator, type <code>m a</code> to go to algebraic mode; next, type <code>(2x + 5 = 10)</code> &#8212; don&#8217;t forget the brackets &#8212; and it should appear as an equation. Finally, type <code>a S</code> to &#8220;solve for&#8221; a variable &#8212; and when prompted, answer <code>x</code>. The answer will appear in your calculator window. How awesome is that?</p>
<p>Back to the challenge. Calling the &#8220;convert to degrees&#8221; function is what we need to do, and the answer is hidden in the trail &#8212; it&#8217;s called <code>deg</code>.</p>
<p>Putting it all together, and we get:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;">ELISP<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>calc-<span style="color: #b1b100;">eval</span> <span style="color: #ff0000;">&quot;deg(37@ 26' 36.42<span style="color: #000099; font-weight: bold;">\&quot;</span>)&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #ff0000;">&quot;37.44345&quot;</span></pre></td></tr></table></div>

<p>That looks right. But the original challenge said that we had to take a string, like the one given above, and map that. So here&#8217;s my solution:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;"><span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">defun</span> hms-to-dec <span style="color: #66cc66;">&#40;</span>hms-str<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>hms <span style="color: #66cc66;">&#40;</span>split-string hms-str <span style="color: #ff0000;">&quot;[°′″NW ]&quot;</span> t<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>
    <span style="color: #66cc66;">&#40;</span>flet <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#40;</span>to-deg <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>
                   <span style="color: #66cc66;">&#40;</span>string-to-number
                    <span style="color: #66cc66;">&#40;</span>calc-<span style="color: #b1b100;">eval</span> <span style="color: #66cc66;">&#40;</span>format <span style="color: #ff0000;">&quot;deg(%s@ %s' %s<span style="color: #000099; font-weight: bold;">\&quot;</span>)&quot;</span>
                                       <span style="color: #66cc66;">&#40;</span>pop hms<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pop hms<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>pop hms<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;">&#41;</span><span style="color: #66cc66;">&#41;</span>
      <span style="color: #66cc66;">&#40;</span><span style="color: #b1b100;">list</span> <span style="color: #66cc66;">&#40;</span>to-deg<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#40;</span>to-deg<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;">&#41;</span></pre></td></tr></table></div>

<p>Calling it from IELM yields the following answer:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="lisp" style="font-family:monospace;">ELISP<span style="color: #66cc66;">&gt;</span> <span style="color: #66cc66;">&#40;</span>hms-to-dec <span style="color: #ff0000;">&quot;37°26′36.42″N 06°15′14.28″W&quot;</span><span style="color: #66cc66;">&#41;</span>
<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">37.44345</span> <span style="color: #cc66cc;">6.25396666667</span><span style="color: #66cc66;">&#41;</span></pre></td></tr></table></div>

<p>Looks good to me. Job done, and a fun challenge.</p>
<p><a class="a2a_button_google_plusone addtoany_special_service" data-href="http://www.masteringemacs.org/articles/2012/04/25/fun-emacs-calc/"></a><a class="a2a_button_twitter_tweet addtoany_special_service" data-count="horizontal" data-url="http://www.masteringemacs.org/articles/2012/04/25/fun-emacs-calc/" data-text="Fun with Emacs Calc"></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.masteringemacs.org%2Farticles%2F2012%2F04%2F25%2Ffun-emacs-calc%2F&amp;title=Fun%20with%20Emacs%20Calc" id="wpa2a_40">Share</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.masteringemacs.org/articles/2012/04/25/fun-emacs-calc/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
