;; -*- lexical-binding: t; -*-

;; Configuration for built-ins that don't fit anywhere else
(use-package custom
  :straight (:type built-in)
  :defer t)

(use-package view
  :straight (:type built-in)
  :defer t
  :config
  (evil-collection-define-key 'normal 'view-mode-map
    "0" 'evil-beginning-of-line
    "g0" 'text-scale-adjust))

(use-package simple
  :straight (:type built-in)
  :general
  (leader-map "!" #'shell-command
              "|" #'shell-command-on-region
              ";" #'async-shell-command)
  (normal special-mode-map
          "gr" #'revert-buffer
          "q" #'quit-window)
  (normal messages-buffer-mode-map
          "gr" #'revert-buffer
          "q" #'quit-window))

(use-package shell
  :straight (:type built-in)
  :general
  (normal shell-mode-map "q" #'bury-buffer))

(use-package ediff
  :defer t
  :straight (:type built-in)
  :config
  (setq ediff-window-setup-function #'ediff-setup-windows-plain)

  ;; Restore window configuration after an ediff session
  (defvar ediff-last-windows nil)

  (defun store-pre-ediff-winconfig ()
    (setq ediff-last-windows (current-window-configuration)))

  (defun restore-pre-ediff-winconfig ()
    (set-window-configuration ediff-last-windows))

  (add-hook 'ediff-before-setup-hook #'store-pre-ediff-winconfig)
  (add-hook 'ediff-quit-hook #'restore-pre-ediff-winconfig))

(use-package replace
  :defer t
  :straight (:type built-in))

(use-package hideshow
  :straight (:type built-in)
  :hook (prog-mode . hs-minor-mode)
  :init
  (general-def 'normal "zM" #'hs-hide-level))

(use-package man
  :straight (:type built-in)
  :commands (man)
  :custom
  (manual-program "gman"))

(provide 'init-built-ins)