;;; init --- naloži org konfiguracijo in še kaj -*- lexical-binding: t -*-

;;; Commentary:
;; Naloži konfiguracije iz ORG datoteke, ostanki nerazvrščenih zadev
;; ter kustomizacije.

(setq warning-minimum-level :error)

;;; Code:
(org-babel-load-file "~/.emacs.d/config.org")

;;;;;;;;;;;
;; Razno ;;
;;;;;;;;;;;

;; Izboljsani default ukazi bolj prijazni

;; Iskanje po fajlih (fulltext)
;(use-package rg
;  :defer t
;  :config
; (rg-enable-default-bindings))

;; ELISP test
(defun odpri-dnevnik ()
  "Dodaj dnevniški zapis v tmp folder sistema."
  (interactive)
  (find-file (format-time-string "/tmp/%Y-%m-%d_dnevnik.org"))
  (insert (concat "\n=====================\n"
                  (shell-command-to-string "date") "\n"
                  (format-time-string "%Y-%m-%d") "\n"
                  "ŠE VEČ TEKSTA!" "\n")))
(global-set-key (kbd "C-M-d") 'odpri-dnevnik)

;; GNU guix
(use-package guix :defer t)

;; Dashboard - homescreen
(use-package dashboard
  :general
  (start/leader-keys
    "b h" 'dashboard-open)
  ;:after nerd-icons
  :init
  (dashboard-setup-startup-hook)
  (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))
  (setq dashboard-banner-logo-title "EMA☭S")
  (setq dashboard-startup-banner 3)
  (setq dashboard-center-content t)
  (setq dashboard-items '((agenda . 5)
                          (recents  . 5)))
  ;(setq dashboard-display-icons-p t) ;; display icons on both GUI and terminal
  ;(setq dashboard-icon-type 'nerd-icons) ;; use `nerd-icons' package
  (setq dashboard-set-heading-icons t)
  (setq dashboard-set-file-icons t)
  (setq dashboard-set-navigator t)
  (setq dashboard-set-init-info t))

;; Bolj fajni IELM REPL
(defun g-ielm-init-history ()
  "Obstojna ielm zgodovina."
  (let ((path (expand-file-name "ielm/history" user-emacs-directory)))
    (make-directory (file-name-directory path) t)
    (setq-local comint-input-ring-file-name path))
  (setq-local comint-input-ring-size 10000)
  (setq-local comint-input-ignoredups t)
  (comint-read-input-ring))
(defun g-ielm-write-history (&rest _args)
  "Tole je povezano z obstojno ielm zgodovino."
  (with-file-modes #o600
    (comint-write-input-ring)))
(use-package ielm
  :defer t
  :hook (ielm-mode-hook . (lambda ()
                            (eldoc-mode)
                            ;(paredit-mode)
                            (g-ielm-init-history)))
  :config
  (advice-add 'ielm-send-input :after 'g-ielm-write-history)
  (define-key inferior-emacs-lisp-mode-map (kbd "C-l")
              'comint-clear-buffer)
  (define-key inferior-emacs-lisp-mode-map (kbd "C-r")
              'helm-comint-input-ring))

;; Sinhronizacija podnapisov (uporablja mpv!)
(use-package subed
  :defer t
  :config
  ;; Remember cursor position between sessions
	(add-hook 'subed-mode-hook 'save-place-local-mode)
	;; Break lines automatically while typing
	(add-hook 'subed-mode-hook 'turn-on-auto-fill)
	;; Break lines at 40 characters
	(add-hook 'subed-mode-hook (lambda () (setq-local fill-column 40)))
	;; Some reasonable defaults
	(add-hook 'subed-mode-hook 'subed-enable-pause-while-typing)
	;; As the player moves, update the point to show the current subtitle
	(add-hook 'subed-mode-hook 'subed-enable-sync-point-to-player)
	;; As your point moves in Emacs, update the player to start at the current subtitle
	(add-hook 'subed-mode-hook 'subed-enable-sync-player-to-point)
	;; Replay subtitles as you adjust their start or stop time with M-[, M-], M-{, or M-}
	(add-hook 'subed-mode-hook 'subed-enable-replay-adjusted-subtitle)
	;; Loop over subtitles
	(add-hook 'subed-mode-hook 'subed-enable-loop-over-current-subtitle)
	;; Show characters per second
	(add-hook 'subed-mode-hook 'subed-enable-show-cps))



;;;;;;;;;;;;
;; CUSTOM ;;
;;;;;;;;;;;;
(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-vc-selected-packages
   '((svg-icon :url "https://github.com/rougier/emacs-svg-icon"))))

(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.
 '(org-document-title ((t (:inherit default :weight bold :family "Sans Serif" :height 2.0 :underline nil))))
 '(org-level-1 ((t (:inherit default :weight bold :family "Sans Serif" :height 1.75))))
 '(org-level-2 ((t (:inherit default :weight bold :family "Sans Serif" :height 1.45))))
 '(org-level-3 ((t (:inherit default :weight bold :family "Sans Serif" :height 1.25))))
 '(org-level-4 ((t (:inherit default :weight bold :family "Sans Serif" :height 1.1)))))


;; supercollider mode load
;(require 'sclang)
