(require 'cl)
;; (defvar *emacs-load-start* (current-time))

;;;;
;;;;;; Path, Load path and libraries
;;;;

(unless (boundp 'user-emacs-directory)
  (defvar user-emacs-directory "~/.emacs.d/"
    "Directory beneath which additional per-user Emacs-specific files are placed.
Various programs in Emacs store information in this directory.
Note that this should end with a directory separator.
See also `locate-user-emacs-file'."))
(unless (fboundp 'locate-user-emacs-file)
  (defun locate-user-emacs-file (new-name &optional old-name)
    "Return an absolute per-user Emacs-specific file name.
If OLD-NAME is non-nil and ~/OLD-NAME exists, return ~/OLD-NAME.
Else return NEW-NAME in `user-emacs-directory'."
    (convert-standard-filename
     (let* ((home (concat "~" (or init-file-user "")))
            (at-home (and old-name (expand-file-name old-name home))))
       (if (and at-home (file-readable-p at-home))
           at-home
         (abbreviate-file-name
          (expand-file-name new-name user-emacs-directory)))))))

(map nil
     (lambda (x) (if (file-directory-p x) (add-to-list 'exec-path x)))
     `(
       "/usr/games"
       "/usr/texbin"
       "/sbin"
       "/usr/sbin"
       "/usr/local/sbin"
       "/bin"
       "/usr/bin"
       "/usr/local/bin"
       ,(concat (getenv "HOME") "/bin")))
(setenv "PATH" (mapconcat 'identity exec-path ":"))

;; add to load-path everything under elisp, recursively
(let ((default-directory (locate-user-emacs-file "elisp")))
  (normal-top-level-add-to-load-path '("."))
  (normal-top-level-add-subdirs-to-load-path))

;; customization file (I don't like it, but some things go there)
(setq custom-file (locate-user-emacs-file "elisp/conf/ew-custom.el"))
(load custom-file t)

;; load site-specific file, if available
(require 'ew-local nil t)

(require 'ew-buffer)
(require 'ew-devel)
(require 'ew-edit)
(require 'ew-font)
(require 'ew-gnus)
(require 'ew-jabber)
(require 'ew-main)
(require 'ew-rc)
(require 'ew-shell)
(require 'ew-vc)
(require 'ew-window)

;;;;
;;;;;; The end
;;;;

;; (message "My .emacs loaded in %ds"
;;          (destructuring-bind (hi lo ms) (current-time)
;;            (- (+ hi lo)
;;               (+ (first *emacs-load-start*) (second *emacs-load-start*)))
;;            ))