about photos bookshelf portfolio blog home
Begin main content

Get emacs to set your xterm title

I very rarely have an xterm open that's not running emacs (I run my shells inside emacs, except on production logins), so an xterm title of 'xterm' doesn't really help distinguish between windows).

First you need xterm-frobs.el from Noah Friedman's emacs lisp code. Place it in your site-lisp directory or wherever you keep custom lisp.

Then add the following code in whatever block your .emacs executes when you're in an xterm:

(require 'xterm-frobs)
(defun my-set-xterm-title ()
(xterm-set-window-title
(concat (getenv "HOSTNAME") "- emacs - " (buffer-name))))

(let ((term (getenv "TERM")))
(when (and (not window-system)
(or (string= term "xterm")
(string= term "rxvt")))
(require 'xterm-frobs)
(add-hook 'window-configuration-change-hook 'my-set-xterm-title)
(add-hook 'emacs-startup-hook 'my-set-xterm-title)))

(I came up with this code based on the following urls:
http://www.macosxhints.com/article.php?story=20041008195252133
http://www.splode.com/~friedman/software/emacs-lisp/
http://paste.lisp.org/display/3528
)

03:31 PM, 04 Jan 2006 by Mark Aufflick Permalink

Add comment