Elisp: Determine OS, Emacs Version, Machine Host Name
The following are useful for setting up emacs init file on different machines.
Get 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"))))
Get Emacs Version
The following variables returns emacs version number.
- emacs-version (a dotted string)
- emacs-major-version (a integer type)
- emacs-minor-version (a integer type)
;; 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
version=version<version<=
;; 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.
system-name→ returns the host name.user-login-name→ returns user login name.- user-emacs-directory → init file dir.
- user-init-file → init file path.
For detail, see:
Check If a Package is Loaded
See: Elisp: Check If a {function, variable, feature} is Defined/Loaded.
Emacs Customization
- How to Set Emacs's User Interface
- Emacs: How to Install Packages Using ELPA, MELPA
- How to Install Emacs Package Manually
- Emacs: How to Define Keys
- Emacs: M-x customize Tutorial
- Emacs: Set File to Open in a Major Mode
- Emacs: Organize Init File
- Emacs: Byte Compile Elisp Files
- Emacs: What's Hook?
- Emacs: Set Environment Variables within Emacs
- Elisp: Determine OS, Emacs Version, Machine Host Name
- Elisp: Check If a {function, variable, feature} is Defined/Loaded
- Emacs: Set Default Window (frame) Size
- Emacs: Font Setup
- Emacs: Set Color Theme
- Emacs: Save Cursor Position
- Emacs: Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files
- Emacs: Stop Cursor Going into Minibuffer Prompt
Liket it? Put $1 at
patreon.
Or Buy Xah Emacs Tutorial. Thanks.