diff --git a/package-build.el b/package-build.el index 16fa8b60..10c35eff 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) @@ -759,6 +761,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." @@ -793,6 +836,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'." @@ -844,8 +889,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))))))