I recently accidentally lost my .emacs file which I'd tweaked and put together over the last 5 years. I though this would be a good chance to ask you, what's in your .emacs file?
I have an emacs.d, which is a superior alternative to a .emacs.
The basic init.el file loads my various language modes, and some other minor modes (e.g., tempbuf-mode). It also loads a bunch of files from the "emacs.d/my_lisp" directory which contains various overrides and new functionality attached to existing modes (e.g., icicles customization, assorted one-off functions I want to add to modes). Lastly, it loads a bunch more files from my emacs.d/lisp directory which implement custom functionality.
For example, the current emacs M-x eshell doesn't behave the way I like. I often want multiple shells, so I've build a "ring of shells" functionality: f6 cycles through the ring of shells, C-f6 creates new shell window in the ring. I did something similar with window configurations.
Also, the emacs.d stores all modes which I use regularly. So when I migrate to a new computer, all I need to do is
Lots of cruft (roughly 10 years worth), although I did recently start to refactor.
Most notable: it's fairly portable and relocatable, thanks to a snippet I cooked up (probably not original, but I haven't seen it else-where):
http://everythingtastesbetterwithchilli.com/initialisation-f...
(check it out anywhere and just symlink init.el to ~/.emacs, it figures out all paths from there. It'll also load platform-specific code, if you need that).
I try and make it lazier by combining autoload and eval-after-load, which helps with startup time.
On an organisational point (still work to be done here!), init.el mostly just loads a bunch of other files, which are roughly grouped by task or mode. Github has been a huge boon, combined with submodules to track a lot of third-party extensions.
I don't change many key bindings (most notable is the Yegge-suggested C-w for backward-kill-word), but I do have a /lot/ of extensions installed. I'm a fairly heavy user, although almost exclusively as an editor (+ lisp or python interaction, etc) -- I don't use it as a mail client, browser, or anything along those lines. The furthest away I get is the occasional twitter or IRC usage.
Clone that as your emacs.d, add a .el file named the same as your logged in user, and add your specific preferences there. (I like to have it include stuff in a jmhodges directory in emacs.d, of course.)
You'll want to check out dotfiles.com also, btw. I considered putting this in a separate link, but thought that since you asked, it wouldn't be too terrible to post here. There are a few things I include in every .emacs file I have across multiple shell accounts, and this is more or less the entirety of it:
;; how emacs behaves generally
(setq scroll-step 1)
(setq next-line-add-newlines nil)
(setq search-highlight t)
(setq-default indent-tabs-mode nil)
;; some niceties on the status bar
(display-time)
(setq column-number-mode t)
(setq line-number-mode t)
;; other shortcuts
(global-set-key "\C-^" 'enlarge-window)
(global-set-key "\C-c\C-w" 'compare-windows)
;; fix broken backspace
(global-set-key "\b" 'backward-delete-char)
(global-set-key "\C-xt" 'term)
;; UTF-8 goodness
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
;; I'm into Perl, but prefer cperl-mode over the default
(defun modify-alist (alist-symbol key value &optional search-cdr)
(let ((alist (symbol-value alist-symbol)))
(while alist
(if (eq (if search-cdr
(cdr (car alist))
(car (car alist))) key)
(setcdr (car alist) value)
(setq alist (cdr alist))))))
(modify-alist 'interpreter-mode-alist 'perl-mode 'cperl-mode t)
(modify-alist 'auto-mode-alist 'perl-mode 'cperl-mode t)
;; the one true indentation level
(setq cperl-indent-level 4)
;; Don't mix tabs and spaces
(setq-default indent-tabs-mode nil)
;; Use "newline-and-indent" when you hit the Enter key so
;; you don't need to keep using TAB to align each line.
(global-set-key "\C-m" 'newline-and-indent)
;; Get rid of the <2> with duplicate file names
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
And then a whole bunch of autoload statements for different programming languages.
;; Use "newline-and-indent" when you hit the Enter key so
;; you don't need to keep using TAB to align each line.
(global-set-key "\C-m" 'newline-and-indent)
I used to set transient-mark-mode to t myself. But being able to set a mark and use C-xC-x to switch the cursor and the mark point is too powerful. It allows you to set a mark, go edit something else, and then go back to where you were.
Granted, you could probably do that with transient mark mode, but seeing everything highlighted would be too annoying.
You can do the same thing with bm.el, but you also get multiple bookmarks (visible in the buffer) which you can then cycle through. I find it helpful to have bookmarks and the region decoupled.
My emacs setup consists of several files, a structure that I shamelessly copied from one and only Stevey Yegge, a true emacs fanatic.
Now, I used to work for Google and most people there let you see their own home directories and I used that as an opportunity to learn from Stevey's setup.
There are a lot of customization going on and I should do a separate blog post about the setup. Here are I just cherry-picked some recent configuration favorites of mine:
;;
;; Superb way to move between Emacs windows
;; Shift+arrow keys
(windmove-default-keybindings)
;; Resize emacs according to the display resoluton
(defun set-frame-size-according-to-resolution ()
(interactive)
(if window-system
(progn
(if (> (x-display-pixel-width) 1900)
(add-to-list 'default-frame-alist (cons 'width 260))
(add-to-list 'default-frame-alist (cons 'width 80)))
(add-to-list 'default-frame-alist
(cons 'height (/ (- (x-display-pixel-height) 50) (frame-char-height))))
(add-to-list 'default-frame-alist
(cons 'top 10))
(add-to-list 'default-frame-alist
(cons 'left 5)))))
Near as I can tell, there is only one reason not to simply rebind C-x C-f to anything-for-files: it doesn't create files. That's fixable:
(defun anything-for-files-create-if-not-found ()
"Just like anything for files, but gives the option to create a file."
(interactive)
(anything '(anything-c-source-ffap-line
anything-c-source-ffap-guesser
anything-c-source-regular-filename-completion
anything-c-source-recentf
anything-c-source-file-not-found
anything-c-source-buffers+
anything-c-source-bookmarks
anything-c-source-file-cache
anything-c-source-files-in-current-dir+
anything-c-source-mac-spotlight)))
Probably my favorite bit of the config is that it uses flymake to run Pyflakes on my Python code as I'm writing it. I also have a little plugin that shows the error in the minibuffer area when the point is over the offending line.
It also disables backup/autosave file littering by using a locked down directory in /tmp.
As far as bindings go, I wrote delete-backward-indent for python-mode which deletes a level of indentation instead of just one space. There's also newline-maybe-indent that doesn't indent if the previous line has no indentation.
Everything else is pretty straightforward customization, I think. flyspell-prog-mode is another thing worth mentioning: it highlights spelling errors, but only in strings and comments.
Apart from the usual utilities, I've got an emacs-lisp version of write-or-die; it deletes words if you stop typing for more than a few seconds. It's an excellent motivator for first drafts.
rebindings are useful, such ctrl-q for M-x goto-line:
(global-set-key "\C-q" 'goto-line)
I cribbed the following from someone else, but i find it most awesome:
; ===== Put auto-save, backup files in one place ===
;; Put autosave files (ie #foo#) in one place, not
;; scattered all over the file system!
(defvar autosave-dir
(concat "/Users/diN0bot/.emacs.d/auto-save-list/"))
;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
(defvar backup-dir (concat "/Users/diN0bot/.emacs.d/backup-file-list/"))
(setq backup-directory-alist (list (cons "." backup-dir)))
Regarding newlines: in Emacs 23, I recommend visual-line-mode over auto-fill-mode, unless you actually need hard line breaks. For when you do want hard newlines, (setq-default fill-column 80). I never understood why the default is 72; it makes text files excessively narrow.
The default is 72, in my understanding, because of the historical use of email.
As folks successively quote each other in a thread, the prepending of '>' to the quoted text requires something narrower than 80, else it'll hit the 80-chars-wide limit and wrap.
72 would allow 4 or 8 quote-levels, depending on if your client decides to insert spaces around the '>'.
178 lines of crap accumulated over about 20 years. I think I only use an indent variable setting, one key binding, and a handful of language autoloads.
One of the things I started doing lately is not moving any dotfiles automatically when I get a new machine. After 3 days of moaning, I go and dig out just the stuff that I have noticed I am missing. (I do the same for firefox plugins and so on). It has definitely helped with the historical crud.
Yeah it really forces you to look into those dotfiles you haven't read in two years, or that hack script you banged out in 5 minutes, and give them all a bit of thought. That "Just get it into my PATH so I can try it out!" impulse has definitely gotten the better of me a number of times.
ditto. I recall spending many late nights optimizing my dot emacs file and it accumulated tons of cruft. Now it is very abbreviated, wait no that was a dream - Just looked at it, still tons of junk that I don't use. Most of what I use is buffer saving (desktop), hot-keys, turn off scrollbars, and mapping odd file extension to modes. Guess I should go through and clean house again.
(setq slime-multiprocessing t)
;; choose one of the below based on Express or non-Express usage
;(setq slime-lisp* "alisp.exe")
(setq slime-lisp "allegro.exe")
The basic init.el file loads my various language modes, and some other minor modes (e.g., tempbuf-mode). It also loads a bunch of files from the "emacs.d/my_lisp" directory which contains various overrides and new functionality attached to existing modes (e.g., icicles customization, assorted one-off functions I want to add to modes). Lastly, it loads a bunch more files from my emacs.d/lisp directory which implement custom functionality.
For example, the current emacs M-x eshell doesn't behave the way I like. I often want multiple shells, so I've build a "ring of shells" functionality: f6 cycles through the ring of shells, C-f6 creates new shell window in the ring. I did something similar with window configurations.
Also, the emacs.d stores all modes which I use regularly. So when I migrate to a new computer, all I need to do is
and tweak a few settings.