

;; autoloads for single .el file in this directory
;; https://stackoverflow.com/a/4189794
;; (load-file (concat config-dir "lisp/update-autoloads.el"))
;; `update-autoloads-in-package-area' will generate -autoloads.el
;; files and create a loaddefs.el
;; (load-file (concat config-dir "lisp/loaddefs.el"))

;; put this path into the load-path automatically
;;;###autoload
(progn
  (setq load-path (cons (file-name-directory load-file-name) load-path)))

;;;###autoload
(defun update-autoloads-in-package-area (&optional file)
  "Update autoloads for files in the diretory containing this file."
  (interactive)
  (let ((base (file-truename
       (file-name-directory
        (symbol-file 'update-autoloads-in-package-area 'defun)))))
(require 'autoload)         ;ironic, i know
(let ((generated-autoload-file (concat base "loaddefs.el")))
  (when (not (file-exists-p generated-autoload-file))
    (with-current-buffer (find-file-noselect generated-autoload-file)
      (insert ";;") ;; create the file with non-zero size to appease autoload
      (save-buffer)))
  (cd base)
  (if file
      (update-file-autoloads file)
    ;; (update-autoloads-from-directories base)  ;; renamed to update-directory-autoloads
    (update-directory-autoloads base)))))

;;;###autoload
(defun update-autoloads-for-file-in-package-area (file)
  (interactive "f")
  (update-autoloads-in-package-area file))


;; autoloads for all sub-directories

;;;###autoload
(defun update-autoloads-sub-packages (&optional file)
  (require 'package)
  (package-generate-autoloads "all-the-icons" (concat config-dir "lisp/all-the-icons"))
  (package-generate-autoloads "dashboard" (concat config-dir "lisp/dashboard"))
  (package-generate-autoloads "diff-hl" (concat config-dir "lisp/diff-hl"))
  (package-generate-autoloads "focus" (concat config-dir "lisp/focus"))
  (package-generate-autoloads "indent-guide" (concat config-dir "lisp/indent-guide"))
  (package-generate-autoloads "iscroll" (concat config-dir "lisp/iscroll"))
  (package-generate-autoloads "ivy" (concat config-dir "lisp/ivy"))
  (package-generate-autoloads "ivy-rich" (concat config-dir "lisp/ivy-rich"))
  (package-generate-autoloads "my" (concat config-dir "lisp/my"))
  (package-generate-autoloads "nerd-icons" (concat config-dir "lisp/nerd-icons"))
  (package-generate-autoloads "olivetti" (concat config-dir "lisp/olivetti"))
  ;; (package-generate-autoloads "org" (concat config-dir "lisp/org"))  ;; already org-loaddefs.el
  (package-generate-autoloads "org-appear" (concat config-dir "lisp/org-appear"))
  (package-generate-autoloads "org-contrib" (concat config-dir "lisp/org-contrib"))
  (package-generate-autoloads "rainbow-mode" (concat config-dir "lisp/rainbow-mode"))
  (package-generate-autoloads "spacemacs-theme" (concat config-dir "lisp/spacemacs-theme"))
  (package-generate-autoloads "srefactor" (concat config-dir "lisp/srefactor"))
  (package-generate-autoloads "swiper" (concat config-dir "lisp/swiper"))
  (package-generate-autoloads "virtual-auto-fill" (concat config-dir "lisp/virtual-auto-fill"))
)

(defun my-byte-compile ()
  "recursive byte-compiling"
  (interactive)
  (byte-recompile-directory (concat user-emacs-directory "lisp") 0))
