(require 'package)
(setq package-archives
      '(("gnu"   . "https://elpa.gnu.org/packages/")
        ("melpa" . "https://melpa.org/packages/")))
(package-initialize)
(unless package-archive-contents
  (package-refresh-contents))
(require 'use-package)

(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(global-display-line-numbers-mode 1)
(global-hl-line-mode 1)

(use-package rainbow-mode :ensure t :hook (prog-mode . rainbow-mode))
(use-package all-the-icons :ensure t :if (display-graphic-p))
(use-package elcord :ensure t :config (elcord-mode 1))

(load-theme 'doom-ir-black t)

(set-frame-parameter (selected-frame) 'alpha '(90 . 90))
(add-to-list 'default-frame-alist '(alpha . (90 . 90)))

(set-face-attribute 'default nil :family "Departure Mono" :height 130)

(setq backup-directory-alist
      `((".*" . "~/.local/tmp/emacsbackup/")))
(setq make-backup-files t)
(setq backup-by-copying t)

(use-package neotree :ensure t :bind ("<f9>" . neotree-toggle))

(use-package vertico
  :ensure t
  :config
  (vertico-mode 1))

(use-package marginalia :ensure t :hook (vertico-mode . marginalia-mode))

(use-package consult
  :ensure t
  :bind (("C-s" . consult-line) ("C-x b" . consult-buffer)))

(use-package which-key :ensure t :config (which-key-mode 1))

(use-package company :ensure t :hook (prog-mode . company-mode))
(use-package yasnippet :ensure t :hook (prog-mode . yas-minor-mode))
(use-package flycheck :ensure t :hook (prog-mode . flycheck-mode))

(use-package lsp-mode
  :ensure t
  :commands lsp
  :init (setq lsp-keymap-prefix "C-c l")
  :hook ((java-mode c-mode sh-mode python-mode rust-mode go-mode typescript-mode
          lua-mode zig-mode web-mode) . lsp))

(use-package lsp-ui
  :ensure t
  :config (require 'lsp-java-boot))

(global-set-key (kbd "C-c t") 'ansi-term)
(global-set-key (kbd "C-s") 'swiper)

(use-package web-mode
  :ensure t
  :mode "\\.html?\\'"
  :config
  (setq web-mode-enable-auto-pairing t
        web-mode-enable-auto-closing t
        web-mode-enable-auto-expanding t))

(use-package emmet-mode
  :ensure t
  :hook ((web-mode html-mode css-mode) . emmet-mode)
  :config
  (setq emmet-expand-jsx-className? t))

(electric-pair-mode 1)
(setq electric-pair-pairs '((?\" . ?\") (?\{ . ?\}) (?\( . ?\)) (?\[ . ?\]) (?\< . ?\>)))
(setq electric-pair-text-pairs electric-pair-pairs)

(use-package nix-mode :ensure t :mode "\\.nix\\'")
(use-package python :mode "\\.py\\'")
(use-package sh-script :mode "\\.sh\\'")
(use-package fennel-mode :ensure t :mode "\\.fnl\\'" :hook (fennel-mode . macrostep-mode))
(use-package macrostep :ensure t)
(use-package zig-mode :ensure t :mode "\\.zig\\'" :hook (zig-mode . lsp-deferred))
(use-package cc-mode)
(use-package markdown-mode :ensure t :mode "\\.md\\'")
(use-package lua-mode :ensure t :mode "\\.lua\\'")
(use-package rust-mode :ensure t :mode "\\.rs\\'")
(use-package go-mode :ensure t :mode "\\.go\\'")
(use-package typescript-mode :ensure t :mode "\\.ts\\'")
(use-package toml-mode :ensure t :mode "\\.toml\\'")
(use-package yaml-mode :ensure t :mode "\\.ya?ml\\'")
(use-package tuareg
  :ensure t
  :mode ("\\.ml\\'" "\\.mli\\'")
  :hook (tuareg-mode . merlin-mode))

(use-package merlin
  :ensure t
  :hook ((tuareg-mode caml-mode) . merlin-mode)
  :config
  (setq merlin-command 'opam))

(use-package merlin-eldoc
  :ensure t
  :hook (merlin-mode . merlin-eldoc-setup))

(use-package utop
  :ensure t
  :hook (tuareg-mode . utop-minor-mode)
  :config
  (setq utop-command "utop -emacs"))

(use-package ocamlformat
  :ensure t
  :hook (tuareg-mode . ocamlformat-setup-indent)
  :custom
  (ocamlformat-enable 'enable-outside-detected-project))


(use-package doom-modeline
  :ensure t
  :init
  (setq doom-modeline-height 25)
  (setq doom-modeline-bar-width 3)
  (setq doom-modeline-buffer-file-name-style 'truncate-with-project)
  (setq doom-modeline-icon t)
  (setq doom-modeline-major-mode-icon t)
  (setq doom-modeline-enable-word-count t)
  (setq doom-modeline-vcs-max-length 12)
  (setq doom-modeline-mode-icon nil)
  (setq doom-modeline-minor-modes nil)
  :config
  (doom-modeline-mode 1)
  (set-face-attribute 'mode-line nil
                      :background "#000000"
                      :foreground "#ffffff"
                      :box nil)
  (set-face-attribute 'mode-line-inactive nil
                      :background "#111111"
                      :foreground "#888888"
                      :box nil))

(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.
 '(custom-safe-themes
   '("014cb63097fc7dbda3edf53eb09802237961cbb4c9e9abd705f23b86511b0a69"
     "c5801b68568b59976a8e58104c40c9b052d46cca72e367c2e43c1f36a9e79abb"
     default))
 '(package-selected-packages
   '(all-the-icons company consult doom-modeline doom-themes elcord
		   emmet-mode fennel-mode flycheck go-mode lsp-java
		   lsp-ui lua-mode macrostep marginalia merlin
		   merlin-eldoc nano-modeline neotree nix-mode
		   ocaml-eglot ocamlformat rainbow-mode rust-mode
		   swiper toml-mode tuareg typescript-mode utop
		   vertico web-mode yaml-mode yasnippet zig-mode)))
(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.
 )
