   (treemacs-follow-mode t)
   (treemacs-filewatch-mode t)
   :bind
+  (:map treemacs-mode-map
+        ("c" . treemacs-create-file)
+        ("C" . treemacs-create-dir)
+        ("d" . treemacs-delete)
+        ("i" . treemacs-visit-node-vertical-split)
+        ("o" . treemacs-visit-node-horizontal-split)
+        ("u" . treemacs-uproot)
+        ("h" . treemacs-toggle-show-dotfiles)
+        ("M-f" . treemacs-follow-mode)
+        ("M-W" . treemacs-toggle-fixed-width)
+        ("M-w" . treemacs-reset-width)
+        ("x" . treemacs-change-root)))
+
+(use-package projectile
+  :init
+  ;; 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)
+  :config
+  (setq projectile-globally-ignored-directories
+        (append '(".git" ".svn" "out" "repl" "project" "target" "venv")
+                projectile-globally-ignored-directories))
+  (setq projectile-globally-ignored-files
+        (append '(".DS_Store" "TAGS" "*.gz" "*.pyc" "*.jar" "*.tar.gz" "*.tgz" "*.zip")
+                projectile-globally-ignored-files))
+  ;; use projectile everywhere
+  (projectile-mode)
+  ;; remove the mode name for projectile-mode, but show the project name
+  ;; :delight '(:eval (concat " " (projectile-project-name)))
+  :bind
   (:map global-map
-   ([f8] . treemacs-toggle)
-   ("<C-M-tab>" . treemacs-toggle)
-   ("M-0" . treemacs-select-window)
-   ("C-c 1" . treemacs-delete-other-windows)
-   :map treemacs-mode-map
-   ("c" . treemacs-create-file)
-   ("C" . treemacs-create-dir)
-   ("d" . treemacs-delete)
-   ("i" . treemacs-visit-node-vertical-split)
-   ("o" . treemacs-visit-node-horizontal-split)
-   ("u" . treemacs-uproot)
-   ("h" . treemacs-toggle-show-dotfiles)
-   ("M-f" . treemacs-follow-mode)
-   ("M-W" . treemacs-toggle-fixed-width)
-   ("M-w" . treemacs-reset-width)
-   ("x" . treemacs-change-root)))
-
-(use-package projectile)
-(use-package irony)
-(use-package irony-eldoc)
+        ("C-x C-q" . projectile-find-file-in-known-projects)
+        ("C-x C-g" . projectile-ripgrep)))
+
+(use-package yasnippet
+  :init
+  (setq yas-snippet-dirs
+        '("~/.emacs.d/snippets"
+          "~/.emacs.d/yasnippet-snippets"))
+  :config
+  (yas-global-mode 1))
+
+;; see http://company-mode.github.io/
+(use-package company
+  :defer 5
+  :preface
+  ;; company interferes with Yasnippet’s native behaviour.
+  (defun check-expansion ()
+    (save-excursion
+            (if (looking-at "\\_>") t
+            (backward-char 1)
+            (if (looking-at "\\.") t
+                (backward-char 1)
+                (if (looking-at "->") t nil)))))
+  (defun rc/do-yas-expand ()
+    (let ((yas/fallback-behavior 'return-nil))
+      (yas/expand)))
+  (defun rc/tab-indent-or-complete ()
+    (interactive)
+    (if (minibufferp)
+        (minibuffer-complete)
+      (if (or (not yas/minor-mode)
+              (null (rc/do-yas-expand)))
+          (if (check-expansion)
+              (company-complete-common)
+            (indent-for-tab-command)))))
+  :init
+  ;; adjust this setting according to your typing speed
+  (setq company-idle-delay 0.4)
+  (setq company-minimum-prefix-length 1)
+  ;; (setq company-show-numbers t)
+  ;; aligns annotation to the right hand side
+  (setq company-tooltip-align-annotations t)
+  ;; (setq company-tern-meta-as-single-line t)
+  ;; (setq company-tooltip-align-annotations t)
+  :config
+  (global-company-mode 1)
+  (add-to-list 'company-backends 'company-tern)
+  (use-package company-web :demand t)
+  (use-package company-tern :demand t)
+  (use-package company-irony :demand t)
+  (use-package company-irony-c-headers :demand t)
+  (with-eval-after-load 'company
+    '(add-to-list 'company-backends
+                  '(company-irony-c-headers
+                    company-irony
+                    merlin-company-backend)))
+  :bind
+  (:map global-map
+   ([tab] . rc/tab-indent-or-complete)))
+
+(use-package irony
+  :defer t
+  :commands irony-mode
+  :config
+  (use-package irony-eldoc :demand t)
+  (add-hook 'c++-mode-hook 'irony-mode)
+  (add-hook 'c-mode-hook 'irony-mode)
+  (add-hook 'objc-mode-hook 'irony-mode)
+  (add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
+  (add-hook 'irony-mode-hook 'irony-eldoc))
+
 (use-package disaster)
-(use-package flycheck)
+
+(use-package flycheck
+  :defer 7
+  :init
+  (setq-default flycheck-disabled-checkers '(emacs-lisp-checkdoc))
+  :config
+  (global-flycheck-mode 1))
+
 (use-package flycheck-rust)
 (use-package flycheck-clojure)
 (use-package flycheck-irony)

(use-package js2-mode)
(use-package js2-refactor)
(use-package json-mode)
(use-package erlang-mode)
(use-package elixir-mode)
(use-package alchemist)
(use-package ensime)
(use-package scala-mode)
(use-package haskell-mode)
(use-package idris-mode)
(use-package reason-mode
  :ensure nil
  :quelpa (reason-mode :repo "arichiardi/reason-mode" :fetcher github :stable t))

(add-to-list 'default-frame-alist '(font . "Source Code Pro 16"))
;; (add-to-list 'default-frame-alist '(font . "VT220-mod 28"))

(set-frame-font "Source Code Pro 16" nil t)
;;(set-frame-font "VT220-mod 28" nil t)

;; disable *GNU Emacs* buffer on startup
(setq inhibit-startup-screen t)

;; disable native fullscreen support
;; I don't like sliding animation on Mac OS X
;; (setq ns-use-native-fullscreen nil)

;; (require 'bookmark)
;; (bookmark-bmenu-list)


  (interactive)
  (tide-setup)
  (flycheck-mode +1)
  (setq
    flycheck-check-syntax-automatically '(save mode-enabled)
    flycheck-tslint-args . ("--type-check"))
  (eldoc-mode +1)
  (tide-hl-identifier-mode +1)
  (add-to-list 'compilation-error-regexp-alist
               '("ERROR in \\(.*\\)\n(\\([0-9]+\\),\\([0-9]+\\)):" 1 2 3))
  (company-mode +1))

(add-hook 'typescript-mode-hook 'setup-tide-mode)

;; enable tide for .tsx files
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode))
