;; keep customizations in a separate file
(setq custom-file "~/.emacs.d/custom.el")
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)
(set-cursor-color "#FF0000")
(setq dotfiles-dir (file-name-directory
(or (buffer-file-name) load-file-name)))
;; get packages from from melpa
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; use package --- https://github.com/jwiegley/use-package
(defun package-require (pkg)
"Install a package only if it's not already installed."
(when (not (package-installed-p pkg))
(package-install pkg)))
;; Setup use-package function
(package-require 'use-package)
(eval-when-compile
(require 'use-package))
(require 'bind-key)
(require 'fringe)
(setq use-package-always-ensure t)
; Disable gui features
(dolist (mode '(menu-bar-mode tool-bar-mode scroll-bar-mode))
(when (fboundp mode) (funcall mode -1)))
;; fix pasteboard error
(setq save-interprogram-paste-before-kill nil)
;; fix the PATH variable in shell
(defun set-exec-path-from-shell-PATH ()
(let ((path-from-shell (shell-command-to-string "TERM=vt100 $SHELL -i -c 'echo $PATH'")))
(setenv "PATH" path-from-shell)
(setq exec-path (split-string path-from-shell path-separator))))
(when window-system (set-exec-path-from-shell-PATH))
;; set backup directory
(setq backup-directory-alist `(("." . "~/.saves")))
;; toggle whitespace
(global-set-key (kbd "C-x w") 'whitespace-mode)
;; hippie expand completion
(global-set-key (kbd "M-/") 'hippie-expand)
;; open eshell
(global-set-key (kbd "C-x t") 'eshell)
;; rgrep
(global-set-key (kbd "C-x e") 'rgrep)
;; open org directory
(global-set-key (kbd "C-c o")
(lambda ()
(interactive)
(find-file "~/org/")))
;; shift + arrow key to move between windows
(windmove-default-keybindings)
;; disable default downcasing keybinding
(put 'downcase-word 'disabled t)
;; set default font
(set-default-font "Iosevka 18")
(add-to-list 'default-frame-alist '(font . "Iosevka 18"))
;; prevent pop-ups on osx
(setq ns-pop-up-frames nil)
;; use tabs instead of spaces
(setq-default indent-tabs-mode nil)
;; set default tab-width to 2
(setq-default tab-width 2)
;; Always ask for y/n keypress instead of typing out 'yes' or 'no'
(defalias 'yes-or-no-p 'y-or-n-p)
;; get rid of left and right side-space
(set-fringe-mode 0)
;; auto-close parens
(electric-pair-mode 1)
;; show matching paren pair
(show-paren-mode 1)
;; fix eshell node repl weirdness
(setenv "NODE_NO_READLINE" "1")
;; navigate window history with C-c arrow
(when (fboundp 'winner-mode)
(winner-mode 1))
;; auto refresh buffers
(global-auto-revert-mode 1)
;; also auto refresh dired, but be quiet about it
(setq global-auto-revert-non-file-buffers t)
(setq auto-revert-verbose nil)
;; fix ls --dired startup error
(setq dired-use-ls-dired nil)
;; ignore dired metadata in ace jumps
(add-hook 'dired-mode-hook
(lambda ()
(setq-local ace-jump-search-filter
(lambda ()
(get-text-property (point) 'dired-filename)))))
(use-package magit
:ensure t
:bind (("C-x g" . magit-status))
:config
;; revert buffers in magit without notification
(setq magit-revert-buffers 'silent)
;; fix a weird magit issue with the wombat color scheme
;; highlighting the selected hunk in diffs
(defun disable-magit-highlight-in-buffer ()
(face-remap-add-relative 'magit-item-highlight '()))
(add-hook 'magit-status-mode-hook 'disable-magit-highlight-in-buffer))
(use-package ivy
:ensure t
:config
(setq ivy-use-virtual-buffers t)
(setq ivy-count-format "(%d/%d) ")
(ivy-mode 1))
(use-package ace-jump-mode
:ensure t
:bind ("C-c SPC" . ace-jump-mode))
(use-package ace-window
:ensure t
:bind ("M-p" . ace-window)
:config
(setq aw-keys '(?q ?w ?e ?r ?t ?y ?u ?i ?o)))
(use-package lsp-mode
:ensure t
:commands (lsp lsp-deferred)
:hook (go-mode . lsp-deferred))
;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
;; Optional - provides fancier overlays.
(use-package lsp-ui
:ensure t
:commands lsp-ui-mode)
(add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
(use-package clojure-mode)
(use-package cider)
(use-package js2-mode
:mode ("\\.js$" . js2-mode)
:config
(setq-default js2-mode-indent-ignore-first-tab t)
(setq-default js2-show-parse-errors nil)
(setq-default js2-strict-inconsistent-return-warning nil)
(setq-default js2-strict-var-hides-function-arg-warning nil)
(setq-default js2-strict-missing-semi-warning nil)
(setq-default js2-strict-trailing-comma-warning nil)
(setq-default js2-strict-cond-assign-warning nil)
(setq-default js2-strict-var-redeclaration-warning nil)
(add-hook 'js-mode-hook (lambda ()
(setq-default js2-basic-offset 2))))
(use-package coffee-mode
:mode (("\\.coffee$" . coffee-mode)
(".*\\.cjsx\\'" . coffee-mode))
:config
(setq coffee-js-mode 'js2-mode)
(defun coffee-compile-region (start end)
"Compiles a region and displays the JS in another buffer."
(interactive "r")
(let ((buffer (get-buffer coffee-compiled-buffer-name)))
(when buffer (kill-buffer buffer)))
(call-process-region start end coffee-command nil
(get-buffer-create coffee-compiled-buffer-name) nil "-s" "-p" "--bare")
(let ((buffer (get-buffer coffee-compiled-buffer-name)))
(with-current-buffer buffer
(funcall coffee-js-mode)
(goto-char (point-min)))
(display-buffer buffer))))
(use-package sws-mode)
(use-package stylus-mode
:mode ("\\.styl\\'" . stylus-mode))
(use-package geiser
:config (setq geiser-active-implementations '(guile)))
(use-package haskell-mode
:config
(add-hook 'haskell-mode-hook 'turn-on-haskell-indentation))
(use-package find-file-in-project
:bind ("C-x f" . find-file-in-project))
(use-package paredit
:config
(setq paredit-hooks
'(emacs-lisp-mode-hook
clojure-mode-hook
geiser-mode-hook))
(dolist (hook paredit-hooks)
(add-hook hook #'enable-paredit-mode)))
;; https://github.com/skeeto/skewer-mode
(use-package simple-httpd)
(use-package skewer-mode
:config
(skewer-setup))
;; web-mode http://web-mode.org/
(use-package web-mode
:mode (("\\.html?\\'" . web-mode)
("\\.eco\\'" . web-mode)
("\\.erb\\'" . web-mode))
:config
(setq web-mode-indent-style 2)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2))
(use-package nyan-mode
:config
(nyan-mode 1)
(setq nyan-bar-length 16))
(use-package rainbow-mode
:config
(defun activate-rainbow-mode ()
(rainbow-mode 1))
(defun stylus-rainbow-mode ()
(when (and (stringp buffer-file-name)
(string-match "\\.styl\\'" buffer-file-name))
(activate-rainbow-mode)))
(add-hook 'css-mode-hook 'activate-rainbow-mode)
(add-hook 'find-file-hook 'stylus-rainbow-mode))
(use-package exec-path-from-shell
:init
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)))
;; the silver searcher --- https://github.com/Wilfred/ag.el
(use-package ag
:config
(global-set-key (kbd "C-x a") 'ag-project))
(use-package yasnippet
:config
(yas-global-mode 1)
;; prevent yasnippet from indenting
(setq yas-indent-line nil)
(setq yas-root-directory
(concat dotfiles-dir "snippets")))
(use-package multiple-cursors
:config
(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this))
(use-package expand-region
:bind ("C-=" . er/expand-region))
(use-package markdown-mode
:mode (("\\.markdown\\'" . markdown-mode)
("\\.mdown\\'" . markdown-mode)
("\\.md\\'" . markdown-mode)))
(use-package org
:pin manual
:config
(eval-after-load "org"
'(progn
(add-hook 'org-mode-hook
(lambda () (local-unset-key (kbd "C-c SPC"))))
(setq org-startup-indented t))))
(use-package org-present
:config
(add-hook 'org-present-mode-hook
(lambda ()
(visual-line-mode t)
(org-present-big)
(org-display-inline-images)
(org-present-hide-cursor)
(org-present-read-only)))
(add-hook 'org-present-mode-quit-hook
(lambda ()
(visual-line-mode -1)
(org-present-small)
(org-remove-inline-images)
(org-present-show-cursor)
(org-present-read-write))))
;; highlight cursor when scrolling
(use-package beacon
:config
(beacon-mode 1)
(setq beacon-size 20))
(use-package company
:ensure t
:config
(global-set-key (kbd "M-n") 'company-complete))
;; company-lsp integrates company mode completion with lsp-mode.
(use-package company-lsp
:ensure t
:commands company-lsp)
(defun reload-init-file ()
(interactive)
(load user-init-file)
(message "reloaded init.el ✓ ☮ ☯ ☮"))
<<package-init>>
<<keybindings>>
<<preferences>>
<<dired>>
<<ace-jump-mode>>
<<lsp>>
<<coffeescript>>
<<stylus>>
<<sass>>
<<clojure>>
<<elisp>>
<<geiser>>
<<haskell>>
<<golang>>
<<elm>>
<<javascript>>
<<magit>>
<<ivy>>
<<find-file-in-project>>
<<paredit>>
<<skewer-mode>>
<<web-mode>>
<<rainbow-mode>>
<<nyan-mode>>
<<ag.el>>
<<yasnippet>>
<<multiple-cursors>>
<<markdown-mode>>
<<org-present>>
<<exec-path>>
<<beacon-mode>>
<<auto-complete>>
<<restclient>>
<<helpers>>
<<org-mode>>