;;; kkk-package.el --- Package Config                -*- lexical-binding: t; -*-

;; Copyright (C) 2023  Vinicius Teshima <vini.tes@pm.me>

;; Author: Vinicius Teshima <vini.tes@pm.me>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; This are my package config

;;; Code:

(defgroup kkk-package nil
  "A group for all my modes."
  :group 'kkk-emacs)

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

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

;; (setq use-package-verbose t)
(setq use-package-always-defer t)

;; GCMH:
(when (> (/ (car (memory-info)) 1024.0 1024.0) 4.0)
  (use-package gcmh
    :demand t
    :delight
    :functions (gcmh-mode gcmh-set-high-threshold)
    :defines gcmh-verbose
    :init (gcmh-mode t)
    :config
    (setq gcmh-verbose t)
    (gcmh-set-high-threshold)))

(straight-use-package 'org)

;; Evil:
(require 'kkk-evil)

;; Modes:
(require 'kkk-modes)

;; Delight:
(use-package delight
  :demand t
  :functions delight
  :config
  (delight '((abbrev-mode " Ab" emacs)
	     (eldoc-mode " Edc" emacs)
	     (glasses-mode nil emacs)
	     (whitespace-mode nil emacs)
	     (global-whitespace-mode nil emacs)
	     (evil-collection-unimpaired-mode nil evil-collection-unimpaired)
	     (org-indent-mode nil emacs)
	     (org-src-mode nil emacs)
	     (gcmh-mode nil gcmh))))

;; ;; Company:
;; (use-package company
;;   :delight " Cp"
;;   :hook (after-init . global-company-mode)
;;   :bind (:map company-active-map
;; 	      ("<tab>" . company-complete-selection))
;;   :config
;;   (setq company-minimum-prefix-length 1
;; 	company-idle-delay 1)

;;   (setq company-global-modes '(not
;; 			       eshell-mode vterm-mode shell-mode term-mode)))


;; FlyCheck:
(defun load-flycheck ()
  "Load FlyCheck using `use-package'."
  (use-package flycheck
    :demand t
    :delight
    :functions global-flycheck-mode
    :defines flycheck-mode-line-prefix
    :init (global-flycheck-mode)
    :config (setq flycheck-mode-line-prefix "FC"))
  (remove-hook 'prog-mode #'load-flycheck)
  )
(add-hook 'prog-mode #'load-flycheck)

;; Helpful
(use-package helpful
  :bind (([remap describe-function] . helpful-function)
	 ([remap describe-command] . helpful-command)
	 ([remap describe-variable] . helpful-variable)
	 ([remap describe-key] . helpful-key)
	 ("C-h M" . helpful-macro)))

;; IEdit:
(use-package iedit
  :bind ("M-E" . iedit-mode))

;; ;; Logos
;; (use-package logos
;;   :bind (([remap narrow-to-region] . logos-narrow-dwim)
;; 	 ([remap forward-page]     . logos-forward-page-dwim)
;; 	 ([remap backward-page]    . logos-backward-page-dwim)))

(use-package fancy-compilation
  :defer 5
  :functions fancy-compilation-mode
  :defines (fancy-compilation-quiet-prelude fancy-compilation-quiet-prolog)
  :init (fancy-compilation-mode)
  :config
  (setq fancy-compilation-quiet-prelude nil
	fancy-compilation-quiet-prolog nil))

(defun load-magit ()
  "Load Magit using `use-package'."

  ;; Magit
  (use-package magit
    :demand t
    :functions (define-package)
    :custom
    (magit-display-buffer-function
     #'magit-display-buffer-same-window-except-diff-v1))

  ;; Magit-Todo
  (use-package magit-todos
    :functions magit-todos-mode
    :after magit
    :init (magit-todos-mode t))
  )

;; Vertigo:
(use-package vertico
  :demand t
  :functions (vertico-mode vertico-exit-input)
  :defines vertico-map
  :bind (:map vertico-map
	   ("C-x RET" . vertico-exit-input))
  :init (vertico-mode))

;; Marginalia
(use-package marginalia
  :functions marginalia-mode
  ;; :bind (("M-A" . marginalia-cycle)
  ;; 	 :map minibuffer-local-map
  ;; 	 ("M-A" . marginalia-cycle))
  :init (marginalia-mode))

;; Ordeless:
(use-package orderless
  :init
  (setq completion-styles '(orderless basic))
  (setq completion-category-defaults nil)
  (setq completion-category-overrides '((file (styles partial-completion)))))

(defun load-popper ()
  "Load Popper using `use-package'."
  ;; Popper
  (use-package popper
    :demand t
    :functions (popper-mode popper-echo-mode)
    :defines popper-referende-buffers
    :bind (("C-c p l" . popper-toggle-latest)
	   ("C-c p c" . popper-cycle)
	   ("C-c p k" . popper-kill-latest-popup)
	   ("C-c p t" . popper-toggle-type))
    :init
    (popper-mode t)
    (popper-echo-mode -1)
    :custom
    (setq popper-reference-buffers
	  '(Custom-mode
	    compilation-mode
	    message-mode
	    messages-buffer-mode "^\\*Messages\\*"
	    help-mode "^\\*Help\\*"
	    helpful-mode "^\\*helpful"
	    occur-mode
	    "^\\*Warning\\*"
	    "^\\*Compile-Log\\*"
	    "^\\*Backtrace\\*"
	    "^\\*evil-registers\\*"
	    "^\\*Apropos"
	    "^Calc:"
	    "^\\*ielm\\*"
	    "^\\*Tex Help\\*"
	    "^\\*Shell Command Output\\*"
	    "^\\*Async Shell Command\\*"
	    "^\\*Completions\\*"
	    "[Oo]utput\\*"))
    )
  )

;; ;; Projectile
(defun load-projectile()
  "Load Projectile using `use-package'."
  (use-package projectile
    :demand t
    :functions projectile-mode
    :defines (projectile-command-map projectile-mode-line-prefix
				     projectile-mode-line-lighter)
    :bind (("C-x p" . projectile-command-map))
    :init (projectile-mode t)
    :config
    (setq projectile-mode-line-prefix " Pj")
    (setq projectile-mode-line-lighter " Pj"))
  )

;; ;; Rainbow Delimiter
(use-package rainbow-delimiters
  :functions rainbow-delimiters-mode
  :hook (prog-mode . rainbow-delimiters-mode))

;; ;; Vterm
(use-package vterm
  :defines (vterm-max-scrollback vterm-clear-scrollback-when-clearing)
  :config
  (setq vterm-max-scrollback 100000
	vterm-clear-scrollback-when-clearing t))

;; Which Key
(use-package which-key
  :delight
  :functions which-key-mode
  :defines which-key-idle-delay
  :init (which-key-mode t)
  :config (setq which-key-idle-delay 1))

(use-package dired
  :straight nil
  :bind (("C-x C-j" . dired-jump))
  :config
  (setq dired-listing-switches "-lagho --group-directories-first")
  (setq dired-kill-when-opening-new-dired-buffer t))

;; Diredfl
(defun load-diredfl()
  "Load Diredfl using `use-package'."
  (use-package diredfl
    :demand t
    :functions diredfl-global-mode
    :init (diredfl-global-mode)
    )
  (remove-hook 'dired-mode-hook #'load-diredfl)
  )

(add-hook 'dired-mode-hook #'load-diredfl)

(unless (display-graphic-p)
  (use-package xclip
    :demand t
    :functions xclip-mode
    :defines xclip-method
    :init (xclip-mode 1)
    :config (setq xclip-method 'emacs))
  )

;; (require 'kkk-org)

(use-package tempel
  :defer 5
  :custom
  (tempel-trigger-prefix "<")
  (setq tempel-path (concat user-emacs-directory "tempel.eld"))
  :init
  (add-hook 'prog-mode-hook #'tempel-abbrev-mode)
  (global-tempel-abbrev-mode)
  )

;; (use-package combobulate
;;   :straight '(combobulate :type git :host github :repo "mickeynp/combobulate")
;;   :preface (setq combobulate-key-prefix "C-c o")
;;   :functions combobulate-mode
;;   :hook ((python-ts-mode . combobulate-mode)
;; 	 (js-ts-mode . combobulate-mode)
;; 	 (css-ts-mode . combobulate-mode)
;; 	 (yaml-ts-mode . combobulate-mode)
;; 	 (json-ts-mode . combobulate-mode)
;; 	 (typescript-ts-mode . combobulate-mode)
;; 	 (tsx-ts-mode . combobulate-mode))
;;   )

(provide 'kkk-package)
;;; kkk-package.el ends here
