
Ask HN Emacs Users: What's in your .emacs file? - grizzydot
Are there any key bindings or modes that have been especially useful for you? If so, what are they?<p>Cheers.
======
daemianmack
Funny, about an hour ago I finally broke down and remapped Ctrl+w to backward-
kill-word[1] after re-reading Yegge's Effective Emacs, and you've just
reminded me to push the commit to my fork of emacs-starter-kit, which is a
great way to get a core set of functionality. Works best if you're tyrannical
about keeping it up to date, which I mostly am.

<http://github.com/daemianmack/emacs-starter-kit/>

Favorite two most recent additions: pyflakes/pylint for Python, and rainbow-
mode for CSS.

[1] Having backward-kill-word a two-finger-stroke, instead of the two-handed
alt+Backspace, is great! On the other hand, it turns out I kill-region a lot
more than I thought I did, so that's a little weird.

~~~
pttr
I too made the switch after reading Yegge's good stuff, but missed kill-region
so badly I had to come up with this:

    
    
        (defun backward-kill-word-or-kill-region (&optional arg)
          (interactive "p")
          (if (region-active-p)
        	  (kill-region (region-beginning) (region-end))
        	(backward-kill-word arg)))
    
        (global-set-key (kbd "C-w") 'backward-kill-word-or-kill-region)
    

This gets me kill-region for an active (transient-mark-mode) region but
backward-kill-word otherwise.

~~~
daemianmack
Excellent idea; thanks!

------
brodie
Here's some stuff I find useful when editing Python:

    
    
        (setq-default show-trailing-whitespace t)
        (setq longlines-show-hard-newlines t) ; displays "\" at the end of lines that wrap past the window's edge
    
        ; camel case word navigation
        (when (boundp 'subword-mode)
          (add-hook 'after-change-major-mode-hook '(lambda () (subword-mode 1))))
    
        ; Bindings
        (defun delete-backward-indent (&optional arg)
          "Erase a level of indentation, or 1 character"
          (interactive "*P")
          (if (= (current-column) 0)
              (delete-backward-char 1)
            (let ((n (mod (current-column) standard-indent)))
              (if (looking-back (concat "^\s*" (make-string n 32)))
                  (if (= n 0)
                      (delete-backward-char standard-indent)
                    (delete-backward-char n))
                (delete-backward-char 1)))))
    
        (defun newline-maybe-indent ()
          "Like newline-and-indent, but doesn't indent if the previous line is blank"
          (interactive "*")
          (if (= (line-beginning-position) (line-end-position))
              (newline)
            (newline-and-indent)))
    
        (add-hook 'python-mode-hook
                  '(lambda ()
                     (hs-minor-mode 1) ; code folding
                     (define-key python-mode-map (kbd "RET") 'newline-maybe-indent)
                     (define-key python-mode-map (kbd "DEL") 'delete-backward-indent)
                     (define-key python-mode-map (kbd "M-RET") 'hs-toggle-hiding)))
    
        ; On-the-fly spell checking
        (add-hook 'python-mode-hook '(lambda () (flyspell-prog-mode)))
    
        ; On-the-fly pyflakes checking
        (require 'flymake-point) ; shows errors in the minibuffer when highlighted (http://bitbucket.org/brodie/dotfiles/src/tip/.emacs.d/plugins/flymake-point.el)
        (setq python-check-command "pyflakes")
        (when (load "flymake" t)
          (defun flymake-pyflakes-init ()
            (let* ((temp-file (flymake-init-create-temp-buffer-copy
                               'flymake-create-temp-inplace))
                   (local-file (file-relative-name
                                temp-file
                                (file-name-directory buffer-file-name))))
              (list "pyflakes" (list local-file))))
          (add-to-list 'flymake-allowed-file-name-masks
                       '("\\.py\\'" flymake-pyflakes-init)))
        (add-hook 'python-mode-hook '(lambda () (flymake-mode 1)))
    
    

I have a feeling there's probably a better way to do that delete-backward-
indent thing. Maybe I should just switch to hungry delete mode.

My entire .emacs is here:
<http://bitbucket.org/brodie/dotfiles/src/tip/.emacs>

~~~
jcsalterego
Oh boy, nethack_el does not play well with `longlines-show-hard-newlines`.

------
Kototama
A few things I found useful:

    
    
      ;; fonts
      (if (eq window-system 'x)
          (set-default-font "Inconsolata-12"))
    
      ;; no tabs, spaces instead!
      (setq-default indent-tabs-mode nil)
    
      ;; Changes all yes/no questions to y/n type
      (fset 'yes-or-no-p 'y-or-n-p)
    
      ;; default modes
      (iswitchb-mode t)
      (icomplete-mo)
      (column-number-mode)
      (ido-mode)
      (tabbar-mode)
      (winner-mode)
    
      ;; ido-mode
    
      ;; do not confirm file creation
      (setq confirm-nonexistent-file-or-buffer nil)
    
      ;; integrate copy/paste with X
      (setq x-select-enable-clipboard t)
      (setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
    
      ;; scroll
      (setq scroll-step 1)
    
      ;; save backup files in this directory
      (setq backup-directory-alist (quote ((".*" . "~/.emacs.d/backups/"))))
    
      ;; global bindings
      (global-set-key [C-tab] 'other-window)
      (global-set-key "\r" 'newline-and-indent)
      (global-set-key (kbd "C-;") 'comment-region)
      (global-set-key (kbd "<f8>") '(lambda ()
                                    (interactive)
                                    (split-window-vertically 25)
                                    (other-window 1)
                                    (slime)))
    
      ; switch buffer with last previous buffer
      (global-set-key (kbd "<C-return>") '(lambda ()
                                          (interactive)
                                          (switch-to-buffer nil)))
      (global-set-key (kbd "C-p") 'backward-char)
      (global-set-key (kbd "C-S-p") 'previous-line)
      (global-set-key (kbd "C-S-j") 'join-line)
      (global-set-key (kbd "C-<prior>") 'tabbar-forward)
      (global-set-key (kbd "C-<next>") 'tabbar-backward)
    
      ;; fullscreen on F11
      (defun toggle-fullscreen (&optional f)
        (interactive)
        (let ((current-value (frame-parameter nil 'fullscreen)))
          (set-frame-parameter nil 'fullscreen
                             (if (equal 'fullboth current-value)
                                 (if (boundp 'old-fullscreen) old-fullscreen nil)
                               (progn (setq old-fullscreen current-value)
                                      'fullboth)))))
    
      (global-set-key [f11] 'toggle-fullscreen)
    

<http://github.com/kototama/unixconf/blob/master/.emacs>

------
zck
My .emacs, which is commented, is located at
<http://github.com/zck/emacs/blob/master/.emacs> . I need to update it and
move it over to bitbucket, though.

Specifically, my favorite things are show-paren-mode, ido-mode, and rebinding
C-, and C-. to move back and forward between windows.

------
mark_h
Mine's on github too: <http://github.com/markhepburn/dotemacs>

It's quite large, and includes a lot of third-party stuff, much of it as
submodules.

It's relocatable (with additional platform and/or machine-specific loads)
which might be semi-interesting:
[http://everythingtastesbetterwithchilli.com/initialisation-f...](http://everythingtastesbetterwithchilli.com/initialisation-
file-portability-tweaks)

Little things off the top of my head that I find useful: * wind-move -- use
shift-arrow keys for window navigation * (fset 'yes-or-no-p 'y-or-n-p) *
browse-kill-ring * mic-paren-mode * rename-file-and-buffer from Yegge *
unscroll (undo inadvertent C-v) from Glickstein's book * lots of little tweaks
like using C-,/. for smooth scrolling up/down * uniquify to keep buffer names
unique * find-file-at-point

Lots of autloads for more efficient initialisation (although that's less of an
issue now that I'm using --daemon at startup)

I do the usual UI tweaks like turning off the menu and tool bar, using ido
mode (with smex -- ido for commands), etc. There's not a lot of keys that I
rebind, but I do change backward-kill-word to C-w (consistent with shell
usage), and kill-region to C-xC-k. Both those suggestions were from Yegge's
effective emacs article which is worth a browse; I've ignored his advice to
also change M-x to C-xC-m though.

------
pyronicide
Check out: <http://github.com/technomancy/emacs-starter-kit>

I've modified it slightly, but overall it set emacs up better than I new was
possible (and introduced me to some add ons I didn't know existed).

------
almost
Very little, my .emacs just loads a whole load of other .el files. There's
quite a lot in them though :) Here's a very very useful few lines if you're on
X Windows:

    
    
        ; Fix copy-paste between emacs and other x programs
        (setq x-select-enable-clipboard t)
        (if (functionp 'x-cut-buffer-or-selection-value)
            (setq interprogram-paste-function 'x-cut-buffer-or-selection-value))
    

All your problems with cut and paste between Emacs and other programs? Gone!

The if statement stops it failing when you use it on other platforms.

EDIT: I also really really like this bit which I've not seen in other peoples
lists:

    
    
        (defun eshell-goto-current-dir (&optional arg)
          (interactive "P")
          (let ((dir default-directory))
            (eshell arg)
            (eshell/cd dir)))
    
        (global-set-key "\C-cs" 'eshell)
        (global-set-key "\C-cS" 'eshell-goto-current-dir)
    

That means I can switch to eshell with C-cs or a can switch to eshell _and_
change the current directory to be the same as the file I was viewing with
C-cS. It also passes through the argument so I can have multiple shells open
and use the numeric argument (M-1, M-2 etc) to select them.

------
avar
My .emacs is on GitHub: <http://github.com/avar/dotemacs/blob/master/.emacs>
along with the elisp library I use <http://github.com/avar/elisp>

Some noteworthy things:

It's a ~1200 line file (and expanding) this is how I navigate it:

    
    
        (defun show-dot-emacs-structure ()
          "Show the outline-mode structure of ~/.emacs"
          (interactive)
          (occur "^;;;;+"))
    

Which shows the outline of the file, e.g.:

    
    
        74 matches for "^;;;;+" in buffer: .emacs
         57:;;;; Debugging
         67:;;;; Load paths
        112:;;;; Emacs' interface
        229:;;;; User info
        236:;;;; Encoding
        253:;;;; Indenting
        273:;;;;; Per-project indentation settings
        275:;;;;;; Git
    

A quiet startup:

    
    
        ;; Don't display the 'Welcome to GNU Emacs' buffer on startup
        (setq inhibit-startup-message t)
        
        ;; Display this instead of "For information about GNU Emacs and the
        ;; GNU system, type C-h C-a.". This has been made intentionally hard
        ;; to customize in GNU Emacs so I have to resort to hackery.
        (defun display-startup-echo-area-message ()
          "If it wasn't for this you'd be GNU/Spammed by now"
          (message ""))
        
        ;; Don't insert instructions in the *scratch* buffer
        (setq initial-scratch-message nil)
    

Core UI settings:

    
    
        ;; Display the line and column number in the modeline
        (setq line-number-mode t)
        (setq column-number-mode t)
        (line-number-mode t)
        (column-number-mode t)
        
        ;; syntax highlight everywhere
        (global-font-lock-mode t)
        
        ;; Show matching parens (mixed style)
        (show-paren-mode t)
        (setq show-paren-delay 0.0)
        
        ;; 'mixed highligts the whole sexp making it unreadable, maybe tweak
        ;; color display?
        (setq show-paren-style 'parenthesis)
        
        ;; Highlight selection
        (transient-mark-mode t)
        
        ;; make all "yes or no" prompts show "y or n" instead
        (fset 'yes-or-no-p 'y-or-n-p)
    

Changing the switching is worth it, but I really need to find something that
allows me to <TAB> between different possibilities once completion is
exhausted, e.g. if I say "foo.c" and have both "foo.c" and "foo.c.txt":

    
    
        ;; Switching
        (iswitchb-mode 1)
        (icomplete-mode 1)
    

I wish I could also turn off the annoying #-files, but they're hardcoded in
Emacs's C code:

    
    
        ;; I use version control, don't annoy me with backup files everywhere
        (setq make-backup-files nil)
        (setq auto-save-default nil)
    

Better file selection:

    
    
        ;;; Electric minibuffer!
        ;;; When selecting a file to visit, // will mean / and
        ;;; ~ will mean $HOME regardless of preceding text.
        (setq file-name-shadow-tty-properties '(invisible t))
        (file-name-shadow-mode 1)
    

I didn't write this, but it's very useful. It emulates vim's sofftab feature.
So indenting with spaces doesn't suck anymore.

    
    
        (defun backward-delete-whitespace-to-column ()
          "delete back to the previous column of whitespace, or just one
        char if that's not possible. This emulates vim's softtabs
        feature."
          (interactive)
          (if indent-tabs-mode
              (call-interactively 'backward-delete-char-untabify)
            ;; let's get to work
            (let ((movement (% (current-column) tab-width))
                  (p (point)))
              ;; brain freeze, should be easier to calculate goal
              (when (= movement 0) (setq movement tab-width))
              (if (save-excursion
                    (backward-char movement)
                    (string-match "^\\s-+$" (buffer-substring-no-properties (point) p)))
                  (delete-region (- p movement) p)
                (call-interactively 'backward-delete-char-untabify)))))
        
        (global-set-key (kbd "<DEL>") 'backward-delete-whitespace-to-column)
    

I _really_ wish I could find something for Emacs which _automatically_ detects
the style of the code I'm editing and switches the coding style to that.

For libraries I use (eval-after-load) for everything and (autoload). It really
speeds up startup.

ack is a much better M-x grep (needs ack.el):

    
    
        ;;;;; ack
        (defalias 'grep 'ack)
    

I have something to make swank work with clojure _and_ sbcl, but it's too
large to include here. clojure-mode et al make it _really_ hard to do this,
unfortunately (upstream isn't really interested in this use case):

    
    
        (defun run-clojure ()
          "Starts clojure in Slime"
          (interactive)
          (pre-slime)
          (slime 'clojure))
        
        (defun run-sbcl ()
          "Starts SBCL in Slime"
          (interactive)
          (pre-slime)
          (slime 'sbcl))
    

You should use nopaste.el (shameless plug): <http://github.com/avar/nopaste>

    
    
        ;;;;; nopaste.el
        (autoload 'nopaste "nopaste" nil t)
        
        (eval-after-load "nopaste"
          '(progn
             (setq nopaste-nickname "avar")
             (setq nopaste-channel  nil)
             (setq nopaste-description nil)))
        
        (global-set-key (kbd "C-c n p") 'nopaste)
        (global-set-key (kbd "C-c n y") 'nopaste-yank-url)
    

Here's how I still tolerate GMail and other web apps. I can click on any text
field in Chrome and edit it in Emacs:

    
    
        ;;;;; Emacs Chrome edit server - http://wiki.github.com/stsquad/emacs_chrome/
        (when (getenv "DISPLAY")
          (require 'edit-server)
          (setq edit-server-new-frame nil)
          (add-hook 'edit-server-done-hook 'on-edit-server-done-do-backup)
          (edit-server-start))
    

And this has saved my many a time from losing web form content (I should
really make this use Git):

    
    
        (defun on-edit-server-done-do-backup ()
          "Run when text is sent to Google Chrome. Do a backup of the
        stuff sent there in case something goes wrong, e.g. Chrome
        crashes."
          (let* ((backup-dir "~/._emacs_chrome-backup")
                (backup-file (format "%s.txt" (float-time)))
                (backup-path (concat backup-dir "/" backup-file)))
            (unless (file-directory-p backup-dir)
              (make-directory backup-dir))
            (write-region (point-min) (point-max) backup-path)))
        

Install browse-kill-ring.el _now_ :

    
    
        (global-set-key (kbd "C-c k") 'browse-kill-ring)
    

That's about it for the really interesting stuff. But there's a lot of other
mundane stuff in there.

~~~
larsberg
> I really wish I could find something for Emacs which automatically detects
> the style of the code I'm editing and switches the coding style to that.

If it makes you feel any better, back when I was managing a team in Visual
Studio, we called this the "When in Rome" feature. And yes, the versions of
this we tried to put together worked as you'd expect... mostly. Determining
peoples' whitespace decisions are not trivial. How many lines does the THEN
clause of an IF need to have before you surround it with curlies? Do you only
put a space before the parens around a function's arguments if there is more
than one argument? And my personal favorite, how do you "funge" your
indentation style if the nesting level gets high enough that you're at
frequent risk of line wrap (soft or hard doesn't matter here)?

People have wacky rules, and as soon as you say you're going to auto-detect
them, you're in for a world of pain. Of course, you might have a user base
that isn't as persnickety, in which case it's really not that bad.

~~~
leif
> How many lines does the THEN clause of an IF need to have before you
> surround it with curlies?

If I'm your manager, 0.

------
uros643
Custom key bindings

    
    
      ;; Makes editing without Paredit more convenient... 
      ;; But if you're on linux, first prevent it from logging you out!
      (global-set-key [C-M-delete] 'backward-kill-sexp)
      (global-set-key [C-M-backspace] 'backward-kill-sexp)
    
      ;; Command key meta forever.
      (labels ((normal-mac-mods (&rest _) (setq ns-alternate-modifier 'none
                                                ns-command-modifier 'meta)))
        (add-hook 'after-make-frame-functions #'normal-mac-mods)
        (normal-mac-mods))
    

Aesthetics

    
    
      (setq-default ...
    
                    ;; Make the default buffer a little shinier... also, put
                    ;;   (message "Ready")
                    ;; at the end of the file
    
                    initial-major-mode 'text-mode
                    initial-scratch-message (concat "                  ···"
                                                    "--—=====   Welcome to Emacs"
                                                    "   =====—--···\n===---···"
                                                    "                 "
                                                    "···---================---···"
                                                    "                ···---===\n\n")

------
silentbicycle
These are pretty minor, but I use them _constantly_ , and they're pretty self-
contained.

    
    
        (global-set-key (kbd "C-=") 'switch-to-previous-buffer)
        (defun switch-to-previous-buffer ()
          (interactive)
          (switch-to-buffer (other-buffer)))
    
        (global-set-key (kbd "C-z") 'shell)
    
        (defun my-shell-mode-hook ()
          (local-set-key (kbd "C-z") 'bury-buffer))
        (add-hook 'shell-mode-hook 'my-shell-mode-hook)

------
rayvega
Between and during Emacs sessions, being able to view a list of my recently
opened files via C-x C-r and then select and re-open them as needed.

    
    
        ;; recent files
        (require 'recentf)
        (recentf-mode 1)
        (setq recentf-max-menu-items 25)
        (global-set-key "\C-x\ \C-r" 'recentf-open-files)
    

<http://www.joegrossberg.com/archives/000182.html>

------
drblast
Viper mode gives you the best of both worlds, although I'm probably considered
a heretic in both religions.

    
    
      (setq viper-mode t)
      (require 'viper)
    
      (custom-set-variables
       '(column-number-mode t)
       '(inhibit-startup-screen t)
       '(show-paren-mode t)
       '(tool-bar-mode nil)
       '(menu-bar-mode nil))
    

I used to have slime config stuff in there, but now Ubuntu does it all for me.
Thanks Ubuntu!

~~~
jemfinch
So _you're_ the other viper-mode user! We should have coffee sometime :)

~~~
zaphar
He's not the only one. viper + vimpulse here.

~~~
DrStrngeluv
Another Viper mode heretic here. 10 years of everyday vi (I started with
elvis!) and then switching to emacs will do that. I use gtags and doxymacs
pretty extensively too.

------
jsulak
* Smex. This adds IDO completion to M-x. Can't live without it. <http://github.com/nonsequitur/smex/>

* Undo-tree. (<http://www.emacswiki.org/emacs/UndoTree>) Makes emacs undo useful.

This has been one of the most useful functions I've added to my .emacs:

    
    
       (defun xsteve-ido-choose-from-recentf ()
         "Use ido to select a recently opened file from the `recentf-list'"
         (interactive)
         (let ((home (expand-file-name (getenv "HOME"))))
           (find-file
            (ido-completing-read "Recentf open: "
                                 (mapcar (lambda (path)
                                           (replace-regexp-in-string home "~" path))
                                         recentf-list)
                                 nil t))))
    
       (global-set-key [(meta f11)] 'xsteve-ido-choose-from-recentf)
    

From: <http://www.xsteve.at/prg/emacs/power-user-tips.html>, which has a bunch
of good tips/key bindings

------
jcsalterego
I went .emacs bankrupt this summer.

gist.el, powershell-mode, yaml-mode, org-mode are a few I've taken out for
brevity.

Otherwise, a few of these are emacs23 specific:

    
    
      ;; syntax highlighting
      (global-font-lock-mode 1)
      
      ;; add .emacs.d to load path
      (setq load-path (cons "~/.emacs.d" load-path))
      
      ;; nethack
      (add-hook 'nethack-mode-hook (lambda () (linum-mode 'nil)))
      (setq load-path (cons "~/.emacs.d/nethack" load-path))
      (autoload 'nethack "nethack" "Play Nethack." t)
      (setq nethack-program "/opt/local/bin/nethack")
      
      ;; 4 spaces in objective-c
      (add-hook 'objc-mode-hook
                (lambda ()
                  (setq tab-width nil)
                  (setq c-basic-offset 4)))
      
      ;; straight to *scratch* buffer please
      (setq inhibit-splash-screen t)
      
      ;; use old navigation for line movement
      (setq line-move-visual nil)
    
      ;; linum mode
      (require 'linum)
      (global-linum-mode 1)
      (add-hook 'linum-before-numbering-hook
      	  (lambda () (setq linum-format "%d ")))

------
nileshk
I have my Emacs config here: <http://github.com/nileshk/emacs>

startup.el is the main starting point (I load that from my .emacs). Can't say
it's the cleanest set of config files, but you might find something of use in
it.

Some of the things I've configured:

\- Detect whether Emacs is running in OS X, Linux, Windows (native), or
Cygwin; and I do platform-specific configuration when necessary

\- For OS X, I use fixpath.el to load my path by executing bash (I've tried
various methods of doing this, and this was the most reliable)

\- For Windows, I have Powershell configured

\- I'm using guess-style ( <http://nschum.de/src/emacs/guess-style/> ): auto-
detects indentation style.

\- I had a Clojure setup that was working nicely, but it's been a while since
I used it and I need to update it for Clojure 1.2

\- ido-mode is great. I have some specific settings for that. For example,
enabling ido-enable-flex-matching makes it easier to quickly match files

\- Backups go to ~/.emacs.d/backup instead of littering ~ files everywhere.
The backup folder is created if necessary.

\- YASnippets. I've created some snippets of my own, such as for wikipedia-
mode

\- I had problems using markdown-mode with YASnippets (both want to use the
tab key), but was able to fix this. See my "eval-after-load 'markdown-mode"
for this.

If you use YASnippet, I've taken Jeff Wheeler's Textmate-to-YASnippet
conversion script and improved it here: <http://github.com/nileshk/snippet-
copier> That also contains a Eclipse template to YASnippet convertor script I
started on which kinda works, though not perfectly.

------
tspiteri
From my customizations, these are the most I use:

Pressing Return starts a new line at column 0, pressing Control j starts a new
indented line. I prefer them the other way round, so I rebind:

    
    
        (global-set-key "\r" 'newline-and-indent)
        (global-set-key "\C-j" 'newline)
    

Also, very often I need to start a new line above or below the current line.
So instead of Control e, Return to start a new indented line below the current
line I use Control Return.

    
    
        (defun next-newline-and-indent ()
          (interactive)
          (end-of-line)
          (newline-and-indent))
        (global-set-key [C-return] 'next-newline-and-indent)
    

And to start a new indented line above the current line, instead of Control a,
Control o, Control i, I use Control Shift Return.

    
    
        (defun prev-newline-and-indent ()
          (interactive)
          (beginning-of-line)
          (open-line 1)
          (indent-according-to-mode))
        (global-set-key [C-S-return] 'prev-newline-and-indent)

------
msg
I have my own preferred color scheme, won't bore you. At bottom, it's
GhostWhite on black.

I don't like tabs!

    
    
      ;; destroy all tabs
      (setq-default indent-tabs-mode nil)
      (defun untab-writable-non-makefiles-and-csv ()
       (if (and
            (not buffer-read-only)
            (not (loop for re in '("[Mm]akefile" "\\.mk" "\\.csv" "\\.txt")
                       if (string-match re buffer-file-name)
                       do (return t)
                       finally (return nil))))
           (untabify (point-min) (point-max))))
      (add-hook 'find-file-hook 'untab-writable-non-makefiles-and-csv)
    

Emacsclient is a real must.

    
    
      ;; use this to start server for emacsclient
      (if (not (boundp 'server-process))
         (server-start))
    

All my shells run inside of Emacs. So they're named, I get completions, and so
on. That includes remote shells, using tramp and ssh-mode.

    
    
      ;; tramp mode...
      (setq load-path (cons "~/emacs/tramp" load-path))
      (require 'tramp)
      (setq tramp-default-method "ssh")
    
      ;; remote shell! Hooray!
      (require 'ssh)
      (add-hook 'ssh-mode-hook 'ssh-directory-tracking-mode)
    

Here's what I use for session.

    
    
      ;; back to emacswiki.org/emacs/DeskTop
      (setq *foo-desktop-dir* (expand-file-name "~/emacs/desktop"))
      (setq desktop-dir *foo-desktop-dir*)
      (setq desktop-path (list *foo-desktop-dir*))
      (desktop-save-mode 1) ;; Switch on desktop.el
      (setq *foo-desktop-file* (concatenate 'string desktop-dir
                                           "/" desktop-base-file-name))
      (setq *foo-desktop-lock* (concatenate 'string desktop-dir
                                           "/" desktop-base-lock-name))
      (defun desktop-in-use-p ()
       (and (file-exists-p *foo-desktop-file*) (file-exists-p *foo-desktop-lock*)))
      (defun autosave-desktop ()
       (if (desktop-in-use-p) (desktop-save-in-desktop-dir)))
      (add-hook 'auto-save-hook 'autosave-desktop)

------
xtacy
I use color-theme.el to manage, well, colour themes and use the twilight
theme: [http://github.com/crafterm/twilight-
emacs/blob/master/color-...](http://github.com/crafterm/twilight-
emacs/blob/master/color-theme-twilight.el)

To mimic some of TextMate's functionality, I use:

1\. autopair.el: <http://www.emacswiki.org/emacs/AutoPairs>.

2\. yasnippet.el: <http://code.google.com/p/yasnippet/>

The latest version of Emacs for the MacOSX has an awesome fullscreen
capability. I followed the instructions here: [http://www.sanityinc.com/full-
screen-support-for-cocoa-emacs...](http://www.sanityinc.com/full-screen-
support-for-cocoa-emacs-on-osx)

iswitchb-mode has awesome minibuffer completion capabilities.
<http://www.emacswiki.org/emacs/IswitchBuffers>

------
jakevoytko
I try to keep it simple. I set my color theme, switch the font to Consolas,
register some major modes (CMake, SLIME, haskell, org, etc), enable some of
the disabled-by-default commands, and have some useful key bindings:

    
    
        ; I type this by mistake 80% of the time
        (global-unset-key (kbd "C-x C-c"))
    
        ; One of my favorite commands
        (global-set-key "\C-x\C-j" 'join-line)
    
        ; I haven't seen a keyboard with "copy" and "paste" buttons since 2008
        ; Honestly, Emacs' defaults, WTF
        (global-set-key (kbd "<f2>") 'clipboard-kill-ring-save)
        (global-set-key (kbd "<f3>") 'clipboard-yank)

------
kirubakaran
<http://github.com/ki/my-dot-emacs/raw/master/dot-emacs.txt>

plus

<http://lisp.pastebin.com/raw.php?i=MRbccMG4>

------
al3x
<http://github.com/al3x/emacs>

------
travisbhartwell
I actually did a huge re-organization of my .emacs file (including moving it
to .emacs.d/init.el) a few months ago, dividing it into topic specific
configuration files (general, files and buffers, programming, python-config,
etc) and have support for loading different configurations depending on which
machine I'm on.

<http://github.com/Nafai77/config/tree/master/HOME/_emacs.d/>

One of the next things I'm going to do is explore using el-get. It's always a
pain moving to a new machine and having to download and checkout all of the
third-party libraries I use.

------
drbaskin
I use emacs mostly for LaTeX editing, so most of my .emacs sets up macros to
make it easy to insert greek letters with a keystroke. (For some reason, I
really hate using LaTeX macros to write shortcuts for these.)

~~~
jedbrown
You don't like LaTeX-math-mode (bound to C-c ~)?

------
ruediger
Some tricks from my .emacs:

    
    
      (server-start)
    
      ;; no Tabs
      (setq-default indent-tabs-mode nil)
      (setq-default tabs-width 2)
    
      ;; List more buffers in the buffer menu
      (setq-default buffers-menu-max-size 30)
    
      ;; Prevent startup message and switch to empty *scratch*
      (setq inhibit-startup-message t)
      (setq initial-scratch-message nil)
    
      ;; Fix C&P
      (setq x-select-enable-clipboard t)
    
      ;; Make Caps Lock LED blink instead of audio bell
      (setq visible-bell 1)
      (setq ring-bell-function
            (lambda ()
              (when (getenv "DISPLAY")
                (call-process-shell-command "xset led named \"Scoll Lock\"; xset -led named \"Scroll Lock\"" nil 0 nil))))
    
      (show-paren-mode 1)
      (column-number-mode 1)
    
      ;; Keep the custom stuff separate
      (setq custom-file "~/.emacs.d/custom.el")
      (load custom-file)
    
      ;; I know what downcase-region does. Me no noob anymore ;). So undisable it.
      (put 'downcase-region 'disabled nil)
    
      ;; This can be a life saver!
      (push '("." . "~/.emacs.d/backups") backup-directory-alist)
    
      ;; Create better buffer names. foo.c++:src, foo.c++:extra instead of foo.c++ and foo.c++<2>
      ;; This should really be the default behaviour for Emacs!
      (require 'uniquify)
      (setq 
        uniquify-buffer-name-style 'reverse
        uniquify-separator ":")
    
      ;; c-mode hook to set better default compile-command if no Makefile exists and activate flyspell-prog-mode
      ;; I have similar hooks for c-mode and fortran-mode
      (add-hook 'c++-mode-hook
              (lambda ()
                (flyspell-prog-mode)
                (unless (or (file-exists-p "Makefile")
                            (local-variable-p 'compile-command)
                            (not buffer-file-name))
                  (set (make-local-variable 'compile-command)
                       (format "%s %s %s"
                               (or (getenv "CXX") "g++")
                               (or (getenv "CXXFLAGS")
                                   "-pipe -std=c++0x -pedantic-errors -Wall -Wextra -Weffc++ -g3")
                               (file-name-nondirectory buffer-file-name))))))
    
      ;; Set f9 to compiler and f8 to make clean
      (global-set-key '[f9] 'compile)
      (global-set-key '[f8] '(lambda ()
                              (interactive)
                              (when (file-exists-p "Makefile") (compile "make clean"))))
    
    

The rest is just some specific mode setup and minor key bindings stuff.

------
technomancy
Paredit, slime, magit, org-mode, eshell, and erc.

The boring stuff is all in the Starter Kit:
<http://github.com/technomancy/emacs-starter-kit>

~~~
dirceut
Emacs Starter Kit allowed me to finally switch to Emacs last year. Thanks a
lot technomancy!

I keep my customizations here: <http://github.com/dirceu/emacs-starter-kit>

------
Keyframe
several syntax highlighting stuff apart from standard ones, of course.

This is super useful to me:

    
    
        (global-set-key [f6] 'linum-mode)
        (global-set-key [f7] 'next-buffer)
        (global-set-key [f8] 'previous-buffer)
    

I also have yasnippet, but I don't really use it at all (I should). Also,
recentf <http://www.emacswiki.org/cgi-bin/wiki/recentf-buffer.el> for a
recently opened stuff (like dired, but for recent stuff).

And most importantly, I setup my font to monaco, tango color scheme and I
prefer full screen emacs, so i have a bit of an involved process where I have
basically this:

    
    
        (global-set-key [f11] 'ds-darkroom)
        (global-set-key [f12] 'menu-bar-mode)
    

where F11 puts me in and out of full screen mode and f12 toggles menu bar. F11
uses a small utility written in C# for windows to make this happen.

clean darkroom - <http://i.imgur.com/LloOY.png>

with menu - <http://i.imgur.com/yTeUz.png>

I'm trying for years to force myself not to move my right hand to arrows and
instead use C-p C-n and C-b C-f, but I can't (well sometimes I do, but not all
the time).

And various tweaks here and there, I might have forgotten something though.

------
hober
My .emacs: <http://edward.oconnor.cx/config/.emacs>

If you use Viper, this is the single nicest tip I have:
<http://edward.oconnor.cx/2009/08/viper-tweaks>

Some tips on running a dedicated Emacs instance for Gnus:
<http://edward.oconnor.cx/2010/08/standalone-gnus>

------
zaphar
my .emacs is on bitbucket:
<https://bitbucket.org/zaphar/dotfiles/src/tip/.emacs.d/>

Some notable items:

    
    
        ;;; allow seperating out the config stuff to 
        ;;; into different files
        (defvar jaw:config-dir (expand-file-name "~/.emacs.d/conf.d")
          "My config parts directory location.")
    
        (defun jaw:load-confs ()
         "Load Jeremy's config file parts"
         (let ((files (sort (directory-files jaw:config-dir) 'string<)))
           (while files
             (setq file (car files)
                   files (cdr files))
             (cond ((string-match ".*\.#[^/]+\.el$" file)
                    nil)
                   ((string-match ".*\.elc?$" file)
                    (load-file (concat jaw:config-dir "/" file)))))))
    
        (jaw:load-confs)
    
    

Automatically installing elpa packages to bootstrap a new emacs system:
[https://bitbucket.org/zaphar/dotfiles/src/tip/.emacs.d/conf....](https://bitbucket.org/zaphar/dotfiles/src/tip/.emacs.d/conf.d/001-my-
packages.el)

------
apgwoz
My kit is on github: <http://github.com/apgwoz/emacs-config>

My favorite new thing is my thumb-through: <http://github.com/apgwoz/thumb-
through>, which allows me to easily read articles from irc (i use rcirc)
without leaving emacs, or loading up w3m-mode.

------
michaelfairley
Previously: <http://news.ycombinator.com/item?id=855963>

------
drhodes

      ;; don't sleep emacs accidentally
      (global-set-key [(control z)] nil)
      
      ;; shortcut buffer navigation
      (global-set-key [f5] 'previous-buffer)
      (global-set-key [f8] 'next-buffer)
      
      ;; show columns by default
      (column-number-mode)
      
      ;; stop the blinking
      (blink-cursor-mode nil)
    

and reams of macros

------
troels
I have a lot of stuff in there. Most notably, I use tabbar and my own custom
textpad-mode, which makes the cursor move around in the same way that textpad
(A windows text editor) does it.

Linky: <http://github.com/troelskn/troelskn-emacs>

------
lvillani
I can't live without:

\- IDO

\- Smex

\- (Enhanced) project-root.el ( <http://piranha.org.ua/project-root/> ) and
its project-root-find-file function.

(and my modular configuration is here: <http://github.com/lvillani/.emacs.d>)

------
vmmenon
(setq make-backup-files nil)

(setq slime-lisp-implementations '((ccl ("/usr/local/ccl/dx86cl64")) (sbcl
("/usr/local/bin/sbcl")))) (add-to-list 'load-path "/usr/local/slime/")
(require 'slime) (slime-setup '(slime-repl slime-banner))

------
ohyes
I used to have more, but I have since streamlined...

My entire .emacs file:

(defun sbcl ()

    
    
      (show-paren-mode)
    
      (setq inferior-lisp-program "sbcl")
    
      (add-to-list 'load-path "~/emacs/slime")
    
      (require 'slime)
    
      (slime-setup))
    

(sbcl)

------
joecomotion
Handy if you're viewing a live log file and want to see what's been appended
since the last time you've opened it:

(defun force-revert-buffer () (interactive) (revert-buffer t t))

(define-key global-map "\C-cr" 'force-revert-buffer)

------
dcreemer
Thanks for this post and everyone's links. I'm just considering a return to
Emacs after a run-in with RSI and several years wandering in the TextMate
forest. This is very helpful.

------
cycojesus
a lot of things, 1376 lines @ <http://github.com/cycojesus/emacs>

It uses org-babel to keep it organized and readable so really there's a short
wrapper init.el that then calls babel-init.org

External packages are installed system-wide using my own .SlackBuild generated
packages (@ <http://github.com/cycojesus/slackbuilds/tree/master/e/> )

Of course I run Slackware.

------
tjpick
org-mode.

------
jbr
<http://gist.github.com/561519>

textmate.el is pretty awesome, as is ide-skel.

------
leif
can't go wrong with paredit or the emacs client/server (google them)

------
lg
for anyone who uses erc on emacs 23 and gets the weird "selecting deleted
buffer" error, adding

    
    
      (setq Buffer-menu-use-frame-buffer-list nil)
    

makes it work.

------
someisaac
any .emacs for php/Mysql/html/css/js ?

~~~
papaf

        (require 'zencoding-mode)
        (add-hook 'sgml-mode-hook 'zencoding-mode)
    

<http://www.emacswiki.org/emacs/ZenCoding>

------
nprincigalli

      ;; move along, nothing to see here :P
      ;; the beef is in ~/.vimrc and under ~/.vim/ ;)

