Skip to content

HKey/el-init

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

el-init

https://github.com/HKey/el-init/workflows/test/badge.svg https://melpa.org/packages/el-init-badge.svg https://stable.melpa.org/packages/el-init-badge.svg

A loader inspired by init-loader.
It loads split configuration files with require instead of load.

Requirements

Basic Usage

For example, there are configuration files like below,

~/.emacs.d/inits
├── ext/
│   └── init-helm.el
├── lang/
│   ├── init-emacs-lisp.el
│   └── init-javascript.el
└── init-package.el

you load them with following code.

(require 'el-init)

(el-init-load "~/.emacs.d/inits"
              :subdirectories '("." "ext" "lang"))

Mechanism of el-init-load

el-init-load adds the elements of subdirectories argument to load-path. Then, el-init-load calls require for all the configuration files in all the directories of subdirectories argument.

So you have to call provide or el-init-provide in configuration files. el-init-provide is an utility to call provide with the file name as a feature name.

Features

  • Determination of non-numbering loading order
  • User extensible require wrapper system

Loading Order

There are two ways to determination of loading order.

Using subdirectories parameter

el-init-load loads configuration files in order of subdirectories parameter. So if you want to load some configuration files earlier, put them into the directory top of subdirectories.

Using require

If a configuration file depends on other configuration files, load requirements with require in the configuration file.

require Wrapper

You can customize require used by el-init-load to whatever you want, for example measuring load times and catching errors.

If you want to set wrappers for loading of el-init-load, use wrappers parameter of el-init-load.

For example, you want to use el-init-require/record-error and el-init-require/record-eval-after-load-error, call el-init-load like below.

(el-init-load "~/.emacs.d/inits"
              :subdirectories '("." "ext" "lang")
              :wrappers '(el-init-require/record-error
                          el-init-require/record-eval-after-load-error))

How to Define a Wrapper

A require wrapper is a function which has the same parameters as require and calls el-init-next like require. If you want to ignore errors, write a wrapper like below.

(defun my-require/ignore-errors (feature &optional filename noerror)
  (ignore-errors (el-init-next feature filename noerror)))

el-init-next calls the next wrapper. If there are no wrappers to call, el-init-next calls require. So a wrapper can skip loading by not calling el-init-next.

El-init Wrappers

el-init-require/benchmark

Benchmarks loading configuration files.

el-init-require/record-error

Records errors while loading configuration files.

el-init-require/ignore-errors

Ignores errors while loading configuration files.

el-init-require/record-eval-after-load-error

Records errors which occur in eval-after-load form.

el-init-require/system-case

Switches configuration files to load by the execution environment.

el-init-require/record-old-library

Records whether a configuration file has an old .elc file.

el-init-require/compile-old-library

Compiles old .elc files of configuration files.

el-init-require/lazy

Provides lazy loading for configuration files.

Migration from init-loader

Add provide

Add provide to the end of file of each configuration file which is loaded by init-loader.

(provide 'CONFIGURATION-FILE-NAME)
;; EOF

You can also use el-init-provide instead of provide, like below.

(require 'el-init) ; It works without this line, but recommended.
(el-init-provide)
;; EOF

Add require properly

If a configuration file depends on other configuration files, add require to the beginning of the configuration file. Because el-init doesn’t determine the loading order by the file name.

For example, if 30-foo.el depends on 20-bar.el, you have to add (require '20-bar) to the beginning of 30-foo.el.

;; BOF
(require '20-bar)

This will probably be hard work. If so, go to the next step and do this step gradually.

Change init-loader-load to el-init-load

If your setting of init-loader like below,

(require 'init-loader)

(init-loader-load "~/.emacs.d/init")

change it to the code below.

(require 'el-init)

(setq el-init-meadow-regexp       "\\`meadow-"
      el-init-carbon-emacs-regexp "\\`carbon-emacs-"
      el-init-cocoa-emacs-regexp  "\\`cocoa-emacs-"
      el-init-nw-regexp           "\\`nw-"
      el-init-mac-regexp          "\\`mac-"
      el-init-windows-regexp      "\\`windows-"
      el-init-linux-regexp        "\\`linux-"
      el-init-freebsd-regexp      "\\`freebsd-")

(el-init-load "~/.emacs.d/init"
              :subdirectories '(".")
              :wrappers '(el-init-require/record-error
                          el-init-require/system-case))

About

A loader inspired by init-loader

Resources

Stars

Watchers

Forks

Packages

No packages published