06.11.07

Customizing Emacs

Posted in How To, Intermediate, Linux, Mac, Windows at 11:24 am by Techie

What’s your favorite editor? Oh, I’m sorry, the correct answer should be emacs. Actually, you should use whatever editor you feel most comfortable with; I’ve just found the ability to record keyboard macros in emacs to be indispensable, all the more so since I’ve been using it for almost ten years. Be I writing on Linux, Windows, or Mac OS X, my preferred text editor is still emacs.

However, once I get on a new machine, I need to customize .emacs, which is the startup configuration file. There are a series of changes that I find quite useful, and often find myself looking up again and again. Without further ado, here are the customizations:

;; Emacs usually has a slash screen on startup.  Let's get rid of that and start with a blank buffer.
(setq inhibit-startup-message t)

;; I like to see what is selected in the buffer.  This turns on visual feedback on selections.
(setq transient-mark-mode t)

;; Activate font-lock mode (syntax coloring).
(global-font-lock-mode t)

;; Line numbers are good.  Getting column numbering as well is better.
(column-number-mode t)

;; Scrollbars go on the right.  Who puts these on the left?
(set-scroll-bar-mode 'right)

;; Enable mouse wheel scrolling.
(if (load "mwheel" t)
    (mwheel-install))

;; Always end files in anewline.
(setq require-final-newline 't)
;; ...or ask to end in newline if needed
; (setq require-final-newline 'query)

;; Match parentheses.  Useful to be sure you've closed everything up.
(show-paren-mode t)

; Display settings
; default size and color options for all frames.
(setq default-frame-alist
 '(
; frame width and height
    (width             . 80)
    (height            . 40)
  ;;;; foreground, background, and cursor colors
  ;;;    (foreground-color  . "grey8")
  ;;;    (background-color  . "grey92")
  ;;;    (cursor-color      . "red3")
  )
)
; places top left corner of initial frame at location (25,25) on screen
(setq initial-frame-alist
 '(
    (top               . 25)
    (left              . 25)
  )
)

; Temporary files cluttering up the space are annoying.  Here's how we
; can deal with them -- create a directory in your home directory, and
; save to there instead!  No more random ~ files.
(defvar user-temporary-file-directory
  "~/.emacs-autosaves/")
(make-directory user-temporary-file-directory t)
(setq backup-by-copying t)
(setq backup-directory-alist
      `(("." . ,user-temporary-file-directory)
        (tramp-file-name-regexp nil)))
(setq auto-save-list-file-prefix
      (concat user-temporary-file-directory ".auto-saves-"))
(setq auto-save-file-name-transforms
      `((".*" ,user-temporary-file-directory t)))

I additionally have some macros that aren’t generally useful. There’s a million things to tweak in the customization, and if you’re fancy, you can even write your own hacks — better brush up on that lisp! Here are a few more resources of interest:

1 Comment »

  1. Sonic said,

    May 3, 2008 at 6:01 pm

    Thank you for this great emacs config file. I found it via Google and it solved my problem to put the scrollbar to the left. Who puts them on the left, you ask? Well, if you’re a left-handed tablet PC user, you do. Otherwise your hand obstructs the view while scrolling. ;)

Leave a Comment

Bad Behavior has blocked 312 access attempts in the last 7 days.