From b164801f7fc8554d41777960eb49d9c5cafed4bb Mon Sep 17 00:00:00 2001 From: Frieder Schlesier Date: Sun, 16 Jul 2023 11:32:06 +0200 Subject: [PATCH] add init.org, use org-mode tangle to build init.el Signed-off-by: Frieder Schlesier --- init.el | 24 ++++++++++++++++++--- init.org | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 init.org diff --git a/init.el b/init.el index ff52944..0b83a81 100644 --- a/init.el +++ b/init.el @@ -1,3 +1,7 @@ +;;; init.el -- Fschl Crafted Emacs user customization file -*- lexical-binding: t; -*- +;; This file is generated from init.org. If you want to edit the +;; configuration, DO NOT edit init.el, edit init.org, instead. + (setq user-emacs-directory "~/.config/crafted-emacs-configdir/") (setq crafted-emacs-home "~/src/crafted-emacs/") (setq custom-file (expand-file-name "custom.el" user-emacs-directory)) @@ -5,21 +9,35 @@ (file-exists-p custom-file)) (load custom-file nil :nomessage)) -(load "~/src/crafted-emacs/modules/crafted-init-config") +(load (expand-file-name "modules/crafted-init-config" crafted-emacs-home)) (require 'crafted-completion-packages) (require 'crafted-evil-packages) (require 'crafted-org-packages) (require 'crafted-ui-packages) +(require 'crafted-ide-packages) + (package-install-selected-packages :noconfirm) (require 'crafted-defaults-config) (require 'crafted-startup-config) (require 'crafted-completion-config) -(require 'crafted-ui-config) -(require 'crafted-org-config) (require 'crafted-evil-config) +(require 'crafted-org-config) +(require 'crafted-ui-config) +(require 'crafted-ide-config) (unless crafted-startup-inhibit-splash (setq initial-buffer-choice #'crafted-startup-screen)) +;; Tangle the code blocks to config.el on save. +(defun org-babel-tangle-config () + (when (string-equal (buffer-file-name) + (expand-file-name "init.org" user-emacs-directory)) + ;; Dynamic scoping to the rescue + (let ((org-confirm-babel-evaluate nil)) + (org-babel-tangle)))) + +(add-hook 'org-mode-hook + (lambda () + (add-hook 'after-save-hook #'org-babel-tangle-config))) diff --git a/init.org b/init.org new file mode 100644 index 0000000..f714720 --- /dev/null +++ b/init.org @@ -0,0 +1,66 @@ +#+title: Setup Crafted Emacs User Configuration File +#+PROPERTY: header-args:emacs-lisp :tangle ./init.el :mkdirp yes + +* Basic configuration + +** Set import directories for =crafted-emacs= +#+begin_src emacs-lisp + ;;; init.el -- Fschl Crafted Emacs user customization file -*- lexical-binding: t; -*- + ;; This file is generated from init.org. If you want to edit the + ;; configuration, DO NOT edit init.el, edit init.org, instead. + + (setq user-emacs-directory "~/.config/crafted-emacs-configdir/") + (setq crafted-emacs-home "~/src/crafted-emacs/") + (setq custom-file (expand-file-name "custom.el" user-emacs-directory)) + (when (and custom-file + (file-exists-p custom-file)) + (load custom-file nil :nomessage)) + + (load (expand-file-name "modules/crafted-init-config" crafted-emacs-home)) +#+end_src + +** Add selected =crafted-emacs= packages +#+begin_src emacs-lisp + (require 'crafted-completion-packages) + (require 'crafted-evil-packages) + (require 'crafted-org-packages) + (require 'crafted-ui-packages) + (require 'crafted-ide-packages) + + (package-install-selected-packages :noconfirm) +#+end_src + +** Load selected =crafted-emacs= packages +#+begin_src emacs-lisp + (require 'crafted-defaults-config) + (require 'crafted-startup-config) + (require 'crafted-completion-config) + (require 'crafted-evil-config) + (require 'crafted-org-config) + (require 'crafted-ui-config) + (require 'crafted-ide-config) + + (unless crafted-startup-inhibit-splash + (setq initial-buffer-choice #'crafted-startup-screen)) +#+end_src + +** Auto-tangle on save + +Whenever you edit =init.org= in Emacs and save it, it updates =init.el= in +the same directory. + +See the [[https://orgmode.org/manual/Extracting-Source-Code.html][Org Manual]] for details and alternatives. + +#+begin_src emacs-lisp + ;; Tangle the code blocks to config.el on save. + (defun org-babel-tangle-config () + (when (string-equal (buffer-file-name) + (expand-file-name "init.org" user-emacs-directory)) + ;; Dynamic scoping to the rescue + (let ((org-confirm-babel-evaluate nil)) + (org-babel-tangle)))) + + (add-hook 'org-mode-hook + (lambda () + (add-hook 'after-save-hook #'org-babel-tangle-config))) +#+end_src