Recently while debugging the behavior of an external package in an emacs -Q session, I came up with the below.
(defmacro emacs-pkg-debug-setup (pkg-alist &rest body)
"Install packages in PKG-ALIST and evaluate BODY.
Each element of PKG-ALIST has the form (((ID . LOCATION) . (PKG1 PKG2 ..)) ..).
The ID and LOCATION are the same as the ones in `package-archives'.
PKG1, PKG2, .. are package names from the ID archive.
Example usage:
1. Launch 'emacs -Q'.
2. Copy this macro definition to its scratch buffer and evaluate it.
3. Evaluate a minimum working example using this macro as below:
(org-mode)) "
(declare (indent 1) (debug t))
`(progn
(require 'package)
(setq user-emacs-directory (concat temporary-file-directory
(getenv "USER") "/" ".emacs.d-debug/"))
(setq package-user-dir (concat user-emacs-directory "elpa/"))
(let ((pkgs ()))
(dolist (archive-alist ,pkg-alist)
(add-to-list 'package-archives (car archive-alist) :append)
(setq pkgs (append pkgs (cdr archive-alist))))
(package-initialize)
(package-refresh-contents)
(dolist (pkg pkgs)
(package-install pkg)
(require pkg))
,@body
)))
Then anyone can safe evaluate just that little form in a fresh emacs -Q session, and let the emacs-pkg-debug-setup macro handle the package-archives updating and package installation. The packages get installed to "/tmp/$USER/.emacs.d-debug/elpa/" by default.