Setup ensure rather than maintaining separate package-selected-packages list

This commit is contained in:
Evie Litherland-Smith 2024-08-07 15:13:03 +01:00
parent b0defada7b
commit 20e22b0d87

View file

@ -16,48 +16,13 @@ time it's used.
(use-package package
:custom
(package-archive-priorities '(("melpa" . 4) ("stable" . 3) ("nongnu" . 2) ("gnu" . 1)))
(package-selected-packages
'(
;; UI
base16-theme doom-modeline nerd-icons nerd-icons-completion
nerd-icons-corfu nerd-icons-dired nerd-icons-ibuffer
ligature which-key diff-hl
;; Completion
vertico orderless marginalia cape corfu corfu-terminal
consult consult-eglot flyspell-correct tempel
;; IDE
treesit-auto magit forge apheleia envrc rainbow-delimiters
flymake-shellcheck flymake-yamllint flymake-clippy
flymake-eslint markdown-mode pandoc-mode python-docstring
nix-mode lua-mode
;; Org + LaTeX
org-roam org-noter citar auctex htmlize
;; Other
password-store emms bbdb ement scad-mode
))
:config
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("stable" . "https://stable.melpa.org/packages/"))
(package-initialize))
#+end_src
Add custom function to ensure required packages are installed and
updated.
#+begin_src emacs-lisp
(defun my/package-ensure ()
"Ensure packages are installed and updated."
(interactive)
(require 'use-package)
(package-refresh-contents)
(package-install-selected-packages)
(package-autoremove)
(package-upgrade-all))
;; Plugins that still need adding / configuring: `auctex' `htmlize'
;; `password-store'
#+end_src
Load =custom.el= if file exists in default location.
@ -107,51 +72,59 @@ Configure the look and feel of Emacs
*** Theme and Icons
#+begin_src emacs-lisp
(use-package base16-theme
:if (package-installed-p 'base16-theme)
:demand
:defines (base16-one-light-theme-colors
my/load-theme-and-configure)
:hook (server-after-make-frame . my/load-theme-and-configure)
:ensure t
:defines (base16-one-light-theme-colors)
:custom
(base16-theme-distinct-fringe-background nil)
(base16-theme-highlight-mode-line 'contrast)
:init
(defun my/load-theme-and-configure ()
"Load theme and configure some faces."
(load-theme 'base16-one-light t)
(base16-theme-highlight-mode-line 'contrast))
;; Change outline headers to follow rainbow order
(require 'outline)
(dolist (pairing '((outline-1 . :base08)
(outline-2 . :base09)
(outline-3 . :base0A)
(outline-4 . :base0B)
(outline-5 . :base0C)
(outline-6 . :base0D)
(outline-7 . :base0E)
(outline-8 . :base0F)))
(set-face-attribute (car pairing) nil
:foreground
(plist-get base16-one-light-theme-colors (cdr pairing)))))
:config
(if (display-graphic-p) (my/load-theme-and-configure)))
(defun my/load-theme-and-configure ()
"Load theme and configure some faces."
(require 'base16-theme)
(load-theme 'base16-one-light t)
;; Change outline headers to follow rainbow order
(require 'outline)
(dolist (pairing '((outline-1 . :base08)
(outline-2 . :base09)
(outline-3 . :base0A)
(outline-4 . :base0B)
(outline-5 . :base0C)
(outline-6 . :base0D)
(outline-7 . :base0E)
(outline-8 . :base0F)))
(set-face-attribute (car pairing) nil
:foreground
(plist-get base16-one-light-theme-colors (cdr pairing)))))
(when (display-graphic-p)
;; (add-hook server-after-make-frame-hook #'my/load-theme-and-configure)
(my/load-theme-and-configure))
(use-package nerd-icons
:if (package-installed-p 'nerd-icons)
:ensure t
:functions (nerd-icons-octicon))
(use-package nerd-icons-dired
:ensure t
:requires nerd-icons
:hook (dired-mode))
(use-package nerd-icons-ibuffer
:ensure t
:requires nerd-icons
:hook (ibuffer-mode))
(use-package nerd-icons-completion
:functions nerd-icons-completion-mode
:ensure t
:requires nerd-icons
:functions nerd-icons-completion-mode
:hook (after-init . (lambda () (nerd-icons-completion-mode +1))))
(use-package nerd-icons-corfu
:ensure t
:requires nerd-icons
:functions nerd-icons-corfu-formatter)
#+end_src
*** Modeline
#+begin_src emacs-lisp
@ -161,6 +134,7 @@ Configure the look and feel of Emacs
(which-function-mode -1)
(use-package doom-modeline
:ensure t
:functions (doom-modeline-mode)
:hook (after-init . (lambda () (doom-modeline-mode +1)))
:custom
@ -194,7 +168,7 @@ Configure the look and feel of Emacs
*** Font ligatures
#+begin_src emacs-lisp
(use-package ligature
:if (package-installed-p 'ligature)
:ensure t
:functions (ligature-set-ligatures
global-ligature-mode)
:config
@ -361,6 +335,7 @@ Configure email with iCalendar event support, to integrate with
(mm-discouraged-alternatives '("text/html")))
(use-package mu4e
:ensure nil
:if (package-installed-p 'mu4e)
:bind
(("C-c m" . mu4e)
@ -706,7 +681,7 @@ Configure email with iCalendar event support, to integrate with
(flyspell-use-meta-tab nil))
(use-package flyspell-correct
:if (package-installed-p 'flyspell-correct)
:ensure t
:after flyspell
:bind ( :map flyspell-mode-map
("C-;" . flyspell-correct-wrapper)))
@ -738,7 +713,7 @@ Configure email with iCalendar event support, to integrate with
(add-hook 'prog-mode-hook #'(lambda () (display-line-numbers-mode +1)))
(use-package which-key
:if (package-installed-p 'which-key)
:ensure t
:functions which-key-mode
:config (which-key-mode +1))
@ -767,7 +742,7 @@ Configure email with iCalendar event support, to integrate with
auto-cleanup)))
(use-package diff-hl
:if (package-installed-p 'diff-hl)
:ensure t
:functions (diff-hl-magit-pre-refresh
diff-hl-magit-post-refresh
global-diff-hl-mode)
@ -794,6 +769,7 @@ Configure email with iCalendar event support, to integrate with
(ediff-window-setup-function #'ediff-setup-windows-plain))
(use-package emms
:ensure t
:defines (emms-browser-mode-map
emms-playlist-mode-map)
:functions (emms-all
@ -940,7 +916,7 @@ Configure email with iCalendar event support, to integrate with
(if (executable-find "sqlite3")
(use-package org-roam
:if (package-installed-p 'org-roam)
:ensure t
:after org
:defines org-roam-directory
:functions org-roam-db-autosync-mode
@ -1030,6 +1006,7 @@ Configure email with iCalendar event support, to integrate with
(org-icalendar-combined-description "Emacs org-mode combined export"))
(use-package org-noter
:ensure t
:after (org doc-view citar)
:commands org-noter
:custom
@ -1044,6 +1021,7 @@ Configure email with iCalendar event support, to integrate with
(org-noter-prefer-root-as-file-level nil))
(use-package citar
:ensure t
:defines (citar-bibliography
citar-indicators)
:functions (citar-indicator-create
@ -1116,7 +1094,7 @@ Configure email with iCalendar event support, to integrate with
(setq org-preview-latex-default-process 'dvisvgm)
(use-package vertico
:if (package-installed-p 'vertico)
:ensure t
:functions vertico-mode
:hook (after-init . (lambda () (vertico-mode +1)))
:custom
@ -1125,7 +1103,7 @@ Configure email with iCalendar event support, to integrate with
(require 'vertico-directory))
(use-package marginalia
:if (package-installed-p 'marginalia)
:ensure t
:functions marginalia-mode
:hook (after-init . (lambda () (marginalia-mode +1)))
:custom
@ -1135,7 +1113,7 @@ Configure email with iCalendar event support, to integrate with
:config (marginalia-mode +1))
(use-package orderless
:if (package-installed-p 'orderless)
:ensure t
:custom
(completion-styles '(orderless basic))
(completion-category-defaults nil)
@ -1143,12 +1121,8 @@ Configure email with iCalendar event support, to integrate with
(eglot (styles orderless))
(eglot-capf (styles orderless)))))
(use-package nerd-icons-corfu
:functions nerd-icons-corfu-formatter
:requires nerd-icons)
(use-package corfu
:if (package-installed-p 'corfu)
:ensure t
:defines (corfu-map
corfu-mode-map
corfu-margin-formatters)
@ -1197,11 +1171,12 @@ Configure email with iCalendar event support, to integrate with
(corfu-popupinfo-delay 0.3))
(use-package corfu-terminal
:ensure t
:requires corfu
:functions corfu-terminal-mode)
(use-package cape
:if (package-installed-p 'cape)
:ensure t
:after corfu
:functions (cape-emoji
cape-file
@ -1215,7 +1190,7 @@ Configure email with iCalendar event support, to integrate with
(cape-dabbrev-min-length (+ corfu-auto-prefix 1)))
(use-package consult
:if (package-installed-p 'consult)
:ensure t
:functions (consult-org-heading
consult-history)
:bind (("<remap> <imenu>" . consult-imenu)
@ -1233,11 +1208,12 @@ Configure email with iCalendar event support, to integrate with
("<remap> <comint-history-isearch-backward-regexp>" . consult-history)))
(use-package consult-eglot
:ensure t
:after (consult eglot)
:bind (("C-c s s" . consult-eglot-symbols)))
(use-package tempel
:if (package-installed-p 'tempel)
:ensure t
:defines tempel-path
:functions (tempel-expand
tempel-abbrev-mode)
@ -1268,11 +1244,11 @@ Configure email with iCalendar event support, to integrate with
)))
(use-package rainbow-delimiters
:if (package-installed-p 'rainbow-delimiters)
:ensure t
:hook (prog-mode))
(use-package envrc
:if (package-installed-p 'envrc)
:ensure t
:hook (after-init . envrc-global-mode)
:custom
(envrc-show-summary-in-minibuffer t))
@ -1288,7 +1264,7 @@ Configure email with iCalendar event support, to integrate with
(treesit-font-lock-level 3))
(use-package treesit-auto
:if (package-installed-p 'treesit-auto)
:ensure t
:requires treesit
:functions (treesit-auto-add-to-auto-mode-alist
global-treesit-auto-mode)
@ -1361,7 +1337,7 @@ Configure email with iCalendar event support, to integrate with
)
(use-package apheleia
:if (package-installed-p 'apheleia)
:ensure t
:defines (apheleia-formatters
apheleia-mode-alist)
:bind (("C-c c f" . apheleia-format-buffer))
@ -1380,28 +1356,28 @@ Configure email with iCalendar event support, to integrate with
(flymake-show-diagnostics-at-end-of-line 'short))
(use-package flymake-shellcheck
:if (package-installed-p 'flymake-shellcheck)
:ensure t
:functions flymake-shellcheck-load
:requires flymake
:hook (sh-mode . (lambda () (if (executable-find "shellcheck" t)
(flymake-shellcheck-load)))))
(use-package flymake-yamllint
:if (package-installed-p 'flymake-yamllint)
:ensure t
:functions flymake-yamllint-setup
:requires flymake
:hook (yaml-ts-mode . (lambda () (if (executable-find "yamllint" t)
(flymake-yamllint-setup)))))
(use-package flymake-clippy
:if (package-installed-p 'flymake-clippy)
:ensure t
:functions flymake-clippy-setup-backend
:requires flymake
:hook (rust-mode . (lambda () (if (executable-find "clippy" t)
(flymake-clippy-setup-backend)))))
(use-package flymake-eslint
:if (package-installed-p 'flymake-eslint)
:ensure t
:functions flymake-eslint-enable
:requires flymake
:hook ((js-base-mode typescript-ts-base-mode) . (lambda () (if (executable-find "eslint" t)
@ -1431,6 +1407,7 @@ Configure email with iCalendar event support, to integrate with
))
(use-package magit
:ensure t
:bind (("C-c g g" . magit-status)
("C-c g d" . magit-dispatch)
("C-c g f" . magit-file-dispatch)
@ -1454,8 +1431,13 @@ Configure email with iCalendar event support, to integrate with
("\\`\\(?:sourcehut:\\|sh:\\)\\([^:]+\\)\\'" "git.sr.ht" "sourcehut.user")
("\\`\\(?:gitea:\\|gt:\\)\\([^:]+\\)\\'" "git.xenia.me.uk" "gitea.user"))))
(use-package nix-mode
:if (package-installed-p 'nix-mode)
(use-package forge
:ensure t
:defer t)
(when (executable-find "nix")
(use-package nix-mode
:ensure t
:mode "\\.nix\\'"
:functions nix-prettify-global-mode
:config
@ -1463,7 +1445,11 @@ Configure email with iCalendar event support, to integrate with
(require 'nix-flake)
(require 'nix-repl)
(require 'nix-store)
(nix-prettify-global-mode +1))
(nix-prettify-global-mode +1)))
(use-package lua-mode
:ensure t
:mode "\\.lua\\'")
(defun my/enable-fill-column (col)
"Set and enable fill column to `COL'."
@ -1492,7 +1478,7 @@ Configure email with iCalendar event support, to integrate with
(setq python-ts-mode-hook python-mode-hook))
(use-package python-docstring
:if (package-installed-p 'python-docstring)
:ensure t
:hook python-base-mode)
(use-package files
@ -1530,7 +1516,7 @@ Configure email with iCalendar event support, to integrate with
(doc-view-image-width 850))
(use-package markdown-mode
:if (package-installed-p 'markdown-mode)
:ensure t
:hook
((markdown-mode . turn-on-auto-fill))
:custom
@ -1544,11 +1530,12 @@ Configure email with iCalendar event support, to integrate with
(set-face-attribute 'markdown-comment-face nil :inherit 'variable-pitch))
(use-package pandoc-mode
:if (package-installed-p 'pandoc-mode)
:ensure t
:after (markdown-mode)
:hook (markdown-mode . conditionally-turn-on-pandoc))
(use-package bbdb
:ensure t
:bind (("M-g b" . bbdb-display-all-records))
:custom
(bbdb-file (locate-user-emacs-file "bbdb.gpg")))
@ -1589,9 +1576,14 @@ Configure email with iCalendar event support, to integrate with
(eww-browse-url-new-window-is-tab nil))
(use-package password-store
:ensure t
:defer t
:functions password-store-get)
(use-package scad-mode
:ensure t
:defer t)
;; Scratch buffer shortcut
(keymap-global-set "C-c w x" #'scratch-buffer)