My .emacs file is a collection of hacks, both stolen from the internet and written myself.
LISP:
- ;; -----------------------------------------------------------------------
- ;; Elliot's .emacs file
- ;; -----------------------------------------------------------------------
- ;; -----------------------------------------------------------------------
- ;; Garbage Collector
- ;; -----------------------------------------------------------------------
- ;; We have extra ram these days. Use 3 megs of memory to speed up
- ;; runtime a bit. This shaves off about 1/10 of a second on startup.
- (setq gc-cons-threshold (max 3000000 gc-cons-threshold))
- ;; -----------------------------------------------------------------------
- ;; Platform Selection
- ;; -----------------------------------------------------------------------
- (defvar running-apple (string-match "apple" system-configuration))
- (defmacro Xlaunch (&rest x)
- (list 'if (eq window-system 'x) (cons 'progn x)))
- (defmacro Aqua (&rest x)
- (list 'if (and (eq window-system 'mac) running-apple) (cons 'progn x)))
- ;; -----------------------------------------------------------------------
- ;; User interface
- ;; -----------------------------------------------------------------------
- ;; ------------------------------------------ [ Initial position for X11 ]
- (Xlaunch
- (setq default-frame-alist
- '((wait-for-wm . nil)
- (top . 0)
- (width . 85)
- (height . 75)
- (tool-bar-lines . 0)
- (menu-bar-lines . 0))))
- ;; ------------------------------------------ [ Initial position for Mac ]
- (Aqua
- (setq default-frame-alist
- '((wait-for-wm . nil)
- (top . 0)
- (width . 85)
- (height . 57)
- (tool-bar-lines . 0)
- (menu-bar-lines . 0))))
- ;; Interface needs to be minimal...
- (put 'scroll-left 'disabled nil)
- (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
- (if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
- (if (fboundp 'blink-cursor-mode) (blink-cursor-mode -1))
- (transient-mark-mode t)
- ;; -----------------------------------------------------------------------
- ;; Load paths
- ;; -----------------------------------------------------------------------
- (defvar my-load-path (expand-file-name "~/.elliot-unix/emacs/site-lisp"))
- (add-to-list 'load-path my-load-path)
- (setq byte-compile-warnings nil)
- ;; -----------------------------------------------------------------------
- ;; Color Themes
- ;; -----------------------------------------------------------------------
- (require 'color-theme)
- ;;(setq color-theme-is-global t)
- ;; Use color themes only in windowed modes.
- (cond (window-system
- (require 'color-theme-black-forest)
- (color-theme-black-forest)))
- ;; -----------------------------------------------------------------------
- ;; Personal Keybindings
- ;; -----------------------------------------------------------------------
- (global-set-key '[f2] 'grepsource)
- (global-set-key '[f3] 'svn-status)
- (global-set-key '[f4] 'gdb)
- (global-set-key '[f5] 'compile)
- ;;;;;;; DO NOT USE [f9], [f10], [f11], OR [f12]. They're taken by the
- ;;;;;;; OS on OSX for the Expose stuff.
- (global-set-key "\C-x\M-f" 'find-file-at-point)
- (global-set-key "\M-gc" 'goto-char)
- ;;; Unbind the stupid minimize that I always hit.
- (global-unset-key "\C-z")
- (global-set-key [(shift home)] '(lambda () (interactive) (other-window -1)))
- (global-set-key [(shift end)] '(lambda () (interactive) (other-window 1)))
- ;; Setup hippie-expand (we're going to have to make an eval-after-load
- ;; section later)
- (global-set-key "\M-/" 'hippie-expand)
- (setq hippie-expand-try-functions-list
- '(try-expand-dabbrev
- try-complete-file-name
- try-expand-all-abbrevs
- try-expand-list
- try-expand-dabbrev-all-buffers
- try-expand-dabbrev-from-kill))
- ;; -----------------------------------------------------------------------
- ;; Global Hook Additions
- ;; -----------------------------------------------------------------------
- ;;(add-hook 'before-save-hook 'copyright-update)
- ;;(setq-default copyright-query nil)
- ;; -----------------------------------------------------------------------
- ;; Initial register values
- ;; -----------------------------------------------------------------------
- (set-register ?e '(file . "~/.elliot-unix/emacs/emacs"))
- (cond ((file-exists-p (expand-file-name "~/Projects/rldev"))
- (set-register ?k '(file . "~/Projects/rldev/lib/reallive.kfn")))
- ((file-exists-p (expand-file-name "~/rldev"))
- (set-register ?k '(file . "~/rldev/lib/reallive.kfn"))))
- ;; -----------------------------------------------------------------------
- ;; Autoloads (aka, the way to make emacs fast)
- ;; -----------------------------------------------------------------------
- (autoload 'hide-ifdef-define "hideif" nil t)
- (autoload 'hide-ifdef-undef "hideif" nil t)
- (autoload 'c-mode "cc-mode" "C Editing Mode" t)
- (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
- (autoload 'objc-mode "cc-mode" "ObjC Editing Mode" t)
- (autoload 'ruby-mode "ruby-mode" "Major mode for editing ruby scripts." t)
- (autoload 'bison-mode "bison-mode" "Major mode for editing yacc files." t)
- (autoload 'flex-mode "flex-mode" "Major mode for editing lex files." t)
- (autoload 'make-regexp "make-regexp"
- "Return a regexp to match a string item in STRINGS." t)
- (autoload 'make-regexps "make-regexp" "Return a regexp to REGEXPS." t)
- (autoload 'ascii-table "ascii-table" "Displays the ASCII table." t)
- (autoload 'filladapt-mode "filladapt" "Filladapt mode." t)
- (autoload 'doxymacs-mode "doxymacs" "Deal with doxygen." t)
- (autoload 'cg-mode "cg-mode" "Edit files written in nVidia's Cg language." t)
- (autoload 'lua-mode "lua-mode" "Lua editing mode." t)
- (autoload 'rubydb "rubydb3x" "Ruby debugger" t)
- (autoload 'svn-status "psvn" "psvn.el status mode." t)
- (autoload 'malyon "malyon" "Z-Machine interpreter." t)
- ;; Autoloads to my custom header inserters
- (autoload 'insert-c++-seperator-line "e-seperators" nil t)
- (autoload 'insert-c-seperator-line "e-seperators" nil t)
- (autoload 'insert-elisp-seperator-line "e-seperators" nil t)
- (autoload 'insert-script-seperator-line "e-seperators" nil t)
- (autoload 'insert-c-section-header "e-seperators" nil t)
- (autoload 'insert-c++-section-header "e-seperators" nil t)
- (autoload 'insert-elisp-section-header "e-seperators" nil t)
- (autoload 'insert-script-section-header "e-seperators" nil t)
- (autoload 'insert-c++-big-header "e-seperators" nil t)
- (autoload 'insert-elisp-big-header "e-seperators" nil t)
- (autoload 'insert-script-big-header "e-seperators" nil t)
- (autoload 'insert-text-seperator-line "e-seperators" nil t)
- ;; RLVM and rldev related modes
- (autoload 'kfn-mode "kfn-mode" nil t)
- (autoload 'kepago-mode "kepago-mode" nil t)
- ;; -----------------------------------------------------------------------
- ;; auto-mode-alist
- ;; -----------------------------------------------------------------------
- (setq auto-mode-alist
- (append '(("\\.[Cc][Xx][Xx]$" . c++-mode)
- ("\\.[Cc][Pp][Pp]$" . c++-mode)
- ("\\.[Hh][Xx][Xx]$" . c++-mode)
- ("\\.[Tt][Cc][Cc]$" . c++-mode)
- ("\\.h$" . c++-mode)
- ("\\.i$" . c++-mode) ; SWIG
- ("\\.mm?$" . objc-mode)
- ("_emacs" . lisp-mode)
- ("\\.el\\.gz$" . lisp-mode)
- ("\\.mak$" . makefile-mode)
- ("\\.conf$" . conf-mode)
- ("Doxyfile.tmpl$" . makefile-mode)
- ("Doxyfile$" . makefile-mode)
- ("\\.ke$" . kepago-mode)
- ("\\.kfn$" . kfn-mode)
- ("\\.rb$" . ruby-mode)
- ("\\.cml$" . xml-mode)
- ("\\.cg$" . cg-mode)
- ("\\.y$" . bison-mode)
- ("\\.yy$" . bison-mode)
- ("\\.l$" . flex-mode)
- ("\\.ll$" . flex-mode)
- ("\\.lua$" . lua-mode)
- ("\\.org$" . org-mode)
- ) auto-mode-alist))
- (setq interpreter-mode-alist
- (append '(("ruby" . ruby-mode))
- interpreter-mode-alist))
- ;; -----------------------------------------------------------------------
- ;; Startup variables
- ;; -----------------------------------------------------------------------
- (setq user-full-name "Elliot Glaysher"
- user-mail-address "glaysher@umich.edu"
- enable-local-variables :safe
- inhibit-startup-message t
- default-major-mode 'text-mode
- require-final-newline t
- default-tab-width 4
- frame-title-format (concat user-login-name "@" system-name))
- (add-hook 'suspend-hook 'do-auto-save) ;; Auto-Save on ^Z
- (setq-default echo-keystrokes 2
- next-screen-context-lines 4
- compilation-scroll-output t
- indent-tabs-mode nil
- tags-revert-without-query t)
- (put 'eval-expression 'disabled nil)
- (fset 'yes-or-no-p 'y-or-n-p) ;; Make all yes-or-no questions as y-or-n
- ;; -----------------------------------------------------------------------
- ;; Modules loaded at startup (and their configuration)
- ;; -----------------------------------------------------------------------
- ;; ----------------------------------------------------------- [ icicles ]
- (require 'icicles)
- (icy-mode 1)
- (define-key icicle-mode-map [f5] nil) ;; Give me my compile back!
- (setq icicle-reminder-prompt-flag 0)
- ;; ---------------------------------------------------------- [ diminish ]
- ;; Makes minor mode names in the modeline shorter.
- (require 'diminish)
- (diminish 'icicle-mode "")
- (eval-after-load "filladapt"
- '(diminish 'filladapt-mode "Fill"))
- (eval-after-load "abbrev"
- '(diminish 'abbrev-mode "Abv"))
- (eval-after-load "doxymacs"
- '(diminish 'doxymacs-mode "dox"))
- ;; -------------------------------------------------------- [ backup-dir ]
- ;; Changes the location where backup files are placed. Instead of
- ;; being spread out all over the filesystem, they're now placed in one
- ;; location.
- (if (file-accessible-directory-p (expand-file-name "~/.Trash"))
- (add-to-list 'backup-directory-alist
- (cons "." (expand-file-name "~/.Trash/emacs-backups/"))))
- ;; ------------------------------------------------------------- [ pager ]
- ;;; Excellent package for better scrolling in emacs
- ;;; should be default package. But now it can be downloaded
- ;;; from: http://user.it.uu.se/~mic/pager.el
- (require 'pager)
- (global-set-key "\C-v" 'pager-page-down)
- (global-set-key [next] 'pager-page-down)
- (global-set-key "\ev" 'pager-page-up)
- (global-set-key [prior] 'pager-page-up)
- (global-set-key '[M-up] 'pager-row-up)
- (global-set-key '[M-kp-8] 'pager-row-up)
- (global-set-key '[M-down] 'pager-row-down)
- (global-set-key '[M-kp-2] 'pager-row-down)
- ;; -------------------------------------------------- [ browse-kill-ring ]
- ;; Select something that you put in the kill ring ages ago.
- (autoload 'browse-kill-ring "browse-kill-ring" "Browse the kill ring." t)
- (global-set-key (kbd "C-c k") 'browse-kill-ring)
- ;; ------------------------------------------------------------- [ shell ]
- (eval-after-load "shell"
- '(progn
- (ansi-color-for-comint-mode-on)))
- ;; ------------------------------------------------------------ [ ispell ]
- (eval-after-load "ispell"
- '(progn
- ;; Use the -C option when running aspell, which will
- ;; ConsiderCamelCaseToBeCorrect
- (setq ispell-extra-args '("-C"))))
- ;;"-W" "3"))))
- ;; ------------------------------------------------------------- [ tramp ]
- (eval-after-load "tramp"
- '(add-to-list 'tramp-default-method-alist
- '(".*\\.umich\\.edu\\'" "" "ssh")))
- ;; ----------------------------------------------------------- [ flymake ]
- ;; Mostly stolen from http://www.emacswiki.org/cgi-bin/emacs-en/FlymakeRuby
- (eval-after-load "flymake"
- '(progn
- (push '(".+\\.rb$" flymake-ruby-init) flymake-allowed-file-name-masks)
- (push '("Rakefile$" flymake-ruby-init) flymake-allowed-file-name-masks)
- (push '("^\\(.*\\):\\([0-9]+\\): \\(.*\\)$" 1 2 nil 3)
- flymake-err-line-patterns)
- (set-face-background 'flymake-errline "red4")
- (set-face-background 'flymake-warnline "dark slate blue")))
- ;; ----------------------------------------------------------- [ ibuffer ]
- ;; *Nice* buffer switching
- (global-set-key (kbd "C-x C-b") 'ibuffer)
- (setq ibuffer-show-empty-filter-groups nil)
- (setq ibuffer-saved-filter-groups
- '(("default"
- ("svn" (or (mode . svn-status-mode)
- (mode . svn-log-edit-mode)
- (name . "^\\*svn-")
- (name . "^\\*vc\\*$")
- (name . "^\\*Annotate")
- (name . "^\\*vc-")))
- ("emacs" (or (name . "^\\*scratch\\*$")
- (name . "^\\*Messages\\*$")
- (name . "^\\*Help\\*$")
- (name . "^\\*info\\*$")
- (name . "^\\*Occur\\*$")
- (name . "^\\*grep\\*$")
- (name . "^\\*Compile-Log\\*$")
- (name . "^\\*Backtrace\\*$")
- (name . "^\\*Process List\\*$")
- (name . "^\\*gud\\*$")
- (name . "^\\*Man")
- (name . "^\\*WoMan")
- (name . "^\\*Kill Ring\\*$")
- (name . "^\\*Completions\\*$")
- (name . "^\\*tramp")
- (name . "^\\*shell\\*$")
- (name . "^\\*compilation\\*$")))
- ("emacs source" (or (mode . emacs-lisp-mode)
- (filename . "/Applications/Emacs.app")
- (filename . "/bin/emacs")))
- ("agenda" (or (name . "^\\*Calendar\\*$")
- (name . "^diary$")
- (name . "^\\*Agenda")
- (name . "^\\*org-")
- (name . "^\\*Org")
- (mode . org-mode)
- (mode . muse-mode)))
- ("latex" (or (mode . latex-mode)
- (mode . LaTeX-mode)
- (mode . bibtex-mode)
- (mode . reftex-mode)))
- ("dired" (or (mode . dired-mode))))))
- (add-hook 'ibuffer-mode-hook
- (lambda ()
- (ibuffer-switch-to-saved-filter-groups "default")))
- ;; Order the groups so the order is : [Default], [agenda], [emacs]
- (defadvice ibuffer-generate-filter-groups (after reverse-ibuffer-groups ()
- activate)
- (setq ad-return-value (nreverse ad-return-value)))
- ;; ------------------------------------------------------------- [ tempo ]
- (defun tempo-space ()
- (interactive "*")
- (or (tempo-expand-if-complete)
- (insert " ")))
- ;; ---------------------------------------------------------- [ org-mode ]
- (define-key global-map "\C-cl" 'org-store-link)
- (define-key global-map "\C-ca" 'org-agenda)
- (define-key global-map "\C-co" 'org-jump-to-project-todo)
- (defun org-jump-to-project-todo ()
- (interactive)
- (cond (local-project-root
- (find-file-other-window
- (expand-file-name (concat "~/org/" local-project-name ".org"))))
- (t (message "No project set!"))))
- (eval-after-load 'org
- '(progn
- ;; Add all org files in the org directory to the agenda
- (mapcar
- (lambda (file)
- (add-to-list 'org-agenda-files file))
- (directory-files (expand-file-name "~/org/") t "\\.org"))))
- ;; ----------------------------------------------------------- [ doxygen ]
- ;; Disable doxymacs prompts
- (defadvice doxymacs-insert-function-comment (around no-prompt activate compile)
- "Prevents tempo from prompting during doxymacs template insertion"
- (let ((tempo-interactive nil)) ad-do-it))
- (defadvice doxymacs-insert-file-comment (around no-prompt activate compile)
- "Prevents tempo from prompting during doxymacs template insertion"
- (let ((tempo-interactive nil)) ad-do-it))
- ;; -----------------------------------------------------------------------
- ;; Utility Methods
- ;; -----------------------------------------------------------------------
- ;; Taken from O'Reilly Writing Emacs Extensions p 30-31
- ;; Restrict buffer movement to existing buffers
- (defadvice switch-to-buffer (before existing-buffer activate compile)
- "When interactive, switch to existing buffers only, unless given a
- prefix argument"
- (interactive
- (list (read-buffer "Switch to buffer: "
- (other-buffer)
- (null current-prefix-arg)))))
- ;; -----------------------------------------------------------------------
- (defadvice switch-to-buffer-other-window (before existing-buffer
- activate compile)
- "When interactive, switch to existing buffers only, unless given a
- prefix argument"
- (interactive
- (list (read-buffer "Switch to buffer: "
- (other-buffer)
- (null current-prefix-arg)))))
- ;; -----------------------------------------------------------------------
- (defadvice switch-to-buffer-other-frame (before existing-buffer activate
- compile)
- "When interactive, switch to existing buffers only, unless given a
- prefix argument"
- (interactive
- (list (read-buffer "Switch to buffer: "
- (other-buffer)
- (null current-prefix-arg)))))
- ;; -------------------------------------------------------- [ grepsource ]
- (defconst grepsource-command
- "find . -name "*.c" -or -name "*.cc" -or -name "*.cpp" -or -name "*.m" -or -name "*.mm" -or -name "*.java" -or -name "*.h" -or -name "*.hh" -or -name "*.hpp" -or -name "*.el" | xargs grep -n "
- "Base command for grepsource. (Basically quoted version of
- whatever my current grepsource alias is.")
- (defun grepsource (cmd-args)
- "Invoke an in-emacs equivalent of my grepsource bash alias,
- defaulting withing the current project."
- (interactive (list (read-from-minibuffer "Grep project for string: ")))
- (let ((default-directory (or local-project-root default-directory)))
- (grep (concat grepsource-command """
- (replace-regexp-in-string """ "\\\\"" cmd-args) """))))
- ;; ------------------------------------------------- [ intelligent-close ]
- (defun intelligent-close ()
- "quit a frame the same way no matter what kind of frame you are on.
- This method, when bound to C-x C-c, allows you to close an emacs frame the
- same way, whether it's the sole window you have open, or whether it's
- a "child" frame of a "parent" frame. If you're like me, and use emacs in
- a windowing environment, you probably have lots of frames open at any given
- time. Well, it's a pain to remember to do Ctrl-x 5 0 to dispose of a child
- frame, and to remember to do C-x C-x to close the main frame (and if you're
- not careful, doing so will take all the child frames away with it). This
- is my solution to that: an intelligent close-frame operation that works in