From 679b0c30dc13a813762bae505bef9ac6911e87c4 Mon Sep 17 00:00:00 2001 From: Ashley Duckworth Date: Fri, 22 Jan 2021 13:07:59 -0600 Subject: Finally sort out the config.org/el loading thing --- config.org | 35 +++++++++++++++++++----------- early-init.el | 22 ++++++++++++++++--- init.el | 68 +++++++++++++++++++++++++++++------------------------------ 3 files changed, 75 insertions(+), 50 deletions(-) diff --git a/config.org b/config.org index d99c918..8945ab1 100644 --- a/config.org +++ b/config.org @@ -1559,18 +1559,29 @@ the needed boolean expression to tangle config.org. Booleans, yall! (config.org (concat config ".org")) (straight-org-dir (expand-file-name "straight/build/org" user-emacs-directory))) - (unless (load config 'no-error)) - ;; A plain require here just loads the older `org' - ;; in Emacs' install dir. We need to add the newer - ;; one to the `load-path', hopefully that's all. - (when (file-exists-p straight-org-dir) - (add-to-list 'load-path straight-org-dir)) - ;; Load config.org - (require 'org) - (org-babel-load-file config.org :compile)) -#+end_src - -*** early-init.el + ;; Okay, let's figure this out. + ;; `and' evaluates each form, and returns nil on the first that + ;; returns nil. `unless' only executes its body if the test + ;; returns nil. So. + ;; 1. Test if config.org is newer than config.el. If it is (t), we + ;; *want* to evaluate the body, so we need to negate that test. + ;; 2. Try to load the config. If it errors (nil), it'll bubble that + ;; to the `and' and the body will be evaluated. + (unless (and (not (file-newer-than-file-p config.org config.el)) + (load config :noerror)) + ;; A plain require here just loads the older `org' + ;; in Emacs' install dir. We need to add the newer + ;; one to the `load-path', hopefully that's all. + (when (file-exists-p straight-org-dir) + (add-to-list 'load-path straight-org-dir)) + ;; Load config.org + (require 'org) + (org-babel-load-file config.org))) + + ;;; init.el ends here +#+end_src + +** early-init.el :PROPERTIES: :header-args: :tangle early-init.el :noweb yes :END: diff --git a/early-init.el b/early-init.el index 5ebc544..f9486ff 100644 --- a/early-init.el +++ b/early-init.el @@ -1,16 +1,30 @@ -;; early-init.el -*- no-byte-compile: t; -*- +;;; early-init.el -*- no-byte-compile: t; -*- +;; Copyright (C) 2020 Case Duckworth + +;; Author: Case Duckworth +;; Created: Sometime during the Covid-19 lockdown, 2019 +;; Keywords: configuration +;; URL: https://tildegit.org/acdw/emacs + +;; This file is not part of GNU Emacs. + +;;; Commentary: ;; This file is automatically tangled from config.org. ;; Hand edits will be overwritten! + +;;; Code: + ;; BOOTSTRAP PACKAGE MANAGEMENT (let ((win-app-dir "~/Applications")) (dolist (path (list ;; Windows + (expand-file-name "exe" win-app-dir) (expand-file-name "Git/bin" win-app-dir) (expand-file-name "Git/usr/bin" win-app-dir) (expand-file-name "Git/mingw64/bin" win-app-dir) + (expand-file-name "Everything" win-app-dir) ;; Linux - (expand-file-name "bin" - user-emacs-directory) + (expand-file-name "bin" user-emacs-directory) (expand-file-name "~/bin") (expand-file-name "~/.local/bin") (expand-file-name "~/Scripts") @@ -68,3 +82,5 @@ (horizontal-scroll-bar-mode -1) (setq-default frame-inhibit-implied-resize t frame-resize-pixelwise t) + +;;; early-init.el ends here diff --git a/init.el b/init.el index 332468c..1ddb5f9 100644 --- a/init.el +++ b/init.el @@ -1,33 +1,20 @@ -;; init.el -*- lexical-binding: t -*- -;; This file is automatically tangled from config.org. -;; Hand edits will be overwritten! +;;; init.el -*- lexical-binding: t -*- +;; Copyright (C) 2020 Case Duckworth -(setq-default load-prefer-newer t) +;; Author: Case Duckworth +;; Created: Sometime during the Covid-19 lockdown, 2019 +;; Keywords: configuration +;; URL: https://tildegit.org/acdw/emacs + +;; This file is not part of GNU Emacs. -(defmacro when-at (conditions &rest commands) - "Run COMMANDS, or let the user know, when at a specific place. +;;; Commentary: +;; This file is automatically tangled from config.org. +;; Hand edits will be overwritten! -CONDITIONS are one of `:work', `:home', or a list beginning with -those and other conditions to check. COMMANDS are only run if -all CONDITIONS are met. +;;; Code: -If COMMANDS is empty or nil, simply return the result of CONDITIONS." - (declare (indent 1)) - (let ((at-work '(memq system-type '(ms-dos windows-nt))) - (at-home '(memq system-type '(gnu gnu/linux gnu/kfreebsd)))) - (pcase conditions - (:work (if commands `(when ,at-work ,@commands) at-work)) - (:home (if commands `(when ,at-home ,@commands) at-home)) - ((guard (eq (car conditions) :work)) - (if commands - `(when (and ,at-work ,@(cdr conditions)) - ,@commands) - `(and ,at-work ,@(cdr conditions)))) - ((guard (eq (car conditions) :home)) - (if commands - `(when (and ,at-home ,@(cdr conditions)) - ,@commands) - `(and ,at-work ,@(cdr conditions))))))) +(setq-default load-prefer-newer t) (let* (;; Speed up init (gc-cons-threshold most-positive-fixnum) @@ -39,12 +26,23 @@ If COMMANDS is empty or nil, simply return the result of CONDITIONS." (config.org (concat config ".org")) (straight-org-dir (expand-file-name "straight/build/org" user-emacs-directory))) - (unless (load config 'no-error)) - ;; A plain require here just loads the older `org' - ;; in Emacs' install dir. We need to add the newer - ;; one to the `load-path', hopefully that's all. - (when (file-exists-p straight-org-dir) - (add-to-list 'load-path straight-org-dir)) - ;; Load config.org - (require 'org) - (org-babel-load-file config.org :compile)) + ;; Okay, let's figure this out. + ;; `and' evaluates each form, and returns nil on the first that + ;; returns nil. `unless' only executes its body if the test + ;; returns nil. So. + ;; 1. Test if config.org is newer than config.el. If it is (t), we + ;; *want* to evaluate the body, so we need to negate that test. + ;; 2. Try to load the config. If it errors (nil), it'll bubble that + ;; to the `and' and the body will be evaluated. + (unless (and (not (file-newer-than-file-p config.org config.el)) + (load config :noerror)) + ;; A plain require here just loads the older `org' + ;; in Emacs' install dir. We need to add the newer + ;; one to the `load-path', hopefully that's all. + (when (file-exists-p straight-org-dir) + (add-to-list 'load-path straight-org-dir)) + ;; Load config.org + (require 'org) + (org-babel-load-file config.org))) + +;;; init.el ends here -- cgit 1.4.1-21-gabe81