+* Basic initialization (from initjj.org)
+First of I want a set of variables defined, makes it easier to refer
+to common things later.
+
+** Variables
+*** System type
+The variable /system-type/ from emacs isn't directly usable in my
+case. It contains gnu/linux and gnu/kfreebsd - which has extra /,
+which is just annoying when using them in a path entry.
+Hence we do a little creative redefinition for ourself.
+#+BEGIN_SRC emacs-lisp
+(defun jj-system-type ()
+ "Return a string depending on the OS we use"
+ (interactive)
+ (cond
+ ((eq system-type 'darwin) "macosx")
+ ((eq system-type 'gnu/linux) "linux")
+ ((eq system-type 'gnu/kfreebsd) "kfreebsd")
+ ((eq system-type 'cygwin) "cygwin")
+ ((eq system-type 'windows-nt) "windows")))
+#+END_SRC
+
+*** jj-dir
+The base directory for all our emacs files. It is based on the
+directory where we load this file from.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-dir (file-name-directory (or load-file-name (buffer-file-name)))
+ "The master directory for Ganneffs emacs configuration and storage.
+Usually ~/.emacs.d/")
+#+END_SRC
+
+*** jj-config-dir
+In which directory do we store the rest of our config?
+#+BEGIN_SRC emacs-lisp
+(defvar jj-config-dir
+ (expand-file-name "config" jj-dir)
+ "Ganneffs main emacs configuration can be found here.")
+#+END_SRC
+
+*** jj-emacs-config
+Name of the main configuration file.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-emacs-config
+ (expand-file-name "emacs.org" jj-config-dir)
+ "Ganneffs main emacs configuration file.")
+#+END_SRC
+
+*** jj-elisp-dir
+Where do I store packages for emacs.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-elisp-dir
+ (expand-file-name "elisp" jj-dir)
+ "This directory stores subdirs for local packages in Ganneffs emacs config.")
+#+END_SRC
+
+*** jj-elisp-local-dir
+Some packages just come with a single file. I put them into this
+local directory instead of giving them an own one.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-elisp-local-dir
+ (expand-file-name "local" jj-elisp-dir)
+ "This directory stores extra elisp files for Ganneffs emacs config.")
+#+END_SRC
+
+*** jj-custom-file
+The customization interface of emacs stores its values in this file.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-custom-file
+ (expand-file-name "customized.el" jj-config-dir)
+ "Changes from the customization interface in Ganneffs emacs config.")
+#+END_SRC
+
+*** jj-cache-dir
+Similar to /var on a unix system, volatile data, cache files, ...
+#+BEGIN_SRC emacs-lisp
+(defvar jj-cache-dir
+ (expand-file-name "cache" jj-dir)
+ "This directory stores cache files and other volatile data.")
+#+END_SRC
+
+*** jj-backup-directory
+Backup copies of files I edit are stored here.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-backup-directory
+ (expand-file-name (concat "emacs-autosave-" user-login-name) jj-cache-dir)
+ "This directory stores backup files.")
+#+END_SRC
+
+*** jj-theme-dir
+Where my theme files are stored.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-theme-dir
+ (expand-file-name "themes" jj-dir)
+ "This directory stores theme files for Ganneffs emacs config")
+#+END_SRC
+
+*** jj-sys-config
+System dependent configuration information stored in here.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-sys-config
+ (expand-file-name (concat system-name ".org") jj-config-dir)
+ "Ganneffs System/Host specific emacs configuration file.")
+#+END_SRC
+
+*** jj-os-config
+Operating System dependent configuration information stored in here.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-os-config
+ (expand-file-name (concat (jj-system-type) ".org") jj-config-dir)
+ "Ganneffs Operating system specific emacs configuration file.")
+#+END_SRC
+
+*** jj-user-config
+User dependent configuration stored in here.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-user-config
+ (expand-file-name (concat user-login-name ".org") jj-config-dir)
+ "Ganneffs username specific emacs configuration file.")
+#+END_SRC
+
+*** jj-ev-config
+Emacs version dependent configuration stored in here.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-ev-config (expand-file-name
+ (concat "emacs"
+ (number-to-string emacs-major-version) ".org")
+ jj-config-dir)
+ "Ganneffs emacs version specific configuration file.")
+#+END_SRC
+
+*** jj-color-style
+Which color scheme should be loaded? I prefer dark very much.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-color-style 'dark "Which color scheme of solarized to select. Dark or Light")
+#+END_SRC
+
+** Processing
+First we want to ensure that our cache and backup directories really exist.
+#+BEGIN_SRC emacs-lisp
+(if (not (file-exists-p jj-cache-dir))
+ (make-directory jj-cache-dir))
+(if (not (file-exists-p jj-backup-directory))
+ (make-directory jj-backup-directory))
+#+END_SRC
+
+Add our local elisp directory to the load path early, as it contains
+files we want to load during configuration processing, before the
+load-path gets set up for real.
+#+BEGIN_SRC emacs-lisp
+;; Have use-package/bindkey in here wich are needed for startup
+(add-to-list 'load-path jj-elisp-local-dir)
+#+END_SRC
+
+I have a function that uses org-tangle to extract all emacs-lisp
+codeblocks out of my org-mode configuration files. After which it
+ensures that the generated elisp files get byte-compiled.
+
+As my configuration requires certain parts of the configuration to
+already be loaded when the byte-compilation happens, this is done
+using an /after-init-hook/.
+#+BEGIN_SRC emacs-lisp
+(defvar jj-init-files '() "Temporary list of files that need a byte-compile")
+(defun jj-byte-compile-init ()
+ "Byte compile a list of files"
+ (let (filename)
+ (dolist (filename jj-init-files)
+ (when (file-exists-p filename)
+ (message "Byte-compiling %s, standby" filename)
+ (byte-compile-file filename))))
+ (makunbound 'jj-init-files)
+ (makunbound 'jj-byte-compile-init)
+ )
+(defun jj-compile-and-load (&optional arg)
+ "Use org-tangle to get the emacs-lisp parts from .org emacs
+config files into .el ones, byte-compile those and then load
+them."
+ (let ((el-file (concat (file-name-sans-extension arg) ".el")))
+ (cond
+ ((file-newer-than-file-p arg el-file)
+ (org-babel-tangle-file arg el-file "emacs-lisp")
+ (add-hook 'after-init-hook 'jj-byte-compile-init)
+ (add-to-list 'jj-init-files (symbol-value 'el-file))))
+ (load-file el-file)
+ ))
+#+END_SRC
+
+And finally we are going to load the various files.
+#+BEGIN_SRC emacs-lisp
+;; Now read my config
+;; Note that those files *can* include further files.
+;; The basic config is always loaded, no matter where we start emacs.
+(jj-compile-and-load jj-emacs-config)
+
+;; All the others are optional. We try the order of os, system, user
+;; specific files and load them, should they be there
+(if (file-exists-p jj-os-config) (jj-compile-and-load jj-os-config))
+(if (file-exists-p jj-sys-config) (jj-compile-and-load jj-sys-config))
+(if (file-exists-p jj-user-config) (jj-compile-and-load jj-user-config))
+(if (file-exists-p jj-ev-config) (jj-compile-and-load jj-ev-config))
+
+(makunbound 'jj-compile-and-load)
+
+;; Lets get a message about startup time out
+(when (require 'time-date nil t)
+ (message "Emacs startup time: %d seconds."
+ (time-to-seconds (time-since emacs-load-start-time)))
+ )
+#+END_SRC