From 92e86ff0cae0a0d9872029516afc1f707d369b24 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 21 Jan 2021 21:48:38 -0600 Subject: 2020-01-21 --- init.el | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) (limited to 'init.el') diff --git a/init.el b/init.el index e8a67fd..221956c 100644 --- a/init.el +++ b/init.el @@ -4,26 +4,51 @@ (setq-default load-prefer-newer t) +(defmacro when-at (conditions &rest commands) + "Run COMMANDS, or let the user know, when at a specific place. + +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. + +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))))))) + (let* (;; Speed up init (gc-cons-threshold most-positive-fixnum) (file-name-handler-alist nil) ;; Config file names (config (expand-file-name "config" - user-emacs-directory)) + user-emacs-directory)) (config.el (concat config ".el")) (config.org (concat config ".org")) (straight-org-dir (expand-file-name "straight/build/org" - user-emacs-directory))) + user-emacs-directory))) ;; Unless config.org is /newer/ than config.el, *or* the config ;; is able to be loaded without errors, load the config from ;; config.org. (unless (or (file-newer-than-file-p config.org config.el) - (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))) + (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))) -- cgit 1.4.1-21-gabe81