Building PLT-Scheme on Ubuntu (Intrepid Ibex)

I had reason to build PLT-Scheme 4.1.5 the other day on an Ubuntu system (Intrepid Ibex) (OK, I was trying to get a build of Fluxus up and running).

It was almost entirely straightforward, except for not knowing ahead of time which development packages were needed for the build to complete successfully. As I had to run the process a number of times on an old laptop, it took quite a few hours with a number of manual interventions. Hopefully, the below steps will save someone some time:

  1. Go to: download.plt-scheme.org
  2. Choose the “Source code for Unix (X11)” platform, and click Download, seleccting the closest location to you.
  3. Save the download to its own folder, then untar it with: tar -xzvf plt-4.1.5-src-unix.tgz
  4. Change directory, to plt-4.5.1/src
  5. You will need a C++ compiler: sudo apt-get install g++
  6. Some windowing packages to compile MrEd: sudo apt-get install libX11-dev libxt-dev libxaw7-dev
  7. You will also need libcrypto.so to prevent the compilation of the web-server’s scribble documentation from breaking horribly: sudo apt-get install libssl-dev
  8. Run the following:
    • ./configure –enable-shared –prefix=/usr/local
    • make
    • sudo make install
  9. Your shiny new build will be installed across the following locations: /usr/local/bin;/usr/local/lib/plt/collects;/usr/local/share/plt/doc;/usr/local/lib;/usr/local/include/plt;/usr/local/lib/plt;/usr/local/share/man

Scheme REPLs and readline (or lack thereof)

Most Scheme implementations provide a command-line REPL, allowing you to interactively enter commands and play about with the language. Unfortunately, they can be incredibly frustrating to use out-of-the-box, all because Scheme distributions tend ship without readline support. As far as I can tell, this is down to licensing issues.

readline is what provides the wonderful interactivity of the command line. If you type a long command and notice an error early on in your text, you can navigate to that spot with cursor keys and edit it, rather than having to delete all your text back to that point. It also provides the command history functionality (typing up and down to navigate through commands you have issued in the past).

Trying to use the editing and history features of readline with readline support enabled, you end up with funny-looking characters being spouted into your REPL.

There are two solutions:

  1. You can recompile your favourite Scheme implementation with readline support. I have never bothered with this, and just booted up DrScheme instead.
  2. Secondly, you can install rlwrap. (You can “apt-get install rlwrap” in Debian/Ubuntu). Once installed, simply invoke “rlwrap {your-favourite-scheme}“, and you magically have readline functionality!
    I have tried this out with mzscheme (it worked fantastically, and it provides you with paren-matching too) and scheme48 (worked well, but no paren-matching).

Now I no longer need to load up the behemoth that is DrScheme when I just want to use a Scheme-based calculator. It took 3 years of dabbling in Scheme before I heard of this. I hope this post saves someone out there some Scheme-related REPL-angst.

Remapping Caps Lock

This week, I bit the bullet and ripped the Caps Lock key out of my keyboard. Not content with that, I ripped out the left Ctrl key too, and stuck it back in where the Caps Lock had been. I didn’t put the Caps Lock back in – I left it on a spike next to my monitor, as a warning against all crap interface design decisions.

Windows

To make the keyboard usable again, I tried the following registry modification: create a file called swapCapCtrl.reg and copy-paste the following lines of text into it:

REGEDIT4
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,03,00,00,00,1d,00,3a,00,3a,00,1d,00,00,00,00,00

Double-clicking this file and rebooting the computer will swap the Caps Lock and Left Control keys around. To undo this, just fire up regedit.exe and remove the entry that was placed in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout and then reboot.

This all works, but you need to go through this rigmarole every time someone who can’t handle this keyboard modification wants to use your computer.

To solve this, download and install AutoHotKey, create a file called swapCapsCtrl.ahk and place the following code in it:

CapsLock::Ctrl
RCtrl::CapsLock

Double-click the file to set the script running in the background, and right-click->Exit its System Tray icon to remove it. This is my preferred method because: I already have and use AutoHotKey; the behaviour is readily toggled; Caps Lock is moved to the Right Ctrl key, where I’m even less likely to hit it accidentally (although, I still find that I do, so I’ve removed that second line entirely).

Linux

Add the following text to your ~/.xmodmap file, then restart your desktop session:

remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L

This deals with the X server side of things, but you must do something else to get this effect in a virtual terminal (i.e. when you press Ctrl-Alt-F1, etc.). Edit the file /etc/console-tools/remap, such that it contains the following line: s/keycode 58 = Caps_Lock/keycode 58 = Control/;

If none of the above works for you, for whatever reason, I refer you to Moving The Ctrl Key, over on the Emacs Wiki.

With this keyboard tweak, I did have something of an uncertain start, but it nows feels to have been worth it. Ctrl-Tabbing and Ctrl-Shift-Tabbing between Firefox tabs seems more natural, and I now look at Ctrl-T on my laptop’s unmodifed keyboard and think did I really used to go to all that effort just to open a new tab?.

Mog

I don’t have RSI but, in the past, I’ve been well on the way to developing it thanks to applications that pretty much make the mouse a requirement (oh, and poor posture).

About 6 months ago, I saw Mouser by Adam Pash, over at LifeHacker, and liked it quite a bit.

You navigate in Mouser by effectively throwing away large sections of screen and navigating around the area that remains. For example, if you move the mouse pointer left, the area that was to the right of the cursor is marked as off-limits and the mouse pointer is placed in the centre of the remaining area. It’s like the navigational equivalent of the binary search method.

As cool as it was, it wasn’t quite a replacement for the mouse. So: I reimplemented it, fixed some unresponsiveness and dodgy behaviour, made it more customizable and released it.

I’ve called it mog, and it’s available for download here: http://code.google.com/p/moggie/ (mog was already taken, sadly, and it’s Windows-only for extra sadness).

It’s _still_ not an effective replacement for the mouse… but I believe it qualifies as an acceptable-for-the-time-being alternative. The problem is the number of key presses required to navigate to a 20×20 pixel area (we rarely require pixel precision). If you have two fairly high resolution monitors, the worst case scenario is about 12-14 key presses. I’d guess that about 8 key presses is the average. Unfortunately, it’s easy to make a mistake and, without an undo feature, this will add another 8 key presses. So I’d say the average number of key presses is more like 12. Not very effective.

Fortunately, I have plans to incorporate other navigation methods into mog. Once I’ve run out of ideas, I intend to look at ways of bringing the best of those ideas to other platforms (AutoHotKey is only available for Windows).

Please do let me know what you think, criticisms and praise both accepted.

Vimperator

Being rather keen on Vim and mouseless-ness in general, I was chuffed to discover Vimperator, a Firefox extension for providing a Vim-like interface to web-browsing. If you’re not already familiar with Vim, this may not be an extension you’ll be wanting to try out soon. At least, not until you’re accustomed to and happy with Vim. Or perhaps I’m wrong, and Vimperator will lead you to Vim. That would be weird.

Vim is a modal text editor. This means you flip between two different modes: one for entering text, and one for doing things with the text, such as manipulation and navigation. Learning Vim can be profoundly irritating to learn, because beginners invariably end up typing text whilst in the wrong mode, and wonder why critical pieces of their novel have had the William Burroughs Cut-up Technique applied. In the end, for many people, this infuriation pays off and we find it actually works pretty well for us. I’m really interested to see how a modal web browser will work for me.

Firstly, download the extension from vimperator.mozdev.org (look for it hovering on the right-hand side). After restarting Firefox, you’ll find things look a little different. In the spirit of Vim, the tools and widgets at the top of the brower window will have been hidden. These can be brought back by hitting escape, and typing :set guioptions+=mT (it can be hidden again with :set guioptions-=mT).

To start off the tour, we’ll do a web search in a new window. ‘:wo google.com’ will open a new window and take you to google.com. Do that, then arrange the window such that it can be seen alongside this text.

  • Press f – this places you in QuickHint mode. A small label is placed next to each interactive element on the page. Type the label name for the main Google search box in lower-case. This gives the search box focus. Search for ‘vimperator’.
  • Use j and k to scroll up and down the page. If this is too slow for you, Ctrl-f and Ctrl-b will do this a page at a time. Firefox’s default bindings of spacebar and Shift-spacebar work equally well. gg and G scrolls to the beginning and end of the document, respectively.
  • Follow a link by using the above method.
  • You can return to the previous page by press H. You can move forward through the browser history by pressing L.
  • Follow a link using the above method, but this time enter the label name in upper-case. This causes the page to be loaded in a tab.
  • You can move between tabs using gt and gT.
  • d closes a tab, and u brings it back.
  • t opens a new tab, inviting you to enter a URL in the status bar.
  • ZZ closes the entire browser window.
  • Occasionally, there will be a need to disable Vimperator’s handling of key presses. Pressing I will cause Vimperator to ignore key presses by handing them straight on to the next event handler. GMail is one such service that can require this feature.
  • Vimperator’s search features are exactly as found in Vim: / searches forwards, ? searches backwards. n and N search for the next and previous result, respectively.

Vimperator has quite a bit more to offer than this. I’ve just listed the features that I personally need to browse mouselessly. If you want to learn more about what Vimperator is capable of, type :help. There’s also a mailing list and a wiki.