summary refs log tree commit diff
path: root/emacs
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-04-19 08:39:45 -0700
committerFranck Cuny <franck@fcuny.net>2022-04-19 08:39:45 -0700
commit352e373f439027f29b491cf0842dbb42c4d00db8 (patch)
tree10324abfef9680f0366390583bc13ee4cb2275de /emacs
parentfeed update (diff)
downloademacs.d-352e373f439027f29b491cf0842dbb42c4d00db8.tar.gz
start to install packages without use-package
Define a list of packages in `init.el', and then use plain `require' in
the various custom modules.

The first two packages installed that way are:
- notmuch
- exec-path-from-shell
Diffstat (limited to '')
-rw-r--r--emacs/custom/my-notmuch.el25
-rw-r--r--emacs/custom/my-settings.el9
-rw-r--r--emacs/init.el50
3 files changed, 48 insertions, 36 deletions
diff --git a/emacs/custom/my-notmuch.el b/emacs/custom/my-notmuch.el
index b009f9e..c997b18 100644
--- a/emacs/custom/my-notmuch.el
+++ b/emacs/custom/my-notmuch.el
@@ -1,20 +1,19 @@
-;;; my-notmuch.el --- Configures notmuch
+;;; my-notmuch.el --- Configures notmuch -*- lexical-binding: t -*-
+
 ;;; Commentary:
+
 ;;; Code:
 
-(require 'use-package)
+(require 'notmuch)
 
-(use-package notmuch
-  :ensure t
-  :if (executable-find "notmuch")
-  :hook
-  (notmuch-message-mode . flyspell-mode)
-  :custom
-  (notmuch-show-logo nil)
-  (notmuch-search-oldest-first nil)
-  (notmuch-always-prompt-for-sender t)
-  (notmuch-show-relative-dates t)
-  (notmuch-archive-tags '("-inbox" "-unread")))
+(setq notmuch-show-logo nil)
+(setq notmuch-search-oldest-first nil)
+(setq notmuch-always-prompt-for-sender t)
+(setq notmuch-show-relative-dates t)
+(setq notmuch-archive-tags '("-inbox" "-unread"))
+
+(add-hook 'notmuch-message-mode-hook 'flyspell-mode)
 
 (provide 'my-notmuch)
+
 ;;; my-notmuch.el ends here
diff --git a/emacs/custom/my-settings.el b/emacs/custom/my-settings.el
index 04d0182..4f6621b 100644
--- a/emacs/custom/my-settings.el
+++ b/emacs/custom/my-settings.el
@@ -64,12 +64,9 @@
   :init
   (savehist-mode))
 
-(use-package exec-path-from-shell
-  :ensure t
-  :if (memq window-system '(mac ns))
-  :hook (emacs-startup . (lambda ()
-                           (setq exec-path-from-shell-arguments '("-l")) ; removed the -i for faster startup
-                           (exec-path-from-shell-initialize))))
+(when (memq window-system '(mas ns))
+  (require 'exec-path-from-shell)
+  (add-hook 'emacs-startup-hook (lambda () (exec-path-from-shell-initialize))))
 
 (provide 'my-settings)
 ;;; my-settings.el ends here
diff --git a/emacs/init.el b/emacs/init.el
index 26f5132..1ef3676 100644
--- a/emacs/init.el
+++ b/emacs/init.el
@@ -14,30 +14,46 @@
 	     '("melpa" .
 	       "https://melpa.org/packages/"))
 
-(progn
-  (message "initializing package")
-  (package-initialize))
+(defvar my/package-list
+  '(use-package
+     exec-path-from-shell
+     notmuch)
+  "List of packages to be installed.")
 
-(unless (package-installed-p 'use-package)
-  (package-refresh-contents)
-  (package-install 'use-package))
+(defun my/packages-installed-p ()
+  "Check if all packages in `my/package-list' are installed."
+  (cl-every #'package-installed-p my/package-list))
+
+(defun my/require-package (package)
+  "Install PACKAGE unless already installed."
+  (unless (memq package my/package-list)
+    (add-to-list 'my/package-list package))
+  (unless (package-installed-p package)
+    (package-install package)))
+
+(defun my/require-packages (packages)
+  "Ensure PACKAGES are installed.
+Missing packages are installed automatically."
+  (mapc #'my/require-package packages))
+
+(defun my/install-packages ()
+  "Install all packages listed in `my/package-list'."
+  (unless (my/packages-installed-p)
+    ;; check for new packages (package versions)
+    (message "%s" "Reloading packages DB...")
+    (package-refresh-contents)
+    (message "%s" " done.")
+    ;; install the missing packages
+    (my/require-packages my/package-list)))
+
+;; run package installation
+(my/install-packages)
 
 (eval-when-compile (require 'use-package))
 
 (setq use-package-verbose t)
 (setq use-package-always-ensure nil)
 
-(defun my/package-install-refresh-contents (&rest args)
-  "Refresh the package content, takes an optional ARGS."
-  ;; Whenever use-package statements use ensure (directly or via
-  ;; use-package-always-ensure), we need to refresh the package contents first,
-  ;; as installation fails otherwise:
-  ;; https://github.com/jwiegley/use-package/issues/256#issuecomment-263313693
-  (package-refresh-contents)
-  (advice-remove 'package-install 'my/package-install-refresh-contents))
-
-(advice-add 'package-install :before 'my/package-install-refresh-contents)
-
 (add-to-list 'load-path (expand-file-name "custom/" user-emacs-directory))
 (add-to-list 'load-path (expand-file-name "elisp/" user-emacs-directory))