.emacs - Customization


What is the .emacs File?

When Xemacs (and Emacs for that matter) starts up it looks for a file in your home directory called ".emacs" (note the leading dot - thus it is a hidden file).

This file contains user specific information and customizations to the Xemacs/Emacs editors. You can setup this file to do all sorts of customizations from building additional menu bars to highlighting to utility functionality.

There are 2 ways of going about customizing Xemacs/emacs...

  1. Manually edit this configuration file - this requires some knowledge of the language used to configure the editor and requires the user to manually edit the ".emacs" file.
  2. Save configuration changes from within the editor - or you can save the changes from within the editor itself, and it knows about the language used and writes out settings automatically to the ".emacs" file.

I find that I tend to use a mixture of both manual and automatic editing of the ".emacs" file.


Sample CMSC 201 .emacs File

This is the sample .emacs file that we were distributing in CMSC 201...

(custom-set-faces)
(global-set-key "\C-h" 'delete-backward-char)
(global-set-key "\C-x?" 'help-command)

;; set style to "Ellemtel" for C++

(add-hook 'c++-mode-hook
          '(lambda ()
             (c-set-style "ellemtel")))



;; set style to "Ellemtel" for C

(add-hook 'c-mode-hook
          '(lambda ()
             (c-set-style "ellemtel")))

;; special effects for 'C'
(add-hook 'c-mode-hook 'turn-on-font-lock)

My Emacs .emacs File

I have some more stuff in my emacs file...

;; no tabs please
(setq-default indent-tabs-mode nil)
(setq default-tab-width 4)

;; line & col nums
(setq line-number-mode t)
(setq column-number-mode t)

;; font coloring
(setq font-lock-auto-fontify t)
(setq font-lock-mode-maximum-decoration t)
(require 'font-lock)

;; my email
(custom-set-variables
 '(user-mail-address "your_username_here@umbc.edu" t)
 '(query-user-mail-address nil))

;; some key bindings
(global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word))))
(global-set-key [f2] 'ispell-word)

;; map that mouse wheel
(global-set-key [button4] 'scroll-down)
(global-set-key [button5] 'scroll-up)

;; automatic indentation upon return
(global-set-key [(return)] 'newline-and-indent)

;; stop beeping
(setq visible-bell 1)

;; makre sure that every file has a newline
(setq require-final-newline t)

Daniel J. Hood
Last modified: Wed Oct 13 17:02:45 EDT 2004