 ;; git frontend
 (use-package magit
   :straight t
+  :defer t
   :bind (("C-c o g" . #'magit-status)
          ("<f5>" . #'magit-status)))
 
 ;; automatic formatting of program buffers on save
 (use-package format-all
+  :straight t
   :commands format-all-mode
-  :straight t)
+  :defer t)
+
+;; xref-backend that supports many languages
+(use-package dumb-jump
+  :straight t
+  :defer t)
 
 ;; IDE-like features through language servers
 (use-package lsp-mode
   :straight t
-  :hook
-  ((lsp-mode . t/lsp-onsave))
+  :defer t
   :commands lsp lsp-deferred
   :init
   (setq lsp-headerline-breadcrumb-enable nil)
   (setq lsp-keymap-prefix "C-c c")
+  (setq lsp-clients-clangd-args '("-j=3"
+                                  "--background-index"
+                                  "--clang-tidy"
+                                  "--completion-style=detailed"
+                                  "--header-insertion=never"
+                                  "--header-insertion-decorators=0"))
   (defvar t/lsp-enabled-modes
     '(python-mode c++-mode)
     "List of major modes which LSP should activate on start.")
-  (defun t/lsp-or-format-all ()
+  (defun t/maybe-lsp ()
     "Enable lsp-mode if the current major mode is included in
-t/lsp-enabled-modes. Otherwise, enable format-all-mode."
+t/lsp-enabled-modes. Otherwise, enable format-all-mode and use
+dumb-jump as the xref backend."
     (cond ((member major-mode t/lsp-enabled-modes)
-           (lsp-deferred))
-          ((derived-mode-p 'prog-mode) (format-all-mode t))))
+           (lsp))
+          ((derived-mode-p 'prog-mode)
+           (progn (when (require 'format-all nil t)
+                    (format-all-mode t))
+                  (when (require 'dumb-jump nil t)
+                    (add-hook 'xref-backend-functions #'dumb-jump-xref-activate nil t))))))
   (defun t/lsp-onsave ()
     "Configure LSP to automatically format all code on save in
 lsp-enabled buffers."
     (lsp-enable-which-key-integration)
-    (add-hook 'before-save-hook #'lsp-format-buffer nil 'local)
+    (if (derived-mode-p 'c++-mode)
+        (add-hook 'before-save-hook #'clang-format-buffer nil 'local)
+      (add-hook 'before-save-hook #'lsp-format-buffer nil 'local))
     (add-hook 'before-save-hook #'lsp-organize-imports nil 'local))
-  (add-hook 'prog-mode-hook #'t/lsp-or-format-all))
+  :hook
+  ((prog-mode . t/maybe-lsp)
+   (lsp-mode . t/lsp-onsave)))
+
+;; UI frontend for language server alerts and info
+(use-package lsp-ui
+  :straight t
+  :defer t
+  :after lsp
+  :config
+  (setq lsp-ui-doc-position 'bottom))
 
 ;; python language server
 (use-package lsp-python-ms
   :straight t
+  :defer t
   :init (setq lsp-python-ms-auto-install-server t)
   :hook (python-mode . (lambda ()
-                          (require 'lsp-python-ms)
-                          (lsp-deferred))))
+                         (require 'lsp-python-ms)
+                         (lsp))))
 ;; format python buffers with black
 (use-package blacken
   :straight t
+  :defer t
   :hook (python-mode . blacken-mode))
+
+;; clang-format
+(use-package clang-format
+  :straight t
+  :defer t
+  :commands (clang-format-buffer))
 
 ;; error checking
 (use-package flycheck
   :straight t
+  :defer t
   :hook (prog-mode . flycheck-mode))
 
 ;; highlight changes in fringe
 (use-package diff-hl
   :straight t
+  :defer t
   :config
   (global-diff-hl-mode)
-  (add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
-  (add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh))
+  :hook
+  (magit-pre-refresh . diff-hl-magit-pre-refresh)
+  (magit-post-refresh . diff-hl-magit-post-refresh))
 
 ;; highlight indentation
 (use-package highlight-indent-guides


;;; Initialization

;; disable garbage collection until post-init
(setq gc-cons-threshold-original gc-cons-threshold
      gc-cons-threshold (* 1024 1024 100))

(setq no-littering-etc-directory
        (expand-file-name "etc" user-emacs-directory)
        no-littering-var-directory
        (expand-file-name ".var" user-emacs-directory)
        straight-base-dir no-littering-var-directory)

(defvar bootstrap-version)
(let ((bootstrap-file


;; add latex class for exports
(use-package ox-latex
  :defer t
  :after org
  :config
  (add-to-list 'org-latex-classes
