Skip to content

Commit ecab5a6

Browse files
authored
Merge pull request #25 from emacs-jp/cl-lib
Switch to cl-lib for avoiding native compile warnings
2 parents 10b8d7b + 9b5eb20 commit ecab5a6

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

init-loader.el

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
;; Author: IMAKADO <[email protected]>
44
;; URL: https://github.com/emacs-jp/init-loader/
55
;; Version: 0.02
6+
;; Package-Requires: ((cl-lib "0.5"))
67

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

7980
;;; Code:
8081

81-
(eval-when-compile (require 'cl))
82+
(require 'cl-lib)
8283
(require 'benchmark)
8384

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

142143
;;;###autoload
143-
(defun* init-loader-load (&optional (init-dir init-loader-directory))
144+
(cl-defun init-loader-load (&optional (init-dir init-loader-directory))
144145
"Load configuration files in INIT-DIR."
145146
(let ((init-dir (init-loader-follow-symlink init-dir))
146147
(is-carbon-emacs nil))
147-
(assert (and (stringp init-dir) (file-directory-p init-dir)))
148+
(cl-assert (and (stringp init-dir) (file-directory-p init-dir)))
148149
(init-loader-re-load init-loader-default-regexp init-dir t)
149150

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

180-
(case init-loader-show-log-after-init
181+
(cl-case init-loader-show-log-after-init
181182
(error-only (add-hook 'after-init-hook 'init-loader--show-log-error-only))
182183
('t (add-hook 'after-init-hook 'init-loader-show-log)))))
183184

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

240241
(defun init-loader--show-log-error-only ()
241242
(let ((err (init-loader-error-log)))

test-init-loader.el

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919

2020
;;; Code:
2121

22-
(eval-when-compile
23-
(require 'cl))
24-
22+
(require 'cl-lib)
2523
(require 'ert)
2624
(require 'init-loader)
2725

@@ -51,12 +49,11 @@
5149
"bsd-config.el"
5250
"bsd-migemo.el"))
5351

54-
;; TODO flet is obsoleted from Emacs 24.3
55-
5652
(ert-deftest init-loader--re-load-files ()
5753
"Test for `init-loader--re-load-files'"
58-
(flet ((directory-files (dir &optional full match nosort)
59-
init-loader-test-files))
54+
(cl-letf (((symbol-function #'directory-files)
55+
(lambda (dir &optional full match nosort)
56+
init-loader-test-files)))
6057
(let ((got (init-loader--re-load-files init-loader-default-regexp "" t))
6158
(expected '("00_utils.el" "01_ik-cmd.el" "20_elisp.el"
6259
"21_javascript.el" "23_yaml.el" "25_perl.el"
@@ -97,9 +94,9 @@
9794

9895
(ert-deftest init-loader-follow-symlink ()
9996
"Test for `init-loader-follow-symlink'"
100-
(flet ((directory-files (dir &optional full match nosort)
101-
init-loader-test-files))
102-
97+
(cl-letf (((symbol-function #'directory-files)
98+
(lambda (dir &optional full match nosort)
99+
init-loader-test-files)))
103100
(let ((symlink "symlink.el")
104101
(thisfile "test-init-loader.el"))
105102
;; setup
@@ -152,14 +149,18 @@
152149
(ert-deftest init-loader-load-file ()
153150
"Test for `init-loader-load-file'"
154151

155-
(flet ((byte-compile-file (el)
156-
(setq is-byte-compiled t))
157-
(load (file)
158-
(setq is-loaded t))
159-
(delete-file (file)
160-
(setq is-deleted t))
161-
(locate-library (lib) lib))
162-
152+
(cl-letf (((symbol-function #'byte-compile-file)
153+
(lambda (el)
154+
(setq is-byte-compiled t)))
155+
((symbol-function #'load)
156+
(lambda (file &optional noerror nomessage nosuffix must-suffix)
157+
(setq is-loaded t)))
158+
((symbol-function #'delete-file)
159+
(lambda (file &optional trash)
160+
(setq is-deleted t)))
161+
((symbol-function #'locate-library)
162+
(lambda (lib &optional nosuffix path interactive-call)
163+
lib)))
163164
;; not byte compile
164165
(let ((init-loader-byte-compile nil))
165166
(init-loader-load-file "foo")

0 commit comments

Comments
 (0)