Skip to content

Instantly share code, notes, and snippets.

@amygrinn
Last active March 24, 2021 20:47
Show Gist options
  • Save amygrinn/d9b97038415405322f7391ab7a0e713b to your computer and use it in GitHub Desktop.
Save amygrinn/d9b97038415405322f7391ab7a0e713b to your computer and use it in GitHub Desktop.
Literate configuration columns view

About

Use column view (C-c C-x C-c) to edit the settings file. Once done, use org-babel-tangle (C-c C-v t) to install to you init file. You can quit column view by putting point in any cell and pressing ‘q’

The machine name can be retrieved by running eval-expression (M-:) and calling (system-name). You can also set the system name using the environment variable “SYSTEM_NAME” outside of emacs.

By default, the output file is user-init-file.

IMPORTANT Editing a cell and leaving it blank is not the same as deleting a property, it will leave an empty string which will break inheritance. Use the custom ‘d’ key binding defined in the utils headline to delete a cell while in column view.

Bootstrap

This block determines how all proceeding src blocks will tangle

(defun determine-tangle-at-point-from-machine-name ()
  "Compare the current system name to the space-separated list of
machine names in the property 'TANGLE_MACHINES'. Return
'OUTPUT_FILE' if defined or `user-init-file' otherwise. If running
in quiet mode, you will be prompted for the init file."
  (unless user-init-file
    (interactive)
    (setq user-init-file
          (read-file-name "User init file: " "~/" nil nil ".emacs")))

  (let ((machines (split-string
                    (or (org-entry-get (point) "TANGLE_MACHINES" t t)
                        "")))
        (allowed-machines (list "*"
                                (system-name)
                                (getenv "SYSTEM_NAME")))
        (output-file (or (org-entry-get (point) "OUTPUT_FILE" t t)
                         user-init-file)))
    (if (and machines (seq-intersection machines allowed-machines))
        output-file
        "no")))
<<bootstrap()>>

Util

(require 'org)
(require 'org-colview)
(defun org-columns-destroy-at-point ()
  "Delete the property at point while in column view"
  (interactive)
  (let ((prop (get-char-property (point)
				     'org-columns-key)))
	      (org-entry-delete (point) prop)
	      (org-columns-redo)))

(org-defkey org-columns-map "d" 'org-columns-destroy-at-point)

Daemon/Server (example src block)

(server-start)
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment