Add package installed check to anything that activates automatically

This commit is contained in:
Evie Litherland-Smith 2024-07-15 08:00:30 +01:00
parent 24b36c5de1
commit e31ba218c1

62
init.el
View file

@ -125,6 +125,7 @@
;; Make `describe-*' screens more helpful ;; Make `describe-*' screens more helpful
(use-package helpful (use-package helpful
:if (package-installed-p 'helpful)
:defines helpful-mode-map :defines helpful-mode-map
:bind (("<remap> <describe-command>" . helpful-command) :bind (("<remap> <describe-command>" . helpful-command)
("<remap> <describe-function>" . helpful-callable) ("<remap> <describe-function>" . helpful-callable)
@ -148,16 +149,10 @@
:hook ((text-mode . flyspell-mode) :hook ((text-mode . flyspell-mode)
(prog-mode . flyspell-prog-mode)) (prog-mode . flyspell-prog-mode))
:init :init
(require 'ispell) (require 'ispell))
(require 'org) ; Fails without org-mode-map for some reason...
:custom
(flyspell-mode-line-string nil)
(flyspell-use-meta-tab nil)
:config
(require 'flyspell-correct)
(require 'consult-flyspell))
(use-package flyspell-correct (use-package flyspell-correct
:if (package-installed-p 'flyspell-correct)
:after flyspell :after flyspell
:bind ( :map flyspell-mode-map :bind ( :map flyspell-mode-map
("C-;" . flyspell-correct-wrapper))) ("C-;" . flyspell-correct-wrapper)))
@ -173,21 +168,24 @@
:defines ibuffer-filter-groups :defines ibuffer-filter-groups
:bind (("C-c b" . ibuffer))) :bind (("C-c b" . ibuffer)))
(use-package avy
:if (package-installed-p 'avy)
:bind (("<remap> <goto-char>" . avy-goto-char)))
(use-package ace-window (use-package ace-window
:if (package-installed-p 'ace-window)
:bind (("<remap> <other-window>" . ace-window)) :bind (("<remap> <other-window>" . ace-window))
:custom :custom
(aw-scope 'frame) (aw-scope 'frame)
(aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))) (aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))
(use-package link-hint (use-package link-hint
:if (package-installed-p 'link-hint)
:bind (("C-c l o" . link-hint-open-link) :bind (("C-c l o" . link-hint-open-link)
("C-c l c" . link-hint-copy-link) ("C-c l c" . link-hint-copy-link)
("C-c l C-o" . link-hint-open-all-link) ("C-c l C-o" . link-hint-open-all-link)
("C-c l C-c" . link-hint-copy-all-link))) ("C-c l C-c" . link-hint-copy-all-link)))
(use-package avy
:bind (("<remap> <goto-char>" . avy-goto-char)))
(use-package comint (use-package comint
:bind ( :map comint-mode-map :bind ( :map comint-mode-map
("<remap> <comint-history-isearch-backward-regexp>" . consult-history))) ("<remap> <comint-history-isearch-backward-regexp>" . consult-history)))
@ -240,6 +238,7 @@
(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)
:functions which-key-mode :functions which-key-mode
:config (which-key-mode +1)) :config (which-key-mode +1))
@ -258,6 +257,7 @@
(pulse-momentary-highlight-one-line (point))) (pulse-momentary-highlight-one-line (point)))
(use-package base16-theme (use-package base16-theme
:if (package-installed-p 'base16-theme)
:demand :demand
:defines (base16-one-light-theme-colors :defines (base16-one-light-theme-colors
my/load-theme-and-configure) my/load-theme-and-configure)
@ -287,6 +287,7 @@
(if (display-graphic-p) (my/load-theme-and-configure))) (if (display-graphic-p) (my/load-theme-and-configure)))
(use-package nerd-icons (use-package nerd-icons
:if (package-installed-p 'nerd-icons)
:functions (nerd-icons-octicon)) :functions (nerd-icons-octicon))
(use-package nerd-icons-dired (use-package nerd-icons-dired
@ -303,12 +304,14 @@
:hook (after-init . (lambda () (nerd-icons-completion-mode +1)))) :hook (after-init . (lambda () (nerd-icons-completion-mode +1))))
(use-package minions (use-package minions
:if (package-installed-p 'minions)
:functions minions-mode :functions minions-mode
:hook (after-init . (lambda () (minions-mode +1))) :hook (after-init . (lambda () (minions-mode +1)))
:custom :custom
(minions-prominent-modes '(envrc-mode flymake-mode))) (minions-prominent-modes '(envrc-mode flymake-mode)))
(use-package ligature (use-package ligature
:if (package-installed-p 'ligature)
:functions (ligature-set-ligatures :functions (ligature-set-ligatures
global-ligature-mode) global-ligature-mode)
:config :config
@ -352,6 +355,7 @@
(display-time-24hr-format t)) (display-time-24hr-format t))
(use-package diff-hl (use-package diff-hl
:if (package-installed-p 'diff-hl)
: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)
@ -523,6 +527,7 @@
"%i" :immediate-finish t)))) "%i" :immediate-finish t))))
(use-package org-roam (use-package org-roam
:if (package-installed-p 'org-roam)
:after org :after org
:defines org-roam-directory :defines org-roam-directory
:functions org-roam-db-autosync-mode :functions org-roam-db-autosync-mode
@ -555,6 +560,7 @@
(org-roam-db-autosync-mode +1)) (org-roam-db-autosync-mode +1))
(use-package org-roam-dailies (use-package org-roam-dailies
:requires org-roam
:custom :custom
(org-roam-dailies-directory "./") (org-roam-dailies-directory "./")
(org-roam-dailies-capture-templates (org-roam-dailies-capture-templates
@ -696,6 +702,7 @@
(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)
:functions vertico-mode :functions vertico-mode
:hook (after-init . (lambda () (vertico-mode +1))) :hook (after-init . (lambda () (vertico-mode +1)))
:custom :custom
@ -704,6 +711,7 @@
(require 'vertico-directory)) (require 'vertico-directory))
(use-package marginalia (use-package marginalia
:if (package-installed-p 'marginalia)
:functions marginalia-mode :functions marginalia-mode
:hook (after-init . (lambda () (marginalia-mode +1))) :hook (after-init . (lambda () (marginalia-mode +1)))
:custom :custom
@ -713,6 +721,7 @@
:config (marginalia-mode +1)) :config (marginalia-mode +1))
(use-package orderless (use-package orderless
:if (package-installed-p 'orderless)
:custom :custom
(completion-styles '(orderless basic)) (completion-styles '(orderless basic))
(completion-category-defaults nil) (completion-category-defaults nil)
@ -725,6 +734,7 @@
:requires nerd-icons) :requires nerd-icons)
(use-package corfu (use-package corfu
:if (package-installed-p 'corfu)
:defines (corfu-map :defines (corfu-map
corfu-mode-map corfu-mode-map
corfu-margin-formatters) corfu-margin-formatters)
@ -777,6 +787,7 @@
:functions corfu-terminal-mode) :functions corfu-terminal-mode)
(use-package cape (use-package cape
:if (package-installed-p 'cape)
:after corfu :after corfu
:functions (cape-emoji :functions (cape-emoji
cape-file cape-file
@ -790,6 +801,7 @@
(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)
:functions (consult-org-heading :functions (consult-org-heading
consult-history) consult-history)
:bind (("<remap> <imenu>" . consult-imenu) :bind (("<remap> <imenu>" . consult-imenu)
@ -809,6 +821,7 @@
:bind (("C-c s s" . consult-eglot-symbols))) :bind (("C-c s s" . consult-eglot-symbols)))
(use-package embark (use-package embark
:if (package-installed-p 'embark)
:functions embark-prefix-help-command :functions embark-prefix-help-command
:bind (("<remap> <describe-bindings>" . embark-bindings) :bind (("<remap> <describe-bindings>" . embark-bindings)
("C-." . embark-act)) ("C-." . embark-act))
@ -820,6 +833,7 @@
:hook (embark-collect-mode . consult-preview-at-point-mode)) :hook (embark-collect-mode . consult-preview-at-point-mode))
(use-package tempel (use-package tempel
:if (package-installed-p 'tempel)
:defines tempel-path :defines tempel-path
:functions (tempel-expand :functions (tempel-expand
tempel-abbrev-mode) tempel-abbrev-mode)
@ -850,9 +864,11 @@
))) )))
(use-package rainbow-delimiters (use-package rainbow-delimiters
:if (package-installed-p 'rainbow-delimiters)
:hook (prog-mode)) :hook (prog-mode))
(use-package envrc (use-package envrc
:if (package-installed-p 'envrc)
: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))
@ -868,6 +884,7 @@
(treesit-font-lock-level 3)) (treesit-font-lock-level 3))
(use-package treesit-auto (use-package treesit-auto
:if (package-installed-p 'treesit-auto)
: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)
@ -882,12 +899,10 @@
(eldoc-echo-area-use-multiline-p 3)) (eldoc-echo-area-use-multiline-p 3))
(use-package eglot (use-package eglot
:demand
:bind ( :map prog-mode-map :bind ( :map prog-mode-map
("C-c c a" . eglot-code-actions) ("C-c c a" . eglot-code-actions)
("C-c c r" . eglot-rename)) ("C-c c r" . eglot-rename))
:hook (((nix-mode lua-mode js-base-mode typescript-ts-base-mode) . eglot-ensure) :hook ((eglot-managed-mode . (lambda () (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t))))
(eglot-managed-mode . (lambda () (add-hook 'flymake-diagnostic-functions 'eglot-flymake-backend nil t))))
:custom :custom
(eglot-menu-string "lsp") (eglot-menu-string "lsp")
(eglot-send-changes-idle-time 1) (eglot-send-changes-idle-time 1)
@ -941,6 +956,7 @@
) )
(use-package apheleia (use-package apheleia
:if (package-installed-p 'apheleia)
: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))
@ -963,23 +979,27 @@
(flymake-show-diagnostics-at-end-of-line nil)) (flymake-show-diagnostics-at-end-of-line nil))
(use-package flymake-popon (use-package flymake-popon
:if (package-installed-p 'flymake-popon)
:functions flymake-popon-mode :functions flymake-popon-mode
:requires flymake :requires flymake
:hook ((flymake-mode . (lambda () (flymake-popon-mode +1))))) :hook ((flymake-mode . (lambda () (flymake-popon-mode +1)))))
(use-package flymake-shellcheck (use-package flymake-shellcheck
:if (executable-find "shellcheck") :if (and (executable-find "shellcheck")
(package-installed-p 'flymake-shellcheck))
:requires flymake :requires flymake
:hook (sh-mode . flymake-shellcheck-load)) :hook (sh-mode . flymake-shellcheck-load))
(use-package flymake-yamllint (use-package flymake-yamllint
:if (executable-find "yamllint") :if (and (executable-find "yamllint")
(package-installed-p 'flymake-yamllint))
:functions flymake-yamllint-setup :functions flymake-yamllint-setup
:requires flymake :requires flymake
:hook (yaml-ts-mode . flymake-yamllint-setup)) :hook (yaml-ts-mode . flymake-yamllint-setup))
(use-package flymake-eslint (use-package flymake-eslint
:if (executable-find "eslint") :if (and (executable-find "eslint")
(package-installed-p 'flymake-eslint))
:functions flymake-eslint-enable :functions flymake-eslint-enable
:requires flymake :requires flymake
:hook ((js-base-mode typescript-ts-base-mode) . flymake-eslint-enable)) :hook ((js-base-mode typescript-ts-base-mode) . flymake-eslint-enable))
@ -1033,12 +1053,14 @@ Calls `project-remember-projects-under' for ~/Projects/"
("\\`\\(?:gitea:\\|gt:\\)\\([^:]+\\)\\'" "git.xenia.me.uk" "gitea.user")))) ("\\`\\(?:gitea:\\|gt:\\)\\([^:]+\\)\\'" "git.xenia.me.uk" "gitea.user"))))
(use-package aggressive-indent (use-package aggressive-indent
:if (package-installed-p 'aggressive-indent)
:hook (elisp-mode :hook (elisp-mode
lisp-mode lisp-mode
lisp-data-mode lisp-data-mode
rust-mode)) rust-mode))
(use-package nix-mode (use-package nix-mode
:if (package-installed-p 'nix-mode)
:mode "\\.nix\\'" :mode "\\.nix\\'"
:functions nix-prettify-global-mode :functions nix-prettify-global-mode
:config :config
@ -1067,6 +1089,7 @@ Calls `project-remember-projects-under' for ~/Projects/"
(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)
:hook python-base-mode) :hook python-base-mode)
(use-package files (use-package files
@ -1104,6 +1127,7 @@ Calls `project-remember-projects-under' for ~/Projects/"
(doc-view-image-width 850)) (doc-view-image-width 850))
(use-package markdown-mode (use-package markdown-mode
:if (package-installed-p 'markdown-mode)
:hook :hook
((markdown-mode . turn-on-auto-fill)) ((markdown-mode . turn-on-auto-fill))
:custom :custom
@ -1117,6 +1141,7 @@ Calls `project-remember-projects-under' for ~/Projects/"
(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)
:after (markdown-mode) :after (markdown-mode)
:hook (markdown-mode . conditionally-turn-on-pandoc)) :hook (markdown-mode . conditionally-turn-on-pandoc))
@ -1138,7 +1163,8 @@ Calls `project-remember-projects-under' for ~/Projects/"
:custom :custom
(bbdb-file (locate-user-emacs-file "bbdb.gpg"))) (bbdb-file (locate-user-emacs-file "bbdb.gpg")))
(load-file (locate-user-emacs-file "modules/my-mu4e.el")) (if (package-installed-p 'mu4e)
(load-file (locate-user-emacs-file "modules/my-mu4e.el")))
(use-package erc (use-package erc
:commands erc-compute-nick :commands erc-compute-nick