2011-01-06

The 'frame title' (window title) that emacs uses in graphical environments
defaults to something like emacs@hostname.

Of course emacs lets us customize this, by changing the value of
frame-title-format. Emacs accepts many different things there, (see the
documentation for frame-title-format and mode-line-format for that), but
let's look at an example.

Instead of the default emacs@hostname, I find it more useful to include the
name of the file I'm working on instead, or, in case of non-file buffers, the
buffer name. To do this, I have something like the following in my .emacs:

As you see, frame-title-format is a template for the items that are present
in the title bar; i.e.. emacs concatenates the items in the list, and it
supports various %-constructs, which are replaced with actual values; see
below.

In addition to the %-constructs, you can use :eval to make emacs evaluate
the expression whenever it wants to update the title bar.

invocation-name is the name of the emacs binary.

abbreviate-file-name replaces the home directory part in file names with
~; for very deep paths it might be nice to do some abbreviation as well as
some shells do; this is left as an exercise to the reader :)

You can experiment with some other things to put in frame-title-format;
use the :eval construct as above to use emacs-lisp functions, and the
various %-specifiers which are replaced by certain values; the emacs
documentation lists the following:

It prompts me for a string to use as a frame title, and it defaults to a string that begins with "emacs (". I can type a project name there, or I can erase the "emacs (" part and type anything I want. If I forget to use a close parenthesis, the function adds it for me.

I have this assigned to a keystroke, and I use it almost every time I start emacs.

When I switch away from emacs, a short while later the window title reverts back to "emacs@hostname". If I switch back to emacs it then updates the title again. I'm using emacs 24 if that makes a difference.