 ;; 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)
-
+
+;; what the fuck is this shit ?
 ;; (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)
+(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
+(add-hook 'prog-mode-hook 'idle-highlight-mode)
 
 ;; 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-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)


;; less GC during startup
;; see: https://github.com/nilcons/emacs-use-package-fast#a-trick-less-gc-during-startup
(setq gc-cons-threshold 64000000)
(add-hook 'after-init-hook
          (lambda ()
            ;; restore after startup
            (setq gc-cons-threshold 800000)))

;; 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
(setq ring-bell-function 'ignore)   ; turn off alarms completely

;; 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)

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

(set-frame-font "Source Code Pro 14" 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)

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

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

;; 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))

;; 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)

;; allow minibuffer commands while in the minibuffer
(setq enable-recursive-minibuffers t)

;; global hotkeys

(global-set-key (kbd "<f11>") 'toggle-frame-fullscreen)

(global-set-key (kbd "C-M-=") 'default-text-scale-increase)
(global-set-key (kbd "C-M--") 'default-text-scale-decrease)

(global-set-key (kbd "C-h") 'windmove-left)
(global-set-key (kbd "C-l") 'windmove-right)
(global-set-key (kbd "C-k") 'windmove-up)
(global-set-key (kbd "C-j") 'windmove-down)

(global-set-key (kbd "C-x C-m") 'magit-status)
(global-set-key (kbd "C-x C-y") 'magit-dispatch-popup)

;; set initial window position
(when (window-system)
  (set-frame-position (selected-frame) 220 130)
  (set-frame-height (selected-frame) 40)
  (set-frame-width (selected-frame) 120))

(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))

;; uncomment if you want to disable GNU MELPA (for some reason)
;; (setq package-archives nil)

;; its ok to use both package-initialize and use-package for a well behaved package:
;; package-initialize will not load the whole package,
;; but only autoload functions selected by the package author
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))
(require 'use-package)
;; install missing packages by default
(setq use-package-always-ensure t)

(use-package base16-theme
  :config
  ;; (load-theme 'base16-grayscale-dark t)
  ;; (set-face-attribute 'vertical-border nil :foreground "#000000")
  ;; (custom-set-faces
  ;;  '(whitespace-line ((t (:background "gray6" :foreground "gray15"))))
  ;;  '(whitespace-space ((t (:background "gray6" :foreground "gray15"))))
  ;;  '(whitespace-tab ((t (:background "gray6" :foreground "gray15")))))
  )

(use-package dracula-theme)
(use-package gotham-theme)
(use-package sublime-themes)
(use-package doom-themes
  :config (load-theme 'doom-vibrant t))

;; packages ;;

(use-package exec-path-from-shell
  :init
  (setq exec-path-from-shell-check-startup-files nil)
  :config
  (setq
    sublimity-scroll-weight 12
    sublimity-scroll-drift-length 0.5
    sublimity-map-size 20
    sublimity-map-fraction 0.3
    sublimity-map-text-scale -10)
  :config
  (require 'sublimity-scroll)
  (require 'sublimity-map) ;; experimental
  (require 'sublimity-attractive)
  (sublimity-map-set-delay 1))

(use-package evil
  :preface
  (defun rc/minibuffer-keyboard-quit ()
    "Abort recursive edit.
    In Delete Selection mode, if the mark is active, just deactivate it;
    then it takes a second \\[keyboard-quit] to abort the minibuffer."
    (interactive)
    (if (and delete-selection-mode transient-mark-mode mark-active)
        (setq deactivate-mark  t)
        (when (get-buffer "*Completions*") (delete-windows-on "*Completions*"))
        (abort-recursive-edit)))
  (defun rc/setup-esc-quits ()
    "Esc should always quit"
    (define-key evil-normal-state-map [escape] 'keyboard-quit)
    (define-key evil-visual-state-map [escape] 'keyboard-quit)
    (define-key minibuffer-local-map [escape] 'rc/minibuffer-keyboard-quit)
    (define-key minibuffer-local-ns-map [escape] 'rc/minibuffer-keyboard-quit)
    (define-key minibuffer-local-completion-map [escape] 'rc/minibuffer-keyboard-quit)
    (define-key minibuffer-local-must-match-map [escape] 'rc/minibuffer-keyboard-quit)
    (define-key minibuffer-local-isearch-map [escape] 'rc/minibuffer-keyboard-quit))
  :init
  ;; to restore missing C-u in evil
  (setq evil-want-C-u-scroll t)
  (use-package evil-magit :demand t)
  (use-package evil-leader
    :init (global-evil-leader-mode)
    :config
    ;; enable leader key
    ;; 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" 'sublimity-mode
      "a" 'counsel-projectile-switch-project
      "c" 'projectile-invalidate-cache
      "g" 'magit-status))
  (use-package evil-org :demand t)
  (use-package evil-numbers :demand t)
  :config
  ;; enable evil-mode globally,
  ;; good for ex-vimmers like me
  (evil-mode 1)
  (rc/setup-esc-quits)
  ;; comment region / uncomment region
  (define-key evil-motion-state-map (kbd "C-c C-r") 'comment-region)
  (define-key evil-motion-state-map (kbd "C-c C-u") 'uncomment-region)
  ;; jumping like in vim
  (define-key evil-normal-state-map (kbd "C-]") (kbd "\\ M-."))
  (global-set-key [escape] 'evil-exit-emacs-state)
  ;; 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))

(use-package whitespace
  :init
  (setq whitespace-display-mappings
        '((space-mark 32 [183] [46])
          (newline-mark 10 [182 10])
          (tab-mark 9 [9655 9] [92 9])))
  :preface
  (defun rc/setup-whitespace-handling ()
    (whitespace-mode 1)
    (add-to-list 'write-file-functions 'delete-trailing-whitespace))
  (defvar rc/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))
  (defvar rc/prev-whitespace-mode nil)
  (make-variable-buffer-local 'rc/prev-whitespace-mode)
  (defun rc/pre-popup-draw ()
    "Turn off whitespace mode before showing company complete tooltip"
    (if whitespace-mode
        (progn
          (setq rc/prev-whitespace-mode t)
          (whitespace-mode -1)
          (setq rc/prev-whitespace-mode t))))
  (defun rc/post-popup-draw ()
    "Restore previous whitespace mode after showing company tooltip"
    (if rc/prev-whitespace-mode
        (progn
          (whitespace-mode 1)
          (setq rc/prev-whitespace-mode nil))))
  :config
  (dolist (mode rc/whitespace-enabled-modes)
    (add-hook mode 'rc/setup-whitespace-handling))
  ;; disable whitespace while popup is displayed
  ;; see: https://github.com/company-mode/company-mode/pull/245#issuecomment-232943098
  (advice-add 'company-pseudo-tooltip-unhide :before 'rc/pre-popup-draw)
  (advice-add 'company-pseudo-tooltip-hide :after 'rc/post-popup-draw)
  :diminish whitespace-mode)

(use-package undo-tree
  :init
  (setq undo-tree-visualizer-diff t)
  (setq undo-tree-visualizer-timestamps t)
  (setq undo-tree-auto-save-history t))

(use-package google-translate
  :init
  (setq google-translate-default-source-language "en")
  (setq google-translate-default-target-language "ru")
  :config
  (require 'google-translate-default-ui)
  :bind
  (:map global-map
        ("C-c C-t" . google-translate-at-point)
        ("C-c C-q" . google-translate-query-translate)))

(use-package rtags)
(use-package ggtags
  :commands ggtags-mode
  :config (add-hook 'c-mode-common-hook 'ggtags-mode)
  :diminish ggtags-mode)

(use-package treemacs
  :defer t
