Sams Teach Yourself Emacs in 24 Hours |
|||||||||||||||||
Hour 2: Using Emacs in Microsoft Windows |
|||||||||||||||||
|
Many Emacs users use multiple computers, often with different operating systems. They use Emacs on all of them in order to provide a consistent interface (as well as to get an excellent editor). It is nice to use one .emacs on all your computers. You usually know which computer you are working on (although with X on UNIX, it isn't always easy). But Emacs has to be told which computer it is on so that it can select attributes and variables specific to each computer.
There is a routine on the CD-ROM in the file what-env.el you can use to tell which environment you are running on. It sets a variable, what-env (short for what environment? ). If you installed Emacs from the CD-ROM, it is in your site-lisp directory. To use it, put the following line into your .emacs file:
(load "what-env")
With what-env in place, if you want to know your environment, you can test for the contents of what-env. For example, on Windows 95, if Emacs displays the time in the mode line, the screen saver never kicks in. This code sets up the time display. However, by first testing what-env for Windows 95, you avoid running the time display on Windows 95. You can use this skeleton to customize your .emacs file for different computers.
; Don't display the time on W95. I have problems w/ this interfering ; with my screen saver/monitor power control SW on w95. NT 4 seems to ; be OK. You need this to enable the appointment notification. (if (not (string-equal what-env "Windows_95")) (progn (setq display-time-24hr-format t) (setq display-time-day-and-date t) (display-time) (message "Time display running!")))
You also might need to examine which version of Emacs you are running. You saw one example of this already with the font-lock fix earlier in this hour:
(when (and (= emacs-major-version 20) (= emacs-minor-version 3)) (let ((emacs-minor-version 2)) (require 'lazy-lock)))
This code looks at the Emacs major and minor version numbers. Only on 20.3 will it execute the next two lines. Another reason to know the version is that a lot of Windows variables are win32-x under Version 19, and w32-x for version 20 and up. You can test for each version, or you can test for one or the other. The following phrase of elisp evaluates to t on Windows regardless of the version of Emacs.
(or (eq window-system 'w32) (eq window-system 'win32))
The following line of code evaluates to w32, win32, or nil, as appropriate:
(memq window-system '(win32 w32))
The computer name is often the only way to tell which of several identical machines you are running on. The following phrase tells you whether Emacs is running on Windows 95 and on the computer named LAPTOP:
(if (and (string-equal what-env "Windows_95") ; do this if on the.span class=compcode>laptop & running w95 (string-equal system-name "LAPTOP")) blah, blah, blah... )
Sams Teach Yourself Emacs in 24 Hours |
|||||||||||||||||
Hour 2: Using Emacs in Microsoft Windows |
|||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.