Setting up Emacs for Win32

article by michal wallace (sabren@manifestation.com)

Abstract

This is just a quick walkthrough of setting up Emacs for Win32. Every time I sit down at a new machine I want to set up Emacs. I used to spend at least ten minutes finding all the files I needed, and after the fifth time.. Well, it gets old. This page has all the steps for a quick, sensible [ie, my own :)] install. Your milage may vary.

Getting Emacs

First, get emacs for Win32:

I usually grab emacs-20.3.1-bin-i386.tar.gz. Download it and unzip it with WinZip or whatever you have handy.

It'll unzip to a directory that looks like emacs-20.3.1 or something. Rename and move it to c:\emacs.

Run c:\emacs\bin\addpm.exe to set up the shortcut on your desktop. (It might also do some registry and path stuff. Who knows? Just run it.)

Ispell

Ispell is the spell checker of choice for Windows. A guy named Brian Tibbets maintains the Win32 version of Ispell. Unfortunately, on the particular night I'm writing this, I'm having trouble connecting to his page, which is at:

Telnet

Yes, you can telnet from Emacs on Win32. You just need a telnet program that uses standard input and output streams as oppsosed to the windowed version that comes with Win32:

Then put the following in your c:\.emacs file:

;;;;;;;;;;;;;; TELNET STUFF ;;;;;;;;;;;;;;;;;;;;

(require 'telnet)
(setq telnet-program "c:/emacs/bin/telnet.exe")
(defun telnet (host)
  "Open a network login connection to host named HOST (a string).
   Communication with HOST is recorded in a buffer `*telnet-HOST*'.
   Normally input is edited in Emacs and sent a line at a time."
  (interactive "sOpen telnet connection to host: ")
  (let* ((comint-delimiter-argument-list '(?\  ?\t))
         (name (concat "telnet-" (comint-arguments host 0 nil) ))
		 (buffer (get-buffer (concat "*" name "*")))
		 process)
    (cond ((string-equal system-type "windows-nt")
		   (setq telnet-new-line "\n")))
    (if (and buffer (get-buffer-process buffer))
		(pop-to-buffer (concat "*" name "*"))
      (pop-to-buffer (make-comint name telnet-program nil host))
      (setq process (get-buffer-process (current-buffer)))
      (set-process-filter process 'telnet-initial-filter)
      (accept-process-output process)      (telnet-mode)
      (setq comint-input-sender 'telnet-simple-send)
      (setq telnet-count telnet-initial-count))))

Even though I do that, I don't use telnet mode very often because emacs doesn't seem to support VT-100 terminal emulation so I can't run programs like Pine (I could be wrong here). I much prefer Simpterm for telnet stuff.

c:\.emacs

Here's the rest of my c:\.emacs file:

;; Michal's c:\.emacs file

;;;;;; FONT LOCK CONFIGURATION ;;;;;;;;;;;;;;;;;;;;

(cond ((fboundp 'global-font-lock-mode) 

       ;; I like this one better.. 
       (set-background-color "navajo white")
       (setq font-lock-face-attributes
       ;; Symbol-for-Face Foreground Background Bold Italic Underline
	     '((font-lock-builtin-face       "DarkBlue")    ;; outline level 4
	       (font-lock-comment-face       "bisque4")  ;; outline level 5
	       (font-lock-constant-face      "DarkRed")
	       (font-lock-function-name-face "Blue")  ;; outline level 1
	       (font-lock-highlighting-face  "gray")
	       (font-lock-keyword-face       "RoyalBlue") ;; outline level 3
	       (font-lock-reference-face     "Medium Purple")
	       (font-lock-string-face        "Dark Violet")
	       (font-lock-type-face          "Black")
	       (font-lock-variable-name-face "firebrick") ;; outline level 2
	       (font-lock-warning-face       "darkolivegreen")
	       )))

       ;; Load the font-lock package.
       (require 'font-lock)
       ;; Maximum colors
       (setq font-lock-maximum-decoration t)
       ;; Turn on font-lock in all modes that support it
       (global-font-lock-mode t)))



;;
;; ispell4:
;;
(autoload 'ispell-word "ispell4" 
  "Check spelling of word at or before point" t)
(autoload 'ispell-complete-word "ispell4" 
  "Complete word at or before point" t)
(autoload 'ispell-region "ispell4" 
  "Check spelling of every word in the region" t)
(autoload 'ispell-buffer "ispell4" 
  "Check spelling of every word in the buffer" t)
(setq ispell-command "c:/emacs/ispell4/exe/ispell.exe"
      ispell-look-dictionary "c:/emacs/ispell4/ispell.words"
      ispell-look-command "c:/emacs/ispell4/exe/look.exe"
      ispell-command-options (list "-d" "c:/emacs/ispell4/ispell.dict"))



;; python
(setq auto-mode-alist
      (cons '("\\.py$" . python-mode) auto-mode-alist))
(setq interpreter-mode-alist
      (cons '("python" . python-mode)
            interpreter-mode-alist))
(autoload 'python-mode "python-mode" "Python editing mode." t)


;; timestamp stuff:
(defun insert-datestamp()
	   "Insert the current date in mmdd.yyyy format."
	   (interactive "*")
	   (insert (format-time-string "%m%d.%Y" (current-time))))
(global-set-key "\C-ct" 'insert-datestamp)




;;;;;;;;;; OUTLINE MODE STUFF ;;;;;;;;;;;;

;; this next line lets you do outlines like this:
;;
;; * one
;;   * two 
;;     * three
;;
;; instead of:
;;
;; * one
;; ** two 
;; *** three

(setq outline-regexp "[ \t]*[*]")

;;;;;;; associate with *.out ;;;;
(setq auto-mode-alist
	  (append 
	   '(("\\.out$" . outline-mode))
	   auto-mode-alist))

;;;;;;;;;; misc stuff ;;;;;;;;;;;;;;;;;;;

;; tab size
(setq default-tab-width 4)


;; allow command.com to work on windows
(setq process-coding-system-alist
     '(("cmdproxy" . (raw-text-dos . raw-text-dos))))



;; column number mode
(column-number-mode t)

;; allow narrow-to-region command
(put 'narrow-to-region 'disabled nil)


;; finally, load my main file..
(find-file "w:/notes.out")
(beginning-of-buffer)
(outline-next-visible-heading 1)
(hide-other)
(hide-subtree)


;; eof 

More Info

The official GNU Emacs for Win32 page/FAQ