Procrastiblog

April 30, 2008

Linux Quickies

Filed under: Emacs, Linux, Tech — Chris @ 8:31 pm


The upgrade from Ubuntu Gutsy to Hardy Heron (cool logo, right?) was relatively uneventful. Some minor points…

  • I always thought the main Ubuntu servers would farm my downloads off to an appropriate mirror, but apparently that’s not the case. You’re likely to get better download times if you choose a mirror in System -> Administration -> Software Sources. If you choose “Other…”, there’s a “Select Best Server” feature. Oddly, my best response times were from New Zealand… maybe because they were all asleep when I tried it.
  • The “ugly fix” for the infamous hard disk annihilating bug stopped working after I upgraded. This new, different (but still ugly) fix worked for me. It would be really great if the Ubuntu team could find a way to make the OS stop trying to kill my hard disk by default.
  • My WiFi light stopped working after the upgrade. This is very easily fixed by installing the package linux-backports-modules-hardy.
  • etckeeper is a great idea: it puts all the config files in /etc under Git, Mercurial, or Bazaar source control and forces APT to commit before and after any upgrade, so it’s easy to isolate and revert changes. (As a side note, using Bazaar for a few weeks makes it physically painful to be forced to deal with CVS.)
  • Anti-aliased fonts in Emacs are really nice. On Ubuntu Hardy, install emacs-snapshot-gtk (on prior releases, downloads “Pretty Emacs”), then run emacs-snapshot instead of emacs (or run update-alternatives to set emacs-snapshot as the default). You should then be able to run, e.g., emacs --font "Monospace-10" and get pretty, pretty (lick-able, as they say) fonts. Other reasonable choices are "BitstreamVeraSansMono-X" or "LiberationMono-X", where X is your desired point size. You can also invoke M-x set-default-font and type your choice interactively, but for some reason the TrueType fonts above won’t tab-complete—if you type a non-existent font, Emacs will silently use the default system fixed-width font (see System -> Preferences -> Appearance -> Fonts). I’ve added the following to my .emacs:

    (if (>= emacs-major-version 23)
    (set-default-font "Monospace-10"))

    (The conditional is necessary if you may come into contact with earlier versions of Emacs, which will barf on TrueType fonts.)

  • In my experience, the fonts in your web browser will look better if you don’t use Microsoft’s gratis TrueType core fonts (package msttcorefonts in Ubuntu/Debian). In particular, the Trebuchet font (which crops up frequently, including at the top of this page) tends to look pretty bad with subpixel rendering turned on. Red Hat’s Liberation fonts (package ttf-liberation) are designed as drop-in replacements for the Microsoft fonts, but I haven’t seen much value in installing them.
  • The instructions I gave last month for hooking up to a projector aren’t complete, because they often won’t let you run the projector at a resolution greater than 640×480. This led to a rather embarrassing scene in front a class of undergraduates, where OpenOffice.org simply refused to operate at such a pathetic resolution. This problem can be solved by the methods presented here, though it requires a bit of tweaking to get things just so. I haven’t yet discovered a minimal solution—first I need to crack the meaning of the X11 “MetaModes” option. When I do, you’ll be the first to know.

January 24, 2008

The Triumphant Return of C-c C-t

Filed under: Emacs, OCaml, Tech — Chris @ 11:46 pm

The upgrade to Ubuntu gutsy and/or Emacs 22 broke my favorite feature of tuareg/ocaml-mode: C-c C-t for “show type” in OCaml buffers (this requires compiling with -dtypes, which generates type annotation files). I suffered without this for a length of time which is either embarrassing or impressive, depending on whether you consider poking around inside Emacs Lisp files a productive or unproductive use of time…

I finally broke down and fixed it today. The problem is simply that Emacs and OCaml packages aren’t cooperating properly. My solution, which may or may not be optimal, is as follows:

  1. Copy the directory /usr/share/emacs/site-lisp/ocaml-mode to a path of your choosing, say ~/.emacs.d/emacs22/ocaml-mode. Let’s call this directory DIR
  2. (Optional) In Emacs 22, execute C-u 0 M-x byte-recompile-directory and choose DIR.
  3. Add the following line to your .emacs file:
    (or (< emacs-major-version 22) (push "DIR" load-path))

The test for whether it worked is: load a .ml file and type C-c C-t. In the mini-buffer, you’ll either see “type: ...“; “Point is not within a typechecked expression or pattern“; or “No annotation file...” If it says “C-c C-t is undefined“, then you have failed.

July 9, 2007

Changing your PATH in Emacs’ compilation mode

Filed under: Emacs, Tech — Chris @ 4:21 pm

[UPDATE: This is not really wrong, but not really right either. See below.]

I was a bit surprised at this problem, but I suppose most people use standard make or gcc to build… I want to build my project with a version of OMake that I have compiled and installed in my home directory. I have ~/tools/bin in my PATH, but for some reason M-x compile still gives me

/bin/bash: omake: command not found

The trick is that Emacs invokes the compile command in a non-interactive, non-login shell, which means that neither your .bash_profile nor your .bashrc (or any variations thereof) are going to get read.* The workaround is to set BASH_ENV to point to a script file that sets your PATHbash reads the file pointed-to by BASH_ENV in non-interactive mode. Here’s my solution:

# In ~/.bash_profile:  
. ~/.bashrc

# In ~/.bashrc:  
export BASH_ENV=~/.bash_env  
. "$BASH_ENV"

# In ~/.bash_env:  
export PATH=/home/chris/tools/bin:$PATH

There’s probably a good reason why this is a bad idea, but it works.

* A quick refresher course: .bash_profile is for login shells; .bashrc is for interactive, non-login shells; BASH_ENV is for non-interactive, non-login shells (which, confusingly, will probably be a sub-process of an interactive and/or login shell, which is why the above example works).

[UPDATE] The compilation shell being non-interactive and non-login is a red herring. While this is certainly the case, a non-interactive, non-login shell will inherit the environment of it’s parent process. So, for instance, if your PATH is properly set in your shell and you invoke Emacs from the command line, things should be fine.

What was really causing my problem is that I was invoking Emacs from the Gnome Panel. The environment that Emacs inherits in this case is Gnome’s, not Bash’s. How do you change the PATH in the Gnome environment? Um… Eh… gnome-session-properties? .gnomerc?

The solution I’ve settled on is to create a ~/.xsession file as follows,

  #! /usr/bin/bash

  if [ -f ~/.bash_env ]; then
    . ~/.bash_env
  fi

  exec gnome-session

where .bash_env is as above.

NOTE: If you leave off the last line, your X session will end before it begins. The .xsession script is the X process: when it ends, the X process ends. Execing gnome-session replaces the script process with the Gnome session process.

[UPDATE 2] Of course, another option is to just use setenv in your .emacs file. TMTOWTDI, in Emacs and Perl alike.

June 29, 2007

Browsing gzipped tarballs in Emacs

Filed under: Emacs, Tech — Chris @ 8:22 pm

Somehow the presence of a hundred billion .tar.gz files on the Internet prevents Google from giving me this very simple tip. Just opening a .tar file in Emacs will let you browse it as if it were a directory. If the file is gzipped, you need to enable auto-compression-mode: either do M-x auto-compression-mode or (setq auto-compression-mode t) (e.g., in your .emacs file).

March 18, 2007

Buffer-local Dictionaries

Filed under: Emacs, LaTeX, Tech — Chris @ 10:00 pm

If you write technical documents—especially technical computer science documents with code snippets and the like—you’re likely to come across a spell-checking dilemma like the following:

Unrecognized word: pBuffer

Replace with: (0) buffer (1) puffer (2) puffier (3) pouffe …
Space: Accept word this time
a: Accept word this session
i: Insert into personal dictionary

“pBuffer” is not a real word that should go in your personal dictionary, so you accept the word for this session. Say you’re going to write 5,000 more drafts of this document. All of those weird little technical words could get pretty annoying after a while.

In Emacs, you can type ‘A’ instead of ‘a’ to insert the word in a “buffer-local dictionary.” You can also presumably add a Local Words comment somewhere in your file by hand, like

% Local Words: pBuffer

Why is it always so hard to figure this stuff out?

Hat tip to the Linux Documentation Project.

Bonus tip: You want an em dash in your blog post? Try &mdash;. You would think I couldn’t be so em dash-happy and not know this already, but I am and I didn’t.

March 4, 2007

Newlines in Regexps

Filed under: Emacs, Tech — Chris @ 7:23 pm

This tip rocks: to search for a newline in Emacs type C-q C-j.

February 7, 2007

Fi, O Fi

Filed under: Emacs, Linux, Tech — Chris @ 7:52 pm

When I cut-and-paste from PDF into Emacs, ligatures come out weird. “specific” comes out . (Note that I had to make that an image, because pasting the same text into a Firefox window renders the ligature correctly. The gobbledygook is a control code that is properly understood by the standard GUI fonts. Note also that the cut-and-paste version is a ligature (fi), but the version I type in directly is not (fi).) Of course, there’s ligatures besides “fi”, and hyphenation is always a problem. Is there a magic Emacs incantation to make this work correctly?

October 31, 2006

Edgy Eft-ing Fonts

Filed under: Emacs, Tech — Chris @ 12:35 am

Where did my fonts go in Emacs? Be calm, child. Somebody got pedantic with path names. Search-and-replace /usr/share/X11/fonts with /usr/share/fonts/X11 in /etc/X11/xorg.conf.

June 27, 2006

Damn you Tabs to Hell

Filed under: Emacs, Tech — Chris @ 8:22 am

Every time I enter a new workplace, I find myself looking up this essay: “Tabs versus Spaces: An Eternal Holy War”. It fills me with a feeling of peace and serenity, and reminds me how to customize my .emacs file.

May 23, 2006

Using Emacs with Cygwin

Filed under: Emacs, Tech — Chris @ 6:08 am

Ah, getting to know Windows… Installing Emacs on Windows and setting up Emacs to work with Cygwin.

The Silver is the New Black Theme. Create a free website or blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 30 other followers