diff --git a/init-loader.el b/init-loader.el index 0fd1776..5c74c73 100644 --- a/init-loader.el +++ b/init-loader.el @@ -3,6 +3,7 @@ ;; Author: IMAKADO ;; 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 @@ -78,7 +79,7 @@ ;;; Code: -(eval-when-compile (require 'cl)) +(require 'cl-lib) (require 'benchmark) ;;; customize-variables @@ -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 @@ -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))))) @@ -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))) diff --git a/test-init-loader.el b/test-init-loader.el index 916a973..7a733a5 100644 --- a/test-init-loader.el +++ b/test-init-loader.el @@ -19,9 +19,7 @@ ;;; Code: -(eval-when-compile - (require 'cl)) - +(require 'cl-lib) (require 'ert) (require 'init-loader) @@ -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" @@ -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 @@ -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")