(use-package org
  :ensure nil
  :commands org-mode
  :bind (
         ("C-c l" . org-store-link)
         ("C-c a" . org-agenda)
         ("C--" . org-timestamp-down)
         ("C-=" . org-timestamp-up)
         )
  :hook (
         (org-mode . (lambda ()
                       (org-indent-mode +1)
                        ))
         )
  :config
  (require 'org-tempo)
  (setq org-export-latex-listings t)
  (setq org-startup-truncated nil)
  (setq org-startup-folded nil)
  (setq org-src-fontify-natively t
        org-src-tab-acts-natively t
        org-confirm-babel-evaluate nil
        )

  ;; Show the full source of org-mode links instead of condensing them. I.E. render "[[foo]]" instead of "foo"
  (setq org-descriptive-links nil)

  ;; Only interpret _ and ^ and sub and superscripts if they're of the form _{subscript} and ^{superscript}
  (setq org-export-with-sub-superscripts '{})
  ;; Don't include a "validate" link at the bottom of html export
  (setq org-html-validation-link nil)


  (setq org-latex-listings 'minted)
  (setq org-latex-minted-options '(("breaklines" "true")
                                   ("breakanywhere" "true")
                                   ("bgcolor" "mintedbg") ("frame" "single") ("framesep" "6pt") ("fontsize" "\\footnotesize")))

  ;; TODO: There is an option to set the compiler, could be better than manually doing this here https://orgmode.org/manual/LaTeX_002fPDF-export-commands.html
  ;; (setq org-latex-compiler "lualatex")
  (setq org-latex-pdf-process
        '("lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"
          "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"
          "lualatex -shell-escape -interaction nonstopmode -output-directory %o %f"))
  (add-to-list 'org-latex-packages-alist '("cache=false" "minted"))
  (add-to-list 'org-latex-packages-alist '("" "svg"))
  (add-to-list 'org-latex-packages-alist '("margin=2cm" "geometry" nil))

  (add-to-list 'org-src-lang-modes '("dot" . "graphviz-dot"))

  (org-babel-do-load-languages 'org-babel-load-languages
                               '((shell      . t)
                                 (js         . t)
                                 (emacs-lisp . t)
                                 (python     . t)
                                 (dot        . t)
                                 (css        . t)
                                 (gnuplot    . t)
                                 (sqlite     . t)
                                 ))

  (require 'color)

  (let ((bg (face-attribute 'default :background)))
    (custom-set-faces
     `(org-block ((t (:inherit default :background ,(color-lighten-name bg 15) :extend ,t))))
     `(org-block-begin-line ((t (:inherit default :background ,"#472300" :extend ,t))))
     `(org-block-end-line ((t (:inherit default :background ,"#472300" :extend ,t))))
     ))
  )

(use-package org-bullets
  :commands org-bullets-mode
  :hook (org-mode . org-bullets-mode)
  )

(use-package gnuplot-mode)
(use-package gnuplot)
(use-package graphviz-dot-mode)

(provide 'lang-org)
