Skip to content
Merged
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
23 changes: 12 additions & 11 deletions init-loader.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
;; Author: IMAKADO <ken.imakado@gmail.com>
;; URL: https://github.com/emacs-jp/init-loader/
;; Version: 0.02
;; Package-Requires: ((cl-lib "0.5"))

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -78,7 +79,7 @@

;;; Code:

(eval-when-compile (require 'cl))
(require 'cl-lib)
(require 'benchmark)

;;; customize-variables
Expand Down Expand Up @@ -140,11 +141,11 @@ example, 00_foo.el, 01_bar.el ... 99_keybinds.el."
:type 'regexp)

;;;###autoload
(defun* init-loader-load (&optional (init-dir init-loader-directory))
(cl-defun init-loader-load (&optional (init-dir init-loader-directory))
"Load configuration files in INIT-DIR."
(let ((init-dir (init-loader-follow-symlink init-dir))
(is-carbon-emacs nil))
(assert (and (stringp init-dir) (file-directory-p init-dir)))
(cl-assert (and (stringp init-dir) (file-directory-p init-dir)))
(init-loader-re-load init-loader-default-regexp init-dir t)

;; Windows
Expand Down Expand Up @@ -177,7 +178,7 @@ example, 00_foo.el, 01_bar.el ... 99_keybinds.el."
(when (not window-system)
(init-loader-re-load init-loader-nw-regexp init-dir))

(case init-loader-show-log-after-init
(cl-case init-loader-show-log-after-init
(error-only (add-hook 'after-init-hook 'init-loader--show-log-error-only))
('t (add-hook 'after-init-hook 'init-loader-show-log)))))

Expand Down Expand Up @@ -229,13 +230,13 @@ example, 00_foo.el, 01_bar.el ... 99_keybinds.el."
;; 2011/JUN/12 zqwell Read first byte-compiled file if it exist.
;; See. http://twitter.com/#!/fkmn/statuses/21411277599
(defun init-loader--re-load-files (re dir &optional sort)
(loop for el in (directory-files dir t)
when (and (string-match re (file-name-nondirectory el))
(or (string-match "elc\\'" el)
(and (string-match "el\\'" el)
(not (locate-library (concat el "c"))))))
collect (file-name-nondirectory el) into ret
finally return (if sort (sort ret 'string<) ret)))
(cl-loop for el in (directory-files dir t)
when (and (string-match re (file-name-nondirectory el))
(or (string-match "elc\\'" el)
(and (string-match "el\\'" el)
(not (locate-library (concat el "c"))))))
collect (file-name-nondirectory el) into ret
finally return (if sort (sort ret 'string<) ret)))

(defun init-loader--show-log-error-only ()
(let ((err (init-loader-error-log)))
Expand Down
37 changes: 19 additions & 18 deletions test-init-loader.el
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

;;; Code:

(eval-when-compile
(require 'cl))

(require 'cl-lib)
(require 'ert)
(require 'init-loader)

Expand Down Expand Up @@ -51,12 +49,11 @@
"bsd-config.el"
"bsd-migemo.el"))

;; TODO flet is obsoleted from Emacs 24.3

(ert-deftest init-loader--re-load-files ()
"Test for `init-loader--re-load-files'"
(flet ((directory-files (dir &optional full match nosort)
init-loader-test-files))
(cl-letf (((symbol-function #'directory-files)
(lambda (dir &optional full match nosort)
init-loader-test-files)))
(let ((got (init-loader--re-load-files init-loader-default-regexp "" t))
(expected '("00_utils.el" "01_ik-cmd.el" "20_elisp.el"
"21_javascript.el" "23_yaml.el" "25_perl.el"
Expand Down Expand Up @@ -97,9 +94,9 @@

(ert-deftest init-loader-follow-symlink ()
"Test for `init-loader-follow-symlink'"
(flet ((directory-files (dir &optional full match nosort)
init-loader-test-files))

(cl-letf (((symbol-function #'directory-files)
(lambda (dir &optional full match nosort)
init-loader-test-files)))
(let ((symlink "symlink.el")
(thisfile "test-init-loader.el"))
;; setup
Expand Down Expand Up @@ -152,14 +149,18 @@
(ert-deftest init-loader-load-file ()
"Test for `init-loader-load-file'"

(flet ((byte-compile-file (el)
(setq is-byte-compiled t))
(load (file)
(setq is-loaded t))
(delete-file (file)
(setq is-deleted t))
(locate-library (lib) lib))

(cl-letf (((symbol-function #'byte-compile-file)
(lambda (el)
(setq is-byte-compiled t)))
((symbol-function #'load)
(lambda (file &optional noerror nomessage nosuffix must-suffix)
(setq is-loaded t)))
((symbol-function #'delete-file)
(lambda (file &optional trash)
(setq is-deleted t)))
((symbol-function #'locate-library)
(lambda (lib &optional nosuffix path interactive-call)
lib)))
;; not byte compile
(let ((init-loader-byte-compile nil))
(init-loader-load-file "foo")
Expand Down