68 lines
2.4 KiB
EmacsLisp
68 lines
2.4 KiB
EmacsLisp
;; -*- coding: utf-8; lexical-binding: t; -*-
|
|
|
|
(defconst creature/pkg-dir
|
|
(expand-file-name
|
|
"../site-lisp"
|
|
(file-name-directory(or load-file-name buffer-file-name)))
|
|
"Package directory.")
|
|
|
|
(require 'cl-lib)
|
|
(require 'subr-x)
|
|
|
|
(cl-defun add-dir-and-subdirs-to-load-path (dir)
|
|
"Add directory and its subdirectoris to `load-path' when no `.nosearch' file exists in DIR.
|
|
Detect whether there are any loadable module in DIR, if so, add DIR to `load-path'.
|
|
Do this recursively for subdirectories of DIR."
|
|
(unless (file-directory-p dir)
|
|
(error "%s is not a directory" dir))
|
|
|
|
;; if a `.nosearch' file exists in dir, skip it directly
|
|
(when (file-exists-p (expand-file-name ".nosearch" dir))
|
|
(cl-return-from add-dir-and-subdirs-to-load-path))
|
|
|
|
(let ((subdirs nil)
|
|
(files nil)
|
|
(temp-filepath nil)
|
|
;; (loadable-suffixes (get-load-suffixes))
|
|
(load-extension (mapcar (lambda (str) (string-remove-prefix "." str)) load-suffixes))
|
|
(exclude-dirs '("." ".."
|
|
"dist" "node_modules" "__pycache__" "test"
|
|
"RCS" "CVS" "rcs" "cvs" ".git" ".github")))
|
|
|
|
(dolist (filename (directory-files dir))
|
|
(setq temp-filepath (file-name-concat dir filename))
|
|
(if (file-directory-p temp-filepath)
|
|
(unless (member filename exclude-dirs)
|
|
(add-to-list 'subdirs temp-filepath t))
|
|
(when (file-regular-p temp-filepath)
|
|
(add-to-list 'files temp-filepath t))))
|
|
|
|
(when (cl-some (lambda (file)
|
|
(member (file-name-extension file) load-extension))
|
|
files)
|
|
(add-to-list 'load-path dir))
|
|
(mapc #'add-dir-and-subdirs-to-load-path subdirs)))
|
|
|
|
(defun add-pkg-in-pkg-dir (pkg)
|
|
"Add PKG located in `creature/pkg-dir' to `load-path'."
|
|
(add-dir-and-subdirs-to-load-path (expand-file-name pkg creature/pkg-dir)))
|
|
|
|
(add-to-list 'load-path creature/pkg-dir)
|
|
|
|
;; add basic packages
|
|
(add-pkg-in-pkg-dir "lazy-load")
|
|
|
|
;; "transient" and "compat" always use submodule package
|
|
;; and "cond-let" is dependency of "transient"
|
|
(dolist (pkg '("transient" "cond-let" "compat"))
|
|
(add-pkg-in-pkg-dir pkg))
|
|
|
|
(dolist (pkg '("transient" "compat"))
|
|
(let ((file (locate-library pkg))
|
|
(feature (intern-soft pkg)))
|
|
(when (and (featurep feature) (string-prefix-p "/usr/share/emacs" file))
|
|
(unload-feature feature t)
|
|
(require feature))))
|
|
|
|
(provide 'init-package)
|