From ae77c7ff77bdc1518a3422eb2652d2e57ed1f8ac Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Sun, 24 Mar 2013 13:08:19 +0000 Subject: [PATCH] Helpers for recipe authors - Add helper function `package-build-create-recipe` - Add `package-build-minor-mode`, enabled for recipes: C-c C-c builds current recipe - Opening recipe files causes `package-build` to get loaded, and `package-build-minor-mode` to get enabled --- package-build.el | 55 ++++++++++++++++++++++++++++++++++++++---- recipes/.dir-locals.el | 6 ++++- 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/package-build.el b/package-build.el index bb4dcccd..299e90db 100644 --- a/package-build.el +++ b/package-build.el @@ -45,17 +45,19 @@ (require 'package) (require 'lisp-mnt) -(defcustom package-build-working-dir (expand-file-name "working/") +(defconst pb/this-dir (file-name-directory (or load-file-name (buffer-file-name)))) + +(defcustom package-build-working-dir (expand-file-name "working/" pb/this-dir) "Directory in which to keep checkouts." :group 'package-build :type 'string) -(defcustom package-build-archive-dir (expand-file-name "packages/") +(defcustom package-build-archive-dir (expand-file-name "packages/" pb/this-dir) "Directory in which to keep compiled archives." :group 'package-build :type 'string) -(defcustom package-build-recipes-dir (expand-file-name "recipes/") +(defcustom package-build-recipes-dir (expand-file-name "recipes/" pb/this-dir) "Directory containing recipe files." :group 'package-build :type 'string) @@ -750,6 +752,47 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs." (current-time-string)) file-name))) + +;;; Helpers for recipe authors + +(defvar package-build-minor-mode-map + (let ((m (make-sparse-keymap))) + (define-key m (kbd "C-c C-c") 'package-build-current-recipe) + m) + "Keymap for `package-build-minor-mode'.") + +(define-minor-mode package-build-minor-mode + "Helpful functionality for building packages." + nil + " PBuild" + package-build-minor-mode-map) + +;;;###autoload +(defun package-build-create-recipe (name fetcher) + "Create a new recipe for package NAME using FETCHER." + (interactive + (list (intern (read-string "Package name: ")) + (intern + (let ((fetcher-types (mapcar #'symbol-name '(github git wiki bzr hg cvs svn)))) + (completing-read + "Fetcher: " + fetcher-types + nil t nil nil (car fetcher-types)))))) + (let ((recipe-file (expand-file-name (symbol-name name) package-build-recipes-dir))) + (when (file-exists-p recipe-file) + (error "Recipe already exists")) + (find-file recipe-file) + (let* ((extra-params + (cond + ((eq 'github fetcher) '(:repo "USER/REPO")) + ((eq 'wiki fetcher) '()) + (t '(:url "SCM_URL_HERE")))) + (template `(,name :fetcher ,fetcher ,@extra-params))) + (insert (pp-to-string template)) + (emacs-lisp-mode) + (package-build-minor-mode) + (beginning-of-buffer)))) + ;;;###autoload (defun package-build-current-recipe () "Build archive for the recipe defined in the current buffer." @@ -784,6 +827,8 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs." (message "%s" (error-message-string err)) nil)))) + + ;;;###autoload (defun package-build-all () "Build all packages in the `package-build-recipe-alist'." @@ -835,8 +880,8 @@ FILES is a list of (SOURCE . DEST) relative filepath pairs." ;; Utility functions -(autoload 'json-encode "json") -(eval-after-load 'json '(load (expand-file-name "json-fix"))) +(require 'json) +(load (expand-file-name "json-fix" pb/this-dir)) (defun package-build-recipe-alist-as-json (fn) (interactive) diff --git a/recipes/.dir-locals.el b/recipes/.dir-locals.el index 38e1fd1a..960d6133 100644 --- a/recipes/.dir-locals.el +++ b/recipes/.dir-locals.el @@ -1,4 +1,8 @@ ((nil . ((eval . (when (and (buffer-file-name) (file-regular-p (buffer-file-name)) (string-match-p "^[^.]" (buffer-file-name))) - (emacs-lisp-mode)))))) + (emacs-lisp-mode) + (unless (featurep 'package-build) + (let ((load-path (cons ".." load-path))) + (require 'package-build))) + (package-build-minor-mode))))))