Determine OS Type (Windows/Mac/Linux) in Emacs

Determine OS Type (Windows/Mac/Linux) in Emacs

Many of us work with several operating systems. When you write your emacs customization (the 〔.emacs〕 file), sometimes you need to know what OS you are on. Here's how to do it.

;; make the mouse 5th button (forward button) do close buffer.
 ((string-equal system-type "windows-nt") ; any flavor of Windows
  (global-set-key (kbd "<mouse-5>") 'close-current-buffer)
 ((string-equal system-type "gnu/linux")
  (global-set-key (kbd "<mouse-9>") 'close-current-buffer)
 ((string-equal system-type "darwin") ; Mac
  (global-set-key (kbd "<mouse-5>") 'close-current-buffer) )

For some odd reason, if you have a 5-button mouse, the 5th button (aka “forward button”) in emacs has syntax <mouse-5>, but on Ubuntu 10.04 Linux, it's <mouse-9>. On Windows and Mac, scrolling mouse wheel down is <wheel-down>, but in linux it's <mouse-5>. (you can find out the syntax of a mouse button/wheel by calling “describe-key” then press a button or wheel.)

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs