This is an Emacs setup with as few (require 'foo)
as possible. It uses
lazy loading in order to not slow down the initial Emacs startup. Loading
and setting up of each feature is postponed to when it is actually needed
the first time. At the time when it is really loaded there is a log to the
messages buffer for learning purposes.
Opionally there is also a special key binding to use ;
as a Control
prefix, ; [
as a ESC/Meta prefix and [
to quit the insert-state in Viper
mode. This makes ; <anything>
work as C-<anything>
and ; [ <anything>
work as C-[ <anything>
which is ESC <anything>
which is M-<anything>
.
To insert a literal ;
or [
use C-q ;
(now also ; q ;
) or C-q [
(now also ; q [
).
If you don’t want Viper mode (the vi emulation) remove the line containing
(require 'viper)
from main.el
.
For a quick first trial:
cd <where_you_have_your_git_clones>
git clone https://github.com/brandm/emacs.d.git
emacs -Q -l emacs.d/main.el
With external packages organized in two main directories:
emacs -Q \
--eval '(setq v-f "<dir_for_single-file-packages>" \
v-d "<dir_with_one_subdir_per_package>")' \
-l '<dir_with_one_subdir_per_package>/emacs.d/main.el'
If you use the Colemak keyboard layout together with Viper mode and want to
swap p
<-> k
and n
<-> j
like me add v-k "co"
to the setq
command above.
If you want to try the special key binding add v-s t
to the setq
command
above.
The functions f-load-path-add and f-auto-loads defined in the file
base-definitions.el
prepare the load-path
and the autoload
and
auto-mode-alist
for lazy feature loading of Emacs packages.
The function f-feature prepares the optional setup of the feature for
running once at feature load time. Add only a wrapper function
f-setup-feature-foo
in order to keep the value of the variable
after-load-alist
uncluttered and informative.
The function add-hook prepares the optional setup of the buffer local
settings to be run each time when a buffer is opened in the corresponding
major mode that processes the mode hook. Add only a wrapper function
f-setup-buffer-foo
to add-hook
in order to keep the value of the buffer
hook uncluttered and informative.
During this Emacs setup phase when the lazy loading is prepared the function
provide
is advised to stop the setup with an error. At the end of the
setup phase the function provide
is advised to just report without error
every provided feature at its load time after the setup.
The error is to track unintended provide
of a feature which means it is
loaded too early instead of lazy loaded sometime after the setup. The report
of provide
is to get an impression of which features are loaded and when.
All features prepared for lazy loading through the function f-feature
are
also tracked to allow to enforce their loading by calling
f-require-lazy-features
interactively at any time.
To mimic a package prefix the functions have the prefix f-*
and the
variables etc. v-*
.
When I started with Emacs in 2000 as a beginner I took every (require
'foo)
into my setup as if it were meant literally and there would be no
other way to load a package. I became comfortable with Emacs Lisp quickly
and added more configuration and functionality. Still using (require 'foo)
kept me away from realizing how the setup entangled more and more with for
example the dependencies of local keymaps. Only after some intermediate
steps I got the whole picture with autoload
, auto-mode-alist
,
with-eval-after-load
and mode hooks to untangle the setup. The code here
is only the part that is already cleaned up. The bigger part with the old
mess is not yet ready to be moved to here.