forked from purcell/emacs.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-marmalade.el
68 lines (59 loc) · 2.63 KB
/
init-marmalade.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(require-package 'marmalade)
;;; Handy code for uploading new versions of my own packages to marmalade
(autoload 'marmalade-upload-buffer "marmalade")
(defun sanityinc/parse-git-version (s)
"Return numeric version array parsed from S, or nil."
(ignore-errors (version-to-list s)))
(defun latest-version-from-git-tag ()
(let ((versions
(remove-if #'null
(mapcar #'sanityinc/parse-git-version
(split-string (shell-command-to-string "git tag"))))))
(sort versions #'version-list-<)
(package-version-join (car (last versions)))))
(defun update-version-header (val)
(save-excursion
(goto-char (point-min))
(re-search-forward "^;;;? ?Version:")
(kill-line)
(insert " " val)))
(defun submit-tar-to-marmalade (buf)
(interactive "bSubmit buffer library as tar: ")
(with-current-buffer buf
(let* ((tag (or (latest-version-from-git-tag) (error "Not tagged")))
(library-name (file-name-nondirectory (file-name-sans-extension buffer-file-name)))
(package-dir-name (concat library-name "-" tag))
(temp-working-dir (make-temp-file "emacs-marmalade" t))
(dest (expand-file-name package-dir-name temp-working-dir))
(tar-cmd (or (executable-find "gtar")
(executable-find "tar")))
(tar (concat dest ".tar")))
(message "Building package in %s" dest)
(make-directory dest)
(let ((command-line (format "cp *.el %s && (cd %s && perl -spi -e 's/\\{\\{VERSION\\}\\}/%s/' *.el) && (cd %s && %s cvf %s %s)" dest dest tag temp-working-dir tar-cmd tar package-dir-name)))
(shell-command command-line))
(save-excursion
(shell-command (format "open %s" temp-working-dir))
;; (find-file tar)
;; (marmalade-upload-buffer (current-buffer))
;; (delete-directory temp-working-dir t)
))))
(defun submit-to-marmalade (buf)
"Submit the elisp library in BUF to Marmalade."
(interactive
(list
(let ((buffers (loop for b in (mapcar 'buffer-name (buffer-list))
when (with-current-buffer b
(and buffer-file-name
(eq major-mode 'emacs-lisp-mode)))
collect b)))
(completing-read "Submit buffer: " buffers nil t nil nil (car buffers)))))
(with-current-buffer buf
(let ((tag (latest-version-from-git-tag)))
(unless tag
(error "Not tagged"))
(update-version-header tag)
(marmalade-upload-buffer buf)
(revert-buffer t t)
(message "Submitted version %s to marmalade" tag))))
(provide 'init-marmalade)