27

I have a shared .emacs file between different Linux systems. I would like to execute an expression based on the hostname of the system I'm running:

(color-theme-initialize)  ;; required for Ubuntu 10.10 and above.

I suppose one way to avoid checking the hostname would be to factor out the system dependencies from .emacs, but it's been convenient having .emacs in version control. Alternative suggestions are welcome.

Jeff Bauer
  • 13,890
  • 9
  • 51
  • 73

1 Answers1

44

The system-name variable might be the simplest way to achieve what you're looking for in Emacs below 25.1:

(when (string= system-name "your.ubuntu.host")
  (color-theme-initialize))

This variable is obsolete since 25.1; use (system-name) instead

So in newer Emacs use this:

(when (string= (system-name) "your.ubuntu.host")
  (color-theme-initialize))
cjohansson
  • 1,058
  • 10
  • 13
Hugh
  • 8,872
  • 2
  • 37
  • 42
  • 4
    @PauloMatos Use the `(system-name)` function instead of the variable. See [how-do-i-retrieve-the-machines-hostname](https://emacs.stackexchange.com/questions/33728/how-do-i-retrieve-the-machines-hostname) on the emacs stackexchange site. – Jeff Bauer Jun 27 '17 at 17:50
  • What does the `string=` there do? – buhtz Jan 10 '23 at 09:06