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.<p>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.<p>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.<p>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<p><pre><code> darcs get me@oldbox:emacs.d
</code></pre>
and tweak a few settings.
<a href="http://github.com/markhepburn/dotemacs" rel="nofollow">http://github.com/markhepburn/dotemacs</a><p>Lots of cruft (roughly 10 years worth), although I did recently start to refactor.<p>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):
<a href="http://everythingtastesbetterwithchilli.com/initialisation-file-portability-tweaks" rel="nofollow">http://everythingtastesbetterwithchilli.com/initialisation-f...</a>
(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).<p>I try and make it lazier by combining autoload and eval-after-load, which helps with startup time.<p>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.<p>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.<p>While I'm rambling: I'd like to make all my key-binding specifications consistent. Currently I have a mix of string specifications, vectors, kbd macros, etc. Does anyone know what the canonical approach is these days? Extra reference: <a href="http://www.nongnu.org/emacs-tiny-tools/keybindings/" rel="nofollow">http://www.nongnu.org/emacs-tiny-tools/keybindings/</a>
and <a href="http://www.emacswiki.org/emacs/KeyBindingNotation" rel="nofollow">http://www.emacswiki.org/emacs/KeyBindingNotation</a>
I wrote a long article and at the last paragraph, I decided to edit a sentence, I selected the "region" and pressed C-w to remove it :-(<p>For uninitiated, C-w is "yank text", i.e. cut it, and Firefox it is "close current tab without warning".
I am completely surprised no one has linked to technomancy's emacs-start-kit: <a href="https://github.com/technomancy/emacs-starter-kit" rel="nofollow">https://github.com/technomancy/emacs-starter-kit</a><p>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.)<p>On that note, my own fork of it with very minor personal changes: <a href="https://github.com/jmhodges/emacs-starter-kit" rel="nofollow">https://github.com/jmhodges/emacs-starter-kit</a>
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 <i>too</i> 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:<p><pre><code> ;; 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)</code></pre>
I only periodically experiment with Emacs as my day-to-day editor, but my configuration isn't too shabby: <a href="http://github.com/al3x/emacs" rel="nofollow">http://github.com/al3x/emacs</a>
Most important:<p><pre><code> ;; 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)
</code></pre>
And then a whole bunch of autoload statements for different programming languages.
Pretty new to emacs, so my first move was to make it more familiar and avoid breaking my fingers:<p>;; Switch buffer<p>(global-set-key [f5] 'buffer-menu)<p>;; Save and load<p>(global-set-key [f2] 'save-buffer)<p>(global-set-key [f3] 'find-file)<p>;; Compile file<p>(global-set-key [f9] 'slime-compile-and-load-file)<p>;; Goto line<p>(global-set-key "\M-l" 'goto-line)<p>;; Go to other window<p>(global-set-key (kbd "<C-tab>") 'other-window)<p>;; And probably the most useful one, numpad Enter for eval line:<p>(global-set-key (kbd "<kp-enter>") 'slime-eval-last-expression)
Some key ones<p>(setq transient-mark-mode t) ; visually show region<p>(setq line-number-mode t) ; show line numbers<p>(setq global-font-lock-mode 1) ; everything should use font<p>(windmove-default-keybindings) ; shift-arrow key moves to window in that direction<p>I set up `webjump' to search online API documentation<p><a href="http://justinsboringpage.blogspot.com/2009/05/emacs-searching-programming-apis-with.html" rel="nofollow">http://justinsboringpage.blogspot.com/2009/05/emacs-searchin...</a><p>I like to send gmail<p><a href="http://justinsboringpage.blogspot.com/2009/02/sending-mail-with-emacs-in-windows.html" rel="nofollow">http://justinsboringpage.blogspot.com/2009/02/sending-mail-w...</a><p>I think this is the most important one<p>(setq visible-bell t) ; annoying beeps off
I work mostly inside git repositories, so this has been really valuable for scoping commands to the current repository:<p><pre><code> (defun my-git-root ()
(if buffer-file-name
(let* ((current-directory (file-name-directory buffer-file-name))
(git-directory (concat current-directory ".git")))
(while (and
current-directory
(not (file-exists-p git-directory)))
(setq current-directory (file-name-directory (substring current-directory 0 -1)))
(setq git-directory (concat current-directory ".git")))
current-directory)))
</code></pre>
I also hated editing system files until I added this function, which I almost definitely cribbed from somewhere:<p><pre><code> (defun sudo-find-file (file-name)
(interactive "FFind file (sudo): ")
(find-file (concat "/sudo::" file-name)))
</code></pre>
I got sick of having to context-switch to the browser when I needed to do a quick search, which is where these come in:<p><pre><code> (defun go-to-doc (base-url)
(let ((default (symbol-name (symbol-at-point))))
(browse-url (concat base-url (read-string "Search term: " nil nil default)))))
(defun rails-doc ()
(interactive)
(go-to-doc "http://apidock.com/rails/search?query="))
(defun ruby-doc ()
(interactive)
(go-to-doc "http://apidock.com/ruby/search?query="))
</code></pre>
I really, really hope package.el is built-in soon:<p><pre><code> (when
(load
(expand-file-name "~/.emacs.d/elpa/package.el"))
(package-initialize))
</code></pre>
and by far the most important line in the whole file:<p><pre><code> (server-start)</code></pre>
My emacs setup consists of several files, a structure that I shamelessly copied from one and only Stevey Yegge, a true emacs fanatic.<p>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.<p>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:<p><pre><code> ;;
;; 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)))))</code></pre>
I use anything: <a href="http://www.emacswiki.org/emacs/Anything" rel="nofollow">http://www.emacswiki.org/emacs/Anything</a><p>And then I have this in my .emacs:<p><pre><code> (require 'anything-config)
(global-set-key "\C-c\C-a" 'anything)
(global-set-key "\C-c\C-e" 'anything-for-files)
</code></pre>
I try to get in the habit of using C-cC-e instead of C-xC-f or C-x b. Anything is just too useful as a file/buffer finder.
<a href="http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs" rel="nofollow">http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs</a><p><a href="http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs.d/plugins/" rel="nofollow">http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs.d/pl...</a><p>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.<p>It also disables backup/autosave file littering by using a locked down directory in /tmp.<p>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.<p>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.
i put third party .el files in .emacs.d and then set the load path in the first line of my .emacs file<p><pre><code> (setq load-path (append load-path (list "/Users/diN0bot/.emacs.d")))
</code></pre>
some useful .el's
auto-save-list/ highlight-current-line.el
auto_save_list/ psvn.el
backup-file-list/ pycomplete.el
cpp-font-lock.el python-mode.el
django-mode.el vc-.el
doctest-mode.el zenburn.el<p>rebindings are useful, such ctrl-q for M-x goto-line:
(global-set-key "\C-q" 'goto-line)<p>I cribbed the following from someone else, but i find it most awesome:<p>; ===== Put auto-save, backup files in one place ===<p>;; Put autosave files (ie #foo#) in one place, <i>not</i>
;; scattered all over the file system!
(defvar autosave-dir
(concat "/Users/diN0bot/.emacs.d/auto-save-list/"))<p>(make-directory autosave-dir t)<p>(defun auto-save-file-name-p (filename)
(string-match "^#.*#$" (file-name-nondirectory filename)))<p>(defun make-auto-save-file-name ()
(concat autosave-dir
(if buffer-file-name
(concat "#" (file-name-nondirectory buffer-file-name) "#")
(expand-file-name
(concat "#%" (buffer-name) "#")))))<p>;; 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)))
I use Phil Hagelberg's starter kit and have made a few minor customizations -- works great and minimal learning curve.<p><a href="http://github.com/technomancy/emacs-starter-kit" rel="nofollow">http://github.com/technomancy/emacs-starter-kit</a>
my emacs.d still needs a few tweaks but I'm convinced it always will.<p>most useful parts:
replacing fundamental mode with text-mode as the default mode when a new buffer is open.<p>(setq default-major-mode 'text-mode)<p>turn auto fill (automatic line wraping) and flyspell (spellchecking) on by default<p>(add-hook 'text-mode-hook 'turn-on-auto-fill)<p>(add-hook 'text-mode-hook 'turn-on-flyspell)<p>also I find yasnippet <a href="http://code.google.com/p/yasnippet/" rel="nofollow">http://code.google.com/p/yasnippet/</a> wonderful for coding html mockups and django templates.<p>my github repo if anyone cares to take a peek:
<a href="http://github.com/bmac/emacs" rel="nofollow">http://github.com/bmac/emacs</a>
<a href="http://github.com/johngunderman/emacs/blob/master/emacs-john.el" rel="nofollow">http://github.com/johngunderman/emacs/blob/master/emacs-john...</a><p>Mine's pretty minimal at the moment, but it does the job.
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.<p><i>delete-delete-delete save-buffer</i> Much better.
Mine has:<p>(require 'activator)
(activator-start)<p>Which then looks at all of the stuff here: <a href="http://github.com/apgwoz/emacs-config" rel="nofollow">http://github.com/apgwoz/emacs-config</a>
My (somewhat extensive) Emacs config can be found here: <a href="http://github.com/bkudria/dotfile" rel="nofollow">http://github.com/bkudria/dotfile</a>
Much of this is cribbed from other places (credited where possible):<p><a href="http://github.com/larrywright/emacs" rel="nofollow">http://github.com/larrywright/emacs</a>