;; package setup
(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)

;; UI & Appearance
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(set-frame-parameter (selected-frame) 'alpha '(90 . 90))
(add-to-list 'default-frame-alist '(alpha . (90 . 90)))
(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-badger t)
;; get rid of stupid buffer saves

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

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

;; Completion/UI stuff
(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 swiper :ensure t :bind ("C-s" . swiper))

;; Completion etc.
(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))

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

;; Terminal
(global-set-key (kbd "C-c t") 'ansi-term)

;; HTML/CSS/JS
(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))

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

;; LANGUAGESSSS
(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\\'")
(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.
 '(package-selected-packages
   '(all-the-icons company consult darcula-theme doom-modeline
		   doom-themes elcord emmet-mode fennel-mode flycheck
		   gemini-mode go-mode lsp-java lsp-ui lua-mode
		   macrostep marginalia neotree nix-mode rainbow-mode
		   rust-mode solarized-theme swiper toml-mode
		   typescript-mode vertico vterm 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.
 )
