Posts Tagged ‘emacs’

Simple Frame Initialization

2010-09-11

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."
  (interactive)
  (my-initialize-frame 3))

(defun my-small-screen ()
  "Set up frame for laptop screen, with two windows."
  (interactive)
  (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)
  (delete-other-windows)
  (dotimes (not-used (1- columns))
    (split-window-horizontally))
  (balance-windows))

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).

Advertisements

Announcing delim-kill.el

2010-05-16

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.

Andy Wingo: recent developments in Guile

2010-04-19

I watched a talk by Andy Wingo recently: recent developments in Guile. GNU Guile is a Scheme implementation, and a library providing an extension language for applications. Guile is actively developed, and promises some exciting stuff in upcoming releases, which is why I took these notes and publish them here–read on.

Andy starts by noting that Guile is different things to different people:

  • A GNU language, with bindings for many components of the GNU system and under LGPL 3.
  • A Scheme implementation, supporting R5RS and part of R6RS, plus other goodies: modules (not the R6RS ones), hygienic macros, the CLOS-like object system Goops with transparent integration with GLib’s gobject, Posix interface, and Unicode support.
  • An extension language for applications, like the Gimp.
  • A part of the GNU system (that we are making, even if we don’t know yet how it will look like).

Andy sees Guile’s perception among developers as its main challenge currently. It’s seen as being slow, although it’s generally faster than Python. But there are also opportunities for its perception: its multilingual vision and support–its next release will support ECMAScript besides Scheme, and Emacs Lisp is coming–, and the GNU brand.

Some technical notes

It uses the Boehm-Weiser garbage collector now, which is fast and reliable.

There are ten committers and monthly releases. This is after the project emerged from a long drought in 2000-2007.

Guile has a VM, and a native compiler is coming. Also: JavaScript support, ELisp coming!

It has really good Emacs integration now with Geiser.

There was also a small remark about licensing. Readline and Guile are not quite license-compatible, which makes using the REPL a pain. This sparked a longish discussion–kinda what you expect from a GNU developers meeting :-)

Spreading the Emacs nature

And now, the meat of the talk: spreading the Emacs nature, to emacsify the GNU system. Yes, that sounds like it!

The upcoming Guile 2.0 (or maybe 2.1?) will have full ELisp support, at the moment about equally fast than Emacs’ own, but it will be much faster. It will also have native compilation for even more performance.

Besides performance, it will have much more to offer:

  • native threads,
  • a clear FFI,
  • modules,
  • other languages, as described above,
  • the Goops object system,
  • lots of library bindings – Emacs-Gnome integration would easily be possible, for instance.

Andy’s plan is to replace Emacs’ Lisp engine with Guile. The rest stays unchanged, existing ELisp code will run as-is. Then no form of coercion should be necessary to get people to start writing their Emacs code in Guile languages. The timeframe is 18-30 months from now–looks like a developer release is not too far off!

Weekly Links #2

2010-04-01

Conrad Barski and James Webb: Casting SPELs in Emacs Lisp

Conrad Barski’s awesome Lisp tutorial Casting SPELs is now also available in an Emacs Lisp version, edited by James Webb. Even if Emacs Lisp is certainly not the greatest Lisp dialect, it shouldn’t matter much for a beginner’s tutorial and it sure is nice to be able to evaluate everything right in your editor.

ars technica: Tentacular, tentacular!

Cthulhu plucked a manila folder from somewhere within the non-Euclidean geometry of his manbag and dropped it on my desk with a thud.

A geeky, hilarious choose-your-own-adventure story written by Cthulhu. What else could you want for your Easter weekend.

A simple Markdown journal in Emacs

2010-01-23

I wanted to get into daily journaling since a long time. Keeping a journal makes it easy to find and go back to all kinds of things you have encountered and thus saves time. But more important is, I believe, that journaling structures your thoughts, like any kind of writing. You need to think clearly about something before you can write it down. Then, the act of writing it down anchors it more deeply in your memory.

Alas, all my previous attempts at journaling failed. Whatever the reason, whether on paper or on the computer, I never felt entirely at home with the solutions I tried. So what’s a hacker to do – write his own solution.

I know that there are already many ways to write a journal in Emacs. Well, here’s another one: simple-journal. It’s tiny and simple, it produces a Markdown format that I love, and having it written myself I feel more inclined to actually use it.

The journal looks like this:

### 2010-01-10

- **18:15** - "XML serializations should be hidden away from
  human view lest small children accidentally see them and become
  frightened." - from the paper *Representing disjunction and
  quantifiers in RDF*, McDermottDou02.pdf.

### 2010-01-17

- **14:45** - Set up a minimal Wicket application with Netbeans (a
  first for me, version 6.8) and Jetty. I want to try out working
  asynchronously with JSON using Wicket. Here are the steps to get the
  application running, serving up an empty page:

  - Start a plain Java SE project in Netbeans.
  - ... 

Being in Markdown, it’s very readable, and can readily be converted to well-formatted HTML. The format is completely hard-coded in the code for the moment. The goal was just to quickly get something simple and small working. Nevertheless, I’m always happy about feedback and ideas.

There’s one item on the TODO list that I’d really like to have, but I’m wondering about how to implement it a somewhat simple and efficient way: showing all entries that have “TODO” in them, or that start with “TODO”. Do I have to go through the buffer to collect them and show them in a temporary buffer? That would be a bit more programming than I feel is appropriate for such a task, and the temp buffer wouldn’t be in sync with the journal. Planet Emacs, ideas? ;-)