Skip to content

Instantly share code, notes, and snippets.

@mattiasb
Created September 3, 2024 12:15
Show Gist options
  • Save mattiasb/13786f7ef4679f3ae8283cc7cdf38df3 to your computer and use it in GitHub Desktop.
Save mattiasb/13786f7ef4679f3ae8283cc7cdf38df3 to your computer and use it in GitHub Desktop.
Building my packages
#!/usr/bin/emacs -x
;; -*- flymake-diagnostic-functions: nil; -*-
(setq user-emacs-directory (locate-dominating-file load-file-name ".git"))
(load (file-name-concat user-emacs-directory "early-init.el"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'package)
(require 'package-vc)
(defvar pkg-local-force (and argv t))
(defvar pkg-local-dir (file-name-concat user-emacs-directory "packages"))
(setopt native-comp-always-compile t)
(defun pkg-intern (filenames)
(seq-map #'intern (seq-map #'file-name-base filenames)))
(defun pkg-local ()
(let* ((pattern (rx (seq bos (+ (in alphanumeric "-+." )) ".el" eos)))
(paths (directory-files pkg-local-dir t pattern))
(wanted (pkg-wanted (pkg-intern paths)))
(forced (pkg-intern argv)))
(seq-union wanted forced)))
(defun pkg-pretty-list (packages)
(format "- %s" (string-join (seq-map #'symbol-name packages) "\n- ")))
(defun pkg-wanted (packages)
(seq-remove #'package-installed-p packages))
(defun pkg-local-install (package)
(let ((file-name (format "%s.el" (symbol-name package))))
(package-install-file (file-name-concat pkg-local-dir file-name))))
(defun +seq-union (&rest sequences)
(seq-reduce 'seq-union sequences '()))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(package-initialize)
(let ((pkg-local (pkg-local))
(pkg-external (pkg-wanted package-selected-packages))
(pkg-external-vc (pkg-wanted (seq-map 'car package-vc-selected-packages))))
(when-let ((pkg-all (+seq-union pkg-external pkg-external-vc pkg-local)))
(message "Installing...")
(message (pkg-pretty-list pkg-all))
(when pkg-external (package-install-selected-packages t))
(when pkg-external-vc (package-vc-install-selected-packages))
(when pkg-local (seq-map #'pkg-local-install pkg-local))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment