hamacs/bootstrap.org
Howard Abrams 465fb840c1 Add journal system as well as auto inserting
One big feature of the org-journal is the ability to auto generate
empty files, and I realized that I needed to kick it up a notch with
the auto-insert. Actually brought my old code from years ago, as it
still works.
2021-11-10 14:31:15 -08:00

6.3 KiB

My Emacs Bootstrap

A literate programming file for bootstraping my Emacs Configuration.

Introduction

This file contains all the variable definitions and library loading for the other files in my project.

Straight Package Installer

I'm going to be installing everything using the straight.el for package installation and management. Here is the initialization/installation for it:

(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))

Let's get the Straight project working with use-package:

(straight-use-package 'use-package)

While that enables the :straight t extension to use-package, let's just have that be the default:

(use-package straight
  :custom (straight-use-package-by-default t))

See the details in this essay.

Basic Libraries

The following packages come with Emacs, but seems like they still need loading:

(require 'subr-x)

Ugh. Why am I getting this error?

  (defun first (elt) (car elt))

While most libraries will take care of their dependencies, I want to install my dependent libraries. Especially, Magnar Sveen's Clojure-inspired dash.el project:

(use-package dash)

The s.el project is a simpler string manipulation library that I (and other projects) use:

(use-package s)

Manipulate file paths with the f.el project:

(use-package f)

My Code Location

Much of my more complicated code comes from my website essays and other projects. The destination, however, shows up here:

(add-to-list 'load-path (f-expand "~/.emacs.d/elisp"))

Hopefully, this will tie me over while I transition.

Emacs Server Control

Sure the Emacs application will almost always have the server-start going, however, I need to control it just a bit (because I often have two instances running on some of my machines). What defines the Emacs instance for work changes … often:

(defun ha-emacs-for-work? ()
  "Return non-nil when the Emacs application's location matches as one for work.
Currently, this is the `emacs-plus' app that I have built with
the native-comp model, but I reserve the right to change this."
  (->> Info-default-directory-list
    (first)
    (s-split "/")
    (--filter (s-starts-with? "emacs-plus" it))
    (first)))
(if (ha-emacs-for-work?)
    (setq server-name "work")
  (setq server-name "personal"))

(server-start)

Load the Rest

The following loads the rest of my org-mode literate files. I add them as they are ready, but eventually, I'll trim this up into a nicer pattern.

  (defvar ha-hamacs-files `("ha-config.org"
                            "ha-display.org"
                            "ha-org.org"
                            "ha-org-word-processor.org"
                            "ha-org-clipboard.org"
                            "ha-org-journaling.org"
                            ;; "org-publishing.org"
                            "ha-org-sprint.org"
                            "ha-capturing-notes.org"
                            "ha-programming.org"
                            ;; "ha-agendas.org"
                            ;; "ha-email.org"
                            ;; "ha-irc.org"
                            ;; "ha-passwords.org"
                            "ha-remoting.org"
                            "ha-feed-reader.org"

                            ,(when (ha-emacs-for-work?)
                               "ha-work.org"))
    "List of org files that complete the hamacs project.")

We can test/debug/reload any individual file, via:

  (defun ha-hamacs-load (file)
    "Load or reload an org-mode FILE containing literate Emacs configuration code."
    (interactive (list (completing-read "Org file: " ha-hamacs-files)))
    (org-babel-load-file (f-join hamacs-source-dir file)))

And we can now load everything:

  (dolist (file ha-hamacs-files)
    (ha-hamacs-load file))