SGML for Windows NT: Setting up a free SGML/XML editing and publishing system on Windows/Cygwin | ||
---|---|---|
Prev | Chapter 5. Emacs | Next |
Unpack the archive
The emacs-21.1 archive contains directory information and long filenames, which both must be preserved when unpacking the files (see your unpacker help). Unpack the archive to your programs directory, e.g. C:\Programs. The unpacker will create the directory \emacs-21.1 in your programs directory with the subdirectories \bin, \etc, \info, \lisp, and perhaps the empty subdirectories \lock and \site-lisp. To save some typing I suggest to rename the emacs directory e.g. to \emacs211.
Create the \emacsen subdirectory
In order to make future updates of NTEmacs as painless as possible, it is useful to keep all Elisp and other files that you will add to your basic NTEmacs installation in a separate directory. Therefore create a sibling of the emacs directory like C:\Programs\emacsen. The trick is that you can add and remove future versions of NTEmacs without touching your local add-ons. You can even run a new version in parallel to your existing version to see whether some of your local add-ons break. In this new subdirectory, create the subdirectories \bin and \site-lisp.
Adjust PATH
Add the \emacs211\bin and \emacsen\bin directories to the PATH environment variable. This will let you start Emacs from the command line. In the control panel, select the "Environment" tab in the System dialog. Append the \bin directories, e.g. c:\Programs\emacs211\bin;c:\Programs\emacsen\bin to the PATH environment variable (this is a semicolon-separated list of directories) in the system variables panel (the upper one in WinNT, the lower one in Win2000) and press Set. Close the dialog by pressing Ok.
Create HOME
Every user on your NT/2000/XP box has to define an environment variable called HOME. This variable will let Emacs find the personal _emacs file. Depending on your system, HOME should point either to a local or a network home directory. The variable is set via the control panel. Select the "Environment" tab in the System dialog and create HOME in the user variables panel (the lower one in NT, the upper one in Win2000 - by now you should see the pattern. I'll leave it as an extra bit of brain jogging for the XP users to find out where the panel is on their systems). Set its value to the appropriate directory, e.g. c:\User\myself and press Set. You can also use %HOMEDRIVE%%HOMEPATH% as a value for HOME instead. Close the dialog by pressing Ok.
If you want to set up Emacs with a system-wide configuration file, set the HOME environment variable of your administrator account to an appropriate directory. After completing the whole SGML setup procedure from your administrator account, simply move the contents of the _emacs in your administrator home directory to one of the system-wide configuration files. This will be described at the end of this tutorial.
Set the load-path
Now you'll have to make the first customizations to the _emacs file. The variable load-path tells Emacs where to look for Lisp files. The following chunk of code should be pretty much at the top of your _emacs file as other packages depend on load-path.
;; append some additional paths to load-path (setq load-path (nconc load-path (list "C:/Programs/emacsen/site-lisp" "C:/Programs/emacsen/site-lisp/psgml-1.2.4"))) |
Adjust the paths as necessary. You could extend this list of paths for any additional Emacs Lisp packages that you install.
Note: This code adds the path of the PSGML package that we will install in the next chapter. Just keep in mind that we already took care of load-path at this point.
Teach Emacs about the Cygwin mount table
Move cygwin-mount.el into your \emacsen\site-lisp directory and byte-compile the file by running Alt-x byte-compile-file [Return] c:/programs/emacsen/site-lisp/cygwin-mount.el. This will create cygwin-mount.elc.
Add the following code to your _emacs file:
; make cygwin paths accessible (require 'cygwin-mount) (cygwin-mount-activate) |
Enable Cygwin symlinks
Add the following lines to your _emacs (the string with the many "\x000" is actually one long line which is wrapped here only for printing purposes; the regular expression after "re-search-forward" is also one long line):
;; follow cygwin symlinks. Handles old-style (text file) symlinks and new-style ;; (.lnk file) symlinks (defun follow-cygwin-symlink () (save-excursion (goto-char 0) (if (looking-at "L\x000\x000\x000\x001\x014\x002\x000\x000\x000\x000 \x000\x0C0\x000\x000\x000\x000\x000\x000\x046\x00C") (progn (re-search-forward "\x000\\([-A-Za-z0-9_\\.\\\\\\$%@(){}~!#^'`][-A-Za-z0-9_\\.\\\\\\$%@(){}~!#^'`]+\\)") (find-alternate-file (match-string 1))) (if (looking-at "!<symlink>") (progn (re-search-forward "!<symlink>\\(.*\\)\0") (find-alternate-file (match-string 1)))) ))) (add-hook 'find-file-hooks 'follow-cygwin-symlink) |
This function ensures that you load the file a Cygwin symlink points to, not the link file itself. Be aware that non-Cygwin-symlink .lnk files (like desktop shortcuts) are still loaded as such.
Use Unix-style line endings
When working with Cygwin it is generally a good idea to use Unix-style line endings (LF instead of CR/LF) in the files that you create with Emacs. The following code snippet sets this as the default (you can override this for individual files if you need to):
;; use Unix-style line endings (setq-default buffer-file-coding-system 'undecided-unix) |
Use bash as the default shell in Emacs
Add the following lines to your _emacs file and adjust the paths as necessary:
;; use bash as the default shell (setq exec-path (cons "C:/cygwin/bin" exec-path)) (setq shell-file-name "bash") (setenv "SHELL" shell-file-name) (setenv "PATH" (concat (getenv "PATH") ";C:\\cygwin\\bin")) (setq explicit-shell-file-name shell-file-name) (setq explicit-shell-args '("--login" "-i")) (setq shell-command-switch "-ic") (setq w32-quote-process-args t) (defun bash () (interactive) (let ((binary-process-input t) (binary-process-output nil)) (shell))) (setq process-coding-system-alist (cons '("bash" . (raw-text-dos . raw-text-unix)) process-coding-system-alist)) |