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