Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load literate user settings #693

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 94 additions & 12 deletions el-get-recipes.el
100644 → 100755
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,24 +54,106 @@ should be placed last in this list."
:group 'el-get :group 'el-get
:type '(choice (const :tag "Off" nil) directory)) :type '(choice (const :tag "Off" nil) directory))


(defcustom el-get-user-package-org-type
(list "org.gpg.bz2" "org.gpg.gz" "org.gpg" "org.bz2" "org.gz" "org")
"Define the .org* file extensions to look for when loading user init
files. The extensions are matched in the order listed and the first
one found is used."
:group 'el-get
:type '(repeat (string)))

(defcustom el-get-user-package-el-type
(list "el.gpg.bz2" "el.gpg.gz" "el.gpg" "el.bz2" "el.gz" "el")
"Define the .el* file extensions to look for when loading user
init files. The extensions are matched in the order listed and
the first one found is used."
:group 'el-get
:type '(repeat (string)))

(defvar el-get-user-package-org-pending 'nil
"Used to track whether org needs to be loaded for user
init files to finish being initialized.")

(defun el-get-user-package-org-load (package-init-file)
"Function for loading user init files stored as .org*"
(condition-case nil
(org-babel-load-file package-init-file)
(error (eval-after-load 'ob-tangle `(org-babel-load-file
,package-init-file))
(setq el-get-user-package-org-pending 't))))

(defun el-get-user-package-org-check ()
"Check to see if any user init files are waiting on ob-tangle.

If 'nil then either `org-babel-load-file' is available, or no
user init files are .org*. If 't then notify user that
org is not yet loaded."
(when el-get-user-package-org-pending
;; Check to see if ob-tangle or org were required after
;; (eval-after-load 'ob-tangle) was called. Org will load
;; ob-tangle as well.
(unless (featurep 'ob-tangle)
(el-get-notify "Loading of user init files incomplete"
"Add Org-Mode to path and run `(require 'org)' to complete initialization."))))

(defun el-get-user-package-el-load (package-init-file)
"Function for loading user init files stored as .el*.

This also respects the settings for `el-get-byte-compile'."
(if el-get-byte-compile
;; Determine what the compiled filename will be. Since the
;; package could have multiple extensions due to archiving and
;; encrypting you cannot simply remove the last extension.
(let ((compile-name (byte-compile-dest-file package-init-file)))
(el-get-byte-compile package-init-file)
;; Load the compiled file. This ensures you do not
;; accidentally load a non .el/.elc file if there is such
;; present in the directory.
(load-file compile-name))
;; Otherwise load the uncompiled file.
(load-file package-init-file)))

(defun el-get-load-package-user-init-file (package) (defun el-get-load-package-user-init-file (package)
"Load the user init file for PACKAGE, called init-package.el "Load the user init file for PACKAGE, called init-package.el
and to be found in `el-get-user-package-directory'. Do nothing and to be found in `el-get-user-package-directory'. Do nothing
when this custom is nil. when this custom is nil.


Will automatically compile the init file as needed and load the If the file is a literate file create in Org Mode it will
compiled version." automatically create a .el as needed based on file modification
times and load it. If the file is a traditional elisp file it
will load it directly."
(when el-get-user-package-directory (when el-get-user-package-directory
(let* ((init-file-name (format "init-%s.el" package)) ;; Match the package against the extension to determine which
(package-init-file ;; command to use when loading it. This returns the first
(expand-file-name init-file-name el-get-user-package-directory)) ;; matching filename+extension to be loaded, as well as the method
(file-name-no-extension (file-name-sans-extension package-init-file)) ;; to load it (org or elisp).
(compiled-init-file (concat file-name-no-extension ".elc"))) (flet ((package-load (base ext-type command)
(when (file-exists-p package-init-file) (catch 'exists
(when el-get-byte-compile (loop for ext in ext-type do
(el-get-byte-compile-file package-init-file)) (let ((filename (format "%s.%s" base ext)))
(el-get-verbose-message "el-get: load %S" file-name-no-extension) (if (file-exists-p filename)
(load file-name-no-extension 'noerror))))) (throw 'exists `(,command ,filename)))))
nil)))
(let* ((package-name (format "init-%s" package))
(base (expand-file-name package-name
el-get-user-package-directory))
;; By preferring .org files over .el files you ensure
;; that changes to the .org files will be taken into
;; account and a new .el file will be tangled to reflect
;; those changes.
(load-method (or
(package-load base
el-get-user-package-org-type
'el-get-user-package-org-load)
(package-load base
el-get-user-package-el-type
'el-get-user-package-el-load))))
;; Perform load evalation here
(if load-method
(progn
(el-get-verbose-message "el-get: load %S" (cdr load-method))
(eval load-method))
(el-get-verbose-message "el-get: No init file for %S" package))))))


(defun el-get-recipe-dirs () (defun el-get-recipe-dirs ()
"Return the elements of el-get-recipe-path that actually exist. "Return the elements of el-get-recipe-path that actually exist.
Expand Down
7 changes: 6 additions & 1 deletion el-get.el
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1037,7 +1037,12 @@ already installed packages is considered."
(el-get-init-and-install (mapcar 'el-get-as-symbol packages)) (el-get-init-and-install (mapcar 'el-get-as-symbol packages))


;; now is a good time to care about autoloads ;; now is a good time to care about autoloads
(el-get-eval-autoloads)))) (el-get-eval-autoloads))

;; Now that package loading is complete, check that .org user init
;; files were loaded and not simply left waiting for
;; 'org-install to be required.
(el-get-user-package-org-check)))


(provide 'el-get) (provide 'el-get)


Expand Down