3af140036e2c6dc77be33c9f343146b16b7e2c04
[emacs.git] / .emacs.d / init.el
1 ;; Ganneff's emacs config
2
3 ;; Emacs can not read its config directly from org-mode files.
4 ;; But as my config nearly completly is inside an org-mode file,
5 ;; emacs need to be told to deal with it.
6 ;; Meet org-tangle/org-babel-load-file, which extracts the emacs-lisp
7 ;; source parts of my config files, writes them into .el files
8 ;; and then lets emacs load those.
9
10 ;; That way I have a nice environment to edit and comment - and easily export
11 ;; to web or elsewhere - while emacs has its elisp. The initial run after
12 ;; a config change takes longer, but as that only happens when I change
13 ;; something in the .org files - I don't care.
14
15 ;; Go go go
16 (message "Emacs is powering up... Be patient, Master %s!" (getenv "USER"))
17
18 ;; I like to see how long it takes to "boot" emacs (usually one or two
19 ;; seconds), so save the start time
20 (setq emacs-load-start-time (current-time))
21
22 ;; We will need a set of directories for stuff
23 ;; Lets define some variables for them
24
25 ;; I might have special configuration based on various states
26 ;; First we set an own variable, as system-type from emacs directly is
27 ;; useless. gnu/linux and gnu/kfreebsd have extra /, which is plenty annoying
28 ;; when you want to use them in a path entry.
29 (defun jj-system-type ()
30 "Return a string depending on the OS we use"
31 (interactive)
32 (cond
33 ((eq system-type 'darwin) "macosx")
34 ((eq system-type 'gnu/linux) "linux")
35 ((eq system-type 'gnu/kfreebsd) "kfreebsd")
36 ((eq system-type 'cygwin) "cygwin")
37 ((eq system-type 'windows-nt) "windows")))
38
39
40 (defvar jj-dir (file-name-directory (or load-file-name (buffer-file-name)))
41 "The master directory for Ganneffs emacs configuration and storage.
42 Usually ~/.emacs.d/")
43 (defvar jj-config-dir (expand-file-name "config" jj-dir)
44 "Ganneffs main emacs configuration can be found here.")
45 (defvar jj-emacs-config (expand-file-name "emacs.org" jj-config-dir)
46 "Ganneffs main emacs configuration file.")
47 (defvar jj-sys-config (expand-file-name (concat system-name ".org") jj-config-dir)
48 "Ganneffs System/Host specific emacs configiraton file")
49 (defvar jj-os-config (expand-file-name (concat (jj-system-type) ".org") jj-config-dir)
50 "Ganneffs Operating system specific emacs configuration file")
51 (defvar jj-user-config (expand-file-name (concat user-login-name ".org") jj-config-dir)
52 "Ganneffs username specific emacs configuration file")
53 (defvar jj-elisp-dir (expand-file-name "elisp" jj-dir)
54 "This directory stores subdirs for packages locally put into Ganneffs emacs config")
55 (defvar jj-elisp-local-dir (expand-file-name "local" jj-elisp-dir)
56 "This directory stores extra elisp files for Ganneffs emacs config")
57 (defvar jj-custom-file (expand-file-name "customized.el" jj-config-dir)
58 "Where do changes from the customization interface end in Ganneffs emacs config")
59 (defvar jj-cache-dir (expand-file-name "cache" jj-dir)
60 "This directory stores cache files and other volatile data")
61 (defvar jj-backup-directory (expand-file-name (concat "emacs-autosave-" user-login-name) jj-cache-dir)
62 "This directory stores backup files")
63
64 ;; Ensure that the cache directory hierarchy exists
65 (if (not (file-exists-p jj-cache-dir))
66 (make-directory jj-cache-dir))
67 (if (not (file-exists-p jj-backup-directory))
68 (make-directory jj-backup-directory))
69
70 ;; Set path to (my, recent) Org-Mode version
71 (add-to-list 'load-path (concat jj-elisp-dir "/org/"))
72 ;; Have use-package/bindkey in here wich are needed for startup
73 (add-to-list 'load-path jj-elisp-local-dir)
74
75 ;; As we use org-mode/org-babel/org-tangle to extract the real emacs
76 ;; config out of the org-mode files, we have to load that first.
77 (setq org-modules (quote
78 (org-bbdb org-bibtex org-crypt org-docview org-gnus
79 org-id org-info org-jsinfo org-habit org-inlinetask
80 org-irc org-protocol org-w3m org-mouse org-checklist
81 org-notmuch icalendar)))
82 (require 'org-install)
83 (require 'ob-tangle)
84
85 ;; Now read my config
86 ;; Note that those files *can* include further files.
87
88 ;; The basic config is always loaded, no matter where we start emacs.
89 (org-babel-load-file jj-emacs-config)
90
91 ;; All the others are optional. We try the order of os, system, user
92 ;; specific files and load them, should they be there
93 (if (file-exists-p jj-os-config) (org-babel-load-file jj-os-config ))
94 (if (file-exists-p jj-sys-config) (org-babel-load-file jj-sys-config))
95 (if (file-exists-p jj-user-config) (org-babel-load-file jj-user-config))
96
97 ;; Lets get a message about startup time out
98 (when (require 'time-date nil t)
99 (message "Emacs startup time: %d seconds."
100 (time-to-seconds (time-since emacs-load-start-time)))
101 )
102 ; (message (concat "Emacs startup time: " (emacs-init-time)))
103
104