tags:

views:

531

answers:

2

I'd like to display the output of (getenv "HOSTNAME") somewhere in my mode line. My display-time-mode is set to 't', so I'm already displaying time, load level and a mail flag in the mode line. Is there an easy way to get the hostname in there, too?

I'd like to have this because I'm ssh'd into 3 remote machines, all running emacs from a common set of init files, and I'd like some fast easy unobtrusive way to know which machine I'm working on.

+1  A: 

You're going to have to futz with mode-line-format to get this to work. This page has an example of doing that, and it even uses the current hostname as part of the example.

Sean Bright
Dang - I hate overlooking stuff in the docs. Thanks!
Bill White
+5  A: 

To build on Sean Bright's answer, specifically you can do this:

(let ((pos (memq 'mode-line-modes mode-line-format)))
  (setcdr pos (cons (getenv "HOSTNAME") (cdr pos))))

This assumes that 'mode-line-modes is a part of your 'mode-line-format, which it is by default. Because you're modifying the list pointed to by the variable 'mode-line-format, you don't have to set the default value. If you were setting the variable itself, you'd have to do something like:

(setq-default mode-line-format (build-list-that-contains-(getenv "HOSTNAME")))
Trey Jackson