Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

trev-dev/org-tangle-config.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Org Tangle Config

This package was written out of the necessity to be able to tangle my literate Emacs init file on-demand without having to (require 'org) early in my init.el. This solution works better than org-babel-load-file for myself because I sometimes like to play around with package managers or different versions of org.

**Archive Notice**: This package was experimental and has been proven to be unneccessary for me. It will no longer be maintained and I doubt it is of much use to anyone, anyway. This package has 3 goals in mind.

  1. Be able to call a tangle on demand.
  2. Be able to automatically tangle a configuration org file after initialization, or after saving said configuration.
  3. Be very explicit about what a “change in configuration” is, and which specific file on a machine is a configuration file.

To properly tangle (and re-tangle) the configuration, a configuration file should be explicitly set with org-tangle-config-org-file. Your method of tangling should then store a subsequent hash of that file’s contents (org-tangle-config-hash) for referring to later.

Installation

As I am not yet on Melpa, or any of the other elpas, you can use something like straight.el for convenience, or manually clone this repository and load it.

straight.el

(straight-use-package '(org-tangle-config :type git :host github :repo "trev-dev/org-tangle-config.el"))

Manually: git clone git@github.com:raxod502/straight.el.git /path/to/package

(add-to-list 'load-path "/path/to/package")
(require 'org-tangle-config)

Basic setup example:

;; Where I presumably might keep this package.
(add-to-list 'load-path "~/.local/lib/emacs-packages")

(require 'org-tangle-config)
;; Check the version of config.org before loading config.el
(org-tangle-config-before-load "~/.config/emacs/config.org")

After you’ve installed the package, and perhaps remove the use of org-babel-load-file, make sure to set your source code parameters to :tangle yes, or this package won’t be very helpful to you.

Customization options

You have the following configuration/customization options at your disposal:

Variables

  1. org-tangle-config-org-file Required: The location of your literate configuration file.
  2. org-tangle-config-enable - Customize to t if you want the org-tangle-config-org-file to re-tangle automatically after it is saved.

Functions

  1. (org-tangle-config-before-load (&optional config)) - Check the version of your configuration against the last known hash. If it’s divergent, re-tangle your configuration. If it’s the same, load the existing “config.el”.
  2. (org-tangle-config) {interactive} - Tangle your config on demand, if there is a new version to be tangled.
  3. (org-tangle-config-enable) {interactive} - Toggle the auto-tangling of your configuration with the after-save-hook.

More examples

Use straight.el, explicitly set configuration file, enable auto-tangling:

;; Bootstrap straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

(straight-use-package
 '(org-tangle-config
   :type git
   :host github
   :repo "trev-dev/org-tangle-config.el"))

(setq org-tangle-config-org-file "~/.emacs.d/config.org" ; set org config
      org-tangle-config-enable t) ; enable auto-tangling
(org-tangle-config-before-load) ; check version before loading config

“I prefer to compose it myself”

(load "~/Projects/org-tangle-config/org-tangle-config.el")
(org-tangle-config-do-tangle
 (org-tangle-config-new-hash
  (org-tangle-config-get-hash
   (set
    'org-tangle-config-org-file
    "~/.config/emacs/config.org")))
 t) ; inhibit pop-up message.
(org-tangle-config-load
 (org-tangle-config-get-config
  "~/.config/emacs/config.org"))

License

gplv3.png

About

A simple Emacs package for tangling your config.org prior to loading your configuration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published