summaryrefslogtreecommitdiffstats
path: root/lisp/init-package.el
blob: 2f4fe741e7333334185c3d164a118caab8060876 (plain) (blame)
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
;;; init-package.el --- configure package management  -*- lexical-binding:t -*-
;;; Commentary:
;;; Code:

;; add melpa repo
(require 'package)
(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives
             '("nongnu" . "https://elpa.nongnu.org/nongnu/") t)
(when (< emacs-major-version 27)
  (package-initialize))

;; emacs and gnutls has recurring issues with tls 1.3
;; the original bug was supposedly fixed in 26.3, but resurfaced in 27.2 on
;; macos (https://emacsformacosx.com build)
;;
;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34341
;; https://www.reddit.com/r/emacs/comments/mk0luk/does_anyone_know_how_to_diagnose_or_fix_emacs_not/
;;
;; disable tls 1.3 if supported by gnutls
(when (>= libgnutls-version 30603)
  (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))

(defun mpolden/require-package (package &optional min-version no-refresh)
  "Install given PACKAGE, optionally requiring MIN-VERSION.
If NO-REFRESH is non-nil, the available package lists will not be
re-downloaded in order to locate PACKAGE."
  (if (package-installed-p package min-version)
      t
    (if (or (assoc package package-archive-contents) no-refresh)
        (package-install package)
      (progn
        (package-refresh-contents)
        (mpolden/require-package package min-version t)))))

(defvar mpolden/inhibited-features nil "List of features that should not be loaded.")

(define-obsolete-variable-alias 'inhibited-packages 'mpolden/inhibited-features "2021-03-28")
(define-obsolete-variable-alias 'mpolden/inhibited-packages 'mpolden/inhibited-features "2021-03-28")

(defun mpolden/maybe-require (feature)
  "Load FEATURE if it's not inhibited."
  (unless (memq feature mpolden/inhibited-features)
    (require feature)))

;; install use-package and diminish
(mpolden/require-package 'use-package)
(mpolden/require-package 'diminish)

;; speed up loading of use-package and dependencies
(eval-when-compile
  (require 'use-package))
(require 'diminish)
(require 'bind-key)

(provide 'init-package)

;;; init-package.el ends here