Simple Frame Initialization


Is anyone else confused by the variety and complexity of packages for Emacs session management out there? I read through some of the documentation recently, but in the end I was overwhelmed and didn’t install anything.

Session management is about open files, buffer positions and the like on the one hand, and about the frame configuration on the other hand. I realized that my actual use case for frame session management was so simple that I could trivially implement it myself.

All I really wanted was that my Emacs would launch in fullscreen, and split it into two or three vertical windows, depending on whether I was using the laptop screen or the larger external screen. If I could accept the two-split as default, and run a function to create the three-window setup when needed, then all I’d need were some small initialization functions.

Like almost everything else, Emacs exposes its window and frame handling in an ELisp API. So here we go:

(defun my-big-screen ()
  "Set up frame for external screen, with three windows."
  (my-initialize-frame 3))

(defun my-small-screen ()
  "Set up frame for laptop screen, with two windows."
  (my-initialize-frame 2))

(defun my-initialize-frame (columns)
  "Set current frame to fullscreen and split it into COLUMNS
vertical windows."
  (set-frame-parameter nil :fullscreen t)
  (dotimes (not-used (1- columns))

This is not rocket science and I hope it didn’t bore the Planet Emacsen readers, but maybe it encourages people to get creative with their Emacs’ frames and windows. Start with the Emacs Lisp manual, chapters 28 (Windows) and 29 (Frames).


Java memory problems


At work, I recently wrote up a page for our internal wiki about Java memory problems and how to debug them. It’s quite simplified and short as it’s geared towards beginning or intermediate Java developers. Nevertheless it might be useful to someone out there.

We first look at the most essential Java memory basics, then see how we can track down out-of-memory problems. I’ve thrown in the most useful references.

Read the rest of this entry »

Semantic hacking: RDF in Perl


Last week, I attended the German Perl Workshop 2010. It was a fun event and I’ll write more on it in the next post.

I gave a 20-minute presentation there called “Semantisches Hacking: RDF in Perl‎”. At Swiss-Prot, we do all our RDF work in Java, but I got interested in how things look on the Perl side, and the Biohackathon in February got me started on exploring that.

Executive summary: The RDF-in-Perl community is organized at, and the core of the available modules is RDF::Trine and RDF::Query by Gregory Williams. For example code, have a look at my simple demo scripts.

At the workshop, I had an audience of about 50-100 people, none of whom had ever worked with RDF or seriously looked into it. So I first introduced RDF in the simplest way possible, as there wasn’t much time, then showed off RDF::Trine and RDF::Query with code examples.

The talk was well received, and I had some interesting conversations afterward where people wanted to know more about RDF. Their questions mainly centered around ontologies/vocabularies, the additional time required to do this properly, and how to build an app on top of a triple store. I had talked about integrating RDF into existing apps in my presentation, for instance using Trine’s support for RDFa, as_hashref, JSON and other possibilities.

Here are the links to the slides (in German), the scripts I took the code snippets from, and the workshop page for the talk.

I think I managed to raise some awareness for RDF and, and an understanding of the core ideas in an audience where almost no one had had any exposure to these topics, and showed some example code in a way the audience seemed to be able to follow, so I’d say it was a success.

Links, where Perl is very much alive


Yeah, I guess my weekly links effort didn’t go so well. Nevertheless, I do still collect interesting links, so let’s restart with a less ambitious irregular series of “Links” posts.

Many programmers today consider Perl to be dying. That is because they read too many shiny new Ruby and Javascript blogs, instead of checking out what the Perl community is actually up to. Damian Conway says it way better than I could.

The slogan of the day, of recent years actually, in the Perl world is Modern Perl. Once you’re ready to get started yourself, get brian d foy’s timely new Effective Perl Programming.

And if you miss the good old days of obfuscated Perl, see the nice Hidden features of Perl collection. You will also find some serious, readable and useful tricks.

Announcing delim-kill.el


A few weeks ago, I had the chance to attend a few courses on Perl and one on giving technical presentations, held by Perl guru and uber-geek Damien Conway. They were fantastic—just like the ones last year—so I should really write a post of its own about them. Strongly recommended.

But for now, this is about one particular thing he said about editing: you need to have a shortcut in your editor that cuts or copies the text between two given characters around cursor, or point in Emacs lingo. This lets you do many frequent editing tasks easily. Say you’re going through a source file and want to move {}-delimited blocks around, or copy the field you’re on in a CSV file, or the current section in a Markdown file (from # to the next #, roughly).

Damian showed this off in Vim. I knew right away that I wanted it in Emacs. There are of course specialized functions for doing things with certain groups of delimiters, such as the ubiquitous sexp-based functions in Emacs, described extensively on the EmacsWiki. But these rely on pre-configured groups of delimiters, and to kill the text, you have to do one extra operation. I liked the idea of having a single function, and thus key binding, to do all of it. And most importantly, it seemed an interesting challenge for my still-developing Emacs and Lisp skills, so I didn’t even do a lot of research before I dug right in and wrote delim-kill.el.

delim-kill.el contains a single convenience function for editing structured data: delim-kill. Given two characters FROM and TO, delim-kill kills the text between the first occurrence of FROM before point and the first occurrence of TO after point. FROM and TO may be identical.

If FROM and TO are not identical, the function preserves the balance between the two characters: For each FROM that is encountered while looking for TO, one additional TO is required; and vice versa. For example, in “{ foo X{bar} baz }”, with X being point and “{” and “}” as delimiters, the text “{ foo {bar} baz }” will be killed, not “{ foo {bar}”.

I had fun writing this. It turned out to be a bit harder than I expected, mainly due to all the corner cases like point being on one of the delimiters—like most programming, really. I wrote plenty of unit tests to be sure to handle these cases. It’s very little code now, but when I first had a working version, it was twice as big. Once I had it working, I could see lots of symmetry between the different cases that I could extract into shared code.

Also, I finally learned the condition-case error handling of Emacs. And being able to pass functions as arguments is just great, coming from my mostly-Java day job.

Try it out if it sounds useful to you, and let me know what you think.

Slightly edited 2010-05-16.