Weblogger

Here i am, finally using Emacs for real to edit posts, thanks to weblogger.

Installing it cannot be easier: download the file, and its only dependency, xml-rpc. Put both of them in your load path, require weblogger (e.g. using M-x load-library and call M-x weblogger-setup-weblog, providing the required information.

For instance, i’ve set up this blog using https://emacs.wordpress.com/xmlrpc.php for the ‘end point’. You can add more than one account, which is kind of nice.

If you then invoke M-x weblogger-fetch-entries, you’ll be presented a collection of your posts, as if they were emails (which i like quite a bit), and there’re are commands to browse and modify them, create new ones, save drafts and, of course, publish new entries. Just check the file header, or the menu, for a list of available commands.

There’s also support for simple templates, and for editing your posts using nxml-mode.

The only capability i’m missing is setting categories in WordPress. Perhaps it’s time to roll-up my sleeves! :)

Happy blogging!

Tidying up for TEOS

As part of a general migration from darcs to git as my default SCM system (a migration whose reasons include magit being so much better than darcsum), i’ve been tidying up a bit my emacs configuration files and factoring out a small set of libraries that people may find useful.

The new git repository, clonable from http://git.hacks-galore.org/jao/emacs.git and browsable online here, contains a subdirectory called lib with the code i’ve factored out so far:

  • emms contains add-ons for the Emacs multimedia system, including OSD notifications, lyrics retrieval and a play-random-album facility.
  • net is a handbag of networkish utilites: mailbox query and display, emacs-w3m sessions and a weather info fetcher.
  • themes is my own color theme engine, implemented on top of the custom-themes package included in Emacs 23. Defining new color themes is, i think, short and sweet.
  • skels contains a collection of skeletons and related utilities that i use to insert templates in new files.
  • sys is a set of system utilities, most of them from my times as a Mac aficionado and, therefore, probably bit-rotten. Except for jao-osd, which gives you (very rudimentary) access to aosd notifications within emacs.
  • org contains an assortment of extensions for org-mode.
  • tracker is actually a C program that i use to query the tracker daemon that indexes all my documents. The actual queries are performed and displayed in emacs by an Anything extension of mine that i haven’t yet extracted from my configuration as a separate library, and that can be found there.
  • bmk is a (web) bookmark manager that i don’t use anymore (all my bookmarks are kept in org files these days).

There’s also a directory called external with other emacs packages that i use unmodified.

As i said, the idea is that the libraries above should be usable independently of my specific configuration bits, which are contained in the custom folder. The files in that folder will give you additional hints on how to customize the libraries.

With very few exceptions, all these packages are anything but well-documented, but perhaps you’ll find some bits useful. A long delayed project of mine is to use this blog to go through all of them in a series of posts that we could call TEOS, The Emacs Operating System. They would be not only about how the individual libraries work together, but, most importantly, about how they integrate with each other and with other stock Emacs packages to provide an operating environment that, in my humble opinion, surpasses any other commonly used operating system in terms of productivity and extensibility. An Elisp Machine where you are in control and have all the fun.

I’ve been playing with the idea of joining PragProWriMo and make this part of a book writing project that would explore in detail TEOS, with intermediate Emacs users in mind. If i finally go for it, you may consider this post as the first in the series, but i haven’t made up my mind yet.

Be it as it may, i hope you’ll find some elisp snippets above worth stealing for your own Emacs Operation System.

Babel

Every now and then i need to translate a word or a phrase, and switching to emacs-w3m to use one of the on-line translation services is a bit of a chore. Thanks to Juergen Hoetzel’s babel, life is easier now.

Keeping your secrets secret

As much as i try to avoid it, i always end up with lots of usernames and passwords to remember, not to mention a couple of bank accounts and a credit card number for on-line shopping. There’s no way i’m going to remember any of them—why, i even need to keep track of my telephone number. Time to write down a tidy nice little list, that is, time to look for and set up an adequate emacs mode or two.

When it comes to keeping lists, the table editor of org-mode is what you need. Org-mode is included in emacs 22, but Carsten &co. keep adding new stuff and fixing bugs, so it won’t hurt you to get the unstable version from its website. It comes with a nice manual and installing it is a freeze. You enter table mode by typing a vertical bar (|) to separate columns:

  * Bank accounts
    |Account | Credit card | Expiry date | Password |
    |-

From there TAB and RET are your friends: new rows are created and column widths adjusted automagically. You can also add separators by starting a line with |- (as i did above) and typing TAB. In no time you’ll have something like this:

* Banks

  |-----------------+------------------+----------|
  | Account         | Credit card      | password |
  |-----------------+------------------+----------|
  | The credit box  | 8180819999999333 | fooo     |
  | GNU Free Credit | 6969696969696969 | boobarp  |
  | Engineering Safe| 0000000111111111 | passwdd  |
  | paypal          |                  | paaassss |
  |-----------------+------------------+----------|

* Sites

  |-------------------------------+------------------------+
  | site                          | user        | password |
  |-------------------------------+------------------------+
  | http://www.gnu.org            | a user name | password |
  | http://journals.foo.org       | a user name | password |
  | http://philosophy.org         | a user name | password |
  | http://linkedin.com           | a user name | password |
  | http://www.pragpro.com        | a user name | password |
  | http://www.tug.org/members    | a user name | password |
  |-------------------------------+------------------------+

* Source code repositories...

All in conveniently foldable sections, so that you can expand only the interesting section.

But, of course, you don’t want to save this as a regular file (let alone publish it on the internet). Even on a Unix machine, protecting it via file permissions is very weak. Nah, what you want is to encrypt the thing. To that end, one can use public key cryptography.

In a nutshell, you generate a pair of keys: one of them is private, only for your eyes, and therefore should be protected by a solid password; the other one is public: you make it available to anyone that wants to communicate with you. People then write their secret text and encrypt it using the public key. When that’s done, only your secret key (barring the NSA) can decipher the text. Of course, nothing prevents you from using the same device to encrypt and decrypt your passwords file.

This being an emacs blog, i won’t delve into the details of using GnuPG to create a key pair if you don’t already have it. But you being an emacs user, i’m sure you’ll be quite able to run gpg --key-gen to generate your keys.

You could now use gpg to manually cipher and decipher the passwords file, but, you know, one uses emacs because it can do almost any thing for you. In this case, EasyPG will take care of the chore of decrypting the file every time you open it and encrypting it back when it goes to disk. The EasyPG package comes bundled with emacs 23, and, again, it is very easy to install if you are using previous emacs versions. This is the configuration i use for this package:

;; Emacs 23: bundled EasyPG
(require 'epa)
(epa-file-enable)

or, if you installed it externally:

;; EasyPG installed in path/to/epg
(add-to-list 'load-path "path/to/epg")
(require 'epa-setup)
(epa-file-enable)

(Yeah, it’s called easy for a reason!) With this magic incantation in place, every time you open a file with the extension .gpg, EasyPG will do the work for you.

So, all that is left to do is to save our file as, say, dobeedoo.gpg and inform emacs that we want to open it as an org-mode file by adding the following first line to it:

-*- mode: org -*- -*- epa-file-encrypt-to: ("my_key_email@foo.org") -*-

As you can see, we’re also telling EasyPG what key it should use for its cryptographic activities.

That’s it. No rocket science here, but very handy nonetheless, and a very nice example of how different major (org) and minor (org-table, epa) emacs modes can work together for you. A perfect use case of minor modes providing functionality orthogonal to that in the major mode, which is caring about the actual file contents. Personally, this is also the use case that got me started with org-mode: may it enlighten you too :)

Happy encrypting!

(BTW, now that you have EasyPG installed, try M-x epa-list-keys, a nice keyring browser, if you ask me.)

Org from the horse’s mouth

After many years using Muse for organising my notes, some moths ago i finally moved to Org for all my planning and note taking. I have some posts in the pipeline with some tricks i used, but i cannot think of a better way to get started than this recent talk by Carsten Dominik, the creator of Org himself:

Enjoy!

An Emacs Client for Google Services

If you use Google’s Blogger, GCal and/or Reader, run-don’t-walk and grab the new Emacs Client For Google Services. Awesome!.

Gnus miscellanea

GnusI’ve spent part of the morning setting up Gnus on my OS X, to replace Mail.app and ease synchronization with my GNU/Linux boxes. I won’t enter in the details of basic Gnus setup (see, for instance, the Gnus tutorial), but offer some customization tips, and mention two of my favourite Gnus-enhancing packages (which are not OS X-specific, by the way).

First thing was to import my Mail.app mailboxes. Easy. Open the mailbox in Mail, select all messages and execute the menu command Save as... (under File); in the save dialog, be sure to select Raw Message Source. The saved file is in mbox format, a Gnus import friendly one. All you need to get those messages into Gnus is to press B f in the *Group* buffer, providing your mbox file when asked. A new group is created with all your messages. You can, for instance, mark all of them and B c to copy them in, say, a regular nnml group.

Setting Gnus to read and send messages via Gmail was also easy following the instructions here. A caveat: you’ll need also the file ssl.el from the Gnus CVS repository to make POP3 work (and of course gnutls, which i installed via the fink package gnutls14; be sure to tell Emacs about your fink path: (add-to-list 'exec-path "/sw/bin")).

With that, I had a functional Gnus running and could move on to more interesting stuff. I don’t know about you, but i absolutely need random mail signatures, selected from my growing collection. To that end, i’ve been using randomsig.el since i can remember. Just put the file in your load path (or, if you’re on Debian, install the gnus-bonus-el package), and add to your initialisation files something along the lines of:

(when (require 'randomsig nil t)
  (define-key message-mode-map (kbd "C-c s") 'randomsig-replace-sig)
  (define-key message-mode-map (kbd "C-c S") 'randomsig-select-sig)
  (require 'gnus-sum) ; probably required for `gnus-summary-save-map'
  (define-key gnus-summary-save-map "-" 'gnus/randomsig-summary-read-sig)
  (setq randomsig-dir "~/Library/Emacs/Gnus/")
  (setq randomsig-files '("signatures.txt"))
  ;; or (setq randomsig-files (randomsig-search-sigfiles))
  ;; or (setq randomsig-files 'randomsig-search-sigfiles)
  (setq message-signature 'randomsig-signature)
  (setq randomsig-delimiter-pattern "^--"))

As you can see, i put my signatures in a file called signatures.txt. Now, every time i start editing an email, a random signature taken from this file is inserted for me. If i don’t like it, i can request another one typing C-c s. And if i’m reading anything inside and Emacs buffer and find a new text to add to my signatures.txt, M-x randomsig-message-read-sig will add the region marked in the buffer to my collection. Perfect bliss.

Mail.app comes with a sophisticated search engine based on Spotlight. But i’ve noticed that i never use the 95% of its features, not to mention that it’s annoyingly slow. What i really need is a simple and quick keyword search, and i’ve had it for many years now with Gnus and nnir.el. This package provides an Emacs/Gnus front-end to several indexers, my preferred one being namazu. So, besides getting nnir.el, you’ll need to install it. In Debian, it’s as easy as installing the corresponding package (namazu2), but, theres no namazu package to be seen in fink. Fortunately, you can compile it from source just by following the instructions: they worked in my MacBook without a glitch. With namazu installed, you can index your extant email in a breeze: create a directory to hold the index files (i use ~/Library/Caches/namazu) and type:

cd ~/Library/Caches/namazu
mknmz --mailnews ~/Library/Emacs/Gnus/Mail

(using the appropriate directories, of course), and the index directory will get populated. Now, with nnir.el in your load path, tell Emacs how to find those index files:

(when (require 'nnir nil t)
  (setq nnir-search-engine 'namazu)
  (setq nnir-namazu-index-directory
        (expand-file-name "~/Library/Caches/namazu"))
  (setq nnir-namazu-remove-prefix
        (expand-file-name "~/Library/Emacs/Gnus/Mail/"))
  (setq nnir-mail-backend (nth 0 gnus-secondary-select-methods)))

(i put this code in my Gnus configuration file). We are all setup: go to the *Group* buffer and type G G to search your emails. A temporal group containing the messages that match your query will be created for you, for your browsing pleasure. Inside that group, G T will teletransport you to the original message, in case you need to recover its context. As you’ll notice, namazu searches are at least an order of magnitude faster than Spotlight.

The only bit left is to set an entry in your crontab running mknmz for you periodically (i’ve got it set up with a period of one hour). Indexing is incremental, i.e., fast. Yeah, it’s not that immediate indexing of Spotlight or Beagle, but, you know, it’s not like i get a mail every five seconds, or that i need engine to find a mail i read twenty minutes ago.

There are many other tricks to play with Gnus, but i’ll save them for future posts :-).

Simple window configuration management

Most of the time, I run Emacs in a single, maximized frame (and, sometimes, just inside a urxvt terminal). Inside that frame i create and destroy windows as needed to contain my buffers [0]. After a while working with Emacs one gets used to a fluid window setup, where windows come and go as need arises.

But I remember that in the early days I felt a bit confused: I started by creating a windows setup (split horizontally, then vertically, open files in each of the windows… that kind of thing) and was non-plussed when any operation (going to a Gnus buffer and reading messages, for instance) destroyed my carefully prepared layout. Over the years i’ve seen many a newbie feeling that way. My advice is usually to let go, and learn how to move around your windows, creating them as needed.

That said, i must admit that, sometimes, i want to recover a certain window configuration in a quick way. A particularly simple one is provided by winner-mode, a package which is part of Emacs. Winner keeps track of your window configurations, and provides functions to navigate your window configuration history.

As advertised, activating winner-mode (which is a global minor mode) is as easy as one can get: just type M-x winner-mode or put this line:

    (winner-mode 1)

in your .emacs. Use Emacs normally, and whenever one cherished window layout gets destroyed, press C-c <left> (where <left> refers to the left cursor key) to recover it–actually, this calls winner-undo, and you can invoke it as many times as you want to visit previous window configurations. As one would expect, C-c <right> (the default binding for winner-redo) navigates configurations in the opposite direction [1]. Simple and very useful, as it should be.

But maybe you want to be automatically tele-transported to a previous configuration without traversing the intermediate ones. No problem: Emacs provides functions to store and retrieve window configurations (which, in fact, are the ones winner-mode is using under the covers). You can store the current window configuration in register ‘a’ (registers are named using single letters or numbers) pressing C-x r w a, and restore it later by means of C-x r j a. Again, it’s that easy.

Although there exist several packages providing more sophisticated window management (named configs, save and restore, etc.), in my experience, the simple tricks described above are more than enough (and work out of the box in any Emacs). As always, YMMV.


[0] For those of you not familiar with Emacs lingo, an Emacs frame is what most window managers would call a window, while an Emacs window is any of the regions displaying a buffer inside a frame. Usual ways of creating windows in Emacs are C-x 2, C-x 3, C-x 4 f, and so on. See Windows and WindowsAndFrames for more.

[1] In Emacs 21, the default keybindings start with C-x instead of C-c.

Type faster with Predictive

I had Predictive in my list of Emacs packages to try out and review, but Mathias Dahl has saved me the trouble by writing a nice tutorial on using Predictive, complete with screenshots and all. In a nutshell,

Predictive is a package for the GNU Emacs Editor that helps you write text faster. It does this by trying to predict what you are going to write by looking at the first few characters of each word you type, looking into a dictionary for matching words, and suggesting words from this dictionary.

Mathias goes on providing all the details you need to get stated with Predictive. Although i have not yet used it, looks pretty interesting.

predictive-02.png

Oh, as an aside, i recommend taking a look at Tony ‘Qubit’ Cubitt’s site for more Emacs (and non-Emacs) goodies, or just to enjoy a beautiful website.

Oh my gawd, it’s full of links!

I’ve been using emacs-muse during several years now to keep a personal knowledge base in the form a local wiki. To me, the killer feature of emacs-muse is its ability to create links to other documents, mails, URLs or any other resource accessible via Emacs (which is to say, virtually any resource). Combined with planner mode, one has a pretty good PIM system that, among many other virtues, is based on plain text files (and, therefore, is easily indexable) and is as portable as Emacs itself.

Emacs-muse is pretty neat, but not perfect. My main quibble with it is that it’s a major mode. That means that, in order to create a link to other resource, you must be in a ‘muse’ document (a sort of wiki page). But wouldn’t if be nice if you could create links in any document. Say you’re writing source code an want to reference another file in the project, or an HTML page detailing an API you’re using, or a PDF with your projects requirements. Or you’re writing an essay in LaTeX and want to link to a text file of related notes, or an email, or… you get the idea. What I’m asking for is, in emacs parlance, a minor mode providing the linking functionality.

As it often happens in the Emacs universe, my prayers have been heard. Linkd is exactly the package i wanted. In the words of its author, David O’Toole, “linkd-mode is a hypertext system for organizing and interlinking all resources available to GNU Emacs. It can be used to make a “personal web” out of all your text files—regardless of file format or major mode.” In addition, linkd trims off some of the features I rarely use in emacs-muse, namely, the publishing functionality.

Although still in alpha, linkd looks already pretty good, with such niceties as proxy icons in links, as shown in this picture:

Linkd in action

Other interesting features of linkd include its ability to mark blocks inside any file that can be link targets, and its tagging functionality. In addition, the list of planned features (searching and indexing, summarize, synthesize links a la remember-mode) makes linkd a package definitely worth exploring and keeping an eye on.

Follow

Get every new post delivered to your Inbox.