May 12, 2006

Portable Emacs

Posted in Emacs at 13:07 by theBlackDragon

While reading gmane.emacs.help I came accross this post where somebody asked how he could make a portable app out of Emacs' Windows version.

So since I'm still at my internship (where they use Windows) and just recently obtained an iAudio X5L portable media player which behaves like an USB2 harddisk to the OS I wondered if I could manage to make Emacs portable.

Short version: I could, the "hardest" part was in fact not even Emacs related, but my sheer lack of knowledge about Windows batch script.

I started by creating a "SOFT" folder on my external drive (named E: by Windows on this box) and extracted the altest Emacs build from the ntemacs project in this directory, thus creating "E:\SOFT\emacs" with all the usual subfolders.

Next I created a site-lisp/site-start.el file and added the following as suggested on usenet:

(let ((home (concat (substring (car command-line-args) 0 2) "/SOFT")))
  (setq user-init-file (concat home "/config/.emacs"))
  (setq auto-save-list-file-prefix (concat home "/config/.emacs.d/auto-save-list/.saves-")))

You'll need to adapt this to your particular environment of course.

This makes Emacs load my user-init-file (aka ".emacs") from "E:/SOFT/config/.emacs" and moves the auto-save-list to the external device as well, this should be superfluous though as I change the location of HOME as described later, but it accounts for the cases that you don't want to change your HOME.

This is in fact the entire Emacs side of the story, though you will probably have some work making your elisp packages work with relative paths if you didn't take that into account before.

Now you need to redefine HOME in Windows (well, you don't need to but I find it useful), you can either do that globally with the System Properties or autoexec.bat in DOS based Windows versions, but I preferred to make it dynamic by writing a wrapper batfile that sets this variable and then launches Emacs. I named it runemacs.bat (how appropriate;)) and put it in Emacs' bin directory, the content looks like this:

set HOME=%CD%\..\..\config
runemacs

That's it! You can now run Emacs entirely from your external drive!

Advertisements

May 11, 2006

Emacs tips #2 : linenumbers

Posted in Emacs at 11:25 by theBlackDragon

A question that pops up pretty often is how you can add line numbers in the margin of your files the way most other editors do.

There are actually two ways of doing this:

  • adding the numbers in the margin
  • adding the numbers to your files, so that they get saved with your file, might be useful in certain cases (COBOL source?)

Unfortunately Emacs doesn't support either out of the box, but fortunately people have written modes that do exactly this. Modes for both the former as the latter can be found on the EmacsWiki.

Personally I (occasionaly) use setnu.el which works extremely well for my purposes.

May 4, 2006

Emacs tips #1

Posted in Emacs at 14:57 by theBlackDragon

I've been using Emacs for some time now but have only recently started to heavily customize it. With this I've also started tracking (or more actively tracking) various Emacs related resources, picking up useful bits of information along the way. I'll try to share the most useful ones here with you on a (hopefully somewhat) regular basis.

I'll kick off with a very short one, the next line enables "focus follows mouse" on Emacs windows (not frames, frames are handled by the window manager).

(setq mouse-autoselect-window t)

So what is "focus follows mouse" anyway? Basically it means that the window your mouse pointer is over receives focus (input) so you don't need to click on it to give it focus (as you have to in, say, Windows). Some people find this confusing, most people can't live without it once they get used to it.

For more information on "focus follows mouse" see here.

May 2, 2006

Self-referential story

Posted in Life, the Universe and Everything at 16:28 by theBlackDragon

I came accross this post on Lambda the Ultimate, which made for quite an interesting read, and a fun one too!

Doubleclick in FvwmScript

Posted in FVWM at 13:34 by theBlackDragon

FvwmScript is a scripting language provided by FVWM that allows you to create windows that can integrate perfectly with your FVWM configuration. Unfortunately it is also very limited. It for example doesn't support some sort of DoubleClic[1] event, even though this name pops up in the sources it doesn't seem to ever have gotten implemented.

I came accross this about half a year ago when writing FvwmMpd, an FvwmScript frontend to mpd where I wanted to start playing a file when one doubleclicked a song in the library as having your song change whenever you singleclick an item is obviously annoying…

So I worked out this little workaround:

Widget 1
Property
 Position 0 24
 Size 450 450
 Type List
 Title { }
Main
 Case message of
  SingleClic :
  Begin
    Set $item = (GetValue 1)
    Set $clicks = (Add $clicks 1)
    If $olditem == $item Then
    Begin
      If $clicks==1 Then
    	Do {Exec mpc play } (GetValue 1) { >/dev/null}
    End
    Else
    Begin
      Set $olditem = $item
      Set $clicks=0
    End
  End
End

It obviously is somewhat of an ugly hack but it's about as good as it gets and since I've been asked how to do something like this a couple of times already I thought I might as well publish it here, it might just help someone 🙂

[1]The single click event is called SingleClic, which is probably due to the fact that the original author was French speaking.