8<--------------------------------------------------------------------------------------------------------------------------->8
** Initialization
*** Instructions
To make literate programming work i need to first bootstrap these
settings. I'm using this system on multiple machines and OS'es there
are some other initializations that also has to be made.
The initialization of the emacs-settings can be subdivided into two
main parts:
1. Bootstraping org-mode literate programming.
2. Loading source-files:
1. OS-specific settings.
2. Loading computer-specific settings.
3. Loading the default settings.
4. Loading computer-specific settings that overrides default
settings.
This setup makes the system very dynamic, although it might become
difficult to maintain... We'll see about that though.
The code for the initialization follows in this file. It has to be
manually folded, the first time run anyways. (Running C-c C-v t in the
buffer whilst in emacs).
*** Bootstraping
The bootstraping of org-mode literate programing is taken from
with some minor modicifations.
#+begin_src emacs-lisp :tangle yes
(setq dotfiles-dir
(file-name-directory
(or (buffer-file-name) load-file-name)))
(setq src-dir (expand-file-name "src" dotfiles-dir))
(setq org-dir (expand-file-name
"lisp" (expand-file-name
"org" src-dir)))
(setq org-contrib-dir (expand-file-name
"lisp" (expand-file-name
"contrib" (expand-file-name
".." org-dir))))
(add-to-list 'load-path src-dir)
(add-to-list 'load-path org-dir)
(add-to-list 'load-path org-contrib-dir)
(require 'org-install)
(require 'ob-tangle)
#+end_src
After this, and given that i have org installed in the right folder
given the above, code written inside org-mode documents can be called
with the function =org-babel-load-file=. This is used in the next
section, [[*Loading of settings][Loading of settings]].
*** Code tangling hook
If any of the literate-files are updated, I want to automatically
compile them when they are tangled the next time.
This, however, does not work with symbolic links. Thus, my setup using
Dropbox to sync the files between my computers and symbolically
linking these files to my home-folders will not update automatically
anyways. This is (kind of) solved, see the next section.
#+begin_src emacs-lisp :tangle yes
(add-hook 'org-babel-post-tangle-hook
(lambda () (progn (eval-buffer (get-file-buffer (buffer-file-name)))
(byte-compile-file (buffer-file-name)))))
#+end_src
*** Code tangling function
This is my temporary solution to the symbolic-link problem discussed
in the section above. First the function delete all files that have
been previously tangled. After that it tangles all ".org" files in the
dotfiles-dir which also automatically compiles them due to the [[*Code%20tangling%20hook][Code
tangling hook]].
This function can be called at any time.
#+begin_src emacs-lisp :tangle yes
(defun gw/tangle ()
"Tangles all the org-files in ~/.emacs.d/
It is a help-function when one of the source-documents are updated
in Dropbox and the local setup also needs to be updated."
(interactive)
(mapc (lambda (file)
(delete-file (expand-file-name file dotfiles-dir)))
(directory-files dotfiles-dir nil ".*\.\\(el\\|elc\\)$"))
(mapc (lambda (file)
(find-file (expand-file-name file dotfiles-dir))
(org-babel-tangle)
(kill-buffer))
(directory-files dotfiles-dir nil ".*\.org$")))
#+end_src
*** Loading of settings
**** Introduction
The loading process is one single step. It checks which OS is in use
and then load the files given this system.
Add files to the org-files list if more are needed.
#+begin_src emacs-lisp :tangle yes
(let* ((org-files (list (expand-file-name "
emacs.org" dotfiles-dir)
(windows-file (expand-file-name "
windows.org" dotfiles-dir))
(linux-file (expand-file-name "
linux.org" dotfiles-dir))
(cond
((eq system-type 'windows-nt)
(if (file-exists-p windows-file)
(mapc #'org-babel-load-file (cons windows-file
(cons custom-start org-files)))))
((eq system-type 'gnu/linux)
(if (file-exists-p linux-file)
(mapc #'org-babel-load-file (cons linux-file
(cons custom-start org-files)))))))
#+end_src
**** OS-specific settings
As stated earlier, I run emacs on multiple systems and keep these
settings synced between the platforms using Dropbox. I have machines
running both Windows, Linux and Mac and these need some customizations
in order to work correctly.
The need for this methodology originally arose from problems with
fileencoding on different systems, where I needed to use Latin-1 to
load paths with non-ASCII characters on windows but wanted UTF-8 to be
the default encoding when editing.
A search on the Internet resulted in the following:
The settings for the respective systems can be found here:
**** Main settings
The main part of the customizations during the loading-process resides
**** Computer-specific settings
The cumputer-specific settings are maintained by two
after the initialization and one that is loaded as a final stage
the default settings made in either the OS-specific settings or the
main settings.
Make sure that the source-files uses the correct encoding, if the
system is windows the fileencoding should be latin-1 and if the system
is linux it should be utf-8. This can be set by adding the following
string to the top of the document:
: # -*- coding: latin-1 -*-
of it's use later in the loading process:
- gw/gtd-root
8<--------------------------------------------------------------------------------------------------------------------------->8
Kind regards