Ask HN: What's in your .emacs file?

by procrastinatuson 10/1/2009, 10:15 PMwith 52 comments

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?

by yummyfajitason 10/2/2009, 12:19 AM

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

    darcs get me@oldbox:emacs.d
and tweak a few settings.

by mark_hon 10/2/2009, 12:47 AM

http://github.com/markhepburn/dotemacs

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.

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: http://www.nongnu.org/emacs-tiny-tools/keybindings/ and http://www.emacswiki.org/emacs/KeyBindingNotation

by mahmudon 10/2/2009, 2:02 AM

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 :-(

For uninitiated, C-w is "yank text", i.e. cut it, and Firefox it is "close current tab without warning".

by jmhodgeson 10/2/2009, 7:58 AM

I am completely surprised no one has linked to technomancy's emacs-start-kit: https://github.com/technomancy/emacs-starter-kit

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.)

On that note, my own fork of it with very minor personal changes: https://github.com/jmhodges/emacs-starter-kit

by scottwon 10/2/2009, 12:52 AM

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)

by al3xon 10/2/2009, 12:24 AM

I only periodically experiment with Emacs as my day-to-day editor, but my configuration isn't too shabby: http://github.com/al3x/emacs

by lackeron 10/1/2009, 11:11 PM

Most important:

  ;; 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.

by radu_floricicaon 10/2/2009, 9:15 AM

Pretty new to emacs, so my first move was to make it more familiar and avoid breaking my fingers:

;; Switch buffer

(global-set-key [f5] 'buffer-menu)

;; Save and load

(global-set-key [f2] 'save-buffer)

(global-set-key [f3] 'find-file)

;; Compile file

(global-set-key [f9] 'slime-compile-and-load-file)

;; Goto line

(global-set-key "\M-l" 'goto-line)

;; Go to other window

(global-set-key (kbd "<C-tab>") 'other-window)

;; And probably the most useful one, numpad Enter for eval line:

(global-set-key (kbd "<kp-enter>") 'slime-eval-last-expression)

by justinhjon 10/2/2009, 4:03 AM

Some key ones

(setq transient-mark-mode t) ; visually show region

(setq line-number-mode t) ; show line numbers

(setq global-font-lock-mode 1) ; everything should use font

(windmove-default-keybindings) ; shift-arrow key moves to window in that direction

I set up `webjump' to search online API documentation

http://justinsboringpage.blogspot.com/2009/05/emacs-searchin...

I like to send gmail

http://justinsboringpage.blogspot.com/2009/02/sending-mail-w...

I think this is the most important one

(setq visible-bell t) ; annoying beeps off

by justinweisson 10/2/2009, 2:41 PM

I work mostly inside git repositories, so this has been really valuable for scoping commands to the current repository:

  (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)))
I also hated editing system files until I added this function, which I almost definitely cribbed from somewhere:

  (defun sudo-find-file (file-name)
    (interactive "FFind file (sudo): ")
    (find-file (concat "/sudo::" file-name)))
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:

  (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="))
I really, really hope package.el is built-in soon:

  (when
      (load
       (expand-file-name "~/.emacs.d/elpa/package.el"))
    (package-initialize))
and by far the most important line in the whole file:

  (server-start)

by dirtyauraon 10/2/2009, 12:40 PM

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)))))

by j_bakeron 10/2/2009, 11:52 AM

I use anything: http://www.emacswiki.org/emacs/Anything

And then I have this in my .emacs:

    (require 'anything-config)
    (global-set-key "\C-c\C-a" 'anything)
    (global-set-key "\C-c\C-e" 'anything-for-files)
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.

by aiiieon 10/2/2009, 12:08 AM

http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs

http://bitbucket.org/[redacted]/dotfiles/src/tip/.emacs.d/pl...

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.

by mikedouglason 10/2/2009, 12:35 AM

Here is a one-liner that's quite useful:

   (add-hook 'c-mode-common-hook
	  (lambda ()
	    (font-lock-add-keywords nil
	     '(("\\<\\(FIXME\\|TODO\\|BUG\\):" 1 font-lock-warning-face t)))))

by diiqon 10/2/2009, 3:24 AM

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.

by diN0boton 10/2/2009, 2:14 PM

i put third party .el files in .emacs.d and then set the load path in the first line of my .emacs file

   (setq load-path (append load-path (list "/Users/diN0bot/.emacs.d")))
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

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/"))

(make-directory autosave-dir t)

(defun auto-save-file-name-p (filename) (string-match "^#.*#$" (file-name-nondirectory filename)))

(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) "#")))))

;; 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)))

by Ben65on 10/2/2009, 11:21 AM

It's hard to live without:

(fset 'yes-or-no-p 'y-or-n-p)

by elqon 10/2/2009, 12:49 AM

http://github.com/elq/dot-emacs/

by grandalfon 10/1/2009, 11:10 PM

I use Phil Hagelberg's starter kit and have made a few minor customizations -- works great and minimal learning curve.

http://github.com/technomancy/emacs-starter-kit

by bmacon 10/2/2009, 12:43 AM

my emacs.d still needs a few tweaks but I'm convinced it always will.

most useful parts: replacing fundamental mode with text-mode as the default mode when a new buffer is open.

(setq default-major-mode 'text-mode)

turn auto fill (automatic line wraping) and flyspell (spellchecking) on by default

(add-hook 'text-mode-hook 'turn-on-auto-fill)

(add-hook 'text-mode-hook 'turn-on-flyspell)

also I find yasnippet http://code.google.com/p/yasnippet/ wonderful for coding html mockups and django templates.

my github repo if anyone cares to take a peek: http://github.com/bmac/emacs

by johngundermanon 10/1/2009, 10:43 PM

http://github.com/johngunderman/emacs/blob/master/emacs-john...

Mine's pretty minimal at the moment, but it does the job.

by jwson 10/1/2009, 11:41 PM

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.

delete-delete-delete save-buffer Much better.

by apgwozon 10/2/2009, 10:35 AM

Mine has:

(require 'activator) (activator-start)

Which then looks at all of the stuff here: http://github.com/apgwoz/emacs-config

by bkudriaon 10/2/2009, 7:02 PM

My (somewhat extensive) Emacs config can be found here: http://github.com/bkudria/dotfile

by larrywrighton 10/2/2009, 3:23 AM

Much of this is cribbed from other places (credited where possible):

http://github.com/larrywright/emacs

by vaporstunon 10/2/2009, 2:33 PM

(setq comint-input-ring-size 2048)

The default undo history is only 32. I like to be able to go further back.

by leifon 10/2/2009, 8:44 AM

mine's in http://github.com/adlaiff6/df.git but I don't really expect you to read it

by twismon 10/2/2009, 1:07 PM

ido.el to find files

    (require 'ido)
    (ido-mode t)

by gibsonf1on 10/2/2009, 3:14 AM

;; Easymacs sets some common Windows key bindings like ctrl-c to copy, ctrl-s to save, etc. (load "c:/Otech/programs/easymacs/easymacs.el")

(defun init-streamfocus () (interactive)

;; Slime is for starting or connecting to SBCL ;; To start: C-x slime RET (add-to-list 'load-path "c:/Otech/sf/lib/slime")

;;(setq inferior-lisp-program "C:/Otech/programs/sbcl-1.0.9/sbcl")

                                        ;(setq inferior-lisp-program "C:/Program Files/LispWorks/lispworks-4450")
(add-hook 'lisp-mode-hook (lambda () (slime-mode t))) (add-hook 'inferior-lisp-mode-hook (lambda () (inferior-slime-mode t))) ;; (defun lw-start () ;; (interactive) ;; (shell-command (concat "C:/Program Files/LispWorks/lispworks-4450.exe -multiprocessing " ;; "-init c:/Otech/swank.lisp&")))

;;;For SBCL on Windows ;(setq inferior-lisp-program "sbcl") ;(add-to-list 'load-path "C:/Program Files/Steel Bank Common Lisp/1.0.22/sbcl.exe")

;;For Allegro on Windows (setq inferior-lisp-program "allegro") (add-to-list 'load-path "C:/Program Files/acl81/allegro.exe")

(require 'slime) (slime-setup '(slime-fancy slime-banner))

;;allegro (global-set-key "\C-cs" 'slime-selector) (setq slime-complete-symbol-fancy t) (setq slime-complete-symbol-function 'slime-fuzzy-complete-symbol)

(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")

  ;;(setq *slime-lisp* "allegro-express.exe")
  (setq *slime-port* 4005)
  
  (global-set-key
   [(f5)]
   '(lambda ()
      (interactive)
      (shell-command 
       (format "%s +B +cm -L c:/.slime.lisp -- -p %s --ef %s &"
               *slime-lisp* *slime-port*
               slime-net-coding-system))
      (delete-other-windows)
      (while (not (ignore-errors (slime-connect "localhost" *slime-port*)))
        (sleep-for 0.2))))  
  
  (let* ((cygwin-root "c:/cygwin")
         (cygwin-bin (concat cygwin-root "/bin")))
                                        ;(setenv "HOME" (concat cygwin-root "/home/frederick"))
    (setenv "PATH" (concat cygwin-bin ";" (getenv "PATH")))
    (setq exec-path (cons cygwin-bin exec-path)))
  (setq shell-file-name "bash")
  (setq explicit-shell-file-name "bash")
  
  (push ".fasl" completion-ignored-extensions)
  (push ".git" completion-ignored-extensions)

  ;;--------------------------------------
;;;; For remote slime ;; see http://a1k0n.net/blah/archives/2005/11/04/T18_00_44/index.ht... (require 'tramp) (defvar cayenne-path "/sshx:streamfocus@cayenne:") (defvar current-tramp-path nil)

  (defun slime-connect-to-host (path port)
    (setq *current-tramp-path* path)
    (setq slime-translate-from-lisp-filename-function
          (lambda (f)
            (if *current-tramp-path*
                (concat *current-tramp-path* f)
              f)))
    (setq slime-translate-to-lisp-filename-function
          (lambda (f)
            (if *current-tramp-path*
                (substring f (length *current-tramp-path*))
              f)))
    (slime-connect "localhost" port))
  
  (defun cayenne-slime ()
    (interactive)
    (slime-connect-to-host *cayenne-path* 4006))
  
  (defun cayenne-find-file ()
    (interactive)
    (find-file (concat *cayenne-path* "/home/streamfocus/sf/")))
  
  
;;;; TRAMP remote editing. See notes for NTEmacs on http://www.emacswiki.org/cgi-bin/wiki/TrampMode (setq tramp-default-method "sshx") ;;;; SLIME settings to edit remote files on rembrandt ;(push (list "^cayenne$" ; (lambda (emacs-filename) ; (subseq emacs-filename (length "/cayenne:"))) ; (lambda (lisp-filename) ; (concat "/cayenne:" lisp-filename))) ; slime-filename-translations)

  ;; http://www.emacswiki.org/cgi-bin/wiki/NTEmacsWithCygwin
  (let* ((cygwin-root "c:/cygwin")
         (cygwin-bin (concat cygwin-root "/bin")))
                                        ;(setenv "HOME" (concat cygwin-root "/home/fred"))
    (setenv "PATH" (concat cygwin-bin ";" (getenv "PATH")))
    (setq exec-path (cons cygwin-bin exec-path)))
  (setq shell-file-name "bash")
  (setq explicit-shell-file-name "bash")
  )
(defun init-clojure () "Inits slime for streamfocus" (interactive) ;; clojure-mode (add-to-list 'load-path "C:/Otech/programs/clojure/clojure-mode") (require 'clojure-mode)

  ;; swank-clojure
  (add-to-list 'load-path "C:/Otech/programs/clojure/swank-clojure")
  (require 'swank-clojure-autoload)
  ;(swank-clojure-config
   (setq swank-clojure-jar-path "C:/Otech/programs/clojure/clojure/clojure.jar")
   
   (setq swank-clojure-extra-classpaths
         (list "C:/Otech/programs/clojure/clojure-contrib/clojure-contrib.jar"))
   ;)
  
  ;; slime
  (eval-after-load "slime"
    '(progn (slime-setup '(slime-repl))))
  
  (add-to-list 'load-path "C:/Otech/programs/clojure/slime")
  (require 'slime)
  (slime-setup) ;;;type alt-x and slime to start repl
  )