about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-11-12T18·46+0100
committerVincent Ambo <github@tazj.in>2017-11-12T21·44+0100
commit99d9981dd9a10e4feade16161a13df64b0580da2 (patch)
tree9647cb63f0c820233a5e9aa1ec8f55f622548cdd
parent5fcabc204a878fa385450febf4eaabaa46386786 (diff)
refactor(init): Refactor package installation process
Refactors package installation to be slightly more sane, for example
package-refresh-contents will only be called if packages are missing.

Removes some other old cruft, too, and paves way for a slightly
different initialisation process.
-rw-r--r--init.el88
-rw-r--r--init/theme.el6
2 files changed, 50 insertions, 44 deletions
diff --git a/init.el b/init.el
index fa2ffc14a91b..4a80e44ed576 100644
--- a/init.el
+++ b/init.el
@@ -1,18 +1,18 @@
-;; Configure package manager
+;;; init.el --- Package bootstrapping. -*- lexical-binding: t; -*-
+
+;; This file bootstraps the Emacs setup by going through package installations.
+;; After all packages are installed, local configuration is loaded.
+
 (require 'package)
-(package-initialize)
+(require 'seq)
 
-;; Add Marmalade repo
+;; Configure Marmalade and MELPA repositories. Packages available on Marmalade
+;; will have precedence.
 (add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
-
-;; ... and melpa. Melpa packages that exist on marmalade will have
-;; precendence.
 (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
 
-;; And load things!
-(package-refresh-contents)
-
-(defvar my-pkgs
+;; This variable controls all packages that should be installed.
+(setq-local desired-packages
   '(;; elisp libraries
     dash
     dash-functional
@@ -57,49 +57,49 @@
     undo-tree
     uuidgen
     yaml-mode
-    )
-  "A list of packages to install at launch.")
-
-(dolist (p my-pkgs)
-  (when (not (package-installed-p p))
-    (package-install p)))
-
-;; Are we on a mac?
-(setq is-mac (equal system-type 'darwin))
-
-;; Or on Linux?
-(setq is-linux (equal system-type 'gnu/linux))
-
-;; What's the home folder?
-(defvar home-dir)
-(setq home-dir (expand-file-name "~"))
+    ))
 
-(add-to-list 'load-path (concat user-emacs-directory "init"))
+(defun installable-packages (pkg-list)
+  "Filter out not-yet installed packages from package list."
+  (seq-filter (lambda (p) (not (package-installed-p p))) pkg-list))
 
-(mapc 'require '(functions
-                 settings
-                 modes
-                 bindings
-                 eshell-setup
-                 haskell-setup
-                 rust-setup
-                 ))
+(defun install-needed-packages (pkg-list)
+  (let ((to-install (installable-packages pkg-list)))
+    (if (< 0 (length to-install))
+        (progn (package-refresh-contents)
+               (mapcar #'package-install to-install))
+      (message "No new packages to install."))))
 
-(add-to-list 'load-path (concat user-emacs-directory "scripts"))
+;; Run package installation!
+(install-needed-packages desired-packages)
 
+;; Configure a few basics before moving on to package-specific initialisation.
 (setq custom-file (concat user-emacs-directory "init/custom.el"))
 (load custom-file)
 
-;; Local configuration
-(load-file-if-exists "~/.emacs.d/init/local.el")
-
-;; Load magnars' string manipulation library
-(require 's)
+(defvar home-dir)
+(setq home-dir (expand-file-name "~"))
 
 ;; Seed RNG
 (random t)
 
-(put 'upcase-region 'disabled nil)
+;; Add 'init' folder that contains other settings to load.
+(add-to-list 'load-path (concat user-emacs-directory "init"))
+
+;; Load configuration that makes use of installed packages:
+
+
+;; Emacs will automatically initialise all installed packages.
+;; After initialisation, proceed to load configuration that requires packages:
+(defun load-other-settings ()
+  (mapc 'require '(theme
+                   functions
+                   settings
+                   modes
+                   bindings
+                   eshell-setup
+                   haskell-setup
+                   rust-setup
+                   )))
 
-;; Configure smart mode line
-(sml/setup)
+(add-hook 'after-init-hook 'load-other-settings)
diff --git a/init/theme.el b/init/theme.el
new file mode 100644
index 000000000000..3ad6a8a81850
--- /dev/null
+++ b/init/theme.el
@@ -0,0 +1,6 @@
+;;; theme.el --- Editor theming. -*- lexical-binding: t; -*-
+
+;; Configure smart mode line
+(sml/setup)
+
+(provide 'theme)