Skip to content

Instantly share code, notes, and snippets.

@danneu danneu/init.el
Last active Dec 26, 2015

Embed
What would you like to do?
~/.emacs.d/
(require 'package)
(add-to-list 'package-archives
'("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
;; Add in your own as you wish:
(defvar my-packages
'(ack-and-a-half ; Ack support
ace-jump-mode ; Jump to letters on screen
auto-complete ; Auto-complete from buffer
ac-nrepl ; Auto-complete support for nrepl's repl
clojure-mode
clojure-test-mode
evil
;; find-file-in-project ; Replaced with Projectile
haskell-mode
;; hackernews ; Didn't seem to work
hlinum ; Highlights current linenumber in gutter
ido-ubiquitous ; Use ido-mode for everything
flx-ido ; Fuzzy-matching in ido-mode
markdown-mode
mustache-mode
nrepl
paredit
projectile ; Great general tools
rainbow-delimiters
smex ; Remember the M-x commands I use most often
)
"A list of packages to ensure are installed at launch.")
;; Boilerplate to auto-install my packages
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
(load "~/.emacs.d/user.el")
;; These are all managed by Emacs. End of user-edittable area.
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-safe-themes (quote ("dc6c0b236bb09603babadd87329aa857e286ee36715811519d4bfe6278ee4367" default)))
'(global-rainbow-delimiters-mode nil)
'(nrepl-mode-hook (quote (nrepl-toggle-pretty-printing)) t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(linum ((t (:inherit (shadow default) :foreground "gray30"))))
'(linum-highlight-face ((t (:inherit default :foreground "White"))))
'(rainbow-delimiters-depth-1-face ((t (:foreground "#888A85"))))
'(rainbow-delimiters-depth-2-face ((t (:foreground "#F0A326"))))
'(rainbow-delimiters-depth-3-face ((t (:foreground "#FDFA2B"))))
'(rainbow-delimiters-depth-4-face ((t (:foreground "#AAF62E"))))
'(rainbow-delimiters-depth-5-face ((t (:foreground "#6CF326"))))
'(rainbow-delimiters-depth-6-face ((t (:foreground "#6AF57E"))))
'(rainbow-delimiters-depth-7-face ((t (:foreground "#67F9FB"))))
'(rainbow-delimiters-depth-8-face ((t (:foreground "#846FFA"))))
'(rainbow-delimiters-depth-9-face ((t (:foreground "white"))))
'(rainbow-delimiters-unmatched-face ((t (:background "Red" :foreground "White")))))
;; - https://gist.github.com/robert-stuttaford/6255383
;; Unbind describe-copying. I always accidentally press this.
(global-unset-key (kbd "C-h C-C"))
;; Set initial Emacs frame size
(setq initial-frame-alist '((top . 0)
(left . 0)
(width . 142)
(height . 44)))
;; (custom-set-variables '(initial-frame-alist (quote ((fullscreen . maximized)))))
;; Quickly navigate to init.el and user.el
;; M-x init
;; M-x user
(defun init ()
(interactive)
(find-file "~/.emacs.d/init.el"))
(defun user ()
(interactive)
(find-file "~/.emacs.d/user.el"))
;; M-x eb to quickly eval changes.
(defalias 'eb 'eval-buffer)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Highlight line numbers
(require 'hlinum)
;; For some reason, Emacs launched from GUI isn't reading
;; Homebrewed packages. (lol, still isn't)
(push "/usr/local/bin" exec-path)
;; Replace default show-buffers with ibuffer
;; I never use this though. I use `C-x b` to switch buffers
;; since it uses Ido+minibuffer thus fuzzymatching.
(global-set-key (kbd "C-x C-b") 'ibuffer)
;; https://github.com/technomancy/better-defaults/blob/master/better-defaults.el
(setq x-select-enable-clipboard t
x-select-enable-primary t
save-interprogram-paste-before-kill t
apropos-do-all t)
;; General settings ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Don't wrap lines
;; (setq-default truncate-lines t)
;; Clojure
;; - Enter clojure-mode for .edn and .cljs files.
;; Sometimes the lord takes on various forms
(setq auto-mode-alist (cons '("\\.edn$" . clojure-mode) auto-mode-alist))
(setq auto-mode-alist (cons '("\\.cljs$" . clojure-mode) auto-mode-alist))
;; *scratch* starts empty
(setq initial-scratch-message nil)
;; Set *scratch* to Clojure mode cuz I'm usually scribbling out
;; some clo-clo.
(when (locate-library "clojure-mode")
(setq initial-major-mode 'clojure-mode))
;; Disable file backups #yolo
(setq make-backup-files nil)
(setq backup-inhibited t)
;; Disable auto-save #yolo
(setq auto-save-default nil)
(setq-default tab-width 2)
;; Turn off tabs
(setq-default indent-tabs-mode nil)
;; Turn off top toolbar chrome with buttons like "save file"
(tool-bar-mode -1)
(tooltip-mode -1)
;; Turn off native scroll bars. Evil's vim ruler is baller.
;; (Shows progress down a page as percentage.)
(scroll-bar-mode -1)
;; Don't blink the cursor
;; - Actually this helps me find it.
;;(blink-cursor-mode -1)
;; Show linenumber in all buffers.
(global-linum-mode t)
(setq linum-format "%2d") ; Make linum gutter 4 chars wide
;; Show paren ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; - This explains how to treat paren when you hover over one
;; and it matches the other
(show-paren-mode t)
;; Highlight the entire inner body of the matches parens.
(setq show-paren-style 'expression) ; '(parenthesis mixed expression)
;; Show it instantly.
(setq show-paren-delay 0)
;; I set the background of the body and parens to a subtle grey.
(set-face-attribute 'show-paren-match-face nil
:overline nil
:background "grey15"
:underline nil
;:weight 'extrabold
;:slant 'oblique
;:strike-through nil
;:box nil
)
;; Let me type y or p when Emacs prompts me
;; with yes or no things.
(defalias 'yes-or-no-p 'y-or-n-p)
;; Place downloaded elisp files in this directory.
;; You'll then be able to load them.
;; For example, if you download yaml-mode.el to ~/.emacs.d/vendor,
;; then you can add the following code to this file:
;;
;; (require 'yaml-mode)
;; (add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
;;
;; Adding this code will make Emacs enter yaml mode whenever
;; you open a .yml file
(add-to-list 'load-path "~/.emacs.d/vendor")
;; Evil-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; >> and << shift 2 spaces instead of 4
(setq evil-shift-width 2)
;; Without this, the cursor was black in all modes.
;; I think this uses the color of cursor defined in the theme.
(setq evil-default-cursor nil)
;; I think you need to set stuff before this evil-mode
;; is set but I don't really understand how load order
;; impacts things.
(evil-mode 1)
;; (define-key evil-normal-state-map
;; (kbd ";a") 'find-file-in-project)
;; ^- I changed this to `C-; f` when I switched from
;; find-file-in-project to Projectile.
;; C-u is an Emacs things but I never needed to use it.
;; So I set it to Vim-scroll-up to match C-d scroll-down.
(define-key evil-normal-state-map
(kbd "C-u") 'evil-scroll-up)
;; nREPL ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq nrepl-hide-special-buffers t) ; Don't show buffers like connection or server
(setq nrepl-popup-on-error nil) ; Don't popup new buffer for errors (show in nrepl buffer)
(setq nrepl-popup-stacktraces-in-repl t) ; Display stacktrace inline
(setq nrepl-popup-stacktraces nil)
(add-hook 'nrepl-mode-hook 'auto-complete-mode)
;(define-key global-map (kbd "RET") 'newline-and-indent)
;; Auto-complete-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://stackoverflow.com/questions/12160209/emacs-auto-complete-installed-by-package-from-http-marmalade-repo-org-doesnt
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-1.4/dict")
(ac-config-default)
;; ac-nrepl provides an nrepl-specific completion source, (from ac-nrepl github)
;; so auto-complete needs to be told to use them when nrepl-mode is active.
(require 'ac-nrepl)
(add-hook 'nrepl-mode-hook 'ac-nrepl-setup)
(add-hook 'nrepl-interaction-mode-hook 'ac-nrepl-setup)
(eval-after-load "auto-complete" '(add-to-list 'ac-modes 'nrepl-mode))
;; hook AC into completion-at-point
(defun set-auto-complete-as-completion-at-point-function ()
(setq completion-at-point-functions '(auto-complete)))
(add-hook 'auto-complete-mode-hook
'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-mode-hook
'set-auto-complete-as-completion-at-point-function)
(add-hook 'nrepl-interaction-mode-hook
'set-auto-complete-as-completion-at-point-function)
;; Paredit-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(paredit-mode t)
;; Start paredit in appropriate modes
(add-hook 'clojure-mode-hook 'paredit-mode)
(add-hook 'nrepl-mode-hook 'paredit-mode)
(add-hook 'emacs-lisp-mode-hook 'paredit-mode)
(add-hook 'lisp-mode-hook 'paredit-mode)
;; Ido-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (require 'flx-ido)
(ido-mode t)
(ido-ubiquitous-mode t)
(ido-everywhere t)
(flx-ido-mode t)
(setq ido-use-faces nil) ; Disable ido faces to see flx highlights
;; Make ido-mode display vertically.
;; https://dl.dropboxusercontent.com/spa/quq37nq1583x0lf/zs04hp0q.png
(setq ido-decorations
(quote
("\n-> " ; Opening bracket around prospect list
"" ; Closing bracket around prospect list
"\n " ; separator between prospects
"\n ..." ; appears at end of truncated list of prospects
"[" ; opening bracket around common match string
"]" ; closing bracket around common match string
" [No match]" ; displayed when there is no match
" [Matched]" ; displayed if there is a single match
" [Not readable]" ; current diretory is not readable
" [Too big]" ; directory too big
" [Confirm]"))) ; confirm creation of new file or buffer
;; Adds C-j and C-k to go up and down ido-mode selection
;; which is much better than C-r and C-s defaults provided by
;; Emacs. I also added C-n and C-p which are nicer when
;; the ido-selections are displayed horizontally.
(add-hook
'ido-setup-hook
(lambda ()
(define-key ido-completion-map (kbd "C-j") 'ido-next-match)
(define-key ido-completion-map (kbd "C-k") 'ido-prev-match)
(define-key ido-completion-map (kbd "C-n") 'ido-next-match)
(define-key ido-completion-map (kbd "C-p") 'ido-prev-match)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Remove visual bell
(setq visible-bell t
ring-bell-function 'ignore)
;; Font
(set-frame-font "Menlo-16")
;; Themes
;; - This lets me drop themes in a folder if I want
;; to make them available.
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(add-to-list 'load-path "~/.emacs.d/themes")
;; These theme ships with Emacs. <3
(load-theme 'wombat t)
;; Toggle window split ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Toggle Window Split with `C-x Shift-|`
;;
;; Toggle between [-] and [|] window arrangement.
;; Source: http://www.emacswiki.org/emacs/ToggleWindowSplit
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
(global-set-key (kbd "C-x |") 'toggle-window-split)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Ensure pretty-printing enabled in nrepl's repl.
(custom-set-variables
'(nrepl-mode-hook '(nrepl-toggle-pretty-printing)))
;(require 'clojure-mode)
;; Tell clojure-mode how to indent these nonstandard symbols.
(define-clojure-indent
(defroutes 'defun)
(GET 1)
(POST 2)
(PUT 2)
(DELETE 2)
(HEAD 2)
(ANY 2)
(context 2)
(select 1)
(insert 1)
(form-to 1)
(go-loop 1))
;(add-hook 'html-mode-hook 'django-highlight-comments)
;; Smex is a M-x enhancement for Emacs. Built on top of Ido,
;; it provides a convenient interface to your recently and
;; most frequently used commands. And to all the other commands, too.
;;
;; Commands
;;
;; C-h f -- while Smex is active, runs describe-function on
;; the currently selected command.
;; M-. -- jumps to the definition of the selected command.
;; C-h w -- shows the key bindings for the selected command. (Via where-is.)
;; (require 'smex)
;; (smex-initialize)
;; (global-set-key (kbd "M-x") 'smex)
;; (global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; ;; This is your old M-x.
;; (global-set-key (kbd "C-c C-c M-x") 'execute-extended-command)
;; ;; Default is ~/.smex-items
;; (setq smex-save-file "~/.emacs.d/.smex-items")
;; This adds path-info to buffers that would otherwise have
;; the same name like if catdog.clj is opened from two
;; different directories.
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; This is awesome and remembers where I was scrolled to in
;; files. It stores info in ~/.emacs.d/saved-places.
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file
(concat user-emacs-directory "saved-places"))
;; I just use / and ?
;; Dunno why this is here.
;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
;; (global-set-key (kbd "C-M-s") 'isearch-forward)
;; (global-set-key (kbd "C-M-r") 'isearch-backward)
;; Markdown ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; gfm-mode is better than markdown-mode so use that.
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdown files" t)
(add-to-list 'auto-mode-alist '("\\.text\\'" . gfm-mode))
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode))
;; Projectile ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; https://github.com/bbatsov/projectile
;; (setq projectile-keymap-prefix (kbd "C-c C-p"))
;; Prefix projectile commands with C-;.
(setq projectile-keymap-prefix (kbd "C-;"))
; Enable it globally
(projectile-global-mode)
;; ace-jump-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; SPC-d will highlight available d's I can jump to.
(define-key evil-normal-state-map (kbd "SPC") 'ace-jump-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; In Vim I use nerd-commenter to toggle comments on
;; selections. This replicates the `; c SPC` sequence
;; to toggle comment on the selected region.
;; TODO: Make it toggle the line if I use it without
;; a visual selection.
(define-key evil-visual-state-map (kbd "; c SPC")
'comment-or-uncomment-region)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Delete trailing whites (end of lines, end of file) on save
(add-hook 'before-save-hook 'delete-trailing-whitespace)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; This is an incomplete attempt to make C-c C-k (eval file
;; with nrepl) save the file automatically so it doesn't
;; prompt me eeeevery time. But unfortunately I got carried
;; away trying to make it also start nrepl if it wasn't
;; already started and never finished it.
(defun filter (pred coll)
(delq nil
(mapcar
(lambda (item)
(and (funcall pred item) item))
coll)))
(defun nrepl-buffer-name? (buff-name)
(string-prefix-p "*nrepl" buff-name))
(mapcar 'nrepl-buffer-name? '("*nrepl*" "lol" "derp"))
;; delq [object list] -- destructively removes items from list where object eq item.
;; eq [item1 item2] -- tests if objects are same object (eq "abc" "abc") => nil
;; equal [item1 item2] -- tests if they have equal components (equal "abc" "abc") => t
(defun nrepl-started? ()
(interactive)
(dolist (buffer (buffer-list))
(when (string-prefix-p "*nrepl" (buffer-name buffer))
(kill-buffer buffer)))
)
(defun save-and-nrepl-load-current-buffer ()
(interactive)
(save-buffer)
;(when (nrepl-jack-in))
(nrepl-load-current-buffer))
(define-key clojure-mode-map (kbd "C-c C-k")
'save-and-nrepl-load-current-buffer)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enable rainbow-delimiters in any programming-language mode.
(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
;; Haskell-mode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'haskell-mode-hook 'turn-on-haskell-doc-mode)
;; Embedded SICP book! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; http://www.neilvandyke.org/sicp-texi/
;;
;; `C-h i` to shows all textinfo docs and you can add a
;; Emacs-friendly SICP book to the available docs
;; to read from within Emacs.
;; This is an effort to load SICP textinfo file from
;; ~/.emacs.d. I don't remember if it worked. I know one
;; of my 3 efforts works when Emacs GUI is run from terminal,
;; another of my 3 efforts works when Emacs GUI is run from
;; Emacs.app. Don't even care anymore.
;; TODO: Apparently there's a package-install package
;; that does this all for you.
(setq Info-default-directory-list
(cons "~/.emacs.d/info" Info-default-directory-list))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.