;;; $DOOMDIR/config.el -*- lexical-binding: t; -*-

;; Some functionality uses this to identify you
(setq user-full-name "{{ user_fullname }}"
      user-mail-address "{{ user_email }}")

(setq-default
 ;; Tabs vs Spaces
 indent-tabs-mode nil
 tab-width 4
 evil-shift-width 4
 standard-indent 4
 line-spacing 2
 ;; from @tecosaur
 delete-by-moving-to-trash t
 window-combination-resize t
 x-stretch-cursor t)

(setq evil-want-fine-undo t
      auto-save-default t
      truncate-string-ellipsis "…")

(global-subword-mode 1) ;; use CamelCase words

;; Font settings
(setq doom-font (font-spec :family "{{ monospace_font }}" :size 18 :weight 'semi-light)
      doom-serif-font (font-spec :family "{{ serif_font }}" :size 18 :weight 'semi-light)
      doom-variable-pitch-font (font-spec :family "{{ sans_font }}" :size 18)
      doom-big-font (font-spec :family "{{ monospace_font }}" :size 26 :weight 'semi-light))
(after! unicode-fonts
  (setq doom-unicode-font doom-font))

(custom-set-faces!
  '(font-lock-comment-face :slant italic)
  '(font-lock-keyword-face :weight bold))

(after! doom-modeline
  (setq doom-modeline-major-mode-icon t
        doom-modeline-major-mode-color-icon t
        doom-modeline-buffer-encoding t
        doom-modeline-enable-word-count t
        doom-modeline-unicode-fallback t))

;; Window split direction
(setq evil-vsplit-window-right t
      evil-split-window-below t)

(after! emojify
  (setq emojify-display-style 'unicode))

(setq doom-theme 'doom-nord)
(setq doom-themes-enable-bold t
      doom-themes-enable-italic t)
(after! treemacs
  (setq doom-themes-treemacs-theme 'doom-colors
        doom-themes-treemacs-enable-variable-pitch nil))

;; Pick an image for dashboard
(defun random-choice (items)
      (let* ((size (length items))
             (index (random size)))
       (nth index items)))
(defvar-local kawaii-image (random-choice (directory-files (expand-file-name "images" doom-user-dir) 'full (rx ".png" eos))))
(setq +doom-dashboard-banner-file (file-truename kawaii-image)
      +doom-dashboard-banner-padding '(0 . 2)
      +doom-dashboard-functions '(doom-dashboard-widget-banner
                                  doom-dashboard-widget-shortmenu
                                  doom-dashboard-widget-loaded))

(setq display-line-numbers-type 'relative)
(setq global-hl-line-modes nil)

(after! git-gutter
  (setq +vc-gutter-default-style nil))

(after! highlight-indent-guides
  (setq highlight-indent-guides-method 'character
        highlight-indent-guides-responsive t))

(after! company
  (setq company-idle-delay 0.5
        company-minimum-prefix-length 2))

;; Quicker which-key
(after! which-key
  (setq which-key-idle-delay 0.5))

;; The parinfer-rust library is compiled manually
(use-package! parinfer-rust-mode
  :init
  (setq parinfer-rust-library (concat doom-data-dir "parinfer-rust/target/release/libparinfer_rust.so")
        parinfer-rust-auto-download nil))

(after! flyspell
  (setq flyspell-lazy-idle-seconds 2))

(after! magit
  (setq magit-diff-refine-hunk 'all))

(after! projectile
  (setq projectile-project-search-path '("~/Code/")
        projectile-auto-discover nil))

(setq org-directory "~/Documents/Org/")
(after! org
  (setq org-default-notes-file "~/Documents/Org/notes.org"
        org-agenda-files '("~/Documents/Org/agenda/agenda.org" "~/Documents/Org/agenda/archive.org")
        org-confirm-babel-evaluate nil
        org-ellipsis "▾"
        org-log-done t
        org-log-into-drawser t
        org-insert-heading-respect-content nil
        org-hide-emphasis-markers t)
  (add-to-list 'org-modules 'ol-info)
  ;; Org-journal
  (setq org-journal-dir "~/Documents/Org/journal/")
  ;; Org-tree-slide
  (setq +org-present-text-scale 2))

;; A mere fraction of writeroom-mode
(defun follie/comfy-org-editing ()
  (setq visual-fill-column-width 100
        visual-fill-column-center-text t)
  (visual-fill-column-mode 1)
  (display-line-numbers-mode -1))
(add-hook 'org-mode-hook 'follie/comfy-org-editing)
(add-hook! org-mode (electric-indent-local-mode -1))

(defun follie/org-toggle-emphasis-markers ()
  "Toggle emphasis markers in an Org buffer"
  (interactive)
  (if org-hide-emphasis-markers
      (setq org-hide-emphasis-markers nil)
    (setq org-hide-emphasis-markers t))
  (org-mode-restart))
(map! :map org-mode-map
      :localleader :desc "org-toggle-emphasis-markers"
      "z" #'follie/org-toggle-emphasis-markers)

(use-package! org-tree-slide
  :commands org-tree-slide-mode
  :config
  (setq org-tree-slide-skip-outline-level 0
        org-image-actual-width nil
        org-tree-slide-heading-emphasis t
        org-tree-slide-modeline-display nil
        org-tree-slide-header t
        org-tree-slide-slide-in-effect t
        org-tree-slide-breadcrumbs " ▶ "
        org-tree-slide-activate-message "Presentation started..."
        org-tree-slide-deactivate-message "Thanks for listening!"))

(use-package! dired-preview
  :after dired
  :config
  (setq dired-preview-max-size (expt 2 30))
  (dired-preview-global-mode 1))
