Skip to content

Instantly share code, notes, and snippets.

@mattd
Created June 11, 2015 21:35
Show Gist options
  • Save mattd/25fd693420a5554618ed to your computer and use it in GitHub Desktop.
Save mattd/25fd693420a5554618ed to your computer and use it in GitHub Desktop.
;;;; Emacs configuration for Matt Dawson
;;;; Inspiration taken from many places, but especially Ron DuPlain's config.
;;;; GNU Emacs 24
;;; Basics
;; Define load paths.
(setq load-path (cons "~/.emacs.d" load-path))
(add-to-list 'load-path "~/.emacs.d/slime")
;; Disable the menu bar.
(menu-bar-mode -1)
;; Turn off decoration.
(setq inhibit-startup-message t)
(setq initial-scratch-message nil)
;; Show the column number in addition to the line number.
(setq-default column-number-mode 1)
;; When scrolling down and up again, point should end up in the same place.
(setq scroll-conservatively 1)
;; Accept y or n when presented with yes or no.
(fset 'yes-or-no-p 'y-or-n-p)
;; Make non-unique buffer names unique and include path info.
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; Always use syntax highlighting.
(global-font-lock-mode 1)
;; Prefer 80 character line length.
(setq-default fill-column 80)
;; Indent only with spaces (default 4).
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil)
;; M-C-SP is inaccessible on OSX, so put mark-sexp elsewhere.
(global-set-key (kbd "C-M-y") 'mark-sexp)
;; Turn on paren matching and change indicator background.
(show-paren-mode 1)
(custom-set-faces
'(show-paren-match ((((class color) (background dark)) (:background "color-238")))))
;; Turn on line numbers
(global-linum-mode 1)
;; Set dynamic line number formatting.
;; See here: http://stackoverflow.com/a/8470136
(defadvice linum-update-window (around linum-dynamic activate)
(let* ((w (length (number-to-string
(count-lines (point-min) (point-max)))))
(linum-format (concat "%" (number-to-string w) "d ")))
ad-do-it))
;; Don't just show me buffers, interact!
(global-set-key "\C-x\C-b" 'electric-buffer-list)
;; Toggle trailing whitespace on F4.
(defun toggle-show-trailing-whitespace ()
"Toggle show-trailing-whitespace between t and nil"
(interactive)
(setq show-trailing-whitespace (not show-trailing-whitespace))
(redraw-display))
(global-set-key [f4] 'toggle-show-trailing-whitespace)
;; Delete trailing whitespace on F5 and on save.
(global-set-key [f5] 'delete-trailing-whitespace)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;; Jump to next whitespace
(global-set-key (kbd "C-c f") 'forward-whitespace)
;; Set windmove shortcuts.
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <down>") 'windmove-down)
;; Maximize any buffer on M-RET.
(defun toggle-maximize-buffer ()
(interactive)
(if (= 1 (length (window-list)))
(jump-to-register '_)
(progn
(window-configuration-to-register '_)
(delete-other-windows))))
(global-set-key (kbd "M-RET") 'toggle-maximize-buffer)
;; Put autosave and backup files in the system temp folder.
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
;;; Packaging
;; Add Marmalade and MELPA to package server list.
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
;; Check if required packages are installed. Install if not.
(mapc
(lambda (package)
(or (package-installed-p package)
(if (y-or-n-p (format "Package %s is missing. Install it? " package))
(package-install package))))
'(js2-mode
markdown-mode
exec-path-from-shell
slime
slime-js
js2-refactor
ac-slime
json-mode
git-commit-mode
magit
scss-mode
redo+
fiplr
auto-complete
ac-js2
ace-jump-mode
coffee-mode))
;;; Extensions
;; Use magit for git interactions.
(global-set-key "\C-xg" 'magit-status)
; Don't split windows when opening magit.
(setq magit-status-buffer-switch-function 'switch-to-buffer)
;; Use redo+ for more sane undo/redo.
(require 'redo+)
(global-set-key (kbd "C-M-z") 'redo)
(global-set-key (kbd "C-z") 'undo)
;; Set a key binding for fiplr, a find-in-project utility.
(global-set-key (kbd "M-t") 'fiplr-find-file)
;; Display ido results vertically, rather than horizontally.
(setq ido-decorations
(quote ("\n-> "
""
"\n "
"\n ..."
"["
"]"
" [No match]"
" [Matched]"
" [Not readable]"
" [Too big]"
" [Confirm]")))
(defun ido-disable-line-truncation ()
(set (make-local-variable 'truncate-lines) nil))
(add-hook 'ido-minibuffer-setup-hook 'ido-disable-line-truncation)
(defun ido-define-keys () ;; C-n/p is more intuitive in vertical layout
(define-key ido-completion-map (kbd "C-n") 'ido-next-match)
(define-key ido-completion-map (kbd "C-p") 'ido-prev-match))
(add-hook 'ido-setup-hook 'ido-define-keys)
;;; Themes
;; Set theme load path.
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
;; Load the default theme.
(load-theme 'zenburn t)
;;; Modes - General Purpose
;; Is it a markup language? Indent to four spaces.
(setq sgml-basic-offset 4)
;; Set the default mode to Text.
(setq default-major-mode 'text-mode)
;; Treat camel-case fragments as words.
(add-hook 'prog-mode-hook 'subword-mode)
;; Interactively Do Things, with fuzzy matching enabled.
(require 'ido)
(ido-mode t)
(setq ido-enable-flex-matching t)
;; Enable dot-mode with a custom binding.
(require 'dot-mode)
(add-hook 'find-file-hooks 'dot-mode-on)
(global-set-key (kbd "M-,") 'dot-mode-execute)
;; Enable only CUA's rectangle selections.
(cua-selection-mode t)
;; Yet Another Snippet system, for code/text snippets.
(require 'yasnippet)
(setq yas-global-mode 1)
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))
(mapc 'yas/load-directory yas/root-directory)
;; Enable auto complete mode.
(require 'auto-complete-config)
(ac-config-default)
(define-key ac-complete-mode-map "\M-/" 'ac-stop)
(ac-linum-workaround)
;; Do quick text jumps with ace jump mode.
(require 'ace-jump-mode)
(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)
;;; Modes - Programming Languages, Formats, & Frameworks
;; C
(setq-default c-basic-offset 4)
;; Org mode
(setq org-todo-keywords
'((sequence "TODO(t)"
"IN PROGRESS(p)"
"DELEGATED(l)"
"|"
"DONE(d)"
"CANCELED(c)"
"MOVED(m)")
(sequence "WAITING(w)"
"|"
"DONE(d)"
"CANCELED(c)"
"MOVED(m)")
(sequence "EVENT(e)"
"IN PROGRESS(p)"
"|"
"DONE(d)"
"CANCELED(c)"
"MOVED(m)")))
;; Markdown
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
;; SCSS
(setq scss-compile-at-save nil)
;; Handlebars
(require 'handlebars-mode)
(setq handlebars-basic-offset 4)
;; JavaScript
(autoload 'js2-mode "js2-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.js.*" . js2-mode))
; Allow autocomplete to do inline evaluation.
(setq ac-js2-evaluate-calls t)
; Add support for json files.
; See here: https://code.google.com/p/js2-mode/issues/detail?id=50#c7
(defadvice js2-reparse (before json)
(setq js2-buffer-file-name buffer-file-name))
(ad-activate 'js2-reparse)
(defadvice js2-parse-statement (around json)
(if (and (= tt js2-LC)
js2-buffer-file-name
(string-equal (substring js2-buffer-file-name -5) ".json")
(eq (+ (save-excursion
(goto-char (point-min))
(back-to-indentation)
(while (eolp)
(next-line)
(back-to-indentation))
(point)) 1) js2-ts-cursor))
(setq ad-return-value (js2-parse-assign-expr))
ad-do-it))
(ad-activate 'js2-parse-statement)
;; js2-mode steals TAB, let's steal it back for yasnippet
(defun js2-tab-properly ()
(interactive)
(let ((yas/fallback-behavior 'return-nil))
(unless (yas/expand)
(indent-for-tab-command)
(if (looking-back "^\s*")
(back-to-indentation)))))
(add-hook 'js2-mode-hook
(lambda ()
(yas-minor-mode 1)
(define-key js2-mode-map (kbd "TAB") 'js2-tab-properly)))
; Use the outdated espresso mode for more sensible tabs.
(autoload 'espresso-mode "espresso")
; Modify js2's syntax table for jsx.
(defun modify-syntax-table-for-jsx ()
(modify-syntax-entry ?< "(>")
(modify-syntax-entry ?> ")<"))
(add-hook 'js2-mode-hook 'modify-syntax-table-for-jsx)
; Add smartparens support for jsx.
(eval-after-load 'js2-mode
'(sp-local-pair 'js2-mode "<" ">"))
; Define js2 specific settings.
(custom-set-variables
'(js2-basic-offset 4)
'(js2-bounce-indent-p t))
; Configure swank-js.
(setq inferior-lisp-program "/usr/local/bin/sbcl")
(require 'slime)
(slime-setup)
(global-set-key [f2] 'slime-js-reload)
(add-hook 'js2-mode-hook
(lambda ()
(slime-js-minor-mode 1)))
(load-file "~/.emacs.d/setup-slime-js.el")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment