     '(javascript-jshint)))
 
 ;; enable minor mode for js refactoring
-(add-hook 'js2-mode-hook #'js2-refactor-mode)
+(add-hook 'js2-mode-hook 'js2-refactor-mode)
 ;; see: https://github.com/magnars/js2-refactor.el#refactorings
 (js2r-add-keybindings-with-prefix "C-c C-j")
 
 ;; use eslint with web-mode for jsx files
 (flycheck-add-mode 'javascript-eslint 'web-mode)
 
-(defun my-web-mode-hook ()
-  "Hook for `web-mode'."
+(defun rc/web-mode-hook ()
+  "Hook for web-mode"
     (set (make-local-variable 'company-backends)
          '(company-tern company-web-html company-yasnippet company-files)))
 
-(add-hook 'web-mode-hook 'my-web-mode-hook)
+(add-hook 'web-mode-hook 'rc/web-mode-hook)
 
 ;; enable JavaScript completion between <script>...</script> etc.
 (defadvice company-tern (before web-mode-set-up-ac-sources activate)

;; highlight the current line in the buffer
(global-hl-line-mode 1)

;; hide the fringe
(set-fringe-style 0)

;; over-write selection to make things
;; slightly less uncomfortable to others
(delete-selection-mode t)

;; disable annoying warning message about environment variables setting
(setq exec-path-from-shell-check-startup-files nil)
;; make Emacs use the $PATH set up by the user's shell
(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))

;; disable autosave for tramp buffers
(setq tramp-auto-save-directory "/tmp")

;; don't wrap long lines
(setq-default truncate-lines t)

;; set left and right margins for every window
(setq-default left-margin-width 2 right-margin-width 2)
(set-window-buffer nil (current-buffer))

;; rainbow ;;

(require 'rainbow-mode)

(defun rc/setup-rainbow-mode ()
  (interactive)
  (rainbow-mode 1))

(let ((rainbow-enabled-modes
       '(
         html-mode-hook
         web-mode-hook
         js2-mode-hook
         typescript-mode-hook
         css-mode-hook)))
  (dolist (mode rainbow-enabled-modes)
    (add-hook mode 'rc/setup-rainbow-mode)))

;; whitespace ;;

(require 'whitespace)

(setq whitespace-display-mappings
      '((space-mark 32 [183] [46])
        (newline-mark 10 [182 10])
        (tab-mark 9 [9655 9] [92 9])))

(defun rc/setup-whitespace-handling ()
  (interactive)
  (whitespace-mode 1)
  (add-to-list 'write-file-functions 'delete-trailing-whitespace))

(let ((whitespace-enabled-modes
       '(
         tuareg-mode-hook
         c++-mode-hook
         emacs-lisp-mode-hook
         java-mode-hook
         lua-mode-hook
         rust-mode-hook
         scala-mode-hook
         markdown-mode-hook
         web-mode-hook
         j2-mode-hook
         typescript-mode-hook
         reason-mode-hook
         elixir-mode-hook
         idris-mode-hook
         haskell-mode-hook)))
  (dolist (mode whitespace-enabled-modes)
    (add-hook mode 'rc/setup-whitespace-handling)))

;; disable whitespace white popup is displayed
;; see: https://github.com/company-mode/company-mode/pull/245#issuecomment-232943098
(defvar my-prev-whitespace-mode nil)
(make-variable-buffer-local 'my-prev-whitespace-mode)
(defun pre-popup-draw ()
  "Turn off whitespace mode before showing company complete tooltip"
  (if whitespace-mode
      (progn
        (setq my-prev-whitespace-mode t)
        (whitespace-mode -1)
        (setq my-prev-whitespace-mode t))))
(defun post-popup-draw ()
  "Restore previous whitespace mode after showing company tooltip"
  (if my-prev-whitespace-mode
      (progn
        (whitespace-mode 1)
        (setq my-prev-whitespace-mode nil))))
(advice-add 'company-pseudo-tooltip-unhide :before #'pre-popup-draw)
(advice-add 'company-pseudo-tooltip-hide :after #'post-popup-draw)

;; google-translate ;;

(require 'google-translate)
(require 'google-translate-default-ui)

(setq google-translate-default-source-language "en")
(setq google-translate-default-target-language "ru")

(global-set-key (kbd "C-c C-t") 'google-translate-at-point)
(global-set-key (kbd "C-c C-q") 'google-translate-query-translate)

;; mode line ;;

(setq sml/no-confirm-load-theme t)
(setq sml/name-width 20)
(setq sml/mode-width 'full)
(setq sml/shorten-directory t)
(setq sml/shorten-modes t)
(setq sml/theme 'dark)
;; (sml/setup)

;; (rich-minority-mode 1)
;; (setq rm-blacklist '(" GitGutter" " MRev" " company" " mate" " Projectile"))

;; show the current time
(setq display-time-24hr-format t)
(display-time-mode 1)

;; show column number
(column-number-mode t)

;; enable automatic line breaking
(auto-fill-mode t)

;; automatically save place in each file
(save-place-mode t)

;; (add-hook 'prog-mode-hook #'highlight-indentation-mode)
(add-hook 'prog-mode-hook #'rainbow-delimiters-mode)
(add-hook 'prog-mode-hook #'idle-highlight-mode)

;; ivy ;;

(ivy-mode 1)

;; add ‘recentf-mode’ and bookmarks to ‘ivy-switch-buffer’.
(setq ivy-use-virtual-buffers t)
;; number of result lines to display
(setq ivy-height 14)
(setq enable-recursive-minibuffers t)
(setq ivy-count-format "(%d/%d) ")

;; enable fuzzy matching
;; see: https://oremacs.com/2016/01/06/ivy-flx/
(setq ivy-re-builders-alist
      '((ivy-switch-buffer . ivy--regex-plus)
        (t . ivy--regex-fuzzy)))

;; omit ^ at the beginning of regexp
(setq ivy-initial-inputs-alist nil)

;; install projectile replacements (counsel-projectile)
(counsel-projectile-on)

;; winner-mode ;;

;; restore split pane config, winner-undo, winner-redo
(winner-mode 1)

;; evil ;;

;; to restore missing C-u in evil
(setq evil-want-C-u-scroll t)

(require 'evil)

;; swap : and ; to make colon commands easier to type in Emacs
(define-key evil-motion-state-map ";" 'evil-ex)
(define-key evil-motion-state-map ":" 'evil-repeat-find-char)

;; comment region / uncomment region
;; (define-key evil-window-map (kbd "C-c") 'comment-region)
;; (define-key evil-window-map (kbd "C-c C-u") 'uncomment-region)

;; evilify everyting
(require 'evil-leader)
(require 'evil-magit)
(require 'evil-org)

;; enable leader key
(global-evil-leader-mode)
;; use your thumbs!
(evil-leader/set-leader "<SPC>")
(evil-leader/set-key
  "v" 'split-window-horizontally
  "s" 'split-window-vertically
  "U" 'winner-undo
  "R" 'winner-redo
  "d" 'delete-window
  "o" 'other-window
  "w" 'ace-window
  "q" 'treemacs-toggle
  "SPC" 'compile
  "RET" 'writeroom-mode
  "a" 'counsel-projectile-switch-project
  "c" 'projectile-invalidate-cache
  "g" 'magit-status)

;; enable evil-mode globally,
;; good for ex-vimmers like me
(evil-mode 1)

;; highlight parens
(setq show-paren-style 'parenthesis)
(show-paren-mode 1)

;; don't create lock files, fuck collisions
(setq create-lockfiles nil)

;; remove menu bars, toolbars, scrollbars
(when (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(when (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(when (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(when (fboundp 'horizontal-scroll-bar-mode) (horizontal-scroll-bar-mode -1))

(setq make-backup-files nil)        ; disable backup files
(setq auto-save-list-file-name nil) ; disable .saves files
(setq auto-save-default nil)        ; disable auto saving

;; turn off alarms completely
(setq ring-bell-function 'ignore)

;; use spaces instead of tabs everywhere
(setq-default indent-tabs-mode nil)
;; display tabs as 2 spaces
(setq-default tab-width 2)

;; y/n instead of yes/no
(fset 'yes-or-no-p 'y-or-n-p)

;; magit ;;

;; magit requires this setting for ivy completion
(setq magit-completing-read-function 'ivy-completing-read)

;; rtags ;;

(require 'rtags)

;; ggtags ;;

(require 'ggtags)

(defun rc/setup-ggtags ()
  (interactive)
  (ggtags-mode 1))

(add-hook 'c-mode-common-hook 'rc/setup-ggtags)

;; dired+ ;;

;; instantly teleports to the currently
;; edited file’s position in a dired buffer
(global-set-key (kbd "C-x C-j") 'dired-jump)

;; undo-tree ;;

(setq undo-tree-auto-save-history t)

;; theme

;; customize-themes ;;

;; (load-theme 'monochrome t)
;; (load-theme 'quasi-monochrome t)
;; (load-theme 'abyss t)
;; (load-theme 'cyberpunk t)
;; (load-theme 'afternoon t)
;; (load-theme 'paganini t)
;; (load-theme 'gotham t)
;; (load-theme 'deeper-blue t)
;; (load-theme 'gruber-darker t)
(load-theme 'base16-grayscale-dark t)
;; (load-theme 'base16-tomorrow t)
;; (load-theme 'base16-atelier-forest-light t)
;; (load-theme 'base16-atelier-heath-light t)
;; (load-theme 'base16-default-light t)
;; (load-theme 'base16-eighties t)
;; (load-theme 'base16-eighties t)

;; additional customizations

(set-face-attribute 'vertical-border nil :foreground "#000000")

;; color-theme ;;

;; (color-theme-initialie)
;; (color-theme-euphoria)

;; projectile ;;

;; projectile requires this setting for ivy completion
(setq projectile-completion-system 'ivy)
;; useful for very large projects
(setq projectile-enable-caching t)

(setq projectile-require-project-root nil)

(when (executable-find "rg")
  (progn

(use-package js2-mode)
(use-package js2-refactor)
(use-package json-mode)
(use-package erlang)

(use-package elixir-mode
  :init
  (use-package alchemist
    :preface
    ;; (defun alchemist-hex-local-keys (&rest args)
    ;;  (evil-leader/set-local-key
    ;;    "i" 'alchemist-hex-info-at-point))
    :init
    (setq
     alchemist-goto-elixir-source-dir "~/projects/github/elixir"
     alchemist-goto-erlang-source-dir "/usr/local/Cellar/erlang/19.2.3")
    :config
    ;; CAREFUL: this is for evil-leader/set-local-mode, which isn't merged yet,
    ;; see: https://github.com/cofi/evil-leader/pull/35
    ;; (advice-add 'alchemist-hex-mode :after #'alchemist-hex-local-keys)

    ;; elixir general key bindings
    (evil-define-minor-mode-key 'normal 'alchemist-mode " t" 'alchemist-mix-test)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " T" 'alchemist-project-run-tests-for-current-file)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " ," 'alchemist-test-toggle-test-report-display)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " h" 'alchemist-help-search-at-point)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " H" 'alchemist-help)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " a" 'alchemist-project-toggle-file-and-tests)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " A" 'alchemist-project-toggle-file-and-tests-other-window)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " m" 'alchemist-mix)

    ;; elixir IEx-specific key bindings
    (evil-define-minor-mode-key 'normal 'alchemist-mode " e" 'alchemist-iex-project-run)
    (evil-define-minor-mode-key 'normal 'alchemist-mode " r" 'alchemist-iex-reload-module)
    (evil-define-minor-mode-key 'visual 'alchemist-mode " e" 'alchemist-iex-send-current-line)
    (evil-define-minor-mode-key 'visual 'alchemist-mode " E" 'alchemist-iex-send-current-line-and-go)
    (evil-define-minor-mode-key 'visual 'alchemist-mode " r" 'alchemist-iex-send-region)
    (evil-define-minor-mode-key 'visual 'alchemist-mode " R" 'alchemist-iex-send-region-and-go)

    ;; elixir HEX-specific key bindings
    (evil-define-minor-mode-key 'normal 'alchemist-hex-mode " i" 'alchemist-hex-info-at-point)
    (evil-define-minor-mode-key 'normal 'alchemist-hex-mode " I" 'alchemist-hex-info)
    (evil-define-minor-mode-key 'normal 'alchemist-hex-mode " r" 'alchemist-hex-releases-at-point)
    (evil-define-minor-mode-key 'normal 'alchemist-hex-mode " R" 'alchemist-hex-releases)
    (evil-define-minor-mode-key 'normal 'alchemist-hex-mode " f" 'alchemist-hex-search))
  :config
  ;; (add-to-list 'elixir-mode-hook (alchemist-mode +1))
  (add-hook 'elixir-mode-hook 'alchemist-mode)
  (add-hook 'elixir-mode-hook
            (lambda ()
              (when (and
                     (string-equal "exs" (file-name-extension buffer-file-name))
                     (string-equal "mix" (file-name-base buffer-file-name)))
                (alchemist-hex-mode 1)))))

(use-package ensime)
(use-package scala-mode)

(use-package haskell-mode
  :config
  (add-hook 'haskell-mode-hook 'haskell-indent-mode)
  (add-hook 'haskell-mode-hook 'interactive-haskell-mode)
  (add-hook 'haskell-mode-hook 'haskell-doc-mode))

(use-package idris-mode)
;; (require 'bookmark)
;; (bookmark-bmenu-list)

