Wednesday, June 01, 2011

Share the same elisp directory between Win32 Emacs and Cygwin Emacs

Do you use Win32 Emacs as well as Cygwin Emacs? I launch Emacs (Win32 or Cygwin) from within a Cygwin shell. Therefore, my my Emacs configuration file is ~/.emacs. The following block of code allows me to share the same elisp directory for both Win32 Emacs and Cygwin Emacs.

(defconst win32-emacs
  (eq system-type 'windows-nt)
  "Are we running Emacs for Windows")

(defconst windows-host
  (and (getenv "OS") (string-match "Windows" (getenv "OS")))
  "Are we running from Windows")

(defconst win32-emacs_on_windows
  (and win32-emacs windows-host)
  "Are we running W32 Emacs launched from windows?")

(defconst username (getenv "USERNAME"))

(if win32-emacs_on_windows
  (defvar elisp-path
    (expand-file-name
      (concat "c:/cygwin/home/" username "/elisp")))
  (defvar elisp-path (expand-file-name "~/elisp"))
)

2 comments:

Sue D. Nymme said...

I use init.el only for platform-specific customizations, such as paths. All of my elisp functions, key bindings, mode customizations, etc are stored in a separate file ("my-init.el"), which I store in my Dropbox.

So the standard init.el simply sets up load-path to the platform-specific location of my Dropbox, then calls (require 'my-init). It's beautiful simplicity, and when I make a change at one location (say, at home), it is immediately reflected everywhere else (say, at work).

tsengf said...

Thanks for the suggestion. Does Dropbox work behind a http proxy? I use a custom rsync script to synchronize between systems.