Skip to content

Instantly share code, notes, and snippets.

@mattdeboard
Created November 26, 2013 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattdeboard/7665139 to your computer and use it in GitHub Desktop.
Save mattdeboard/7665139 to your computer and use it in GitHub Desktop.
;; With numeric ARG, display the tool bar if and only if ARG is
;; positive. Tool bar has icons document (read file), folder (read
;; directory), X (discard buffer), disk (save), disk+pen (save-as),
;; back arrow (undo), scissors (cut), etc.
(tool-bar-mode 0)
;; Get rid of the annoying splash and startup screens
(setq HOME (expand-file-name "~/"))
(setq PATH (getenv "PATH"))
(setenv "PATH" (concat PATH ":/opt/vagrant/bin:" (concat HOME "bin")))
(setq inhibit-splash-screen t
inhibit-startup-message t)
(setenv "GOPATH" "/usr/bin/go")
(setq GO-PKG-PATH "/usr/lib/go/src/pkg/")
;; -----------------
;; package.el config
;; -----------------
(require 'package)
;; (add-to-list 'package-archives
;; '("marmalade" . "http://marmalade-repo.org/packages/") t)
(add-to-list 'package-archives
'("ELPA" . "http://tromy.com/elpa/") t)
(add-to-list 'package-archives
'("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-initialize)
(require 'auto-complete)
;; automatically clean up bad whitespace
(setq whitespace-action '(auto-cleanup))
;; only show bad whitespace
(setq whitespace-style '(trailing space-before-tab
indentation empty
space-after-tab))
(setq default-buffer-file-coding-system 'utf-8-unix)
(setq dotfiles-dir (concat HOME ".emacs.d/"))
(visual-line-mode)
(column-number-mode)
(linum-mode)
(define-key global-map (kbd "RET") 'newline-and-indent)
(setq gist-view-gist t)
(setq require-final-newline t)
(add-hook 'html-mode-hook
(lambda ()
;; Default indentation is usually 2 spaces, changing to 4.
(set (make-local-variable 'sgml-basic-offset) 4)))
(setq sgml-basic-offset 4)
(setq-default default-tab-width 2)
(setq-default tab-width 2)
(setq-default indent-tabs-mode nil)
(setq python-indent-offset 4)
(setq coding-system-for-write 'utf-8-unix)
;; Path bindings
(add-to-list 'load-path (concat HOME "bin/"))
(add-to-list 'load-path dotfiles-dir)
(add-to-list 'load-path (concat dotfiles-dir "clojure-mode"))
(add-to-list 'load-path (concat dotfiles-dir "coffee-mode/"))
(add-to-list 'load-path (concat dotfiles-dir "color-theme"))
(add-to-list 'load-path (concat dotfiles-dir "elpa/"))
(add-to-list 'load-path (concat dotfiles-dir "js2-mode"))
(add-to-list 'load-path (concat dotfiles-dir "magit/"))
(add-to-list 'load-path (concat dotfiles-dir "puppet-mode"))
(add-to-list 'load-path (concat dotfiles-dir "python.el"))
(add-to-list 'load-path (concat dotfiles-dir "virtualenv.el"))
(setq coffee-tab-width 4)
(eval-after-load 'coffee-mode
'(define-key coffee-mode-map (kbd "M-r") 'coffee-compile-buffer))
(eval-after-load 'coffee-mode
'(define-key coffee-mode-map (kbd "C-c f") 'coffee-compile-file))
(setq flymake-coffee-coffeelint-configuration-file
(concat HOME ".coffeelintrc"))
(add-hook 'coffee-mode-hook 'flymake-coffee-load)
(add-hook 'puppet-mode-hook 'linum-mode)
(add-hook 'puppet-mode-hook 'whitespace-mode)
;; nrepl
(add-hook 'nrepl-interaction-mode-hook
'nrepl-turn-on-eldoc-mode)
(setq nrepl-popup-stacktraces nil)
(add-to-list 'same-window-buffer-names "*nrepl*")
(add-to-list 'auto-mode-alist '("\\.cljs$" . clojure-mode))
(add-to-list 'auto-mode-alist '("Vagrantfile$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.pp$" . puppet-mode))
(add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.hbs$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.less$" . css-mode))
(add-to-list 'auto-mode-alist '("\\.json$" . json-mode))
(add-to-list 'auto-mode-alist '("\\.coffeelintrc$" . json-mode))
(add-to-list 'auto-mode-alist '("xmobarrc$" . haskell-mode))
;; (require 'go-flymake)
;; (require 'go-flycheck)
;; tramp
(require 'tramp)
;; tramp path bindings
(add-to-list 'load-path (concat dotfiles-dir "tramp/lisp/"))
(add-to-list 'Info-default-directory-list (concat dotfiles-dir "tramp/info/"))
;; js2-mode
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(setq js2-highlight-level 3
js2-bounce-indent-p t
js2-consistent-level-indent-inner-bracket-p t
js2-pretty-multiline-decl-indentation-p t)
;; Custom indentation function since JS2 indenting is terrible.
;; Uses js-mode's (espresso-mode) indentation semantics.
;;
;; Based on:
;; http://mihai.bazon.net/projects/editing-javascript-with-emacs-js2-mode
(defun bjh-js2-indent-function ()
(interactive)
(save-restriction
(widen)
(let* ((inhibit-point-motion-hooks t)
(parse-status (save-excursion (syntax-ppss (point-at-bol))))
(offset (- (current-column) (current-indentation)))
(indentation (js--proper-indentation parse-status))
node)
(save-excursion
;; I like to indent case and labels to half of the tab width
(back-to-indentation)
(if (looking-at "case\\s-")
(setq indentation (+ indentation (/ js-indent-level 2))))
;; consecutive declarations in a var statement are nice if
;; properly aligned, i.e:
;;
;; var foo = "bar",
;; bar = "foo";
(setq node (js2-node-at-point))
(when (and node
(= js2-NAME (js2-node-type node))
(= js2-VAR (js2-node-type (js2-node-parent node))))
(setq indentation (+ 4 indentation))))
(indent-line-to indentation)
(when (> offset 0) (forward-char offset)))))
(defun bjh-js2-mode-hook ()
(if (not (boundp 'js--proper-indentation))
(progn (js-mode)
(remove-hook 'js2-mode-hook 'bjh-js2-mode-hook)
(js2-mode)
(add-hook 'js2-mode-hook 'bjh-js2-mode-hook)))
(set (make-local-variable 'indent-line-function) 'bjh-js2-indent-function)
(define-key js2-mode-map [(return)] 'newline-and-indent)
(define-key js2-mode-map [(backspace)] 'c-electric-backspace)
(define-key js2-mode-map [(control d)] 'c-electric-delete-forward))
;; Add the hook so this is all loaded when JS2-mode is loaded
(add-hook 'js2-mode-hook 'bjh-js2-mode-hook)
(require 'xscheme)
;; Set browser choice for browse-url
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "google-chrome")
(defun run-coding-hook ()
(run-hooks 'coding-hook))
(add-hook 'puppet-mode-hook 'auto-complete-mode)
(add-hook 'inferior-python-mode-hook 'auto-complete-mode)
(add-hook 'coding-hook 'auto-complete-mode)
(add-hook 'coding-hook 'highlight-80+-mode)
(add-hook 'coding-hook 'highlight-parentheses-mode)
(add-hook 'coding-hook 'linum-mode)
(add-hook 'coding-hook 'whitespace-mode)
(add-hook 'coding-hook 'hs-minor-mode)
;; Go hooks
(add-hook 'before-save-hook 'gofmt-before-save)
(add-hook 'go-mode-hook (lambda ()
(local-set-key (kbd "C-c C-r")
'go-remove-unused-imports)))
(add-hook 'go-mode-hook (lambda ()
(local-set-key (kbd "C-c i") 'go-goto-imports)))
;; General coding hooks
(mapc (lambda (mode-hook)
(add-hook mode-hook 'run-coding-hook))
'(c-mode-hook
clojure-mode-hook
coffee-mode-hook
csharp-mode-hook
css-mode-hook
emacs-lisp-mode-hook
go-mode-hook
haskell-mode-hook
html-mode-hook
js2-mode-hook
json-mode-hook
lisp-mode-hook
python-mode-hook
ruby-mode-hook
scala-mode-hook
sql-mode-hook))
(eval-after-load 'hideshow
'(define-key hs-minor-mode-map [(mouse-9)] 'hs-mouse-toggle-hiding))
(remove-hook 'html-mode-hook 'highlight-80+-mode)
;; clojure-mode
(require 'clojure-mode nil t)
;; color-theme
;; C-u C-x = to get font info at point
(require 'color-theme)
(color-theme-initialize)
(setq color-theme-is-global t
frame-background-mode 'dark)
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
(load-theme 'tango-dark t)
;; python-mode
(require 'python)
(add-hook 'python-mode-hook 'flymake-python-pyflakes-load)
;; haskell-mode
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
;;Ido config
(require 'ido)
(ido-mode t)
(ido-everywhere t)
;;python.el integration with auto-complete.el
(defvar ac-source-python
'((candidates . (lambda() mapcar
'(lambda (completion)
(first (last (split-string completion "\\." t))))))))
;;load authinfo for all processes handled by rcirc
;;rcirc config
(let ((irc-password-file (expand-file-name "~/.rcirc-authinfo.el")))
(when (file-regular-p irc-password-file)
(load irc-password-file)
(require 'rcirc)
;;rcirc default settings
(setq rcirc-prompt "$> "
rcirc-default-nick "mdeboard"
rcirc-default-user-name "mdeboard"
rcirc-default-full-name "Matt"
rcirc-keywords '("matt" "indiana" "@MattDeBoard")
rcirc-authinfo `(("184.106.93.223" nickserv "mdeboard"
,rcirc-freenode-password)
("mattdeboard.net" bitlbee "mdeboard"
,rcirc-bitlbee-password))
rcirc-server-alist `(("184.106.93.223"
:nick "mdeboard"
:password ,rcirc-freenode-password
:port 9275)
("mattdeboard.net"
:nick "mdeboard"
:password ,rcirc-bitlbee-password
:port 6667)))
(add-hook 'rcirc-mode-hook '(lambda () (rcirc-track-minor-mode 1))))
(add-hook 'rcirc-mode-hook 'linum-mode)
)
(defun my-rcirc-complete ()
(interactive)
(let ((current-channel rcirc-target)
(completion (rcirc-complete)))
(concat "@" (rcirc-complete))))
;; (if (member rcirc-target rcirc-hipchat-channels)
;; (concat "@" completion)
;; completion)))
(define-key rcirc-mode-map (kbd "C-c <C-tab>") 'my-rcirc-complete)
;;/reconnect command to re-establish connection w/o opening a new buffer.
(defun-rcirc-command reconnect (arg)
"Reconnect the server process."
(interactive "i")
(unless process
(error "There's no process for this target"))
(let* ((server (car (process-contact process)))
(port (process-contact process :service))
(nick (rcirc-nick process))
channels query-buffers)
(dolist (buf (buffer-list))
(with-current-buffer buf
(when (eq process (rcirc-buffer-process))
(remove-hook 'change-major-mode-hook
'rcirc-change-major-mode-hook)
(if (rcirc-channel-p rcirc-target)
(setq channels (cons rcirc-target channels))
(setq query-buffers (cons buf query-buffers))))))
(delete-process process)
(rcirc-connect server port nick
rcirc-default-user-name
rcirc-default-full-name
channels)))
(defun-rcirc-command clear (arg)
"Clear rcirc buffer."
(interactive "i")
(let ((inhibit-read-only t))
(delete-region
(point-min) rcirc-prompt-start-marker)))
(eval-after-load 'rcirc
'(defun-rcirc-command ld (arg)
"Look of disapproval"
(interactive "i")
(rcirc-send-message process target "ಠ_ಠ")))
(eval-after-load 'rcirc
'(defun-rcirc-command flip (arg)
"Table flip"
(interactive "i")
(rcirc-send-message process target "(╯°□°)╯︵ ┻━┻")))
(eval-after-load 'rcirc
'(defun-rcirc-command unflip (arg)
"Calm down"
(interactive "i")
(rcirc-send-message process target "┬──┬◡ノ(° -°ノ) chill out bro")))
(eval-after-load 'rcirc
'(defun-rcirc-command yey (arg)
"YAAAAAAAAAAAAAAAAAAAAAAAY"
(interactive "i")
(rcirc-send-message process target "\\(。◕‿◕。)/")))
(eval-after-load 'rcirc
'(defun-rcirc-command dead (arg)
"DEAD"
(interactive "i")
(rcirc-send-message process target "(✖╭╮✖)")))
(eval-after-load 'rcirc
'(defun-rcirc-command hypno (arg)
"Zombie/Hypno"
(interactive "i")
(rcirc-send-message process target "(◎_◎)")))
(eval-after-load 'rcirc
'(defun-rcirc-command commie (arg)
"Hammer & Sickle"
(interactive "i")
(rcirc-send-message process target "(☭_☭)")))
(eval-after-load 'rcirc
'(defun-rcirc-command gangnam (arg)
"Gangnam Style"
(interactive "i")
(rcirc-send-message process target "ヘ( ̄ー ̄ヘ)  Op(ノ ̄ー ̄)ノ Op(〜 ̄▽ ̄)〜 Op〜 ( ̄△ ̄〜) Op(☞゚∀゚)☞ Oppan Gangnam Style")))
(eval-after-load 'rcirc
'(defun-rcirc-command haha (arg)
"Nelson from the Simpsons"
(interactive "i")
(rcirc-send-message process target "http://www.youtube.com/watch?v=aIrhVo1WA78")))
(eval-after-load 'rcirc
'(defun-rcirc-command wtf (arg)
"Tom Delonge WTF gif"
(interactive "i")
(rcirc-send-message process target "http://i.imgur.com/QAfZsIX.gif")))
;; Duplicate a line
(defun duplicate-line()
(interactive)
(move-beginning-of-line 1)
(kill-line)
(yank)
(open-line 1)
(next-line 1)
(yank)
)
(defun quote-wrap-line ()
"Wrap marked region with a specified PREFIX and SUFFIX."
(interactive)
(set (make-local-variable 'prefix) (read-from-minibuffer "prefix: "))
(set (make-local-variable 'suffix) (read-from-minibuffer "suffix: "))
(save-excursion (goto-char (region-beginning)) (insert prefix))
(save-excursion (goto-char (region-end)) (insert suffix)))
(define-key python-mode-map "\C-c\M-w" 'quote-wrap-line)
;; Keybinds
(global-set-key (kbd "C-c C-e") 'duplicate-line)
(global-set-key (kbd "<C-tab>") 'other-window)
(global-set-key "\C-xy" 'clipboard-yank)
(global-set-key "\d" 'delete-backward-char)
(global-set-key (kbd "C-c g") 'find-grep-dired)
(global-set-key (kbd "C-c m") 'magit-status)
;; Squirrel backup files (foo.py~) in their own directory.
(setq backup-directory-alist '(("." . "~/.emacs_backups")))
;; This environment variable must be set to `WORKON_HOME' for `virtualenv'
;; to work properly.
(setenv "WORKON_HOME" (concat HOME "Envs"))
(require 'virtualenv)
;; Use virtualenv directory for running Pyflake instead of needing it installed
;; globally.
(eval-after-load 'virtualenv
'(defun virtualenv-python-check (command)
(interactive
(let ((virtualenv-bin-dir (concat (getenv "WORKON_HOME") "/"
virtualenv-workon "/bin/")))
(list (read-string "Check command: "
(concat virtualenv-bin-dir python-check-command " "
(file-name-nondirectory buffer-file-name))))))
(python-check command)))
;; Run Django's 'shell' management command from within the context of the
;; virtualenv for the current file. Won't work unless you're using it in a
;; Python buffer with virtualenv active.
(eval-after-load 'virtualenv
'(defun django-shell (command)
(interactive
(let ((virtualenv-bin-dir (concat (getenv "WORKON_HOME") "/"
virtualenv-workon "/bin/"))
(manage-cmd
(file-name-nondirectory (concat virtualenv-default-directory
"/manage.py"))))
(list (read-string "Django Shell Command: "
(concat (file-name-nondirectory virtualenv-bin-dir)
"python " manage-cmd " shell")))))
(run-python command nil t)))
(require 'rvm)
(rvm-use-default)
(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.
'(column-number-mode t)
'(comment-multi-line t)
'(comment-style (quote multi-line))
'(custom-safe-themes
(quote
("55b1828c9c462df8a00eb65aed6522e5aa576e5a2749a265d84bd8b019c84a7e" "253175c48e22ca39a961ed6a1be980890b5ba47220871006e2a500ac20b48b62" "b444ff29051f88cdcc7a9857fc3eaf0899ba9a5b9dcf1c4641df599d08194407" "fbe1cab4ace68fbf4cc326f8cf5fbac4c675bcedbb9e8d95a8c1f3fbb9119619" default)))
'(js2-auto-indent-p t)
'(js2-basic-offset 2)
'(js2-indent-on-enter-key t)
'(python-indent-offset 4)
'(safe-local-variable-values
(quote
((python-shell-completion-module-string-cod . "';'.join(module_completion('''%s'''))
")
(python-shell-completion-string-code . "';'.join(get_ipython().Completer.all_completions('''%s'''))
")
(python-shell-completion-module-string-code . "';'.join(module_completion('''%s'''))
")
(python-shell-completion-setup-code . "from IPython.core.completerlib import module_completion")
(python-shell-interpreter-args . "")
(python-shell-interpreter . "ipython"))))
'(tab-width 4))
(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.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment