aboutsummaryrefslogtreecommitdiff
path: root/modules/local-repository.el
blob: b97b74f41804d33af37e0b610f9907fe2f8906d0 (plain)
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
;;; local-repository.el --- local repository functionality -*- lexical-binding: t; coding: utf-8; -*-
;; author Craig Jennings <c@cjennings.net>

;;; Commentary:
;;
;; Layer: 4 (Optional).
;; Category: O/D/P.
;; Load shape: eager.
;; Eager reason: none; local package-mirror workflow, a command-loaded deferral
;;   candidate.
;; Top-level side effects: none.
;; Runtime requires: elpa-mirror.
;; Direct test load: yes.
;;
;;; Code:

(require 'elpa-mirror nil t)  ;; optional; cj/update-localrepo-repository fails at call-time if absent

;; ------------------------------ Utility Function -----------------------------


(defun car-member (value list)
  "Check if VALUE exists as the car of any cons cell in LIST."
  (member value (mapcar #'car list)))

;; ------------------------------- Customizations ------------------------------

(defcustom localrepo-repository-id "localrepo"
  "The name used to identify the local repository internally.

Used for the package-archive and package-archive-priorities lists.")

(defcustom localrepo-repository-priority 100
  "The value for the local repository in the package-archive-priority list.

A higher value means higher priority. If you want your local packages to be
preferred, this must be a higher number than any other repositories.")

(defcustom localrepo-repository-location
  (concat user-emacs-directory "/.localrepo")
  "The location of the local repository.

It's a good idea to keep this with the rest of your configuration files and
keep them in source control.")

(defun cj/update-localrepo-repository ()
  "Update the local repository with currently installed packages."
  (interactive)
  (elpamr-create-mirror-for-installed localrepo-repository-location t))

(defun localrepo-initialize ()
"Add the repository to the package archives, then gives it a high priority."
  (unless (car-member localrepo-repository-id package-archives)
	(add-to-list 'package-archives
				 (cons localrepo-repository-id localrepo-repository-location)))

  (unless (car-member localrepo-repository-id package-archive-priorities)
	(add-to-list 'package-archive-priorities
				 (cons localrepo-repository-id localrepo-repository-priority))))

(provide 'local-repository)
;;; local-repository.el ends here.