Search code examples
elisp

elisp conditional based on hostname


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.


Solution

  • 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))