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

;; If ~/.emacs.d/config/base.el exists, just load it.  Otherwise,
;; first bootstrap Straight and load Org to make sure we end up with
;; the right Org version, then tangle ~/.emacs.d/init.org to
;; ~/.emacs.d/config/base.el

(defvar init-org-file (expand-file-name "~/.emacs.old/init.org"))
(defvar config-base-file (expand-file-name "~/.emacs.old/config/base.el"))

(when (not (file-exists-p "~/.emacs.old/config"))
  (make-directory "~/.emacs.old/config"))

(when (not (file-exists-p config-base-file))
  (message "Bootstrapping init file...")
  (defvar bootstrapping-init t)
  (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 'org-plus-contrib)
  (require 'org)
  (org-babel-tangle-file init-org-file))

(load-file config-base-file)