-
Notifications
You must be signed in to change notification settings - Fork 0
/
use-package-ensure-git-repo.el
100 lines (82 loc) · 3.57 KB
/
use-package-ensure-git-repo.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
;;; use-package-ensure-git-repo.el --- auto install packages from git repository -*- lexical-binding: t; -*-
;; Author: Jian Wang <[email protected]>
;; URL: https://github.com/leuven65/use-package-ensure-git-repo
;; Version: 0.1.0
;; Keywords: use-package, git, github
;; This file is not part of GNU Emacs
;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; For a full copy of the GNU General Public License
;; see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;; Code:
(require 'use-package)
(defvar use-package-ensure-git-repo-always-update t
"Update the git repo by default")
(defun use-package-ensure-git-repo-clone-git-repo (repo-url local-dir)
"clone git repo"
(let ((cmd (format "git clone --depth 1 '%s' '%s'"
repo-url local-dir)))
(message "Try to clone: %s" cmd)
(call-process-shell-command cmd)))
(defun use-package-ensure-git-repo-update-git-repo (local-dir)
"git pull"
(let* ((default-directory local-dir))
(message "Try to update repo '%s'" default-directory)
(call-process-shell-command "git pull")))
(defun use-package-ensure-git-repo-get-package-dir (dir-name)
(expand-file-name (concat "packages/" dir-name)
user-emacs-directory))
(defun use-package-ensure-git-repo-process (repo-url dir-name)
"clone or update git repo to ~/.emacs.d/packages/dir-name"
(let ((local-dir (use-package-ensure-git-repo-get-package-dir dir-name))
(autoload-filename (concat dir-name "-autoloads.el"))
(bool-need-compile nil))
(if (file-exists-p (expand-file-name ".git" local-dir))
(when use-package-ensure-git-repo-always-update
;; update git repo
(use-package-ensure-git-repo-update-git-repo local-dir)
(setq bool-need-compile t))
;; clone git repo
(use-package-ensure-git-repo-clone-git-repo repo-url local-dir)
(setq bool-need-compile t))
(when bool-need-compile
;; delete autoloads file
(delete-file (expand-file-name autoload-filename local-dir) nil)
;; Generate autoloads file
(ignore-errors
(package-generate-autoloads dir-name local-dir))
;; force to compile all *.el files
(byte-recompile-directory local-dir 0 t))
;; load the autoload file
(add-to-list 'load-path local-dir)
(load autoload-filename)
)
)
;;;###autoload
(defun use-package-normalize/:ensure-git-repo (_name-symbol keyword args)
"Turn `arg' into a list of cons-es of (`git-repo-rul' . `local-dir-name')."
(use-package-only-one (symbol-name keyword) args
(lambda (_label arg)
(cond
((consp arg) arg)
((stringp arg) (cons arg (symbol-name _name-symbol)))
))))
;;;###autoload
(defun use-package-handler/:ensure-git-repo (name _keyword arg rest state)
"Execute the handler for `:ensure-git-reop' keyword in `use-package'."
(let ((body (use-package-process-keywords name rest state)))
(use-package-concat
`((use-package-ensure-git-repo-process ,(car arg) ,(cdr arg)))
body)))
;; let this keyword to be the first to be processed
(add-to-list 'use-package-keywords :ensure-git-repo)
(provide 'use-package-ensure-git-repo)
;;; use-package-ensure-git-repo.el ends here