(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name
        "straight/repos/straight.el/bootstrap.el"
        (or (bound-and-true-p straight-base-dir)
            user-emacs-directory)))
      (bootstrap-version 7))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(setopt inhibit-splash-screen t)
(setopt make-backup-files nil)
(setopt auto-save-default nil)
(setopt create-lockfiles nil)

(setopt initial-major-mode 'fundamental-mode)

(setopt auto-revert-avoid-polling t)
(setopt auto-revert-interval 5)
(setopt auto-revert-check-vc-info t)
(global-auto-revert-mode)

(windmove-default-keybindings 'control)

(setopt sentence-end-double-space nil)
(cua-mode 1)

(menu-bar-mode -1)

(when (display-graphic-p)
  (context-menu-mode))

(setopt enable-recursive-minibuffers t)
(setopt completion-cycle-threshold 1)
(setopt completions-detailed t)
(setopt tab-always-indent 'complete)

(setopt completion-auto-help 'always)
(setopt completions-max-height 20)
(setopt completions-format 'one-column)
(setopt completion-auto-select 'second-tab)

(keymap-set minibuffer-mode-map "TAB" 'minibuffer-complete)

(setopt line-number-mode t)
(setopt column-number-mode t)

(setopt x-underline-at-descent-line nil)
(setopt switch-to-buffer-obey-display-actions t)

(setopt mouse-wheel-tilt-scroll t)
(setopt mouse-wheel-flip-direction t)

(blink-cursor-mode -1)
(pixel-scroll-precision-mode)

(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(add-hook 'text-mode-hook 'display-line-numbers-mode)
(setopt display-line-numbers-width 3)

(add-hook 'text-mode-hook 'visual-line-mode)

(let ((hl-line-hooks '(text-mode-hook prog-mode-hook)))
  (mapc (lambda (hook) (add-hook hook 'hl-line-mode)) hl-line-hooks))

(setopt tab-bar-show 1)

(add-to-list 'tab-bar-format 'tab-bar-format-align-right 'append)
(add-to-list 'tab-bar-format 'tab-bar-format-global 'append)

(straight-use-package 'use-package)
(setq straight-use-package-by-default t)

(use-package emacs
  :hook
  ((prog-mode . electric-pair-mode))
  :config
  (load-theme 'modus-operandi-tinted t))

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

(use-package orderless
  :custom
  (completion-styles '(orderless))
  (completion-category-overrides '((file (styles partial-completion)))))

(use-package magit
  :bind (("C-x g" . magit-status)))

(use-package which-key
  :config
  (which-key-mode))

(use-package eglot
  :hook
  ((lua-mode . eglot))
  :config
  (fset #'jsonrpc--log-event #'ignore))

(use-package git-gutter
  :config
  (global-git-gutter-mode 1))

(use-package marginalia
  :config
  (marginalia-mode))

(use-package vertico
  :init
  (vertico-mode))

(use-package eat
  :custom
  (eat-term-name "xterm")
  :bind
  (("C-c t" . eat))
  :config
  (eat-eshell-mode)
  (eat-eshell-visual-command-mode))

(use-package no-littering
  :custom
  (custom-file (no-littering-expand-etc-file-name "custom.el")))

(use-package scad-mode
  :defer t)

(use-package org-publish-rss
  :straight (org-publish-rss :type git :host nil
			     :repo "https://git.sr.ht/~taingram/org-publish-rss"))

(load-file (expand-file-name "org.el" user-emacs-directory))
