MBR | 22 May 2012 06:31
Favicon

.emacs file(s) for multiple versions of Emacs on Windows

After way too long, I'm finally getting around to upgrading from Emacs 21.3.1 to Emacs 23.4.1.  I downloaded the precompiled Windows version from http://ftp.gnu.org/pub/gnu/emacs/windows/emacs-23.4-bin-i386.zip, unpacked it, and created a Windows shortcut to bin/runemacs.exe.  The OS is Windows XP SP3.

When I start up the new version, it finds that I've got an initialization file at C:/.emacs, and it looks like some of the Lisp code that works under 21.3.1 no longer works under 23.4.1.  For the moment I want to keep both versions installed.  Is there some way to have the different versions initialize themselves from different .emacs files?  Alternatively, is there some Lisp code I can insert to test which version of Emacs is running, so I can conditionalize the code to do the right thing for each version?
Mark Rosenthal
mbr <at> arlsoft.com

Eli Zaretskii | 22 May 2012 06:51
Picon

Re: .emacs file(s) for multiple versions of Emacs on Windows

> Date: Tue, 22 May 2012 00:31:53 -0400
> From: MBR <mbr <at> arlsoft.com>
> 
> Is there some way to have the different versions initialize
> themselves from different .emacs files?

Not easily (you could make a batch file for each version that sets
HOME in the environment as appropriate for each version, but that's
ugly and will probably bite you down the road, as HOME is used for
more than just .emacs).

> Alternatively, is there some Lisp code I can insert to test which
> version of Emacs is running, so I can conditionalize the code to do
> the right thing for each version?

  (if (>= emacs-major-version 23) ...

David J. Biesack | 22 May 2012 18:46
Picon
Favicon

Re: .emacs file(s) for multiple versions of Emacs on Windows


> Is there some way to have the different versions initialize
> themselves from different .emacs files?

I use the following in my ~/.emacs:

(defun optional-load-library (name)
  "Optionally load a library from a NAME. If NAME is null, do nothing."
  (when name
    (setq name (downcase name))
    (condition-case err
        (and (file-exists-p (concat (getenv "HOME") "/emacs/" name ".el"))
             (load-library name)
             (message "loaded optional library %s" name))
      (error (message err)))))

  (optional-load-library (format "my-emacs%d" emacs-major-version)) ;; my-emacs21.el or
my-emacs22.el my-emacs23.el

and put version-specific elisp in each of those files (i.e. my-emacs23.el )

I do something similar for window-system and even specific hosts:

  (optional-load-library (symbol-name window-system)) ;; w32.el or win32.el or x.el
  (optional-load-library (symbol-name system-type))
  (optional-load-library (or (getenv "HOSTNAME") (getenv "HOST") (getenv "COMPUTERNAME")))

djb

--

-- 
David J. Biesack | Principal API Architect | SAS
 <at> davidbiesack | 919-531-7771 | www.sas.com


Gmane