This afternoon I have changed the way my
emacspeak initialization works.
Until now I have always used the file:
For my initialization. But today, in reading about how
and library-loading works, to try to understand how T.V. Raman does it and how
his files in the
git repository all hang together, I have made
a discovery which has made me understand things a lot better and change my strategy.
emacs will look for any of these files for it's initialization:
So, I changed from using
Not only that but I have made some other discoveries, things which I did not know about before.
.emacs files we have usually had two blocks of
lisp that begin with:
These two blocks of code are places into which changes are made when the
screens are used to make adjustments, hence the commentary in these blocks which warn about editing
them by hand and not having more than one occurrence of each block.
Now, of course when adding stuff to the
emacs initialization files by hand it is very easy to screw something up and
stop the initialization from working.
emacspeak this is always immediately obvious because it comes up talking very, very
slowly. Assuming of course you have
emacspeak configured to talk more quickly than the default.
It is possible, it seems, to place the
custom-set-faces code blocks into a separate file, name it as the custom
file and then load it from the main initialization file.
So, bearing in mind we are now using
~/.emacs.d/init.el as our initialization file, place these two lines at the top
(setq custom-file "~/.emacs.d/custom.el")
The first of these lines instructs
emacs that we want to use a different file from our main
initialization file for custom changes made by the
The second line instructs
emacs to load it.
Now we can merrily add other stuff to
~/.emacs.d/init.el, knowing that we are at no
risk of messing up those customizations added with the
Loading Personal Libraries
Instead of loading everything we want in our initialization file, we can split it up, and make it
much more modular. In this way we can tinker with
something new, and when something breaks, we know more easily what broke it and probably how to fix it.
The first thing we need to do, again in our shiny new
~/.emacs.d/init.el file, is to add some paths to
load-path variable in
emacs. It is this variable which acts a bit like
$PATH environment variable in the bash shell.
Put this fragment of code in your
~/.emacs.d/init.el file, just
underneath the top two lines which specify and load the custom file:
;; add some paths to load-path
(let ((default-directory "~/.emacs.d/lisp/"))(setq load-path
(let ((load-path (copy-sequence load-path))) ;; Shadow
(copy-sequence (normal-top-level-add-to-load-path '(".")))
This will add:
And all of the sub-directories thereof to the
load-path variable. Well,
not ALL the sub-directories. It will ignore things like version-control related paths, sub-directory
names that start with a dot etc., very useful if you want to put your
initialization stuff in
Now we can add a whole bunch of
load-library directives below this to load individual personal libraries of
These are just a few libraries I have created from splitting off the code which I previously used to have in my
It should be obvious from the names what each library is for.
What was left in ~/.emacs?
There were a few lines of code remaining in my original ~/.emacs file which I left in the new initialization file:
(setq-default truncate-lines t)
(setq inhibit-splash-screen t)
Before I did this work today it was very hard to wade through all of the
custom stuff, the markdown initialization code, the rst initialization
code, and find these lines.
By doing this stuff this afternoon I think I have:
- Split my original
emacs initialization file into multiple library files which I load individually
- Split my manually added initialization code from the code added and changed
by the Emacs customization mechanism, which should make identifying errors easier
- Dramatically increased the modularity of my initializations, making it more scalable
- Made tinkering with
emacs configuration less scary and hence more inclined to get done
- Learned some valuable stuff about Emacs and Emacs Lisp
By adding the path to our personal-libraries to the
load-path variable we can
leave out the
.el extension of our libraries.
If byte-compiled versions of any of our libraries exist in
.elc files, these will be
loaded in preference to
.el files, giving us an appreciable speed advantage.
To batch compile all the
.el files in
emacs -batch -f batch-byte-compile *.el
The above will create
.elc versions of each of the
.el files. These will be the files which are
loaded in preference to the