diff options
Diffstat (limited to 'init.el')
-rw-r--r-- | init.el | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/init.el b/init.el index 332468c..1ddb5f9 100644 --- a/init.el +++ b/init.el | |||
@@ -1,33 +1,20 @@ | |||
1 | ;; init.el -*- lexical-binding: t -*- | 1 | ;;; init.el -*- lexical-binding: t -*- |
2 | ;; This file is automatically tangled from config.org. | 2 | ;; Copyright (C) 2020 Case Duckworth |
3 | ;; Hand edits will be overwritten! | ||
4 | 3 | ||
5 | (setq-default load-prefer-newer t) | 4 | ;; Author: Case Duckworth <acdw@acdw.net> |
5 | ;; Created: Sometime during the Covid-19 lockdown, 2019 | ||
6 | ;; Keywords: configuration | ||
7 | ;; URL: https://tildegit.org/acdw/emacs | ||
8 | |||
9 | ;; This file is not part of GNU Emacs. | ||
6 | 10 | ||
7 | (defmacro when-at (conditions &rest commands) | 11 | ;;; Commentary: |
8 | "Run COMMANDS, or let the user know, when at a specific place. | 12 | ;; This file is automatically tangled from config.org. |
13 | ;; Hand edits will be overwritten! | ||
9 | 14 | ||
10 | CONDITIONS are one of `:work', `:home', or a list beginning with | 15 | ;;; Code: |
11 | those and other conditions to check. COMMANDS are only run if | ||
12 | all CONDITIONS are met. | ||
13 | 16 | ||
14 | If COMMANDS is empty or nil, simply return the result of CONDITIONS." | 17 | (setq-default load-prefer-newer t) |
15 | (declare (indent 1)) | ||
16 | (let ((at-work '(memq system-type '(ms-dos windows-nt))) | ||
17 | (at-home '(memq system-type '(gnu gnu/linux gnu/kfreebsd)))) | ||
18 | (pcase conditions | ||
19 | (:work (if commands `(when ,at-work ,@commands) at-work)) | ||
20 | (:home (if commands `(when ,at-home ,@commands) at-home)) | ||
21 | ((guard (eq (car conditions) :work)) | ||
22 | (if commands | ||
23 | `(when (and ,at-work ,@(cdr conditions)) | ||
24 | ,@commands) | ||
25 | `(and ,at-work ,@(cdr conditions)))) | ||
26 | ((guard (eq (car conditions) :home)) | ||
27 | (if commands | ||
28 | `(when (and ,at-home ,@(cdr conditions)) | ||
29 | ,@commands) | ||
30 | `(and ,at-work ,@(cdr conditions))))))) | ||
31 | 18 | ||
32 | (let* (;; Speed up init | 19 | (let* (;; Speed up init |
33 | (gc-cons-threshold most-positive-fixnum) | 20 | (gc-cons-threshold most-positive-fixnum) |
@@ -39,12 +26,23 @@ If COMMANDS is empty or nil, simply return the result of CONDITIONS." | |||
39 | (config.org (concat config ".org")) | 26 | (config.org (concat config ".org")) |
40 | (straight-org-dir (expand-file-name "straight/build/org" | 27 | (straight-org-dir (expand-file-name "straight/build/org" |
41 | user-emacs-directory))) | 28 | user-emacs-directory))) |
42 | (unless (load config 'no-error)) | 29 | ;; Okay, let's figure this out. |
43 | ;; A plain require here just loads the older `org' | 30 | ;; `and' evaluates each form, and returns nil on the first that |
44 | ;; in Emacs' install dir. We need to add the newer | 31 | ;; returns nil. `unless' only executes its body if the test |
45 | ;; one to the `load-path', hopefully that's all. | 32 | ;; returns nil. So. |
46 | (when (file-exists-p straight-org-dir) | 33 | ;; 1. Test if config.org is newer than config.el. If it is (t), we |
47 | (add-to-list 'load-path straight-org-dir)) | 34 | ;; *want* to evaluate the body, so we need to negate that test. |
48 | ;; Load config.org | 35 | ;; 2. Try to load the config. If it errors (nil), it'll bubble that |
49 | (require 'org) | 36 | ;; to the `and' and the body will be evaluated. |
50 | (org-babel-load-file config.org :compile)) | 37 | (unless (and (not (file-newer-than-file-p config.org config.el)) |
38 | (load config :noerror)) | ||
39 | ;; A plain require here just loads the older `org' | ||
40 | ;; in Emacs' install dir. We need to add the newer | ||
41 | ;; one to the `load-path', hopefully that's all. | ||
42 | (when (file-exists-p straight-org-dir) | ||
43 | (add-to-list 'load-path straight-org-dir)) | ||
44 | ;; Load config.org | ||
45 | (require 'org) | ||
46 | (org-babel-load-file config.org))) | ||
47 | |||
48 | ;;; init.el ends here | ||