1 * Basic initialization (from initjj.org)
2 First of I want a set of variables defined, makes it easier to refer
3 to common things later.
7 The variable /system-type/ from emacs isn't directly usable in my
8 case. It contains gnu/linux and gnu/kfreebsd - which has extra /,
9 which is just annoying when using them in a path entry.
10 Hence we do a little creative redefinition for ourself.
11 #+BEGIN_SRC emacs-lisp
12 (defun jj-system-type ()
13 "Return a string depending on the OS we use"
16 ((eq system-type 'darwin) "macosx")
17 ((eq system-type 'gnu/linux) "linux")
18 ((eq system-type 'gnu/kfreebsd) "kfreebsd")
19 ((eq system-type 'cygwin) "cygwin")
20 ((eq system-type 'windows-nt) "windows")))
24 The base directory for all our emacs files. It is based on the
25 directory where we load this file from.
26 #+BEGIN_SRC emacs-lisp
27 (defvar jj-dir (file-name-directory (or load-file-name (buffer-file-name)))
28 "The master directory for Ganneffs emacs configuration and storage.
33 In which directory do we store the rest of our config?
34 #+BEGIN_SRC emacs-lisp
36 (expand-file-name "config" jj-dir)
37 "Ganneffs main emacs configuration can be found here.")
41 Name of the main configuration file.
42 #+BEGIN_SRC emacs-lisp
43 (defvar jj-emacs-config
44 (expand-file-name "emacs.org" jj-config-dir)
45 "Ganneffs main emacs configuration file.")
49 Where do I store packages for emacs.
50 #+BEGIN_SRC emacs-lisp
52 (expand-file-name "elisp" jj-dir)
53 "This directory stores subdirs for local packages in Ganneffs emacs config.")
56 *** jj-elisp-local-dir
57 Some packages just come with a single file. I put them into this
58 local directory instead of giving them an own one.
59 #+BEGIN_SRC emacs-lisp
60 (defvar jj-elisp-local-dir
61 (expand-file-name "local" jj-elisp-dir)
62 "This directory stores extra elisp files for Ganneffs emacs config.")
66 The customization interface of emacs stores its values in this file.
67 #+BEGIN_SRC emacs-lisp
68 (defvar jj-custom-file
69 (expand-file-name "customized.el" jj-config-dir)
70 "Changes from the customization interface in Ganneffs emacs config.")
74 Similar to /var on a unix system, volatile data, cache files, ...
75 #+BEGIN_SRC emacs-lisp
77 (expand-file-name "cache" jj-dir)
78 "This directory stores cache files and other volatile data.")
81 *** jj-backup-directory
82 Backup copies of files I edit are stored here.
83 #+BEGIN_SRC emacs-lisp
84 (defvar jj-backup-directory
85 (expand-file-name (concat "emacs-autosave-" user-login-name) jj-cache-dir)
86 "This directory stores backup files.")
90 Where my theme files are stored.
91 #+BEGIN_SRC emacs-lisp
93 (expand-file-name "themes" jj-dir)
94 "This directory stores theme files for Ganneffs emacs config")
98 System dependent configuration information stored in here.
99 #+BEGIN_SRC emacs-lisp
100 (defvar jj-sys-config
101 (expand-file-name (concat system-name ".org") jj-config-dir)
102 "Ganneffs System/Host specific emacs configuration file.")
106 Operating System dependent configuration information stored in here.
107 #+BEGIN_SRC emacs-lisp
109 (expand-file-name (concat (jj-system-type) ".org") jj-config-dir)
110 "Ganneffs Operating system specific emacs configuration file.")
114 User dependent configuration stored in here.
115 #+BEGIN_SRC emacs-lisp
116 (defvar jj-user-config
117 (expand-file-name (concat user-login-name ".org") jj-config-dir)
118 "Ganneffs username specific emacs configuration file.")
122 Emacs version dependent configuration stored in here.
123 #+BEGIN_SRC emacs-lisp
124 (defvar jj-ev-config (expand-file-name
126 (number-to-string emacs-major-version) ".org")
128 "Ganneffs emacs version specific configuration file.")
132 Which color scheme should be loaded? I prefer dark very much.
133 #+BEGIN_SRC emacs-lisp
134 (defvar jj-color-style 'dark "Which color scheme of solarized to select. Dark or Light")
138 First we want to ensure that our cache and backup directories really exist.
139 #+BEGIN_SRC emacs-lisp
140 (if (not (file-exists-p jj-cache-dir))
141 (make-directory jj-cache-dir))
142 (if (not (file-exists-p jj-backup-directory))
143 (make-directory jj-backup-directory))
146 Add our local elisp directory to the load path early, as it contains
147 files we want to load during configuration processing, before the
148 load-path gets set up for real.
149 #+BEGIN_SRC emacs-lisp
150 ;; Have use-package/bindkey in here wich are needed for startup
151 (add-to-list 'load-path jj-elisp-local-dir)
154 I have a function that uses org-tangle to extract all emacs-lisp
155 codeblocks out of my org-mode configuration files. After which it
156 ensures that the generated elisp files get byte-compiled.
158 As my configuration requires certain parts of the configuration to
159 already be loaded when the byte-compilation happens, this is done
160 using an /after-init-hook/.
161 #+BEGIN_SRC emacs-lisp
162 (defvar jj-init-files '() "Temporary list of files that need a byte-compile")
163 (defun jj-byte-compile-init ()
164 "Byte compile a list of files"
166 (dolist (filename jj-init-files)
167 (when (file-exists-p filename)
168 (message "Byte-compiling %s, standby" filename)
169 (byte-compile-file filename))))
170 (makunbound 'jj-init-files)
171 (makunbound 'jj-byte-compile-init)
173 (defun jj-compile-and-load (&optional arg)
174 "Use org-tangle to get the emacs-lisp parts from .org emacs
175 config files into .el ones, byte-compile those and then load
177 (let ((el-file (concat (file-name-sans-extension arg) ".el")))
179 ((file-newer-than-file-p arg el-file)
180 (org-babel-tangle-file arg el-file "emacs-lisp")
181 (add-hook 'after-init-hook 'jj-byte-compile-init)
182 (add-to-list 'jj-init-files (symbol-value 'el-file))))
187 And finally we are going to load the various files.
188 #+BEGIN_SRC emacs-lisp
189 ;; Now read my config
190 ;; Note that those files *can* include further files.
191 ;; The basic config is always loaded, no matter where we start emacs.
192 (jj-compile-and-load jj-emacs-config)
194 ;; All the others are optional. We try the order of os, system, user
195 ;; specific files and load them, should they be there
196 (if (file-exists-p jj-os-config) (jj-compile-and-load jj-os-config))
197 (if (file-exists-p jj-sys-config) (jj-compile-and-load jj-sys-config))
198 (if (file-exists-p jj-user-config) (jj-compile-and-load jj-user-config))
199 (if (file-exists-p jj-ev-config) (jj-compile-and-load jj-ev-config))
201 (makunbound 'jj-compile-and-load)
203 ;; Lets get a message about startup time out
204 (when (require 'time-date nil t)
205 (message "Emacs startup time: %d seconds."
206 (time-to-seconds (time-since emacs-load-start-time)))