tag:blogger.com,1999:blog-39925308077503848682024-02-07T06:12:32.355+02:00emacs-fuuseful tricks for emacsUnknownnoreply@blogger.comBlogger137125tag:blogger.com,1999:blog-3992530807750384868.post-56110803690150519532013-03-17T20:13:00.002+02:002013-03-17T20:13:37.800+02:00editing with root-privileges -- once more<div class="outline-text-2" id="text-1">
<p>
We've already discussed editing root-owned files here a few times; it's one
of those tasks where in a reflex I still open a terminal and use <code>vi</code> to do
the job… the only way to overcome that seems to be to make it <i>really</i>
easy to do the same from within my running emacs:
</p>
<pre class="src src-elisp"> (<span style="color: #bc8383; font-weight: bold;">defun</span> <span style="color: #8fb28f; font-weight: bold;">djcb-find-file-as-root</span> ()
<span style="color: #8fb28f; font-style: italic;">"Like `ido-find-file, but automatically edit the file with</span>
<span style="color: #8fb28f; font-style: italic;">root-privileges (using tramp/sudo), if the file is not writable by</span>
<span style="color: #8fb28f; font-style: italic;">user."</span>
(interactive)
(<span style="color: #bc8383; font-weight: bold;">let</span> ((file (ido-read-file-name <span style="color: #6ca0a3;">"Edit as root: "</span>)))
(<span style="color: #bc8383; font-weight: bold;">unless</span> (file-writable-p file)
(<span style="color: #bc8383; font-weight: bold;">setq</span> file (concat <span style="color: #6ca0a3;">"/sudo:root@localhost:"</span> file)))
(find-file file)))
<span style="color: #9fc59f;">;; </span><span style="color: #7f9f7f; font-style: italic;">or some other keybinding...</span>
(global-set-key (kbd <span style="color: #6ca0a3;">"C-x F"</span>) 'djcb-find-file-as-root)
</pre>
<p>
We could take it one step further still – overload the normal
<code>(ido-)find-file</code> with a version that checks the permissions first, and if
needed, use the above function to open it. But maybe that is <i>too</i> easy; we
should be careful with root-owned files after all.
</p></div>
Unknownnoreply@blogger.com9tag:blogger.com,1999:blog-3992530807750384868.post-41033195720937707982012-10-15T11:46:00.000+03:002012-10-15T11:46:19.872+03:00mu4e v0.9.9 is out!<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
I few months ago, I introduced <code>mu4e</code>, a modest little emacs mail client that
I wrote. It seems many people picked it up, great!
</p>
</div>
<div id="outline-container-1-1" class="outline-3">
<h3 id="sec-1-1">what's new?</h3>
<div class="outline-text-3" id="text-1-1">
<p>
I have just released <a href="http://code.google.com/p/mu0/downloads/detail?name=mu-0.9.9.tar.gz">mu/mu4e version 0.9.9</a>. There are quite a few changes,
both user-visible and 'under-the-hood'. I've also spent some time on improving
<a href="http://code.google.com/p/mu0/downloads/detail?name=mu4e-manual-0.9.9.pdf">the manual</a> (pdf), and I'm quite happy about it.
</p>
<p>
Some of the more visible new things in <code>mu4e</code> are:
</p>
<ul>
<li>Support for crypto (decrypting messages, signing them)
</li>
<li>Support for <i>refiling</i> (like <code>mutt</code>, Wanderlust)
</li>
<li>Dynamic folders (instead of hard-coding the sent/draft/trash/refile folder,
they can be <i>functions</i> that return different folders based on the message
we're dealing with, see the example below)
</li>
<li>Same for the folder to save attachments
</li>
<li>A lot of smaller and bigger UI improvements
</li>
</ul>
<p>
Also, the core <code>mu</code> program has seen a lot of improvements (many of which
directly improve <code>mu4e</code> as well)
</p>
<ul>
<li>Better support for non-ascii locales / character sets, such as <code>ISO-2022-JP</code>
</li>
<li>Improved on-line help ('<code>mu help ...</code>')
</li>
<li>Performance improvements for threaded display (~ 25% for 23K messages)
</li>
</ul>
<p>
For a more complete list, see <a href="https://github.com/djcb/mu/blob/master/NEWS">NEWS</a>.
</p>
</div>
</div>
<div id="outline-container-1-2" class="outline-3">
<h3 id="sec-1-2">dynamic folders</h3>
<div class="outline-text-3" id="text-1-2">
<p>
As mentioned, <code>mu4e</code> now supports <i>dynamic folders</i>. Before, you'd set your
trash folder to some static string:
</p>
<pre class="src src-elisp">(<span class="org-keyword">setq</span> mu4e-trash-folder <span class="org-string">"/trash"</span>)
</pre>
<p>
In some cases, you may want to have a bit more flexibility – for example,
have a separate trash-folder (or sent-folder, drafts-folder, refile-folder)
for private mail and work mail. You can now do something like:
</p>
<pre class="src src-elisp">(<span class="org-keyword">setq</span> mu4e-trash-folder
(<span class="org-keyword">lambda</span> (msg)
(<span class="org-keyword">if</span> (and msg <span class="org-comment-delimiter">;; </span><span class="org-comment">msg may be nil</span>
(mu4e-message-contact-field-matches msg <span class="org-builtin">:to</span> <span class="org-string">"me@work.com"</span>))
<span class="org-string">"/trash-work"</span>
<span class="org-string">"/trash"</span>)))
</pre>
</div>
</div>
<div id="outline-container-1-3" class="outline-3">
<h3 id="sec-1-3">refiling</h3>
<div class="outline-text-3" id="text-1-3">
<p>
After I have dealt with some e-mail, I either delete it or move it to some
archive folder – <i>refiling</i>. For this, there is now the <code>r</code> keybinding, and
<code>mu4e-refile-folder</code>; and a place where dynamic folders really shine:
</p>
<pre class="src src-elisp">(<span class="org-keyword">setq</span> mu4e-refile-folder
(<span class="org-keyword">lambda</span> (msg)
(<span class="org-keyword">cond</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">messages to the mu mailing list go to the /mu folder</span>
((mu4e-message-contact-field-matches msg <span class="org-builtin">:to</span>
<span class="org-string">"mu-discuss@googlegroups.com"</span>)
<span class="org-string">"/mu"</span>)
<span class="org-comment-delimiter">;; </span><span class="org-comment">messages sent directly to me go to /archive</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">also `</span><span class="org-comment"><span class="org-constant">mu4e-user-mail-address-regexp</span></span><span class="org-comment">' can be used</span>
((mu4e-message-contact-field-matches msg <span class="org-builtin">:to</span> <span class="org-string">"me@example.com"</span>)
<span class="org-string">"/private"</span>)
<span class="org-comment-delimiter">;; </span><span class="org-comment">messages with football or soccer in the subject go to /football</span>
((string-match <span class="org-string">"football</span><span class="org-string"><span class="org-regexp-grouping-backslash">\\</span></span><span class="org-string"><span class="org-regexp-grouping-construct">|</span></span><span class="org-string">soccer"</span> (or (mu4e-message-field msg <span class="org-builtin">:subject</span>) <span class="org-string">""</span>))
<span class="org-string">"/football"</span>)
<span class="org-comment-delimiter">;; </span><span class="org-comment">everything else goes to /archive</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">important to have a catch-all at the end!</span>
(t <span class="org-string">"/archive"</span>))))
</pre>
<p>
How cool is that? After reading my inbox folder, I select all messages (<code>C-x h</code>), press <code>r</code>, and they're all moved to the right refiling folder.
</p>
</div>
</div>
<div id="outline-container-1-4" class="outline-3">
<h3 id="sec-1-4">crypto support</h3>
<div class="outline-text-3" id="text-1-4">
<p>
<code>mu4e</code> already supported signing/encrypting messages, but now it supports
decryption and verifying signatures as well. This was one of the most
requested new features. I think it is still a bit rough, but it has been
working very well for me.
</p>
</div>
</div>
<div id="outline-container-1-5" class="outline-3">
<h3 id="sec-1-5">so…</h3>
<div class="outline-text-3" id="text-1-5">
<p>
I think version 0.9.9 is a great new step for <code>mu4e</code>. It already goes far
beyond I ever planned to do. I received a lot of suggestions for new
features, which is great! I'm not planning to implement all of those, but I
will try to make <code>mu4e</code> even more programmable – it should be easy to augment
<code>mu4e</code> with your own little elisp-snippets – the <i>Barbapapa principle</i> of
software, already so clearly present in emacs itself.
</p></div>
</div>
</div>
Unknownnoreply@blogger.com16tag:blogger.com,1999:blog-3992530807750384868.post-48349231820312975992012-08-20T22:31:00.000+03:002012-09-16T23:16:06.743+03:00introducing mu4e, an e-mail client for emacs<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
</div>
<div id="outline-container-1-1" class="outline-3">
<h3 id="sec-1-1">background</h3>
<div class="outline-text-3" id="text-1-1">
<p>
I've haven't written too much here lately. This is because I have spent most
of my emacs hacking time on <code>mu4e</code>, an emacs e-mail client. It's only
slightly over six months old since its first release, but it has progressed
rather quickly! So, I think it is time to give it an introduction to a wider
audience. In future posts, I'll go into more detail.
</p>
<p>
E-mail is a very important means of communication for me; and for purposes of
integration, it prefer to do my e-mail with emacs. For a long time, I used
<code>mutt</code> with emacs as the editor; a few years back I switched to <a href="http://www.gohome.org/wl/">Wanderlust</a>,
and wrote <a href="http://emacs-fu.blogspot.fi/search/label/wanderlust">a few articles</a> about it.
</p>
<p>
There's a lot to like about Wanderlust: it's very featureful, and allows for
a lot of customization. Still, there were a few things I was not fully happy
with; the most important one was the speed of some operations; another
annoyance was the fact that I got rather frequent cache-corruptions when
using newer emacs versions.
</p>
<p>
So, what was I to do? Well, a few years back, I had written an e-mail
indexer/searcher, called <a href="http://www.djcbsoftware.nl/code/mu">mu</a>. It takes the messages in a maildir-folder, and
allows you to query them. I wondered if I could use <code>mu</code> as the backend for
an emacs-based e-mail client. So, I fired up emacs, started writing some code
and some later I had a first version of… <code>mu4e</code>.
</p>
</div>
</div>
<div id="outline-container-1-2" class="outline-3">
<h3 id="sec-1-2">how does it work?</h3>
<div class="outline-text-3" id="text-1-2">
<p>
<code>mu4e</code> is an emacs front-end for <code>mu</code>; when you start it, <code>mu4e</code> connects to a
<code>mu</code> server process (started on-demand). It accepts simple commands, and
responds with emacs <i>s-expressions</i>, in asynchronous fashion. In practice, all
the heavy work is done in this server process, and emacs shows the results
when it is ready (usually almost instantly). Emacs does not need to <i>wait</i> for
the backend, and things stay snappy, even with tens of thousands (or more)
e-mail messages. The only operation that may still require some waiting is
<i>sending mail</i>, since that uses the emacs built-in <code>smtpmail</code>, which blocks
during its operation.
</p>
<p>
<code>mu</code> expects your e-mail messages to be stored in a <a href="http://en.wikipedia.org/wiki/Maildir">maildir</a> (a
one-file-per-message system); you can get these mails there through tools
like <a href="http://offlineimap.org/">offlineimap</a> or <a href="http://www.fetchmail.info/">fetchmail</a>. <code>mu</code> periodically indexes the messages, and
stores the results in a <a href="http://xapian.org/">Xapian</a> database. A lot of what <code>mu4e</code> does is
querying this database – so for example, what you see as 'my inbox folder'
in the <code>mu4e</code>-frontend, is in fact just the result of a <i>query</i> of all
message that happen to live in that folder. You can query for many things –
message sender, subject, date, words in the body and more.
</p>
<p>
<code>mu4e</code> does not just query messages; it can also move messages between
folders, delete them, modify their flags and so on (and afterwards update the
database). All 'state' is in the file system, and the database is just a quick
way to get to it; if you delete the database and then re-index, nothing is
lost, and changes made with other tools (e.g. <code>mutt</code>) are picked up by <code>mu</code> as
well.
</p>
</div>
</div>
<div id="outline-container-1-3" class="outline-3">
<h3 id="sec-1-3">trying mu4e</h3>
<div class="outline-text-3" id="text-1-3">
<p>
Some Linux distributions ship <code>mu4e</code>, but not necessarily a very recent
version; and because <code>mu4e</code> is developing quickly, you may want to use the
<a href="http://code.google.com/p/mu0/downloads/list">latest official release</a>, or (if you are more adventurous) check out the <a href="https://github.com/djcb/mu">git repository</a>. You'll need GNU/Emacs 23 or 24, GLib, GMime >= 2.4 and Xapian.
</p>
<p>
After installing <code>mu4e</code>, you can check the <a href="http://www.djcbsoftware.nl/code/mu/mu4e/index.html">mu4e manual</a>, which should be
fairly complete. In fact, one of the goals of <code>mu4e</code> is to make it easy to
set up; for that reason, the documentation includes complete examples of how
to <a href="http://www.djcbsoftware.nl/code/mu/mu4e/Example-configuration.html#Example-configuration">set things up</a>. The <a href="http://www.djcbsoftware.nl/code/mu/mu4e/Getting-started.html#Getting-started">Getting started</a> chapter should get you up to speed
quickly.
</p>
<p>
So, give it a try if you're interested; the <code>mu=/=mu4e</code> project is very open
to suggestions (and even bugs reports!), so feel free to put them here or
subscribe to the <a href="https://groups.google.com/forum/?fromgroups#!forum/mu-discuss">mu mailing list</a>.
</p>
</div>
</div>
<div id="outline-container-1-4" class="outline-3">
<h3 id="sec-1-4">a small tour</h3>
<div class="outline-text-3" id="text-1-4">
<p>
I'll end this with a number of screenshots, to give you a rough idea of how
things look.
</p>
</div>
<div id="outline-container-1-4-1" class="outline-4">
<h4 id="sec-1-4-1">The main screen</h4>
<div class="outline-text-4" id="text-1-4-1">
<p>
When you start <code>mu4e</code> (<code>M-x mu4e</code>), you're taken to the main screen, which
list the things you can do. The entries should speak for themselves. Note
that you can define you're own bookmarks. In general, <code>mu4e</code> tries to make
things as easy as possible, and provide auto-completions where possible.
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaCL11CXZvtFSKnbQMVt3s-1l-tUvBadKeZAK1HNSxq6CHLg0Tjjv8eYBsa_LVqcaPT0lfAPyRC1IbTqE9fd-djWZ7KvnD_IKYcibV7aY-EiCbeUTKjOUrNXf9G1F9qLDIjg4muVif3bk/s1600/mu4emain.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="387" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgaCL11CXZvtFSKnbQMVt3s-1l-tUvBadKeZAK1HNSxq6CHLg0Tjjv8eYBsa_LVqcaPT0lfAPyRC1IbTqE9fd-djWZ7KvnD_IKYcibV7aY-EiCbeUTKjOUrNXf9G1F9qLDIjg4muVif3bk/s400/mu4emain.png" /></a></div>
</p>
</div>
</div>
<div id="outline-container-1-4-2" class="outline-4">
<h4 id="sec-1-4-2">The headers / view split-screen</h4>
<div class="outline-text-4" id="text-1-4-2">
<p>
The results of your queries are shown as a list of headers; if you click one
of the headers, <code>mu4e</code> splits the screen horizontally (optionally, you can
split the screen vertically, or only show the message view). You can
customize the headers shown, re-order them and so on.
</p>
<p>
The message view supports html message, inline images, and has a mechanism
to associate user-functions with messages and attachments (such as 'view in
browser' or 'pipe through command'); see the manual for some examples.
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDGIk78PHspu92yG5iKbx5GKCKioizC7LDBf24nmYR-29DpRWGutX1gtC0NbA2E8B2uIykFB__kUvwl8Jv7AgeQHwc4D-mjaU5WngPvJjq0PynWACW0z7LlRe_ax3fPYBymX1NWe45rfY/s1600/mu4eheaders.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="387" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDGIk78PHspu92yG5iKbx5GKCKioizC7LDBf24nmYR-29DpRWGutX1gtC0NbA2E8B2uIykFB__kUvwl8Jv7AgeQHwc4D-mjaU5WngPvJjq0PynWACW0z7LlRe_ax3fPYBymX1NWe45rfY/s400/mu4eheaders.png" /></a></div>
</p>
</div>
</div>
<div id="outline-container-1-4-3" class="outline-4">
<h4 id="sec-1-4-3">The message composition view</h4>
<div class="outline-text-4" id="text-1-4-3">
<p>
Obviously, you can reply to messages, forward them, or compose a new
message. For writing and sending messages, <code>mu4e</code> reuses emacs' built-in
<code>message-mode</code>. There's support for auto-completing addresses (based on the
e-mails you've sent/received before).
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuTgzBaKNEm6DBCEma4deD-N10iCAtWDPkGIGDmbQcceE2qU-2kW_40pbP3VkFLCeNfc_V-dDBJjx_l2NCvVbY05twlG1BDBc1MI-3NGCMVNjYfoxf1dk_Kx1_PkEvfXuBudmpdkPGbuU/s1600/mu4ecompose.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="292" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhuTgzBaKNEm6DBCEma4deD-N10iCAtWDPkGIGDmbQcceE2qU-2kW_40pbP3VkFLCeNfc_V-dDBJjx_l2NCvVbY05twlG1BDBc1MI-3NGCMVNjYfoxf1dk_Kx1_PkEvfXuBudmpdkPGbuU/s400/mu4ecompose.png" /></a></div>
</p>
<p>
There's even (experimental) support for writing you're messages using
<code>org-mode</code>, and then sending them as rich-text (html) messages.
</p>
</div>
</div>
</div>
<div id="outline-container-1-5" class="outline-3">
<h3 id="sec-1-5">parting thoughts</h3>
<div class="outline-text-3" id="text-1-5">
<p>
So, this was a short introduction to <code>mu4e</code>, barely scratching the surface,
but hopefully conveying the main ideas. The manual discusses things in much
more detail, and I'll write more about it in the future.
</p>
<p>
<code>mu4e</code> is still a young project, but, for what's it worth, I've been using it
full-time for over six months, and a growing number of people are doing the
same. So, if you're interested, give it try and let us know you think!
</p>
<p>
Have fun!
</p>
</div>
</div>
</div>
Unknownnoreply@blogger.com24tag:blogger.com,1999:blog-3992530807750384868.post-40237972841842916972012-08-10T18:03:00.000+03:002012-08-10T18:03:10.948+03:00file management with sunrise-commander<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
I tend to do a lot of file management from the shell (<code>zsh</code>, in my case); this
is very flexible / powerful and so on. But, for some things a bit more
graphical approach is nicer.
</p>
<p>
There are fully graphical file-managers like <i>Nautilus</i> or <i>Thunar</i>, but for a
bit more keyboard-friendly file-management, there are so-called <i>orthodox file managers</i> - the archetypical Norton Commander and its descendants, like
<a href="http://www.midnight-commander.org">midnight-commander</a> (mc) and <a href="http://www.nongnu.org/gcmd/">gnome commander</a>.
</p>
<p>
Not surprisingly, emacs has its own incarnation - it is called the <a href="http://www.emacswiki.org/emacs/Sunrise_Commander">sunrise commander</a> and happily it's obtainable through <a href="http://emacs-fu.blogspot.fi/2011/11/package-management-revisited.html">ELPA</a>. It's become an important
of my workflow. When you're used to Midnight Commander, you'll feel right at
home.
</p>
<p>
If you want to use <code>emacs</code> for <i>yet another</i> of your computer-based
activities, give it a try.
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB7pGfWkSa14tA24M-mN18DtrU03HMgD5xmbNre_1NWYvFF3hOJlpt5Iq_IG16g7FxAPzxbswPVJ9DE6TNcqi4rcPFluVpix3IvK34V4q4LYs1vP4qxHWBaKAJ0oCPyyCSDshSsOnMFrE/s1600/Screenshot+from+2012-08-10+17%253A58%253A53.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="235" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgB7pGfWkSa14tA24M-mN18DtrU03HMgD5xmbNre_1NWYvFF3hOJlpt5Iq_IG16g7FxAPzxbswPVJ9DE6TNcqi4rcPFluVpix3IvK34V4q4LYs1vP4qxHWBaKAJ0oCPyyCSDshSsOnMFrE/s400/Screenshot+from+2012-08-10+17%253A58%253A53.png" /></a></div>
</div>
</div>Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-3992530807750384868.post-59398399261633803132012-07-09T11:36:00.001+03:002012-07-14T17:42:44.181+03:00replace-regexp and numbering lines<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
I saw the <a href="http://emacsworld.blogspot.fi/2012/06/numbering-lines-and-lists-in-emacs.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+GotEmacs+(Got+Emacs?)">Got Emacs? posting</a> showing off the new emacs-24
<code>rectangle-number-lines</code> command, to number a bunch of lines in buffer,
i.e..:
</p>
<pre class="example">foo
bar
cuux
</pre>
<p>
becomes:
</p>
<pre class="example">1 foo
2 bar
3 cuux
</pre>
<p>
Very cool! An alternative is to use <code>cua-mode</code>, mark the column for the
numbers with <code>cua-set-rectangle-mark</code> (<code>C-RET</code>), and then use <code>M-x cua-sequence-rectangle</code> (which takes you throught the steps, and has a lot of
flexibility.
</p>
<p>
But let's look at yet another way: using <code>replace-regexp</code>. If we select (mark)
the list once more, we can do <code>M-x replace-regexp RET ^ RET \#. RET</code> Note that
the <code>#</code> is a special meta-character that represents <i>the number of replacements already made</i>. This has the somewhat clumsy side-effect that your
list be numbered, starting at 0 rather than 1, so you should add a
dummy-element at the beginning. Clearly, <code>replace-regexp</code> is inferior for
simply adding some line numbers – however, it has the flexibility to do some
smarter things.
</p>
<p>
Smarter things? Yes! <code>replace-regexp</code> allows you to use arbitrary
Lisp-expressions in the replace strings. So, let's suppose that we want to use
<i>letters</i> instead of numbers for our lines. Easy – again, select (mark) your
lines, <code>M-x replace-regexp RET ^ RET \,(format "%c. " (+ ?a \#)) RET</code> and we get:
</p>
<pre class="example">a. foo
b. bar
c. cuux
</pre>
<p>
Admittedly, not the most world-shattering thing, but it does show the powers
hidden in something as common as <code>replace-regexp</code>.
</p></div>
</div>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-3992530807750384868.post-23690754627621715772012-06-20T21:34:00.001+03:002012-06-20T21:34:02.650+03:00who holds this value?<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Something from the category of useful things hiding in emacs… Suppose you
are looking for the variable that holds a certain value. How to find it?
</p>
<p>
Easy: <code>M-x apropos-value</code>
</p>
<p>
So, for example, finding all variables that hold your e-mail address:
</p>
<p>
<code>M-x apropos-value RET me@example.com RET</code>
</p>
<p>
and you'll get all the matches in the <code>*Apropos*</code>-buffer. HT: Stephen
Eglen.
</p>
<p>
Also check the various other <code>M-x apropos-...</code> commands, they all help you
find useful information if you can remember a word. Except for… <code>M-x apropos-zippy</code>… eh?
</p>
</div>
</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-3992530807750384868.post-11621710935146635292012-06-06T07:42:00.001+03:002012-06-06T19:11:08.939+03:00euro 2012 games in your org-mode agenda<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Things have been rather quiet at emacs-fu - reason for this is that most of my
emacs hacking time has been spent on <a href="http://www.djcbsoftware.nl/code/mu/">mu4e</a>, the emacs e-mail client I
wrote. It's been shaping up pretty nicely, I should probably write some
emacs-fu posts about it :)
</p>
<p>
Another interesting pastime (esp. in Europe) is football/soccer, in particular
the Euro2012 games; long-time readers will remember the <a href="http://emacs-fu.blogspot.fi/2010/06/worldcup-games-in-your-org-mode-agenda.html">schedule for world cup games</a>; I made a new one for Euro2012: <a href="https://github.com/djcb/org-euro2012">https://github.com/djcb/org-euro2012</a>.
</p>
<p>
In order to have the games show up in your agenda, make sure the file is in
your org-agenda-files. If needed, you could add it with something like this in
your org-mode settings (change the directory path to wherever you have put
<code>euro2012.org</code>):
</p>
<pre class="src src-emacs-lisp">(add-to-list 'org-agenda-files <span class="org-string">"~/org/euro2012.org"</span>)
</pre>
<p>
One small issue with the schedule is that it uses the central-european summer
time (UTC+2), and there is no automatic way to adjust times for the local time
zone. As a work-around, Juan Pechiar provided the following function which makes
it easy to update all org-timestamps in a file:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">defun</span> <span class="org-function-name">update-org-hours</span> (n)
<span class="org-doc">"Change all org-mode timestamps in the current buffer by N hours."</span>
(interactive <span class="org-string">"nAdd hours: "</span>)
(<span class="org-keyword">save-excursion</span>
(goto-char (point-min))
(<span class="org-keyword">while</span> (re-search-forward <span class="org-string">"[[<]"</span> nil t)
(<span class="org-keyword">when</span> (org-at-timestamp-p t)
(org-timestamp-change n 'hour)))))
</pre>
<p>
Evaluate this function. After that, you can go to the file with the schedule,
and give an M-x update-org-hours, provide the offset for your timezone, compared to
UTC+2.
</p>
<p>
Let the games begin!
</p></div>
</div>Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-3992530807750384868.post-28071502411336100542012-03-16T18:44:00.001+02:002012-03-18T19:18:20.043+02:00social networking with bitlbee and erc<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Instant messaging (IM) is one of the great time sinks of our age. Emacs-users,
social butterflies as we are, of course want to take part in that --
preferrably from the comfort of our own environment.
</p>
<p>
There are various ways to use services like <i>MS Live Messenger</i>, <i>Facebook Chat</i>, <i>GTalk</i>, <i>Yahoo</i> etc. from within emacs – the one I use is called
<a href="http://www.bitlbee.org/">BitlBee</a>. BitlBee is a program that presents all the various forms of IM as
IRC-channels. In other words, while BitlBee knows all the details about
communicating with these networks, all <b>you</b> need is an IRC-client to connect
to BitlBee. This IRC-client does not <i>have</i> to be Emacs-based - any client can
be used - but I am using <a href="http://emacs-fu.blogspot.com/search/label/erc">ERC</a>. Note, the below assumes you are somewhat
familiar with it.
</p>
<p>
So, let's see how we can set up BitlBee on our system; there are public
BitlBee-servers available online, but in the case of IM, I wouldn't
necessarily want to trust them with my account data… so I'm using my own.
</p>
</div>
<div id="outline-container-1-1" class="outline-3">
<h3 id="sec-1-1">Setting up Bitlbee</h3>
<div class="outline-text-3" id="text-1-1">
<p>
So, how can we set this up? First, install BitlBee – many distributions have
ready-made packages, otherwise you can <a href="http://www.bitlbee.org/main.php/download.html">build from source</a>. In the examples
below, I am assuming you are using <b>Bitlbee version 3</b> or higher; if you use
a different version, the details will vary a bit.
</p>
<p>
You can either run Bitlbee as a system-wide daemon, or just use it on your
own. I am doing the former (for the latter, <a href="http://www.emacswiki.org/emacs/bitlbee.el">bitlbee.el</a> is useful).
</p>
<p>
To connect ERC to the Bitlbee daemon, you can use something like the
following:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">defun</span> <span class="org-function-name">i-wanna-be-social</span> ()
<span class="org-doc">"Connect to IM networks using bitlbee."</span>
(interactive)
(erc <span class="org-builtin">:server</span> <span class="org-string">"localhost"</span> <span class="org-builtin">:port</span> 6667 <span class="org-builtin">:nick</span> <span class="org-string">"user"</span>))
</pre>
<p>
I'm sure you can come up with a better nick than <code>user</code>… Anyhow, with this
function in your <code>~/.emacs</code>, we can connect to bitlbee with:
</p>
<pre class="example">M-x i-wanna-be-social RET
</pre>
<p>
This should connect us to BitlBee; when all goes well, this will look
something like this:
</p>
<pre class="example">*** You have joined channel &bitlbee
*** mindcrime has changed mode for &bitlbee to +t
*** Users on &bitlbee: @user @root
*** Topic for &bitlbee: Welcome to the control channel. Type help for help
information.
<root> Welcome to the BitlBee gateway!
<root>
<root> If you've never used BitlBee before, please do read the help
information using the help command. Lots of FAQs are answered there.
<root> If you already have an account on this server, just use the identify
command to identify yourself.
<root> The nick is (probably) not registered
*** &bitlbee modes: +t
<ERC>
</pre>
<p>
Now, this first time, you will need to <b>register</b> yourself (this is only
needed once); use the same nick (<code>user</code> in the example) that you used before:
</p>
<pre class="example"><user> register user secretpassword
<root> Account successfully created
</pre>
<p>
We're registered! This means, that bitlbee knows about you, and will save your
settings.
</p>
</div>
</div>
<div id="outline-container-1-2" class="outline-3">
<h3 id="sec-1-2">Re-entering bitlbee</h3>
<div class="outline-text-3" id="text-1-2">
<p>
Just to complete the bitlbee-connecting part: the next time you want to use
<code>bitlbee</code>, use <code>i-wanna-be-social</code> as before. However, now you need to
<code>identify</code> yourself (rather than <code>register</code>):
</p>
<pre class="example"><user> identify user secretpassword
<root> Password accepted, settings and accounts loaded
</pre>
<p>
This can be automated by adding something like the following to your config:
</p>
<pre class="src src-elisp">(<span class="org-keyword">defun</span> <span class="org-function-name">bitlbee-identify</span> ()
(<span class="org-keyword">when</span> (and (string= <span class="org-string">"localhost"</span> erc-session-server)
(string= <span class="org-string">"&bitlbee"</span> (buffer-name)))
(erc-message <span class="org-string">"PRIVMSG"</span> (format <span class="org-string">"%s identify user secretpassword"</span>
(erc-default-target)
djcb-bitlbee-password))))
(<span class="org-keyword">add-hook</span> 'erc-join-hook 'bitlbee-identify)
</pre>
<p>
Modify <code>user</code> and <code>secretpassword</code> as desired. If you don't want write out
your passwords in your emacs config files, take a look at <a href="http://emacs-fu.blogspot.com/2011/02/keeping-your-secrets-secret.html">keeping your secrets secret</a>.
</p>
</div>
</div>
<div id="outline-container-1-3" class="outline-3">
<h3 id="sec-1-3">Adding accounts</h3>
<div class="outline-text-3" id="text-1-3">
<p>
Now, let's add some IM-accounts (just some examples here; also see <a href="http://wiki.bitlbee.org/quickstart">Bitlbee Quickstart</a>. Note, add any point during this, you can see your accounts with
the command:
</p>
<pre class="example"><user> account list
</pre>
<p>
and using the numbers (or the accounts 'tag') you can switch an account <code>on</code>
(and <code>off</code>):
</p>
<pre class="example"><user> account 0 on
</pre>
<p>
There are many other commands – use <code>help</code> command the consult the built-in
documentation.
</p>
</div>
</div>
<div id="outline-container-1-4" class="outline-3">
<h3 id="sec-1-4">Connecting to IM networks</h3>
<div class="outline-text-3" id="text-1-4">
<p>
To connect to IM networks, you have to add the accounts to BitlBee. It will
save them, so you only need to do that once. Let's do it - in each case,
replace user and password with whatever you use for those.
</p>
<p>
You can see your combined logged-in buddy list using <code>M-x erc-channel-names</code>
(or <code>C-c C-n</code>). Or use the <code>blist</code> command (see <code>help blist</code>).
</p>
<p>
After adding an account, it's a good idea to issue the <code>save</code> command, to
ensure that bitlbee saves it.
</p>
</div>
<div id="outline-container-1-4-1" class="outline-4">
<h4 id="sec-1-4-1">Jabber</h4>
<div class="outline-text-4" id="text-1-4-1">
<pre class="example"><user> account add jabber foobar@jabber.org mypassword
<root> Account successfully added with tag jabber
<user> account jabber on
<root> jabber - Logging in: Connecting
<root> jabber - Logging in: Connected to server, logging in
<root> jabber - Logging in: Converting stream to TLS
<root> jabber - Logging in: Connected to server, logging in
<root> jabber - Logging in: Authentication finished
<root> jabber - Logging in: Authenticated, requesting buddy list
<root> jabber - Logging in: Logged in
</pre>
<p>
(and of course, you can use other servers beside <code>jabber.org</code>)
</p>
</div>
</div>
<div id="outline-container-1-4-2" class="outline-4">
<h4 id="sec-1-4-2">GoogleTalk</h4>
<div class="outline-text-4" id="text-1-4-2">
<p>
GoogleTalk (<code>gtalk</code>) is implemented using XMPP (jabber), and it's
recommended to use <code>oauth</code> for authentication. Note, the <code>foobar</code> below is
just a placeholder (for a password); bitlbee wants us to put <i>something</i>
there, but since we'll be using <code>oauth</code>, it's not actually used.
</p>
<pre class="example"><user> account add jabber myaccount@gmail.com foobar
<root> Account successfully added with tag gtalk
<user> account gtalk set oauth on
<root> oauth = `on'
<user> account gtalk set nick_source full_name
<root> nick_source = `full_name'
<user> account gtalk on
<root> gtalk - Logging in: Starting OAuth authentication
</pre>
<p>
Now, a second window will open with a URL:
</p>
<pre class="example"><jabber_oauth> Open this URL in your browser to authenticate:
https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.\
com/auth/googletalk&response_type=code&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_i\
d=78312399893489.apps.googleusercontent.com
<jabber_oauth> Respond to this message with the returned authorization
token.
</pre>
<p>
Follow this URL in your browser, and it will take you to some Google page
for authentication. When that is completed, you will receive some string
cookie, which you paste back into the newly opened window.
</p>
<pre class="example"><user> 4/sIns904fdlkP5nudjCF4mBHF7Go_-E0g8
*** jabber_oauth is AWAY: Offline
</pre>
<p>
Et voilà! We're connected to Gtalk (don't worry about the <code>Offline</code>-warning).
</p>
</div>
</div>
<div id="outline-container-1-4-3" class="outline-4">
<h4 id="sec-1-4-3">Facebook</h4>
<div class="outline-text-4" id="text-1-4-3">
<p>
Apart from being a social website, Facebook can also be used for IM. You can
do this through the website, or you can use its jabber interface. It works
very similar to <code>gtalk</code>; only important thing is that you get yourself a
<a href="https://www.facebook.com/help/search/?q=username">Facebook username</a>:
</p>
<pre class="example"><user> account add jabber myusername0@chat.facebook.com
<root> Account successfully added with tag fb
<root> You can now use the /OPER command to enter the password
<root> Alternatively, enable OAuth if the account supports it: account
fb set oauth on
<user> account fb set oauth on
<root> oauth = `on'
<user> account gtalk set nick_source full_name
<root> nick_source = `full_name'
<user> account fb on
<root> fb - Logging in: Starting OAuth authentication
</pre>
<p>
Then, go through the <code>oath</code>-authentication steps (see the discussion about
adding Gtalk accounts above).
</p>
<p>
Once authenticated, you'll get something like this:
</p>
<pre class="example"><root> fb - Logging in: Requesting OAuth access token
<root> fb - Logging in: Connecting
<root> fb - Logging in: Connected to server, logging in
<root> fb - Logging in: Converting stream to TLS
<root> fb - Logging in: Connected to server, logging in
<root> fb - Logging in: Authentication finished
<root> fb - Logging in: Server claims your JID is
`-748234518@chat.facebook.com' instead of
`myusername0@chat.facebook.com'. This mismatch may cause problems with
groupchats and possibly other things.
<root> fb - Logging in: Authenticated, requesting buddy list
<root> fb - Logging in: Logged in
</pre>
<p>
It's to now act upon the warning, so, we log out, change the user name and
long back in:
</p>
<pre class="example"><user> account fb off
<root> fb - Signing off..
<user> account fb set username -748234518@chat.facebook.com
<root> username = `-748234518@chat.facebook.com'
<user> account fb on
</pre>
</div>
</div>
<div id="outline-container-1-4-4" class="outline-4">
<h4 id="sec-1-4-4">MSN / Live Messenger</h4>
<div class="outline-text-4" id="text-1-4-4">
<p>
MSN uses its own protocol (although apparently they're also supporting XMPP
("jabber") now). Suppose you have an account there, user
<code>partygirl89@hotmail.com</code> with password <code>iamcute</code>:
</p>
<pre class="example"><user> account add msn partygirl89@hotmail.com iamcute
<root> Account successfully added
<user> account msn on
<root> msn - Logging in: Connecting
<root> msn - Logging in: Connected to server, waiting for reply
<root> msn - Logging in: Transferring to other server
<root> msn - Logging in: Connected to server, waiting for reply
<root> msn - Logging in: Authenticated, getting buddy list
<root> msn - Login error: Error reported by MSN server: Invalid
(non-existent) handle [12:17]
<root> msn - Logging in: Logged in
</pre>
<p>
The 'Error reported' does not seem to matter.
</p>
</div>
</div>
<div id="outline-container-1-4-5" class="outline-4">
<h4 id="sec-1-4-5">Other accounts</h4>
<div class="outline-text-4" id="text-1-4-5">
<p>
It's similarly easy to setup <a href="http://wiki.bitlbee.org/HowtoTwitter">Twitter-accounts</a> and <a href="http://wiki.bitlbee.org/HowtoIdentica">Identi.ca-accounts</a>; I've
stopped using those though, as it turned out to be a little too easy for
some typing in the wrong window to end op as a tweet… The risk is less
with <a href="http://www.emacswiki.org/emacs/TwitteringMode">twittering-mode</a> and <a href="http://www.emacswiki.org/emacs/Identica-mode">identica-mode</a>.
</p>
<p>
For ICQ/Yahoo/AIM see below – replace the username/password with your
own.
</p>
<ul>
<li id="sec-1-4-5-1">ICQ<br/>
<pre class="example"><user> account add oscar ICQ-ID PASSWORD login.icq.com
<root> ...
</pre>
</li>
</ul>
<ul>
<li id="sec-1-4-5-2">AIM<br/>
<pre class="example"><user> account add oscar AIM-NICK PASSWORD login.aol.oscar.com
<root> ...
</pre>
</li>
</ul>
<ul>
<li id="sec-1-4-5-3">Yahoo!<br/>
<pre class="example"><user> account add yahoo YAHOO-NICK PASSWORD
<root> ...
</pre>
<p>
And I'm not even talking about combining bitlbee and Skype – yes, that is
possible, too.
</p>
</li>
</ul>
</div>
</div>
</div>
<div id="outline-container-1-5" class="outline-3">
<h3 id="sec-1-5">Chatting</h3>
<div class="outline-text-3" id="text-1-5">
<p>
Now, chatting is easy, following the normal ERC conventions (and
settings). When people talk to you, a window opens (or a frame – see
<code>erc-auto-query</code>. And you can initiate conversations with people by using
<code>/msg nick</code>, with <code>nick</code> of course being the nickname of the person you want
to talk to.
</p>
<p>
ERC/Bitlbee also work together nicely with <a href="http://emacs-fu.blogspot.com/2011/12/sauron-keeping-eye-on-whats-going-on.html">Sauron</a>, the emacs event tracker.
</p>
<p>
Have fun! I have only scratched the surface here - you now have the full
arsenal of Elisp and <a href="http://emacs-fu.blogspot.com/2009/06/erc-emacs-irc-client.html">ERC power</a> available for your chatting.
</p></div>
</div>
</div>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-3992530807750384868.post-79853456792865255242012-02-10T21:57:00.003+02:002012-02-11T09:16:33.349+02:00special characters<div id="outline-container-1" class="outline-2">
<h2 id="sec-1">Special characters</h2>
<div class="outline-text-2" id="text-1">
<p>
Living in a post-<a href="http://en.wikipedia.org/wiki/Ascii">ASCII</a> world offers great opportunities, but brings some
problems, too. After all, it's nice to be able to write <i>Ångström</i> or
<i>Καλημέρα</i> or <i>☺☎☯</i>, but it's not necessarily easy to enter those
characters.
</p>
</div>
<div id="outline-container-1-1" class="outline-3">
<h3 id="sec-1-1">input methods</h3>
<div class="outline-text-3" id="text-1-1">
<p>
So - what to do? First, you can set the input-method, as <a href="http://www.gnu.org/software/emacs/manual/html_node/emacs/Input-Methods.html">explained in the emacs manual</a>. This is the best solution if you're writing a non-Latin
language – Russian, Thai, Japanese, …
</p>
<p>
If you only occasionally need some accented character, input methods like
<code>latin-postfix</code> (e" -> ë), <code>latin-prefix</code> ("e -> ë) or <code>TeX</code> (\"e -> ë) are
useful. They also tend to annoy me a bit, as they often assume I need an
accented character, when all I want is to put a word in quotation marks…
</p>
</div>
</div>
<div id="outline-container-1-2" class="outline-3">
<h3 id="sec-1-2">compose key</h3>
<div class="outline-text-3" id="text-1-2">
<p>
Another method is to use a special compose key; for example, under Gnome 3
it's in the the <i>Region and Language</i> applet, under <code>Options...</code>, in Gnome 2
it's in the <i>Keyboard</i> applet in <i>Layouts/Options…</i>. This works for all
programs, not just emacs (see <a href="https://help.ubuntu.com/community/ComposeKey">this Ubuntu help page</a> for some details). I've
set my Compose-key to Right-Alt, so <code>Right-Alt</code> "e -> ë.
</p>
<p>
Using the compose key works pretty well for me; setting the input method may
be more convenient when you need to write <i>a lot</i> of accented characters.
</p>
<p>
Now, his may be good and well for the accented characters and other variants
of Latin characters, such as the German Ess-Zet ligature "ß" (note, you can
get that character with <code>latin-prefix</code> "s -> ß, <code>latin-postfix</code> s" -> ß or
<code><compose-key></code> ss -> ß). But what about Greek characters? Mathematical
symbols? Smileys?
</p>
</div>
</div>
<div id="outline-container-1-3" class="outline-3">
<h3 id="sec-1-3">ucs-insert</h3>
<div class="outline-text-3" id="text-1-3">
<p>
One way to add characters like <i>α</i>, <i>∞</i> or <i>☺</i> is to use <code>ucs-insert</code>, by
default bound to <code>C-x 8 RET</code>. If you know the official Unicode name for a
character, you can find it there; note that there's auto-completion and you
can use <code>*</code> wild-cards. For the mentioned characters, that would be <code>GREEK SMALL LETTER ALPHA</code>, <code>INFINITY</code> and <code>WHITE SMILING FACE</code>.
</p>
<p>
You can also use the Unicode code points; so <code>C-x 8 RET 03b1 RET</code> will insert
<code>α</code> as well, since its code point is <code>U+03B1</code>. In case you don't know the code
points of Unicode characters, a tool like the <i>Character Map</i> (<code>gucharmap</code>) in
Gnome may be useful.
</p>
</div>
</div>
<div id="outline-container-1-4" class="outline-3">
<h3 id="sec-1-4">abbrev</h3>
<div class="outline-text-3" id="text-1-4">
<p>
Since <code>ucs-insert</code> may not be convenient in all cases, you may want to add
shortcuts for oft-used special characters to you <i>abbrev table</i>. See the
entry on <a href="http://www.gnu.org/software/emacs/manual/html_node/elisp/Abbrevs.html#Abbrevs">Abbrevs</a> in the emacs manual. I usually edit the entries by hand with
<code>M-x edit-abbrevs</code>, and I have entries like:
</p>
<pre class="example">(text-mode-abbrev-table)
"Delta0" 0 "Δ"
"^2" 0 "²"
"^3" 0 "³"
"almost0" 0 "≈"
"alpha0" 0 "α"
"any0" 0 "∀"
"beta0" 0 "β"
"c0" 0 "©"
"deg0" 0 "℃"
"delta0" 0 "δ"
"elm0" 0 "∈"
"epsilon0" 0 "ε"
"eta0" 0 "η"
"heart0" 0 "♥"
"inf0" 0 "∞"
"int0" 0 "∫"
"notis0" 0 "≠"
</pre>
<p>
Now, <code>alpha0</code> will be auto-replaced with <i>α</i>. I'm using the <code>0</code> suffix for
most entries so I can easily remember them, without making it hard to use
<code>alpha</code> as a normal word. Note, <code>abbrevs</code> are a bit picky when it comes to
the characters in the shortcut – for example, setting <code>!=</code> -> <code>≠</code> won't
work.
</p>
</div>
</div>
<div id="outline-container-1-5" class="outline-3">
<h3 id="sec-1-5">inheriting abbrevs from other modes</h3>
<div class="outline-text-3" id="text-1-5">
<p>
If you have set up a nice set of abbreviations for <code>text-mode</code>, you may want
to use them in other modes as well; you can accomplish this by including the
<code>text-mode</code> abbreviations into the table for the current one, for example in
your ERC setup:
</p>
<pre class="src src-elisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">inherit abbrevs from text-mode</span>
(abbrev-table-put erc-mode-abbrev-table <span class="org-builtin">:parents</span> (list text-mode-abbrev-table))
</pre>
</div>
</div>
</div>Unknownnoreply@blogger.com5tag:blogger.com,1999:blog-3992530807750384868.post-57840786871693359442012-02-01T20:24:00.000+02:002012-02-01T20:24:56.869+02:00update<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Regular emacs-fu programming will resume shortly, but for now I'll provide a
brief update on some of my projects.
</p>
<ul>
<li>Recently, I discussed <a href="http://emacs-fu.blogspot.com/2011/12/sauron-keeping-eye-on-whats-going-on.html">sauron</a>, and event-tracking tool for emacs. I added
some new features, fixed some bugs, and got some contributions (yay!)
<ul>
<li>tweak/improve priority handling
</li>
<li>add a backend for the emacs-24 notification system
</li>
<li>add settings to make the sauron frame 'sticky', and to hide the mode-line
</li>
<li>enable dbus-message source outside your session; useful for cron/procmail
etc.
</li>
<li>display events in a tabular fashion
</li>
<li>add support for John Wiegley's <code>event.el</code>
</li>
<li>much improved documentation
</li>
<li>other things…
</li>
</ul>
<p> Sauron version 0.2 is available through <a href="http://marmalade-repo.org/">Marmalade</a> (see <a href="http://emacs-fu.blogspot.com/2011/11/package-management-revisited.html">Package Management Revisited</a>)
</p>
</li>
<li>I released version 0.9.8 of <a href="http://www.djcbsoftware.nl/code/mu">mu</a> (e-mail searcher/indexer, previously
discussed in <a href="http://emacs-fu.blogspot.com/2011/03/searching-e-mails-with-wanderlust-and.html">Searching e-mails with Wanderlust and mu</a>). Now, for emacs-users
I've added <a href="http://www.djcbsoftware.nl/code/mu/mu4e.html">mu4e</a> (<a href="http://www.djcbsoftware.nl/code/mu/mu4e/index.html">manual</a>), a new & experimental e-mail client. It won't be
big and professional like <code>gnus</code>, but it's fun to hack on, and I've been
using it for a few months.
</li>
</ul>
</div>
</div>Unknownnoreply@blogger.com14tag:blogger.com,1999:blog-3992530807750384868.post-68418112789799364962011-12-22T00:01:00.000+02:002011-12-22T08:19:22.611+02:00sauron: keeping an eye on what's going on<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
I'm a fairly busy person, and need to keep track of a lot of things. That
includes following a bunch of internal IRC channels, attending meetings, meeting
deadlines and so on. But I don't want to stare at my <code>org-mode</code> calendar, or
flip through <a href="http://emacs-fu.blogspot.com/2009/06/erc-emacs-irc-client.html">ERC</a> buffers all the time.
</p>
<p>
Instead, I'd like to have one little emacs frame (window) that gathers these
('events'), and transfers me to wherever the event came from when I click it - some
IRC-channel in ERC, my org-calendar etc. and other inputs. Note, using
<a href="http://www.bitlbee.org">Bitlbee</a>, you can include Facebook-contacts, GoogleTalk-buddies and
Twitter-tweets, … in ERC - so, you can track just about <i>anything</i>.
</p>
<p>
In addition, with so many inputs, I'd also like the possibility to filter out unwanted
events, and generate various light/sound effects and fireworks, proportional
to the priority of the event.
</p>
<p>
For all this, I wrote a little emacs-tool called <b>Sauron</b> that does just
that. <code>M-x sauron-start</code> pops up a frame that receives events, and <code>M-x sauron-stop</code> hides it and stops listening. It works with <code>ERC</code>, <code>org</code>, and
listens for <a href="http://emacs-fu.blogspot.com/2009/01/using-d-bus-example.html">D-Bus messages</a>; so it's pretty easy to get events from all over
the place.
</p>
<p>
It's a bit of a balancing act to get all the important information while not
being swamped in noise, but Sauron allows you to fine-tune it to whatever
works the best for you. I've tried to have sane defaults though, so things
should mostly work without too much configuration - but if you need the power,
it's there. I also added some convenience functions to make it easy to get
sounds and other special effects.
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioE_ZNi-BKQVFOoQLTwVkF99tZwmm11rmGSCzQ2mbiQGcUJjuzq1Vx0NA7X_LTmvmM7jSmU2Z9F7uG7_EyjmDmScPRCzjnl04Ak80YFUajg4QPb4vwrKeeW6IGlJPoUSUMh99tpFdDRlA/s1600/sauron.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="108" width="400" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEioE_ZNi-BKQVFOoQLTwVkF99tZwmm11rmGSCzQ2mbiQGcUJjuzq1Vx0NA7X_LTmvmM7jSmU2Z9F7uG7_EyjmDmScPRCzjnl04Ak80YFUajg4QPb4vwrKeeW6IGlJPoUSUMh99tpFdDRlA/s400/sauron.png" /></a></div>
<p>
So - it's brand new, it is of <i>seems-to-work-for-me</i>-quality, and I'd like to
invite others to try it out, hack it, give feedback, add new back-ends and so
on – what better Christmas present to ask for!
</p>
<p>
There's <a href="https://github.com/djcb/sauron#readme">documentation, examples</a> etc. to be found in <a href="https://github.com/djcb/sauron">Sauron's github repository</a>.
</p>
</div>
</div>Unknownnoreply@blogger.com17tag:blogger.com,1999:blog-3992530807750384868.post-10947080364033729282011-12-10T14:33:00.001+02:002011-12-12T08:01:06.892+02:00system administration with emacs<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
When performing system administration tasks, one often needs to edit files
owned by <code>root</code>.
</p>
<p>
For both security and safety reasons, it's a good idea to do as <i>little</i> as
possible as root (or with root privileges). For that reason, you probably
don't want to run Emacs as 'root', because it's simply <i>too powerful</i>. I often
see people use <code>vi</code> (usually, <code>vim</code>) instead – but since it allows you to do
just about anything as well (like running shell commands), that's not much of
an improvement.
</p>
<p>
Now, a while back we discussed <a href="http://emacs-fu.blogspot.com/2009/10/editing-files-owned-by-root.html">editing files owned by root with tramp</a> – you
can use emacs with your normal user-account, and use <code>sudo</code> to write the
root-owned file. That makes it much harder to screw things up.
</p>
<p>
Another reason people use <code>vi</code> for little editing jobs is because its startup
time is significantly shorter than the startup time for a new emacs
instance. For that, however, we have <a href="http://emacs-fu.blogspot.com/2009/02/emacs-daemon.html">emacs daemon</a>.
</p>
<p>
Combining <i>tramp</i> and <i>emacs daemon</i> and a shell function:
</p>
<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">edit file with root privs</span>
<span class="org-keyword">function</span> <span class="org-function-name">E</span>() {
emacsclient -c -a emacs <span class="org-string">"/sudo:root@localhost:$1"</span>
}
</pre>
<p>
Now, we can very quickly edit any file owned by root using 'E' --
</p>
<pre class="example">$ E /etc/hosts
</pre>
<p>
So, if you prefer emacs, there's little reason to use <code>vi</code>, even for editing
system files – although I have to admit that it takes time to evict 'sudo vi
<system file>' from my muscle memory.
</p>
<p>
<b>Update</b> reader <i>Yi Wang</i> mentions that, in fact, we can make this a bit more
general using <code>sudoedit</code>; so, instead of using Tramp, we can use:
</p>
<pre class="src src-sh"><span class="org-comment-delimiter"># </span><span class="org-comment">edit file with root privs</span>
<span class="org-builtin">alias</span> <span class="org-variable-name">E</span>=<span class="org-string">"SUDO_EDITOR=\"emacsclient -c -a emacs\" sudoedit"</span>
</pre>
<p>
This works also without absolute paths.
</p></div>
</div>Unknownnoreply@blogger.com13tag:blogger.com,1999:blog-3992530807750384868.post-34003453495779988002011-11-21T22:22:00.001+02:002011-11-28T09:01:47.827+02:00package management revisited<div id="outline-container-1" class="outline-2"><div class="outline-text-2" id="text-1"><p><a href="http://emacs-fu.blogspot.com/2009/04/elpa.html">Ages ago</a> we discussed <a href="http://tromey.com/elpa/">ELPA</a>, the emacs packaging system. It allows you to<br />
browse through an online repository of emacs packages and install, uninstall<br />
and upgrade them, all from within the emacs comfort zone (menu:<br />
<code>Options/Manage Emacs Packages</code>).<br />
</p><p>Emacs 24.1 (a <a href="http://article.gmane.org/gmane.emacs.devel/144290">pretest</a> is available) will include a version of ELPA --<br />
<code>package.el</code>; the version included with emacs 24 supports multiple<br />
archives. The <i>official</i> archive is the one provided by GNU, then there is<br />
the current one for ELPA, but there's now a third one available: <a href="http://marmalade-repo.org/">Marmalade</a>.<br />
</p><p>Marmelade ('<i>Spreadable Elisp</i>') offers a very easy way for developers to<br />
make their packages available to emacs users, and an even easier way for<br />
users to test out interesting packages.<br />
</p><p>To use <i>all</i> available package repositories (GNU, ELPA and Marmalade), add<br />
the following snippet to your <code>.emacs</code>:<br />
</p><pre class="src src-emacs-lisp">(<span style="color: #8ac6f2; font-weight: bold;">setq</span> package-archives '((<span style="color: #95e454;">"ELPA"</span> . <span style="color: #95e454;">"http://tromey.com/elpa/"</span>)
(<span style="color: #95e454;">"gnu"</span> . <span style="color: #95e454;">"http://elpa.gnu.org/packages/"</span>)
(<span style="color: #95e454;">"marmalade"</span> . <span style="color: #95e454;">"http://marmalade-repo.org/packages/"</span>))<span style="color: #ccaa8f; background-color: #332323; font-weight: bold;">)</span>
</pre><p>This works out-of-the-box for Emacs 24; for Emacs 23, you'll need the newer<br />
<code>package.el</code>, which you can get from the <a href="http://bzr.savannah.gnu.org/lh/emacs/trunk/annotate/head:/lisp/emacs-lisp/package.el">emacs 24 repo</a> (if necessary, remove<br />
the old <code>package.el</code> first).<br />
</p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWH0i1cRjPQas8_KUetWROOwKgiJcWdsw8rdLz5wb9XukjX8N6fVrwwa023AIu9RomzTmi35IIoYvXe7YIuAcsVykjDoe5VzO6onYCqhqaZXszHgZiS9caXlhLMc5aBoa8jyL40cZUN1E/s1600/package.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="297" width="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWH0i1cRjPQas8_KUetWROOwKgiJcWdsw8rdLz5wb9XukjX8N6fVrwwa023AIu9RomzTmi35IIoYvXe7YIuAcsVykjDoe5VzO6onYCqhqaZXszHgZiS9caXlhLMc5aBoa8jyL40cZUN1E/s320/package.png" /></a></div><p>Currently, there are <b>870</b> packages listed in the three repositories – a lot of<br />
toys to play with! In fact, it is already getting quite hard to find what<br />
you're looking for; a bit more structured way (maybe using categories) would<br />
be useful. Also, a bit more information than the one-line description would<br />
be very useful.<br />
</p><p>Nevertheless, it's a great addition to emacs, which will make it much easier<br />
to play with packages – without even having to read the installation<br />
instructions.<br />
</p></div></div>Unknownnoreply@blogger.com18tag:blogger.com,1999:blog-3992530807750384868.post-14142911099119620662011-09-15T21:49:00.001+03:002011-09-16T15:56:24.376+03:00quick note-taking with deft and org-mode<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Emacs must be gathering a lot of enthusiasts lately; there's hardly a week
where I don't discover some new gem. Recently, I discovered <a href="http://jblevins.org/projects/deft/">deft</a>. And
apparently, I wasn't the only one.
</p>
<p>
So what is it <code>deft</code> good for? Well, often I want to jot down some quick thing
during a meeting or a telephone-call. Of course, I don't want to think about
file names or anything else distracting me from my task, just get me that note
already! In addition, at some later time, I want to be able to quickly search
through the notes I made.
</p>
<p>
For MacOS, there's a program called <a href="http://notational.net/">Notational Velocity</a> which does this. But
really - it sounds like a typical task for emacs - wouldn't it be nice to have
an emacs package that does roughly the same?
</p>
<p>
And that is what <code>deft</code> does - enable you to quickly write notes, and
retrieving them later. The author has an excellent introduction on his
website, so my job is very easy :) <code>deft</code> is not part of <a href="http://orgmode.org/">org-mode</a>, but they
can work together seamlessly. Here's my set-up:
</p>
<pre class="src src-emacs-lisp"><span style="color: #99968b;">;; </span><span style="color: #99968b;">http://jblevins.org/projects/deft/</span>
(<span style="color: #8ac6f2; font-weight: bold;">when</span> (<span style="color: #8ac6f2; font-weight: bold;">require</span> '<span style="color: #e5786d;">deft</span> nil 'noerror)
(<span style="color: #8ac6f2; font-weight: bold;">setq</span>
deft-extension <span style="color: #95e454;">"org"</span>
deft-directory <span style="color: #95e454;">"~/Org/deft/"</span>
deft-text-mode 'org-mode)
(global-set-key (kbd <span style="color: #95e454;">"<f9>"</span>) 'deft))
</pre>
<p>
This blob goes in my <code>.emacs</code>. Note, the first line ensures that emacs starts
without errors, even when I run on a system without <code>deft</code>. Apart from that, I
make <code>deft</code> use <code>org</code> files for note taking, which makes it all very familiar.
</p>
<p>
All notes are saved <code>~/Org/deft</code> - you can set it to something else of
course. A Dropbox-folder seems to be a popular choice for synchronizing
between machines.
</p>
<p>
Finally, the last line binds <code>F9</code> to <code>deft-mode</code>. So, when I need a quick
note, I can type <code>F9 C-c C-n</code> and start writing.
</p></div>
</div>Unknownnoreply@blogger.com14tag:blogger.com,1999:blog-3992530807750384868.post-22131139534931341382011-09-08T23:22:00.000+03:002011-09-08T23:22:31.583+03:00finding just about anything<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Buffer-switching is one of those things I do all the time in Emacs. And it
should be quick and efficient, or it will break my 'flow'. There are many
ways to customize the buffer switching experience, and we already discussed
quite a few of those here: using <a href="http://emacs-fu.blogspot.com/2008/12/cycling-through-your-buffers-with-ctrl.html">Ctrl-Tab</a>, <a href="#APPT-Mordor-Scrum-2011-08-30-Tue-11-15-11-30-1w-http-emacs-fu.blogspot.com-2009-02-switching-buffers.html">iswitchb/ido</a>, <a href="http://emacs-fu.blogspot.com/2010/02/dealing-with-many-buffers-ibuffer.html">ibuffer</a>, the <a href="http://emacs-fu.blogspot.com/2010/07/navigating-through-files-and-buffers.html">lusty explorer</a> and others.
</p>
<p>
Some of those packages - <code>ido</code> and <code>lusty-explorer</code> - do not solely focus on
buffer-switching - they also let you open files using the same user
interface. But why stop at files and buffers - wouldn't it be nice if we
could quickly find just about <i>anything</i> quickly?
</p>
<p>
Indeed that would be nice - and there's a way to do just that - using the
aptly named <a href="http://www.emacswiki.org/emacs/Anything">anything</a> package. I was always a bit put off by this package due
to the screenshots (see link), but once I got over that, I've become a very
happy user.
</p>
<p>
Anyhow, what can <code>anything</code> find? I mentioned buffers and files, but it can
also find bookmarks, recently used files, <i>any</i> file on your system (using
<code>locate</code>), man-pages, info-pages, emacs-function/variables,
<code>FIXME</code>-comments, <code>org</code>-headlines, bbdb-contacts, google-suggests… and a
million other things. It can probably find your car keys, too.
</p>
<p>
Installation is pretty straightforward, using the git-repository:
</p>
<pre class="src src-sh">git clone git://repo.or.cz/anything-config.git
</pre>
<p>
Then, go into the just-cloned directory and execute <code>make</code>. After that, add
to your <code>.emacs</code> (or <code>~/.emacs.d/init.el</code>):
</p>
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">path-to-anything is the path which has the 'anything' we just cloned</span>
(add-to-list 'load-path <span class="org-string">"path-to-anything"</span>)
(<span class="org-keyword">require</span> '<span class="org-constant">anything-config</span>)
</pre>
<p>
This will add a menu with various <code>anything</code>-commands, and a bunch of
key-bindings, starting with F5. Play around a bit with it, it's nice. The
results are shown in a little temporary buffer, and pressing <code>Tab</code> will let
you do (search-type dependent) actions on the matches - for example
<code>ediff</code> two buffers.
</p>
<p>
Of course, the <i>real</i> fun starts when we super-charge some of the normal
emacs functions with anything-based ones. Let's look at buffer
switching. Let's create an <code>anything</code>-based version, and assign it to <code>C-x b</code>, the good-old <code>switch-to-buffer</code>.
</p>
<p>
The thing to consider is that while anything can find just about
<i>anything</i>, you (well, I) usually only want to search for a certain set of
things; when I want to switch to another buffer, I <i>don't</i> want to match
man-pages. Luckily, <code>anything</code> allows for making nifty function which use
certain subsets of the search sources. So for buffer switching, I have:
</p>
<pre class="src src-emacs-lisp">(global-set-key (kbd <span class="org-string">"C-x b"</span>)
(<span class="org-keyword">lambda</span>() (interactive)
(anything
<span class="org-builtin">:prompt</span> <span class="org-string">"Switch to: "</span>
<span class="org-builtin">:candidate-number-limit</span> 10 <span class="org-comment-delimiter">;; </span><span class="org-comment">up to 10 of each </span>
<span class="org-builtin">:sources</span>
'( anything-c-source-buffers <span class="org-comment-delimiter">;; </span><span class="org-comment">buffers </span>
anything-c-source-recentf <span class="org-comment-delimiter">;; </span><span class="org-comment">recent files </span>
anything-c-source-bookmarks <span class="org-comment-delimiter">;; </span><span class="org-comment">bookmarks</span>
anything-c-source-files-in-current-dir+ <span class="org-comment-delimiter">;; </span><span class="org-comment">current dir</span>
anything-c-source-locate)))) <span class="org-comment-delimiter">;; </span><span class="org-comment">use 'locate'</span>
</pre>
<p>
This will search in buffers, then in my recent-files, then in my bookmarks,
the files in the current directory, and finally check with the <code>locate</code>
tool. That last one is pretty neat, and finally gives me something back for
the countless times I've wondered why the hard disk is grinding – indeed,
it was <code>locate</code>, updating its database.
</p>
<p>
Then, I've defined another binding for searching general documentation on
my system; I've put it under <code>C-c I</code>. This looks look something like the
following:
</p>
<pre class="src src-emacs-lisp">(global-set-key (kbd <span class="org-string">"C-c I"</span>) <span class="org-comment-delimiter">;; </span><span class="org-comment">i -> info</span>
(<span class="org-keyword">lambda</span> () (interactive)
(anything
<span class="org-builtin">:prompt</span> <span class="org-string">"Info about: "</span>
<span class="org-builtin">:candidate-number-limit</span> 3
<span class="org-builtin">:sources</span>
'( anything-c-source-info-libc <span class="org-comment-delimiter">;; </span><span class="org-comment">glibc docs</span>
anything-c-source-man-pages <span class="org-comment-delimiter">;; </span><span class="org-comment">man pages</span>
anything-c-source-info-emacs)))) <span class="org-comment-delimiter">;; </span><span class="org-comment">emacs </span>
</pre>
<p>
These are sources I query quite regularly; there are many more to be
found - for most packages with info-pages there's a corresponding
<code>anything-c-source-info-...</code>; there's a list in <a href="http://www.emacswiki.org/emacs/anything-config.el">anything-config.el</a>.
</p>
<p>
Now, those are my <i>general</i> documentation sources; in specific modes, I
have specialized information sources; for example, for <code>elisp-mode</code>:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">add-hook</span> 'emacs-lisp-mode-hook
(<span class="org-keyword">lambda</span>()
<span class="org-comment-delimiter">;; </span><span class="org-comment">other stuff...</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">...</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">put useful info under C-c i</span>
(local-set-key (kbd <span class="org-string">"C-c i"</span>)
(<span class="org-keyword">lambda</span>() (interactive)
(anything
<span class="org-builtin">:prompt</span> <span class="org-string">"Info about: "</span>
<span class="org-builtin">:candidate-number-limit</span> 5
<span class="org-builtin">:sources</span>
'( anything-c-source-emacs-functions
anything-c-source-emacs-variables
anything-c-source-info-elisp
anything-c-source-emacs-commands
anything-c-source-emacs-source-defun
anything-c-source-emacs-lisp-expectations
anything-c-source-emacs-lisp-toplevels
anything-c-source-emacs-functions-with-abbrevs
anything-c-source-info-emacs))))
</pre>
<p>
This post just scratches the surface of what is possible – so go and
experiment :) One interesting thing is to add your own sources; I played a
bit with that already,
</p>
<p>
There are <i>many</i> things in <code>anything</code> I did not cover yet. First, there are
many more sources to search - and it's pretty easy to write your own – see
the <a href="http://www.emacswiki.org/emacs/Anything">EmacsWiki-page</a>.
</p>
</div>
</div>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-3992530807750384868.post-9815149341796430032011-08-25T23:48:00.001+03:002011-08-25T23:50:49.757+03:00customizing the mode-line<div class="outline-2" id="outline-container-1">
<div class="outline-text-2" id="text-1">
The mode-line is the emacs 'status bar', the bar just above the minibuffer
that shows various pieces of information, such as the buffer name, the major
mode, maybe the current line number, some indicators for active minor modes,
and so on. As I'm looking at it, it starts with <code>1<U:**-</code> (which is:
input-method: <code>latin-1-alt-postfix</code>, buffer-coding-system: <code>utf8-unix</code>,
line-ending: unix-style, buffer is writable and buffer is modified – the
tooltips help).
<br />
As with just about <i>anything</i> in emacs, the mode-line can be customized just
the way you like. I give some example below, not because I think it is
necessarily the <i>best</i> way, but just to give you a bit of an example to
start with when making your own best-mode-line-ever.
<br />
I'm not going through all the details of the example, but let me highlight a
few things that make it a bit easier to understand.
<br />
First of all, the mode-line can be customized by setting the variable
<code>mode-line-format</code>; this variable becomes buffer-local automatically when
changed, so if you want to set it for <i>all</i> buffers, you'll need to use
<code>setq-default</code> in your <code>.emacs</code> (or equivalent). The format is quite similar
to the one for <code>frame-title-format</code>, which we discussed in <a href="http://emacs-fu.blogspot.com/2011/01/setting-frame-title.html">setting the frame title</a> a while back.
<br />
<code>mode-line-format</code> is a <i>list</i> of items which are evaluated, and put
together as a string which then ends up as the mode-line contents. These
properties can be any string. The following types of items can be used:
<br />
<ul>
<li>First, normal strings are just shown as-is;
</li>
<li>Then, there are some special format parameters which will be replaced with
their value in the mode-line, from the Emacs-documentation:
</li>
</ul>
<pre class="example"> %b -- print buffer name. %f -- print visited file name.
%F -- print frame name.
%* -- print %, * or hyphen. %+ -- print *, % or hyphen.
%& is like %*, but ignore read-only-ness.
% means buffer is read-only and * means it is modified.
For a modified read-only buffer, %* gives % and %+ gives *.
%s -- print process status. %l -- print the current line number.
%c -- print the current column number (this makes editing slower).
To make the column number update correctly in all cases,
`column-number-mode' must be non-nil.
%i -- print the size of the buffer.
%I -- like %i, but use k, M, G, etc., to abbreviate.
%p -- print percent of buffer above top of window, or Top, Bot or All.
%P -- print percent of buffer above bottom of window, perhaps plus Top,
or print Bottom or All.
%n -- print Narrow if appropriate.
%t -- visited file is text or binary (if OS supports this distinction).
%z -- print mnemonics of keyboard, terminal, and buffer coding systems.
%Z -- like %z, but including the end-of-line format.
%e -- print error message about full memory.
%@ -- print @ or hyphen. @ means that default-directory is on a
remote machine.
%[ -- print one [ for each recursive editing level. %] similar.
%% -- print %. %- -- print infinitely many dashes.
Decimal digits after the % specify field width to which to pad.
</pre>
<ul>
<li>Forms of the type <code>(:eval ...)</code> are evaluated each time the mode-line is
drawn (just like the '%'-parameters) ; so, if you have a value that
changes of the course your emacs session, you should use <code>(:eval ...)</code>.
For example, for your emacs-uptime you could use <code>(:eval (emacs-uptime "%hh"))</code>; while the emacs-PID does not change, so simply you could simply
use <code>(format "PID:%d")</code>.
<br />
The format parameter mentioned above are of evaluated each time as
well. Note that you have to be a bit careful with evaluations - don't do
too heavy operations there, and be careful the updates don't recurse.
<br />
</li>
<li>There are many others which I won't go into now - please check the Elisp
reference. It's a rather baroque format…
</li>
</ul>
Now, let's put this all together in an example (tested with emacs 23 and
24). As I said, this is for demonstration purposes only; but hopefully it
gives you some inspiration. A lot of the 'magic' (colors, tooltips, faces)
happens with the <code>propertize</code> function; again, the Elisp documentation can
tell you a lot more about that. I'm (ab)using the various <code>font-lock</code>-faces to
have colors that blend in nicely with your current theme.
<br />
And it has a limitation still, namely that it does not react to mouse clicks;
how to that, I will discuss in some future article.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCZ89HM6lk_kgILcZHCIPo-ZAc8WfhjXffqrMb6rgfQmEDskHIWEG4OilKccOBbGgs6qJy_fb_K-V8RSr7hODSdM__CYp2K3e3PPuYdX-lwrH4qDr-hCgax82WTw0aeVMcDvTx5etBW6s/s1600/modeline.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCZ89HM6lk_kgILcZHCIPo-ZAc8WfhjXffqrMb6rgfQmEDskHIWEG4OilKccOBbGgs6qJy_fb_K-V8RSr7hODSdM__CYp2K3e3PPuYdX-lwrH4qDr-hCgax82WTw0aeVMcDvTx5etBW6s/s1600/modeline.png" /></a></div>
<br />
<br />
<pre class="src src-elisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">use </span><span class="org-comment"><span class="org-keyword">setq</span></span><span class="org-comment">-default to set it for /all/ modes</span>
(<span class="org-keyword">setq</span> mode-line-format
(list
<span class="org-comment-delimiter">;; </span><span class="org-comment">the buffer name; the file name as a tool tip</span>
'(<span class="org-builtin">:eval</span> (propertize <span class="org-string">"%b "</span> 'face 'font-lock-keyword-face
'help-echo (buffer-file-name)))
<span class="org-comment-delimiter">;; </span><span class="org-comment">line and column</span>
<span class="org-string">"("</span> <span class="org-comment-delimiter">;; </span><span class="org-comment">'%02' to set to 2 chars at least; prevents flickering</span>
(propertize <span class="org-string">"%02l"</span> 'face 'font-lock-type-face) <span class="org-string">","</span>
(propertize <span class="org-string">"%02c"</span> 'face 'font-lock-type-face)
<span class="org-string">") "</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">relative position, size of file</span>
<span class="org-string">"["</span>
(propertize <span class="org-string">"%p"</span> 'face 'font-lock-constant-face) <span class="org-comment-delimiter">;; </span><span class="org-comment">% above top</span>
<span class="org-string">"/"</span>
(propertize <span class="org-string">"%I"</span> 'face 'font-lock-constant-face) <span class="org-comment-delimiter">;; </span><span class="org-comment">size</span>
<span class="org-string">"] "</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">the current major mode for the buffer.</span>
<span class="org-string">"["</span>
'(<span class="org-builtin">:eval</span> (propertize <span class="org-string">"%m"</span> 'face 'font-lock-string-face
'help-echo buffer-file-coding-system))
<span class="org-string">"] "</span>
<span class="org-string">"["</span> <span class="org-comment-delimiter">;; </span><span class="org-comment">insert vs overwrite mode, input-method in a tooltip</span>
'(<span class="org-builtin">:eval</span> (propertize (<span class="org-keyword">if</span> overwrite-mode <span class="org-string">"Ovr"</span> <span class="org-string">"Ins"</span>)
'face 'font-lock-preprocessor-face
'help-echo (concat <span class="org-string">"Buffer is in "</span>
(<span class="org-keyword">if</span> overwrite-mode <span class="org-string">"overwrite"</span> <span class="org-string">"insert"</span>) <span class="org-string">" mode"</span>)))
<span class="org-comment-delimiter">;; </span><span class="org-comment">was this buffer modified since the last save?</span>
'(<span class="org-builtin">:eval</span> (<span class="org-keyword">when</span> (buffer-modified-p)
(concat <span class="org-string">","</span> (propertize <span class="org-string">"Mod"</span>
'face 'font-lock-warning-face
'help-echo <span class="org-string">"Buffer has been modified"</span>))))
<span class="org-comment-delimiter">;; </span><span class="org-comment">is this buffer read-only?</span>
'(<span class="org-builtin">:eval</span> (<span class="org-keyword">when</span> buffer-read-only
(concat <span class="org-string">","</span> (propertize <span class="org-string">"RO"</span>
'face 'font-lock-type-face
'help-echo <span class="org-string">"Buffer is read-only"</span>))))
<span class="org-string">"] "</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">add the time, with the date and the emacs uptime in the tooltip</span>
'(<span class="org-builtin">:eval</span> (propertize (format-time-string <span class="org-string">"%H:%M"</span>)
'help-echo
(concat (format-time-string <span class="org-string">"%c; "</span>)
(emacs-uptime <span class="org-string">"Uptime:%hh"</span>))))
<span class="org-string">" --"</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">i don't want to see minor-modes; but if you want, uncomment this:</span>
<span class="org-comment-delimiter">;; </span><span class="org-comment">minor-mode-alist ;; list of minor modes</span>
<span class="org-string">"%-"</span> <span class="org-comment-delimiter">;; </span><span class="org-comment">fill with '-'</span>
))
</pre>
Have fun playing with this!
</div>
</div>
Unknownnoreply@blogger.com21tag:blogger.com,1999:blog-3992530807750384868.post-82180941395402392992011-05-16T22:59:00.001+03:002011-08-26T00:46:46.725+03:00toward balanced and colorful delimiters<div class="outline-3" id="outline-container-1">
<div class="outline-text-3" id="text-1">
Emacs has the very useful feature of blinking the corresponding left "(" when
you type its partner ")" (and the same for other delimiters like "[]", "{}"
etc., depending on the mode). This is very useful for programming, especially
for languages like Lisp and Scheme and the like.<br />
<br />
<br />
Further help can come from tools like <a href="http://emacs-fu.blogspot.com/2010/06/automatic-pairing-of-brackets-and.html">autopair</a> or <a href="http://www.emacswiki.org/emacs/ParEdit">paredit</a> – although the
latter is a bit too much <i>bondage & discipline</i> for me, many people love it.
<br />
Anyway, recently I discovered a new helper in the quest for balance in
delimited universe: <a href="http://www.emacswiki.org/emacs/RainbowDelimiters">rainbow-delimiters</a>. With this package, the delimiters all
get different colors based on their nesting level. It works wonderfully well.
<br />
Installation is straightforward:
<br />
<ul>
<li>download <a href="http://www.emacswiki.org/emacs/rainbow-delimiters.el">rainbow-delimiters</a> and put it in your <code>load-path</code>
</li>
<li>add something like the following in your <code>.emacs</code>:
</li>
</ul>
<pre class="src src-elisp">(<span class="org-keyword">when</span> (<span class="org-keyword">require</span> '<span class="org-constant">rainbow-delimiters</span> nil 'noerror)
(<span class="org-keyword">add-hook</span> 'scheme-mode-hook 'rainbow-delimiters-mode))
</pre>
That's it – of course you'll need to do the equivalent for modes where you'd
like to enable it. See the screenshot below – maybe a bit <i>too</i> colorful for
some people, but I like it and I have found it <i>actually useful</i> to see the
corresponding delimiters without having to move the cursor over them.<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimGNCFCrS0FIVTiplBd3pcaFarw8IVnZng_00o-Py81obDgCz3S6Q-66ddRGAjmwQZhF6y1PLvdBOmlNndlK0ThSw5MpwFah7_p2L6Tib76qQaFV0bzcmp2V8FmbqADiEELScpGuwYx70/s1600/rainbow-delimiter.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="206" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimGNCFCrS0FIVTiplBd3pcaFarw8IVnZng_00o-Py81obDgCz3S6Q-66ddRGAjmwQZhF6y1PLvdBOmlNndlK0ThSw5MpwFah7_p2L6Tib76qQaFV0bzcmp2V8FmbqADiEELScpGuwYx70/s400/rainbow-delimiter.png" width="400" /></a></div>
<br />
<br />
I already added some nice Zenburn colors for this to the <a href="https://github.com/djcb/elisp/blob/master/themes/zenburn-theme.el">Zenburn theme for Emacs-24</a>, as can be seen in the screenshot.
</div>
</div>
Unknownnoreply@blogger.com10tag:blogger.com,1999:blog-3992530807750384868.post-67988757759635584402011-05-08T12:05:00.000+03:002011-05-08T12:05:02.558+03:00porting the zenburn theme to emacs 24<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Just a small note: I already mentioned the <a href="http://emacs-fu.blogspot.com/search?q=zenburn">zenburn color theme</a> a couple of
times. I have now ported the full (big) set of customizations to the emacs-24 format
– <a href="https://github.com/djcb/elisp/blob/master/themes/zenburn-theme.el">find it at github</a>; so if you run emacs 24 (the development version) and
enjoy <a href="http://slinky.imukuppi.org/zenburnpage/">zenburn</a> like me, you can give it try. Suggestions, additions are
welcome.
</p>
<p>
Note, there seems to be a limitation with the <code>:inherit</code>-attribute for themes
– in practice it means that some aspects of the theme may not work if a
package sets the face before the theme does. Therefore, best to load the theme
early from your <code>.emacs</code> or <code>init.el</code>; or alternatively visit the theme file
(<code>zenburn-theme.el</code> in this case) and evaluate the buffer.
</p>
</div>
</div>Unknownnoreply@blogger.com18Helsinki, Finland60.1698125 24.9382401000000360.0313735 24.70242710000003 60.3082515 25.17405310000003tag:blogger.com,1999:blog-3992530807750384868.post-79518734644288282602011-04-12T20:57:00.000+03:002011-04-12T20:57:52.053+03:00nice-looking pdfs with org-mode and xetex<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
I've discussed the wonderful <code>org-mode</code> here a <a href="http://emacs-fu.blogspot.com/search/label/org-mode">number of times</a> already. It has
become a pretty important part of my overall workflow. One thing I am using
<code>org-mode</code> for, is to produce all kinds of PDF-documents that I can share with
other people.
</p>
</div>
<div id="outline-container-1_1" class="outline-3">
<h3 id="sec-1_1">org-mode & LaTeX </h3>
<div class="outline-text-3" id="text-1_1">
<p>
In the past, I often used straight <a href="http://en.wikipedia.org/wiki/LaTeX">LaTeX</a> for such things; I wrote my thesis
with it, but also many other documents. There are many things I like about
LaTeX, one of them being that I can use emacs for writing. Still, there are
also a few things I do <i>not</i> particularly like. First, I think LaTeX is quite
heavy with formatting directives, which hinder my writing flow (e.g., when I
want to include an image, a table or a source code snippet). Another thing is
that I find the default LaTeX styles a bit <i>boring</i>. Nothing wrong with it,
but there just too many documents with the exact same lay-out.
</p>
<p>
Now, back to <code>org-mode</code>. One way to use <code>org-mode</code> is as a friendly way to
generate LaTeX (and, consequently, PDFs). This is a big improvement! Much
more than LaTeX itself, <code>org-mode</code> allows to focus on the contents of the
document, rather than instructing LaTeX what to do. This comes at the price
of small bit of flexibility, but, if needed <code>org-mode</code> allows you include
straight LaTeX when needed – so while keeping easy things easy, hard things
are still possible. The latter does require a bit of experience with LaTeX a
though.
</p>
</div>
</div>
<div id="outline-container-1_2" class="outline-3">
<h3 id="sec-1_2">setting up XeTeX </h3>
<div class="outline-text-3" id="text-1_2">
<p>
Now, for the second issue, the way documents <b>look</b>, there are other
solutions, and they live on the LaTeX side of things. I'm sure many have seen
<a href="http://nitens.org/taraborelli/latex">The Beauty of LaTeX</a>. Using the <i>XeTeX</i> implementation of LaTeX and the
<code>fontspec</code> package, you can create LaTeX documents with a bit 'refreshed'
look.
</p>
<p>
So, the steps to get this working with <code>org-mode</code>:
</p>
<ul>
<li>install the <code>texlive-xetex</code> packages on Ubuntu and Debian (this installs a
<i>huge</i> set of packages)
</li>
<li>install the SIL fonts (I'm using <code>ttf-sil-gentium</code> and <code>ttf-sil-charis</code>, but
there are more)
</li>
<li>I'm also using DejaVu Mono (<code>ttf-dejavu</code>)
</li>
</ul>
</div>
</div>
<div id="outline-container-1_3" class="outline-3">
<h3 id="sec-1_3">teaching org-mode about the new XeTeX stuff </h3>
<div class="outline-text-3" id="text-1_3">
<p>
We now need to define some LaTeX document class for <code>org-mode</code> that uses
<i>XeTeX</i> and some of these new fonts. Let's call the document class
<code>djcb-org-article</code> (as I often use the <code>djcb-</code> prefix for my own stuff), it
could be something like the following (add to your <code>org</code>-setup – e.g., in
your <code>.emacs</code>, make sure there is a <code>(require 'org)</code> before this:
</p>
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">'djcb-org-article' for export org documents to the LaTex 'article', using
</span><span class="org-comment-delimiter">;; </span><span class="org-comment">XeTeX and some fancy fonts; requires XeTeX (see org-latex-to-pdf-process)
</span>(add-to-list 'org-export-latex-classes
'(<span class="org-string">"djcb-org-article"</span>
<span class="org-string">"\\documentclass[11pt,a4paper]{article}
\\usepackage[T1]{fontenc}
\\usepackage{fontspec}
\\usepackage{graphicx}
\\defaultfontfeatures{Mapping=tex-text}
\\setromanfont{Gentium}
\\setromanfont [BoldFont={Gentium Basic Bold},
ItalicFont={Gentium Basic Italic}]{Gentium Basic}
\\setsansfont{Charis SIL}
\\setmonofont[Scale=0.8]{DejaVu Sans Mono}
\\usepackage{geometry}
\\geometry{a4paper, textwidth=6.5in, textheight=10in,
marginparsep=7pt, marginparwidth=.6in}
\\pagestyle{empty}
\\title{}
[NO-DEFAULT-PACKAGES]
[NO-PACKAGES]"</span>
(<span class="org-string">"\\section{%s}"</span> . <span class="org-string">"\\section*{%s}"</span>)
(<span class="org-string">"\\subsection{%s}"</span> . <span class="org-string">"\\subsection*{%s}"</span>)
(<span class="org-string">"\\subsubsection{%s}"</span> . <span class="org-string">"\\subsubsection*{%s}"</span>)
(<span class="org-string">"\\paragraph{%s}"</span> . <span class="org-string">"\\paragraph*{%s}"</span>)
(<span class="org-string">"\\subparagraph{%s}"</span> . <span class="org-string">"\\subparagraph*{%s}"</span>)))
</pre>
<p>
Of course, this can be customized to your own preference; e.g.,
North-Americans may not be using A4-paper.
</p>
<p>
<code>org-mode</code> takes care of the export from its own format to LaTeX, but we need
to tell it to use <code>xelatex</code> to process the LaTeX to PDF:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">setq</span> org-latex-to-pdf-process
'(<span class="org-string">"xelatex -interaction nonstopmode %f"</span>
<span class="org-string">"xelatex -interaction nonstopmode %f"</span>)) <span class="org-comment-delimiter">;; </span><span class="org-comment">for multiple passes
</span></pre>
<p>
That's all that's needed on the setup-side.
</p>
</div>
</div>
<div id="outline-container-1_4" class="outline-3">
<h3 id="sec-1_4">creating a document </h3>
<div class="outline-text-3" id="text-1_4">
<p>
Now, let's create a little test document, <code>test.org</code>, to show how it works:
</p>
<pre class="src src-org-mode">#+LaTeX_CLASS: djcb-org-article
#+TITLE: My little document
* Introduction
This is my document. There are many like it, but this is mine. It's easy to
write without *too* _many_ /distractions/.
** Normal distribution
Probability density of the normal distribution, using familiar TeX notation
for formulae:
$$\frac{1}{\sqrt{2\pi\sigma^2}}e^{ -\frac{(x-\mu)^2}{2\sigma^2} }$$
** Some table
| *Greek God* | *Roman God* | *Element* |
|-------------+-------------+----------------|
| Zeus | Jupiter | Sky and clouds |
| Hera | Juno | Family |
| Poseidon | Neptune | Sea |
| Hades | Pluto | Underworld |
</pre>
<p>
We can export this to a PDF using <code>C-c C-e p</code> (or <code>C-c C-e d</code> to
automatically open the PDF in a PDF-viewer). This should all work nicely; if
it doesn't, note that when exporting, say, <code>test.org</code>, <code>org-mode</code> will create
a file called <code>test.tex</code>, and visit in a buffer. There's also a buffer with
the output from various commands, but sometimes it can be useful to run LaTeX
(<code>xelatex</code> in this case) on the file by hand, to find any problems. The
wonderful <code>org</code>-documentation about <a href="http://orgmode.org/worg/org-tutorials/org-latex-export.html">exporting to LaTeX</a> has more information.
</p>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj57k0mfPxCt4N78C0JiVV09zIHsn93eEcQjHXNiaYzFKQqLYr8i_YcSYN4G2hV0Ryh61KHCwgnuFfbK08jOeDl_sFVysUi0BfdSBWAGgBIy9s6fHST9Xnzlka7pgOmmNTkwOHmhnJ_SoA/s1600/org-docs.png" imageanchor="1" style="margin-left:1em; margin-right:1em"><img border="0" height="231" width="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj57k0mfPxCt4N78C0JiVV09zIHsn93eEcQjHXNiaYzFKQqLYr8i_YcSYN4G2hV0Ryh61KHCwgnuFfbK08jOeDl_sFVysUi0BfdSBWAGgBIy9s6fHST9Xnzlka7pgOmmNTkwOHmhnJ_SoA/s320/org-docs.png" /></a></div>
<p>
I think the result is pretty nice – it stays true to the class LaTeX article
class, but freshens it up a bit with some news font. If you can make
something better – which is not unlikely – you are of course invited to
contribute your own!
</p>
</div>
</div>
<div id="outline-container-1_5" class="outline-3">
<h3 id="sec-1_5">Concluding </h3>
<div class="outline-text-3" id="text-1_5">
<p>
<code>org-mode</code> is a pretty convenient way to write nice-looking PDFs. Combined
with <code>xelatex</code>, they don't have to look too plain :). However, I'm aware of
my limitations when it comes to the coolness/aesthetic aspects, but I hope
others can show the way here.
</p>
<p>
Maybe <code>org-mode</code> could ship with a number of ready-made templates to make
it easy to make nice-looking documents, resumes, reference cards, reports,
meeting notes and so on.
</p></div>
</div>
</div>Unknownnoreply@blogger.com21tag:blogger.com,1999:blog-3992530807750384868.post-14356923436540936082011-03-31T21:10:00.002+03:002011-04-02T09:33:26.913+03:00searching e-mails with wanderlust and mu<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
I have discussed the Wanderlust e-mail client a <a href="http://emacs-fu.blogspot.com/search/label/wanderlust">couple of times</a> already. I'm
still using it, so I keep on learning new tricks. Even though there has been
quite a bit of action in the competing <a href="http://www.gnus.org/">gnus</a> e-mail client, for my particular
use-case, Wanderlust is still the best option.
</p>
<p>
'My particular use-case' consists of storing my mail in Maildirs, which I fill
with either <a href="https://github.com/nicolas33/offlineimap">offlineimap</a> (which has fortunately found a new maintainer) or
<a href="http://fetchmail.berlios.de/">fetchmail</a>.
</p>
</div>
<div id="outline-container-1_1" class="outline-3">
<h3 id="sec-1_1">mu </h3>
<div class="outline-text-3" id="text-1_1">
<p>
When dealing with e-mail, one particularly important feature for me is the
ability to <i>search</i> my messages. In fact, it's so important for me that I
wrote some software to do this for me; the software is called <a href="http://www.djcbsoftware.nl/code/mu">mu</a>; it indexes
the messages in my Maildirs, and then allows for searching them using
queries, based on message contents, headers, or other message properties.
</p>
<p>
<code>mu</code> works through a command-line interface, although there is an
experimental GUI available as well. The command-line interface makes it
possible to hook <code>mu</code> up with various mail-clients, such as <code>mutt</code>, or
Wanderlust. Some Linux distributions ship <code>mu</code>, but since the versions they
ship are often a bit outdated, I recommend building it yourself from the
sources linked on the <code>mu</code> website. The process is fairly straightforward;
and there is plenty of documentation in the form of man pages.
</p>
</div>
</div>
<div id="outline-container-1_2" class="outline-3">
<h3 id="sec-1_2">mu and wanderlust </h3>
<div class="outline-text-3" id="text-1_2">
<p>
I've been combining <code>mu</code> and <code>wanderlust</code> for a while (see <b>mu and wanderlust - the old way</b>, below), but this week <i>Sam B.</i> on the <code>mu</code> mailing
list showed a way to do so in a much more elegant way - using <i>virtual</i> or
<i>query</i> folders.
</p>
<p>
How does this work? Well, after installing <code>mu</code>, add the following to your
Wanderlust setup file (<code>~/.wl</code> or it's moral equivalent – see the older
Wanderlust posts for the details):
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">require</span> '<span class="org-constant">elmo-search</span>)
(elmo-search-register-engine
'mu 'local-file
<span class="org-builtin">:prog</span> <span class="org-string">"/usr/local/bin/mu"</span> <span class="org-comment-delimiter">;; </span><span class="org-comment">or wherever you've installed it
</span> <span class="org-builtin">:args</span> '(<span class="org-string">"find"</span> pattern <span class="org-string">"--fields"</span> <span class="org-string">"l"</span>) <span class="org-builtin">:charset</span> 'utf-8)
(<span class="org-keyword">setq</span> elmo-search-default-engine 'mu)
<span class="org-comment-delimiter">;; </span><span class="org-comment">for when you type "g" in folder or summary.
</span>(<span class="org-keyword">setq</span> wl-default-spec <span class="org-string">"["</span>)
</pre>
<p>
So, to start with the last part, whenever you type <code>g</code> in folder or summary,
in the mode-line you will get something like <code>Folder name (.inbox): [</code>. Now
simply type your <code>mu</code> search expression and press Enter, and <code>wanderlust</code>
opens a (temporary) folder with the search results. Brilliant!
</p>
<p>
Next, to add virtual folders for searches you do often, simply add some
folder specifications like the following to your <code>.folders</code> file (again,
check the older Wanderlust posts if you're not familiar with folders-file):
</p>
<pre class="example">VFolders {
# message I received today
[date:today..now]!mu "Today"
# messages bigger than 1Mb
[size:1m..100m]!mu "Big"
# signed messages i got in 2010 related to emacs
[date:2010..2011 flag:signed emacs]!mu "Signed-Emacs2010"
# unread messages
[not flag:seen]!mu "Unread"
# or (for mu >= 0.9.4):
# [flag:unread]! mu "Unread"
}
</pre>
<p>
After this, restart Wanderlust, and there you go! Wanderlust will display
your brand new virtual folders with an icon that looks like a little whale.
</p>
<p>
You can put arbitrary <code>mu</code> search expressions between the <code>[]</code>, matching
whatever is useful in a certain case. Check the <code>mu</code> documentation to see how
to do this.
</p>
<p>
Note, the messages you get in these virtual folders are <i>links to</i> the
original messages. In practice, this means that changes you make to the links
do no affect the originals – if you delete a link you're not deleting the
message.
</p>
</div>
</div>
<div id="outline-container-1_3" class="outline-3">
<h3 id="sec-1_3">mu and wanderlust - the old way </h3>
<div class="outline-text-3" id="text-1_3">
<p>
This discussion would not complete without a description of the <i>old</i> way I
used search. This method may still be useful for integrating <code>mu</code> with other
clients such as <code>mutt</code>.
</p>
<p>
What I've been using for a while is a (in retrospect) rather clumsy way to
integrate message searches with Wanderlust: based on the results of a query,
I would create some special Maildir and fill it with symbolic links to the
matched messages, and the visit this special Maildir with Wanderlust. I'll
include the code here to contrast it with the more elegant solution that we
saw before, but also because the approach taken might be easily adapted for
other mail-clients.
</p>
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">search using mutt
</span>(<span class="org-keyword">defvar</span> <span class="org-variable-name">mu-wl-mu-program</span> <span class="org-string">"/usr/local/bin/mu"</span>)
(<span class="org-keyword">defvar</span> <span class="org-variable-name">mu-wl-search-folder</span> <span class="org-string">"search"</span>)
(<span class="org-keyword">defun</span> <span class="org-function-name">mu-wl-search</span> ()
<span class="org-doc">"search for messages with `</span><span class="org-doc"><span class="org-constant">mu</span></span><span class="org-doc">', and jump to the results"</span>
(<span class="org-keyword">let*</span> ((muexpr (read-string <span class="org-string">"Find messages matching: "</span>))
(sfldr (concat elmo-maildir-folder-path <span class="org-string">"/"</span>
mu-wl-search-folder))
(cmdline (concat mu-wl-mu-program <span class="org-string">" find "</span>
<span class="org-string">"--clearlinks --format=links --linksdir='"</span> sfldr <span class="org-string">"' "</span>
muexpr))
(rv (shell-command cmdline)))
(<span class="org-keyword">cond</span>
((= rv 0) (message <span class="org-string">"Query succeeded"</span>))
((= rv 2) (message <span class="org-string">"No matches found"</span>))
(t (message <span class="org-string">"Error running query"</span>)))
(= rv 0)))
(<span class="org-keyword">defun</span> <span class="org-function-name">mu-wl-search-and-goto</span> ()
<span class="org-doc">"search and jump to the folder with the results"</span>
(interactive)
(<span class="org-keyword">when</span> (mu-wl-search)
(wl-summary-goto-folder-subr
(concat <span class="org-string">"."</span> mu-wl-search-folder)
'force-update nil nil t)
(wl-summary-sort-by-date)))
<span class="org-comment-delimiter">;; </span><span class="org-comment">search by pressing 'Q'
</span>(define-key wl-summary-mode-map (kbd <span class="org-string">"Q"</span>) <span class="org-comment-delimiter">;; </span><span class="org-comment">=> query
</span> '(<span class="org-keyword">lambda</span>()(interactive)(mu-wl-search-and-goto)))
(define-key wl-folder-mode-map (kbd <span class="org-string">"Q"</span>) <span class="org-comment-delimiter">;; </span><span class="org-comment">=> query
</span> '(<span class="org-keyword">lambda</span>()(interactive)(mu-wl-search-and-goto)))
</pre>
<p>
After installing <code>mu</code> and putting the above in your <code>wanderlust</code> startup
file, you should be able to search by pressing <code>Q</code>. The <code>mu</code> documentation
has an example for <code>mutt</code> as well.
</p>
</div>
</div>
<div id="outline-container-1_4" class="outline-3">
<h3 id="sec-1_4">conclusion </h3>
<div class="outline-text-3" id="text-1_4">
<p>
It's straightforward to integrate advanced searching capabilities to
Wanderlust using <code>mu</code>, and thanks to Sam B., it's gotten a lot easier! The
second (old) approach may be useful as 'inspiration' for use in other e-mail
clients as well, if they do not provide the kind of hooks that the first
solution needs.
</p>
</div>
</div>
</div>Unknownnoreply@blogger.com16tag:blogger.com,1999:blog-3992530807750384868.post-42554443891725921002011-03-26T14:18:00.000+02:002011-03-26T14:18:37.642+02:00IELM: a REPL for emacs<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
Emacs-lisp (elisp) is a nice language to play around with code and try things as
you develop them – <i>explorative programming</i>. I often use the <code>*scratch*</code>
buffer for that, but sometimes it's nice to use a so-called '<a href="http://en.wikipedia.org/wiki/REPL">REPL</a>' (
<i>Read-Eval-Print-Loop</i>) instead. A REPL is a sort-of command-line interface
where your expressions are evaluated as soon as they are considered 'complete'
and you press <code>Enter</code>.
</p>
<p>
So, enter Emacs's built-in repl: <code>IELM</code>. You can activate it with <code>M-x ielm</code>,
and the interaction looks something like the following:
</p>
<pre class="example">*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> 123
123
ELISP> (+ 1 2)
3
ELISP> ;; comment
ELISP> (defun fac (n)
(if (= 0 n)
1
(* n (fac (- n 1)))))
fac
ELISP> (fac 5)
120
ELISP>
</pre>
<p>
By default, IELM evaluates <b>complete</b> expressions automatically as soon you as
you press Enter. So one thing to remember is that if you want to have
multi-line expression (like above), you must make sure that after each line
the expression is <i>not</i> complete (i.e., the brackets are not balanced) --
otherwise the expression will be evaluated too early. That makes modes like
<a href="http://emacs-fu.blogspot.com/2010/06/automatic-pairing-of-brackets-and.html">autopair</a> or <a href="http://www.emacswiki.org/emacs/ParEdit">paredit</a> a bit inconvenient for this.
</p>
<p>
If you don't like that behavior, you can do:
</p>
<p>
(setq ielm-dynamic-return nil)
</p>
<p>
which will allow you to Enter as much as you want and only evaluate things when
you press <code>C-j</code>. But then you might as well use <code>*scratch*</code> I
suppose. Personally, I use IELM mostly as a calculator.
</p></div>
</div>Unknownnoreply@blogger.com7tag:blogger.com,1999:blog-3992530807750384868.post-25562998545169994202011-02-27T14:32:00.003+02:002011-02-27T14:36:39.255+02:00executable source code blocks with org-babel<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
<a href="http://orgmode.org/worg/org-contrib/babel/">org-babel</a> is the mechanism that <code>org-mode</code> offers for evaluating (executing)
blocks of source code embedded in your <code>org-mode</code>-documents. This is useful
for so-called <a href="http://reproducibleresearch.net/index.php/Main_Page">reproducible research</a>, i.e., where you allow your readers to go
through the steps that led to your results.
</p>
<p>
Here, I'm just scratching the surface with some simple examples.
</p>
</div>
<div id="outline-container-1_1" class="outline-3">
<h3 id="sec-1_1">source code blocks </h3>
<div class="outline-text-3" id="text-1_1">
<p>
Let's first look at how it all began: source code blocks. I guess most
<code>org-mode</code>-users will be familiar with those: the ability to include
syntax-highlighted ('font-locked') snippets of source code in
<code>org</code>-documents. We discussed source blocks <a href="http://emacs-fu.blogspot.com/2009/05/writing-and-blogging-with-org-mode.html">before</a>, they look like this:
</p>
<pre class="example">#+begin_src perl
sub my_func {
print "Hello, world!\n";
}
#+end_src
</pre>
<p>
And note that code blocks can be edited in their 'native mode' using <code>C-c'= (or, =org-edit-src-code</code>).
</p>
<p>
When code block like this are exported to, say, HTML, they'll look like the
following fully highlighted snippet (assuming you're reading Emacs-fu in
it's full-color version):
</p>
<pre class="src src-perl"><span class="org-keyword">sub</span> <span class="org-function-name">my_func</span> {
<span class="org-cperl-nonoverridable">print</span> <span class="org-string">"Hello, world!\n"</span>;
}
</pre>
</div>
</div>
<div id="outline-container-1_2" class="outline-3">
<h3 id="sec-1_2">evaluating source code </h3>
<div class="outline-text-3" id="text-1_2">
<p>
<code>org-babel</code> takes this a few steps further: instead of just <i>looking</i> at
source code, we can actually evaluate (execute) it, using the
<code>org-mode</code>-based system called <code>org-babel</code>.
</p>
<p>
If you have a recent version of <code>org-mode</code> (7.x or later), add the
following to your <code>.emacs</code> (or equivalent):
</p>
<pre class="src src-emacs-lisp">(org-babel-do-load-languages
'org-babel-load-languages
'( (perl . t)
(ruby . t)
(sh . t)
(python . t)
(emacs-lisp . t)
))
</pre>
<p>
This enables <code>org-babel</code> for the mentioned languages; there are <i>many</i>
other languages <a href="http://orgmode.org/worg/org-contrib/babel/languages.php">available as well</a>.
</p>
<p>
Now, suppose we have a snippet of <code>python</code> in an <code>org-mode</code>-buffer:
</p>
<pre class="example">#+begin_src python
def hello(str):
return "Hello, " + str + "!"
return hello ("dude")
#+end_src
</pre>
<p>
You can move the cursor (point) inside the src-block and press <code>C-c C-c</code> (or,
<code>org-confirm-babel-evaluate</code>). This causes the block of code to be evaluated
(executed), after asking you for confirmation. The result will inserted below
the block, like:
</p>
<pre class="example">#+results:
: Hello, dude!
</pre>
<p>
Note, in the <code>hello</code> example, the result of the block is the <i>value</i> of the
evaluation - that is, the value of the last expression evaluated. This is
the also the default, so we don't need to (but could) write:
</p>
<pre class="example">#+begin_src python :results value
</pre>
<p>
The alternative is to use the (standard) <i>output</i> of the function, which is
activated with <code>:results output</code>, e.g.:
</p>
<pre class="example">#+begin_src sh :results output
echo "Hello $USER! Today is `date`"
#+end_src
</pre>
<p>
Moving to this block and pressing <code>C-c C=c</code> would get you something like
the following – probably with a different username and time:
</p>
<pre class="example">˜#+results:
: Hello djcb! Today is Sun Feb 27 13:51:50 EET 2011
</pre>
</div>
</div>
<div id="outline-container-1_3" class="outline-3">
<h3 id="sec-1_3">almost like functions </h3>
<div class="outline-text-3" id="text-1_3">
<p>
<code>org-babel</code> also allows you to refer to the code blocks from elsewhere in
your document, by labeling your code-blocks with <code>srcname</code>. Let's say we
have some Ruby code to revert a string:
</p>
<pre class="example">#+begin_src ruby
def revert(s)
if s == "" then
return ""
else
return s[-1].chr + revert(s.slice(0, s.length()-1))
end
end
revert(str)
#+end_src
</pre>
<p>
We can now 'call' this block; note that we get the result of <i>evaluating the block</i>. So if you want to use the result of a function in the block, you also
need to add the call to that function (see the last line).
</p>
<p>
Now, we can use:
</p>
<pre class="example">#+call: revert(str="VeryCoolStuff")
</pre>
<p>
And we get:
</p>
<pre class="example">: ffutSlooCyreV
</pre>
<p>
Note, due to some limitation/bug in my version of <code>org-babel</code>, the strings
should not contain spaces or other special characters, so the following
will give result in an error note:
</p>
<pre class="example">˜#+call: revert(str="Very Cool Stuff")
</pre>
<p>
Whenever you try to evaluate a code block, emacs will ask for confirmation --
this is important, because of the obvious security implications of executing
unknown code. Anyway, if you <b>do</b> trust the code, you can use the following
to skip the confirmation:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">setq</span> org-confirm-babel-evaluate nil)
</pre>
<p>
These simple examples do not really capture the power that <code>org-babel</code>
brings, but it's a start. There is quite a bit of <a href="http://orgmode.org/worg/org-contrib/babel/">documentation</a> for
<code>org-babel</code> to help you further. Finally, if you are already using
<code>org-babel</code>, feel free to share your experiences in the comments!
</p></div>
</div>
</div>Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-3992530807750384868.post-66315125240668519242011-02-10T22:42:00.002+02:002011-02-13T21:49:48.268+02:00keeping your secrets secret<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
If you want to keep your secrets secret, it is a good idea to <i>encrypt</i> your
data; I usually do that for files with passwords for various services, banking
data, and so on. Since version 23, Emacs includes a package called <a href="http://epg.sourceforge.jp/">EasyPG</a> (an
interface to <a href="http://www.gnupg.org/">GnuPG</a>) which makes this seamless – just make sure that you have
<a href="http://www.gnupg.org/">GnuPG</a> installed.
</p>
<p>
It's easy to use EasyPG – the only thing you need to do is adding the <code>.gpg</code>
-extension to your files, and EasyPG will automatically encrypt/decrypt them
when writing/reading. So, for example, to create an encrypted <code>org-mode</code>-file,
simply visit (<code>C-x C-f</code>) a file with a name like <code>myfile.org.gpg</code>; emacs opens
this in Org-Mode (just like any <code>.org</code>-file). When you want to save the file,
emacs will ask you for a password, and with this same password, you can open
it again. Don't forget that password!
</p>
</div>
<div id="outline-container-1_1" class="outline-3">
<h3 id="sec-1_1">account data </h3>
<div class="outline-text-3" id="text-1_1">
<p>
You can store <i>any</i> kind of secret data in your encrypted files. One type I
find particularly useful is to store <i>account data</i> (user names, passwords)
for various services there. For example, I use the <a href="http://blog.nethazard.net/identica-mode-for-emacs/">emacs identi.ca-mode client</a>, which gets its account data through variables <code>identica-username</code> and
<code>identica-password</code>.
</p>
<p>
I do not want to put this information in my main <code>.emacs</code> file for safety
reasons, but instead, put it an encrypted file, together with the account data
for other services (mail, twitter etc.). Emacs' <code>require</code> does not understand
encrypted files, but <code>load-library</code> does. To deal with that, I have two files,
<code>secrets.el</code> and <code>secrets.el.gpg</code> (in my <code>load-path</code>):
</p>
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">secrets.el
</span>(load-library <span class="org-string">"secrets.el.gpg"</span>)
(<span class="org-keyword">provide</span> '<span class="org-constant">secrets</span>)
</pre>
<p>
and
</p>
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">secrets.el.gpg
</span>(<span class="org-keyword">setq</span> identica-username <span class="org-string">"djcb"</span>
identica-password <span class="org-string">"$ekr3t"</span>)
<span class="org-comment-delimiter">;; </span><span class="org-comment">... other passwords ...
</span></pre>
<p>
Now, in my <code>.emacs</code> I have a function for various services, like:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">defun</span> <span class="org-function-name">start-identica</span> ()
(interactive)
(<span class="org-keyword">require</span> '<span class="org-constant">secrets</span>)
(identica-friends-timeline))
</pre>
<p>
This will prompt me for the password, but only if I use anything that requires
the secret data, and <b>only once</b> per session.
</p>
<p>
<b>Update</b>: as Richard notes in the comments, you can also use <tt>require</tt> by
explicitly specifying the filename (parameter two). That might actually be easier --
thanks Richard!
</p>
</div>
</div>
<div id="outline-container-1_2" class="outline-3">
<h3 id="sec-1_2">using public keys </h3>
<div class="outline-text-3" id="text-1_2">
<p>
By default, EasyPG performs <a href="http://en.wikipedia.org/wiki/Symmetric_encryption">symmetric encryption</a>; if you want to use <a href="http://en.wikipedia.org/wiki/Public-key_cryptography">public key encryption</a> instead (useful when you want to share the encrypted files with
others), you can use:
</p>
<pre class="src src-emacs-lisp"><span class="org-comment-delimiter">;; </span><span class="org-comment">'silent to use symmetric encryption
</span><span class="org-comment-delimiter">;; </span><span class="org-comment">nil to ask for users unless specified
</span><span class="org-comment-delimiter">;; </span><span class="org-comment">t to always ask for a user
</span>(<span class="org-keyword">setq</span> epa-file-select-keys t)
</pre>
<p>
The 'users' in this snippet are the people in your GnuPG-keyring – EasyPG
lists your keyring inhabitants, allowing for easy selection. You can also
specify the people who can decrypt your file by putting something like the
following at the beginning of the file you want to encrypt.
</p>
<pre class="src src-text"># -*- epa-file-encrypt-to: ("foo@bar.org") -*-
</pre>
</div>
</div>
<div id="outline-container-1_3" class="outline-3">
<h3 id="sec-1_3">so </h3>
<div class="outline-text-3" id="text-1_3">
<p>
EasyPG brings more functionality for encryption, decryption, signing, managing
your keyring and so on, but I haven't used that much yet. Anyhow, the
automatic support for reading/writing file is really nice.
</p>
</div>
</div>
</div>Unknownnoreply@blogger.com19tag:blogger.com,1999:blog-3992530807750384868.post-2466558388269155632011-02-02T20:40:00.000+02:002011-02-02T20:40:56.298+02:00extending ERC with your own commands<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
<code>ERC</code> is the leading Emacs-based <a href="http://en.wikipedia.org/wiki/IRC">IRC</a>-client; I already discussed ERC <a href="http://emacs-fu.blogspot.com/2009/06/erc-emacs-irc-client.html">before</a>. I
have been using ERC a <i>lot</i> in recent times, as it's an essential way to
communicate at work with team members in remote locations. There are other
IRC-clients – most people around me seem to use either <code>irssi</code> or <code>xchat</code>,
but these don't integrate so well with my emacs-based workflow, the easy with
which it can be extended to do exactly what I want; in this although they have
their own strenghts. One of the great strengths of ERC is article I give some
examples.
</p>
<p>
Apart from chatting, you can send commands (<a href="http://en.wikipedia.org/wiki/List_of_Internet_Relay_Chat_commands">long list</a>) to the IRC-server,
for example to request information about other users, change your 'nick',
leave the channel, and so on. As in most IRC-clients, you can send these
commands with ERC by prefixing them with <code>/</code>, so you'd type:
</p>
<pre class="example">/nick ninjaturtle
</pre>
<p>
to change your nickname.
</p>
<p>
The nice thing about ERC is how easy it to add your own commands to this. In
your <code>.emacs</code> (after loading ERC), you can add something like:
</p>
<pre class="src src-elisp">(<span class="org-keyword">defun</span> <span class="org-function-name">erc-cmd-MYSYSTEM</span> ()
<span class="org-doc">"show some information about my system"</span>
(<span class="org-keyword">let</span> ((str (shell-command-to-string <span class="org-string">"uname -a"</span>)))
(<span class="org-keyword">when</span> str (erc-send-message str))))
</pre>
<p>
Or, add add a function called <code>erc-cmd-XXXX</code> (with the <code>XXXX</code> being the
command name in capitals, will add command <code>XXXX</code>, which you can invoke with
<code>/XXXX</code> or <code>/xxxx</code>). So, with the above function, I can now do something like:
</p>
<pre class="example">ERC> /mysystem
<djcb> Linux cthulhu 2.6.35-25-generic #44 SMP Fri Jan 21 17:40:48 UTC
2011 i686 GNU/Linux
</pre>
<p>
Let's look at some other (somewhat) useful command: <code>/calc</code>; again, just a
small example, I'm sure something can come up with something a bit more
elegant - perhaps using emacs' built-in <code>calc</code>.
</p>
<pre class="src src-elisp">(<span class="org-keyword">defun</span> <span class="org-function-name">erc-cmd-CALC</span> (<span class="org-type">&rest</span> args)
<span class="org-doc">"calculate value of some expression using bc"</span>
(<span class="org-keyword">let</span> ((expr (mapconcat 'identity args <span class="org-string">" "</span>)))
(<span class="org-keyword">when</span> (length expr)
(<span class="org-keyword">let</span> ((result (shell-command-to-string (concat <span class="org-string">"echo '"</span> expr <span class="org-string">"' | bc "</span>))))
(<span class="org-keyword">when</span> result (erc-send-message (concat expr <span class="org-string">" = "</span> result)))))))
</pre>
<pre class="example">ERC> /calc 2 * (3 + 4) / 7
<djcb> 2 * (3 + 4) / 7 = 2
</pre>
<p>
Now, a small warning, just because it's <i>easy</i> to dump the output of, say,
<a href="http://en.wikipedia.org/wiki/Cowsay">cowsay</a> in an IRC-channel using your own <code>/cowsay</code> command, does not mean it is
a good idea – in fact, using something like that is guaranteed to get you
kicked out fairly quickly from many channels.
</p>
<p>
That being said, I'm sure many people have come up with much more clever
things than the examples here; feel free to share your inventions in the
comments!
</p></div>
</div>Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-3992530807750384868.post-75836008055003872322011-01-06T17:47:00.002+02:002011-01-06T17:47:52.395+02:00setting the frame title<div id="outline-container-1" class="outline-2">
<div class="outline-text-2" id="text-1">
<p>
The 'frame title' (window title) that emacs uses in graphical environments
defaults to something like <code>emacs@hostname</code>.
</p>
<p>
Of course emacs lets us customize this, by changing the value of
<code>frame-title-format</code>. Emacs accepts many different things there, (see the
documentation for <code>frame-title-format</code> and <code>mode-line-format</code> for that), but
let's look at an example.
</p>
<p>
Instead of the default <code>emacs@hostname</code>, I find it more useful to include the
name of the file I'm working on instead, or, in case of non-file buffers, the
buffer name. To do this, I have something like the following in my <code>.emacs</code>:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">setq</span> frame-title-format
'(<span class="org-string">""</span> invocation-name <span class="org-string">": "</span>(<span class="org-builtin">:eval</span> (<span class="org-keyword">if</span> (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
<span class="org-string">"%b"</span>))))
</pre>
<p>
As you see, <code>frame-title-format</code> is a template for the items that are present
in the title bar; i.e.. emacs concatenates the items in the list, and it
supports various <code>%</code>-constructs, which are replaced with actual values; see
below.
</p>
<p>
In addition to the <code>%</code>-constructs, you can use <code>:eval</code> to make emacs evaluate
the expression whenever it wants to update the title bar.
</p>
<p>
<code>invocation-name</code> is the name of the emacs binary.
</p>
<p>
<code>abbreviate-file-name</code> replaces the home directory part in file names with
<code>~</code>; for very deep paths it might be nice to do some abbreviation as well as
some shells do; this is left as an exercise to the reader :)
</p>
<p>
You can experiment with some other things to put in <code>frame-title-format</code>;
use the <code>:eval</code> construct as above to use emacs-lisp functions, and the
various <code>%</code>-specifiers which are replaced by certain values; the emacs
documentation lists the following:
</p>
<pre class="src src-text">%b -- print buffer name. %f -- print visited file name.
%F -- print frame name.
%* -- print %, * or hyphen. %+ -- print *, % or hyphen.
%& is like %*, but ignore read-only-ness.
% means buffer is read-only and * means it is modified.
For a modified read-only buffer, %* gives % and %+ gives *.
%s -- print process status.
%i -- print the size of the buffer.
%I -- like %i, but use k, M, G, etc., to abbreviate.
%p -- print percent of buffer above top of window, or Top, Bot or All.
%P -- print percent of buffer above bottom of window, perhaps plus Top,
or print Bottom or All.
%n -- print Narrow if appropriate.
%t -- visited file is text or binary (if OS supports this distinction).
%z -- print mnemonics of keyboard, terminal, and buffer coding systems.
%Z -- like %z, but including the end-of-line format.
%e -- print error message about full memory.
%@ -- print @ or hyphen. @ means that default-directory is on a
remote machine.
%[ -- print one [ for each recursive editing level. %] similar.
%% -- print %. %- -- print infinitely many dashes.
Decimal digits after the % specify field width to which to pad.
</pre>
<p>
So, if we'd like to include the host (system) name and some indication of the
status of this buffer, we could do something like:
</p>
<pre class="src src-emacs-lisp">(<span class="org-keyword">setq</span> frame-title-format
'(<span class="org-string">"emacs%@"</span> (<span class="org-builtin">:eval</span> (system-name)) <span class="org-string">": "</span> (<span class="org-builtin">:eval</span> (<span class="org-keyword">if</span> (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
<span class="org-string">"%b"</span>)) <span class="org-string">" [%*]"</span>))
</pre>
<p>
Of course, some of the information is available elsewhere already, but it
might be clearer in the frame-title. Or not – there's a lot of room for
tweaking and experimentation here.
</p></div>
</div>Unknownnoreply@blogger.com12