Elisp: Determine OS, Emacs Version, Machine Host Name

By Xah Lee. Date: . Last updated: .

The following are useful for setting up emacs init file on different machines.

Find Operating System Type

Here's how to find out what operating system emacs is running on.

;; check OS type
(cond
 ((string-equal system-type "windows-nt") ; Microsoft Windows
  (progn
    (message "Microsoft Windows")))
 ((string-equal system-type "darwin") ; Mac OS X
  (progn
    (message "Mac OS X")))
 ((string-equal system-type "gnu/linux") ; linux
  (progn
    (message "Linux"))))

Find Emacs Version

The following variables returns emacs version number.

;; full emacs version number. A string.
emacs-version
;; sample value: "24.5.1"

;; A integer, emacs major version number.
emacs-major-version
;; sample value: 24

;; A integer, emacs minor version number.
emacs-minor-version
;; sample value: 5

Compare Version String

;; check emacs version
(if (version< emacs-version "24.4")
    (message "is before 24.4")
  (message "is 24.4 or after"))

Get Host Name, User Name, Init File Path

Here's some other useful elisp function or variable to determine machine name (host name), user name, emacs init path.

For detail, see:

Check If a Package is Loaded

Elisp: Check If a {function, variable, feature} is Defined/Loaded

Emacs Customization

  1. Emacs init file
  2. What's Major Mode
  3. What's Minor Mode
  4. M-x customize
  5. Organize Init File
  6. Byte Compile Elisp
  7. What's Hook
  8. Avoid Lambda in Hook
  9. Environment Variables in Emacs
  10. Check OS, Version, Host Name
  11. Check Defined/Loaded

packages

  1. Install Packages
  2. Install Package Manually

text editing

  1. Define Keys
  2. Tabs, Space, Indentation Setup
  3. Brackets electric-pair-mode
  4. Isearch space for - _
  5. Ido Completion
  6. Icomplete Completion
  7. Move Cursor by camelCase
  8. Stop Cursor Going into Minibuffer Prompt
  9. Sync Clipboard with Linux X11

file

  1. Default Major Mode
  2. Auto Backup Off
  3. Auto Save
  4. Restore Opened Files
  5. Save Cursor Position
  6. Dired Customization
  7. Open Recently Opened

appearance

  1. Show Line Numbers
  2. Show Cursor Position
  3. Visual Line Mode, Wrap Lines
  4. High Light Current Line
  5. Font Setup
  6. Show Formfeed ^L as Line
  7. Line Spacing
  8. Set Color Theme
  9. Highlight Brackets ()[]{}
  10. Show lambda as λ
  11. Color CSS Hex Code
  12. Default Window Size

misc

  1. Default Browser
  2. Misc Init Tips

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs

Emacs

Emacs Lisp

Misc