Configuring Emacs

Emacs can be configured to your own habits through a custom configuration file located in your home directory, ~/.emacs. There are a ton of things you can do here, but below are a few must-haves of my own that I encourage you to consider. At the very least, I hope you will make a .emacs file of your own and remember that you can customize to your heart's content later on. A google search on this topic will turn up a lot.

An example bare-bones configuration file    [top]

Below is a bare-bones file derived from my own .emacs file. If you have no configuration file of your own, this isn't a bad place to start. It hase a few features I cannot live without, and I'll discuss those. But for now just get the below file and call it .emacs and put it in your home directory. Or you can just use wget:

  $ cd
  $ wget http://oceanai.mit.edu/ivpman/docs/.emacs

Here's the file.

 ;; A bare-bones .emacs configuration file. 

 ;; Set up the keyboard so the delete key on both the regular keyboard
 ;; and the keypad delete the character under the cursor and to the right
 ;; under X, instead of the default, backspace behavior.
 (global-set-key [delete] 'delete-char)
 (global-set-key [kp-delete] 'delete-char)
 (global-set-key [home] 'beginning-of-buffer)

 ;; Always end a file with a newline
 (setq require-final-newline t)

 ;; Stop at the end of the file, not just add lines
 (setq next-line-add-newlines nil)

 ;; Set the fill column width - used in auto-filling
 (setq fill-column 80)

 ;; An absolute must-have in my book 
 (define-key ctl-x-map "\C-b" 'electric-buffer-list)

 (define-key esc-map "g" 'goto-line)

 (global-set-key "\M-t" 'beginning-of-buffer)
 (global-set-key "\M-b" 'end-of-buffer)
 (global-set-key "\M-i" 'overwrite-mode)

 (defun scroll-one-line-ahead ()
   "Scroll ahead one line."
   (interactive)
   (scroll-up 1))

 (defun scroll-one-line-behind ()
   "Scroll behind one line."
   (interactive)
   (scroll-down 1))

 ;; Useful for toggling between .h and .cpp files of a C++ class
 (global-set-key "\M-o" 'ff-find-other-file)

 (global-set-key [M-down] 'scroll-one-line-ahead)
 (global-set-key [M-up]   'scroll-one-line-behind)

Electric Buffer List    [top]

To switch between the currently open file to another file in emacs, one normally types C-x, C-f, and types in the new file name. This gets cumbersome, especially if you're going back and forth between files. The electric buffer list refers to list of files already opened by the user during the current emacs session. To switch files, you can type C-x, C-b and you will notice the window switches temporarily to a list of already-opened files. You can use the up and down arrow keys to select the file you want to jump to, and hit Enter. The screen then returns to the contents of the newly selected file.


Document Maintained by: mikerb@mit.edu        
Page built from LaTeX source using texwiki, developed at MIT. Errata to issues@moos-ivp.org. Get PDF