Update experimental emacs config

This commit is contained in:
Andrew Scott 2023-08-28 13:02:51 -04:00
parent e2e94bd302
commit 264a5bc37f
Signed by: a
GPG key ID: 7CD5A5977E4931C1
2 changed files with 274 additions and 157 deletions

View file

@ -46,7 +46,7 @@
native-comp-async-report-warnings-errors nil))
;; Raise garbage collection threshold
(setq gc-cons-threshold 100000000
(setq gc-cons-threshold 500000000
gc-cons-percentage 0.1)
;; Don't advertise instructions for frame exit
@ -67,7 +67,7 @@
(set-face-font 'fixed-pitch "Hack-24")
(set-face-font 'variable-pitch "DejaVu Sans-24")
;; Disable some GUI options
;; Some GUI options
(push '(tool-bar-lines . 0) default-frame-alist)
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)
@ -77,15 +77,16 @@
(expand-file-name "emacs/" (or (getenv "XDG_DATA_HOME") "~/.local/share/")))
;; Set cache directory
(setq xdg-cache-home (expand-file-name "emacs/" (or (getenv "XDG_CACHE_HOME") "~/.cache/")))
(unless (file-directory-p xdg-cache-home)
(make-directory xdg-cache-home))
(setq xdg_cache_home
(expand-file-name "emacs/" (or (getenv "XDG_CACHE_HOME") "~/.cache/")))
(unless (file-directory-p xdg_cache_home)
(make-directory xdg_cache_home))
;; Move eln-cache to XDG_CACHE_HOME
(when (fboundp 'startup-redirect-eln-cache)
(if (< emacs-major-version 29)
(push (expand-file-name "eln-cache/" xdg-cache-home) native-comp-eln-load-path)
(startup-redirect-eln-cache (expand-file-name "eln-cache/" xdg-cache-home))))
(push (expand-file-name "eln-cache/" xdg_cache_home) native-comp-eln-load-path)
(startup-redirect-eln-cache (expand-file-name "eln-cache/" xdg_cache_home))))
(provide 'early-init)
;;; early-init.el ends here

View file

@ -32,7 +32,7 @@
;;; Code:
;; Profile emacs startup
(add-hook 'emacs-startup-hook
(add-hook 'elpaca-after-init-hook
(lambda ()
(message "Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
@ -88,43 +88,43 @@
;;; Built-in features
(use-package emacs
:elpaca nil
:bind
(:map global-map
;; Disable suspend-frame shortcut
("C-z" . nil)
;; Escape behaves like C-g
("<escape>" . keyboard-escape-quit)
;; Resizing buffers
("S-C-<left>" . shrink-window-horizontally)
("S-C-<right>" . enlarge-window-horizontally)
("S-C-<down>" . shrink-window)
("S-C-<up>" . enlarge-window))
:init
;;; General Options
;; Discard external customizations
(setq-default custom-file null-device)
;; Don't ask about running processes on exit
(setq confirm-kill-processes nil)
;; Better scrolling
(setq scroll-step 1
scroll-conservatively 1000
scroll-preserve-screen-position t
mouse-wheel-follow-mouse 't
mouse-wheel-follow-mouse t
mouse-wheel-progressive-speed nil
;; 1st #: lines to scroll, 2nd #: while holding shift
mouse-wheel-scroll-amount '(2 ((shift) .1)))
(when (fboundp 'pixel-scroll-precision-mode)
(pixel-scroll-precision-mode t))
;; Cursor
(setq-default cursor-type 'bar
blink-cursor-delay 1.0)
;; Tabs
(setq tab-always-indent 'complete)
(setq-default tab-width 4
indent-tabs-mode nil)
;; Line/Column numbers
;; Column numbers
(setq column-number-mode t)
(dolist (hook '(conf-mode-hook
prog-mode-hook
text-mode-hook))
(add-hook hook #'display-line-numbers-mode))
;; Disable suspend-frame shortcut
(global-set-key (kbd "<C-z>") nil)
;; Escape behaves like C-g
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
;; Prefer UTF-8 character coding
(prefer-coding-system 'utf-8)
@ -132,16 +132,6 @@
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; More reasonable keybinds for resizing windows
(global-set-key (kbd "S-C-<left>") 'shrink-window-horizontally)
(global-set-key (kbd "S-C-<right>") 'enlarge-window-horizontally)
(global-set-key (kbd "S-C-<down>") 'shrink-window)
(global-set-key (kbd "S-C-<up>") 'enlarge-window)
;; Built-in C settings
(setq-default c-basic-offset 2
c-default-style "k&r")
;;; Vertico
;; Add prompt to `completing-read-multiple'
(defun crm-indicator (args)
@ -161,74 +151,107 @@
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode))
(use-package compile
:elpaca nil
:commands (compile recompile)
:custom (compilation-scroll-output t))
(use-package cus-edit
:elpaca nil
:init (setq-default custom-file null-device))
(use-package display-fill-column-indicator
:elpaca nil
:hook ((conf-mode markdown-mode prog-mode) . display-fill-column-indicator-mode)
:hook ((conf-mode
markdown-mode
lsp-mode) . display-fill-column-indicator-mode)
:config (setq-default fill-column 80))
(use-package display-line-numbers
:elpaca nil
:hook ((conf-mode lsp-mode) . display-line-numbers-mode))
(use-package elec-pair
:elpaca nil
:defer 3
:config (electric-pair-mode))
;; Move auto saves to XDG_CACHE_HOME
(use-package files
:elpaca nil
:init
(let ((auto-save-directory (concat xdg-cache-home "auto-save-list/")))
(setq backup-directory-alist `(".*" . ,auto-save-directory)
auto-save-file-name-transforms `(".*" ,auto-save-directory t)))
:config
(setq delete-old-versions t
kept-new-versions 5
kept-old-versions 3
require-final-newline t
version-control t))
(let ((auto_save_directory (concat xdg_cache_home "auto-save-list/")))
(setq backup-directory-alist `((".*" . ,auto_save_directory))
auto-save-file-name-transforms `((".*" ,auto_save_directory t))))
:custom
(backup-by-copying t)
(confirm-kill-processes nil)
(delete-old-versions t)
(kept-new-versions 5)
(kept-old-versions 3)
(require-final-newline t)
(version-control t))
(use-package flyspell
:elpaca nil
:defer 3
:hook
(((git-commit-mode markdown-mode) . flyspell-mode)
(lsp-mode . flyspell-prog-mode)))
(use-package paren
:elpaca nil
:defer 3
:config (show-paren-mode))
(use-package recentf
:elpaca nil
:init (setq recentf-save-file (expand-file-name "recentf" xdg-cache-home))
:init (setq recentf-save-file (concat xdg_cache_home "recentf"))
:config
(setq recentf-auto-cleanup 'never
recentf-max-menu-items 15
recentf-max-saved-items 100)
(recentf-mode))
(recentf-mode)
:custom
(recentf-auto-cleanup 'never)
(recentf-max-menu-items 15)
(recentf-max-saved-items 100))
(use-package savehist
:elpaca nil
:init (setq savehist-file (concat xdg-cache-home "history"))
:defer 3
:init (setq savehist-file (concat xdg_cache_home "history"))
:config
(setq savehist-autosave-interval 60
savehist-additional-variables '(search-ring regexp-search-ring))
(savehist-mode))
(savehist-mode)
:custom
(savehist-autosave-interval 60)
(savehist-additional-variables '(search-ring regexp-search-ring)))
(use-package saveplace
:elpaca nil
:init (setq save-place-file (concat xdg-cache-home "places"))
:defer 1
:init (setq save-place-file (concat xdg_cache_home "places"))
:config (save-place-mode))
(use-package whitespace
:elpaca nil
:init
(dolist (hook '(conf-mode-hook
prog-mode-hook
text-mode-hook))
(add-hook hook #'whitespace-mode))
(add-hook 'before-save-hook #'whitespace-cleanup)
:hook
((conf-mode
prog-mode
text-mode) . whitespace-mode)
:config
(setq whitespace-line-column 100
whitespace-style '(big-indent
face
lines-tail
missing-newline-at-eof
tabs
trailing)))
(add-hook 'before-save-hook #'whitespace-cleanup)
:custom
(whitespace-line-column 100)
(whitespace-style '(big-indent
face
lines-tail
missing-newline-at-eof
tabs
trailing)))
(elpaca-wait)
;;; Packages
;; Benchmark Emacs startup
(use-package esup
:defer t
:config (setq esup-depth 0))
;; Theme
(use-package everforest
:elpaca (everforest
@ -237,6 +260,7 @@
:config
(setq custom-safe-themes t)
(load-theme 'everforest-hard-dark t)
(set-face-attribute 'cursor nil :background "#7fbbb3")
(let ((line (face-attribute 'mode-line :foreground))
(inactive (face-attribute 'mode-line-inactive :background)))
(set-face-attribute 'mode-line nil :overline line)
@ -246,50 +270,57 @@
(set-face-attribute 'mode-line-inactive nil :box nil)
(set-face-attribute 'mode-line-inactive nil :background inactive)))
(elpaca-wait)
;; Mode line
(use-package minions
:defer 1
:config (minions-mode))
(use-package keycast
:defer t
:config
(setq keycast-mode-line-insert-after 'moody-mode-line-buffer-identification))
(use-package moody
:defer 1
:config
(setq x-underline-at-descent-line t)
:custom
(x-underline-at-descent-line t)
(moody-replace-eldoc-minibuffer-message-function)
(moody-replace-mode-line-buffer-identification)
(moody-replace-mode-line-front-space)
(moody-replace-vc-mode))
(use-package minions
:after (moody)
:config (minions-mode))
(use-package keycast
:defer t
:custom
(keycast-mode-line-insert-after 'moody-mode-line-buffer-identification))
;; Show keybind hints
(use-package which-key
:defer 1
:defer 3
:config
(setq which-key-idle-delay 0.3)
(which-key-mode))
(which-key-mode)
:custom
(which-key-idle-delay 0.3))
;; Flyspell corrections
(use-package flyspell-correct
:after (flyspell)
:bind (:map flyspell-mode-map ("C-M-." . flyspell-correct-wrapper)))
;; Better annotations
(use-package marginalia
:defer 1
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle))
:defer 3
:bind (:map minibuffer-local-map ("M-A" . marginalia-cycle))
:config (marginalia-mode))
;; Better undo/redo
(use-package undo-tree
:defer 3
:config
(setq undo-tree-auto-save-history t
undo-tree-history-directory-alist
`((".*" . ,(concat xdg-cache-home "undo-tree/"))))
(global-undo-tree-mode))
:init (setq undo-tree-history-directory-alist
`((".*" . ,(concat xdg_cache_home "undo-tree/"))))
:config (global-undo-tree-mode)
:custom (undo-tree-auto-save-history t))
;; Completion style
(use-package orderless
:defer 1
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion)))))
@ -297,14 +328,14 @@
;; Completion UI
(use-package vertico
:init (vertico-mode)
:config
(setq vertico-cycle t
vertico-count 10
vertico-resize t
vertico-scroll-margin 1
completion-ignore-case t
read-buffer-completion-ignore-case t
read-file-name-completion-ignore-case t))
:custom
(vertico-cycle t)
(vertico-count 10)
(vertico-resize t)
(vertico-scroll-margin 1)
(completion-ignore-case t)
(read-buffer-completion-ignore-case t)
(read-file-name-completion-ignore-case t))
;; Command menu for items around point
(use-package embark
@ -396,29 +427,29 @@
;; Consult-specific Embark actions
(use-package embark-consult
:defer 3
:after (embark consult)
:hook (embark-collect-mode . consult-preview-at-point-mode))
;; In-buffer completion
(use-package corfu
:defer 3
:elpaca (corfu :files (:defaults "extensions/*"))
:init
:bind (:map corfu-map ("M-SPC" . corfu-insert-separator))
:config
(setq corfu-min-width 60
corfu-max-width corfu-min-width
corfu-auto t
corfu-auto-delay 0.3
corfu-cycle t
corfu-popupinfo-delay 0.6
corfu-separator ?\s)
(global-corfu-mode)
(corfu-popupinfo-mode)
:custom
(corfu-min-width 60)
(corfu-max-width corfu-min-width)
(corfu-auto t)
(corfu-auto-delay 0.3)
(corfu-cycle t)
(corfu-popupinfo-delay 0.6)
(corfu-separator ?\s)
:bind (:map corfu-map ("M-SPC" . corfu-insert-separator)))
(corfu-popupinfo-mode))
(use-package kind-icon
:after corfu
:init (setq svg-lib-icons-dir (concat xdg-cache-home "svg-lib/"))
:after (corfu)
:init (setq svg-lib-icons-dir (concat xdg_cache_home "svg-lib/"))
:config
(setq kind-icon-default-face 'corfu-default
kind-icon-blend-background nil)
@ -426,22 +457,17 @@
;; Git
(use-package magit
:init
(setq transient-history-file (concat xdg-cache-home "transient-history"))
:bind ("C-M-;" . magit-status)
:commands (magit-status
magit-get-current-branch)
:custom
(magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1))
:init (setq transient-history-file (concat xdg_cache_home "transient-history"))
:custom (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)
:bind ("C-M-;" . magit-status))
(use-package git-timemachine
:bind ("C-M-'" . git-timemachine))
;; Project Managment
;; Project Management
(use-package projectile
:defer 1
:init
(setq projectile-known-projects-file (concat xdg-cache-home "projectile-bookmarks"))
:init (setq projectile-known-projects-file (concat xdg_cache_home "projectile-bookmarks"))
:bind ("C-c p" . projectile-command-map)
:config
(push "*node_modules" projectile-globally-ignored-directories)
@ -449,7 +475,7 @@
(use-package treemacs
:defer 1
:init (setq treemacs-persist-file (concat xdg-cache-home "treemacs-persist"))
:init (setq treemacs-persist-file (concat xdg_cache_home "treemacs-persist"))
:bind
(:map global-map
("M-0" . treemacs-select-window)
@ -463,24 +489,61 @@
(treemacs-filewatch-mode)
(treemacs-git-commit-diff-mode))
(use-package consult-projectile)
(use-package consult-projectile
:after (consult projectile))
(use-package treemacs-magit)
(use-package treemacs-magit
:after (treemacs magit))
(use-package treemacs-projectile)
(use-package treemacs-projectile
:after (treemacs projectile))
;;; Language support
;; Auto-format
(use-package apheleia
:defer 5
:defer 3
:config (apheleia-global-mode))
(use-package reformatter ; required for zig fmt
:after zig-mode)
(use-package reformatter ; required for zig fmt
:after (zig-mode))
;; Templates
(use-package tempel
:init
;; Completion at point
(defun tempel-setup-capf ()
(setq-local completion-at-point-functions
(cons #'tempel-expand ; or `tempel-complete' w/ `tempel-trigger-prexfix'
completion-at-point-functions)))
;; :custom (tempel-trigger-prefix "<")
:bind
(("M-+" . tempel-complete) ; or `tempel-expand'
("M-*" . tempel-insert))
:hook
((conf-mode
lsp-mode
text-mode) . tempel-setup-capf))
(use-package tempel-collection
:after (tempel))
(use-package yasnippet
:bind
("C-c y s" . yas-insert-snippet)
("C-c y v" . yas-visit-snippet-file)
:config (yas-reload-all)
:hook (lsp-mode . yas-minor-mode))
(use-package yasnippet-snippets
:after (yasnippet))
(use-package consult-yasnippet
:after (yasnippet consult))
;; Visualize color names
(use-package rainbow-mode
:hook ((conf-mode prog-mode) . rainbow-mode))
:commands (rainbow-mode)
:hook ((conf-mode lsp-mode) . rainbow-mode))
;; Syntax parsing/highlighting
(use-package treesit-auto
@ -492,18 +555,23 @@
;; Syntax checking
(use-package flycheck
:hook (lsp-mode . flycheck-mode)
:config (setq flycheck-python-flake8-executable "flake8"))
:config (setq flycheck-python-flake8-executable 'flake8))
(use-package consult-flycheck)
(use-package consult-flycheck
:after (consult flycheck))
;; LSP
(use-package lsp-mode
:commands lsp lsp-deferred
:hook
(((c-mode c++-mode python-mode zig-mode) . lsp)
(((c-ts-mode
c++-ts-mode
go-ts-mode
python-ts-mode
zig-mode) . lsp)
(lsp-mode . lsp-enable-which-key-integration))
:config
(setq lsp-idle-delay 0.6
(setq lsp-session-file (concat xdg_cache_home "lsp-session")
lsp-idle-delay 0.6
lsp-prefer-flymake nil))
(use-package lsp-ui
@ -519,32 +587,36 @@
lsp-ui-peek-enable t))
(use-package consult-lsp
:after (consult lsp-mode)
:bind
(:map lsp-mode-map
([remap xref-find-apropos] . consult-lsp-symbols)))
(use-package lsp-treemacs)
(use-package lsp-treemacs
:after (lsp-mode treemacs))
;; Debugging
(use-package dap-mode
:after lsp-mode
:after (lsp-mode)
:bind
(:map dap-mode-map
("<f5>" . dap-debug)
("<f10>" . dap-next)
("<f11>" . dap-step-in)
("S-<f5>" . dap-disconnect)
("C-S-<f5>" . dap-debug-restart))
("C-S-<f5>" . dap-debug-restart)
("C-c d" . dap-debug-last))
:config
(setq dap-auto-configure-features '(sessions locals tooltip)
dap-lldb-debug-program "/usr/bin/lldb-vscode"
(setq dap-breakpoints-file (concat xdg_cache_home "dap-breakpoints")
dap-utils-extension-path (concat user-emacs-directory "dap-extensions/")
dap-auto-configure-features '(sessions locals tooltip)
dap-lldb-debug-program 'lldb-vscode
dap-python-debugger 'debugpy)
(eval-when-compile
(require 'cl-lib))
(require 'dap-python)
(require 'dap-lldb)
(require 'dap-gdb-lldb)
(dap-gdb-lldb-setup)
;; Templates
(dap-register-debug-template
"Rust :: LLDB Run Configuration"
@ -553,28 +625,72 @@
:name "LLDB::Run"
:gdbpath "rust-lldb")))
(use-package realgud)
(use-package realgud
:defer t)
(use-package realgud-lldb)
(use-package realgud-lldb
:defer t)
;; Go
(use-package go-mode
:hook (go-ts-mode . go-mode)
:config (add-hook 'before-save-hook #'lsp-organize-imports))
;; JavaScript
(use-package js2-mode
:interpreter (("nodejs" . js2-mode) ("node" . js2-mode))
:hook (js-ts-mode . js2-minor-mode)
:config
(setq js-indent-level 2
js2-mode-show-strict-warnings t))
;; Python
(use-package lsp-pyright
:after (python)
:hook (python-ts-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or `lsp-deferred'
(use-package numpydoc
:after (python)
:bind (:map python-mode-map
("C-c C-n" . numpydoc-generate))
:config (setq numpydoc-insert-examples-block nil))
(use-package conda
:after (python)
:init
(setq conda-anaconda-home (expand-file-name "/opt/miniconda3")
conda-env-home-directory (expand-file-name "~/.conda/envs"))
(conda-env-initialize-interactive-shells)
;; (conda-env-autoactivate-mode)
:hook
('find-file-hook . (lambda ()
(when (bound-and-true-p conda-project-env-path)
(conda-env-activate-for-buffer)))))
;; Web templates
(use-package web-mode
:config
(setq web-mode-code-indent-offset 2
web-mode-enable-front-matter-block t
web-mode-markup-indent-offset 2
web-mode-attribute-indent-offset 2)
:mode
(("\\.astro\\'" . web-mode)
("\\.html?\\'" . web-mode)))
;; Zig
(use-package zig-mode
:init
(push '(zig-mode . "zig") lsp-language-id-configuration)
(lsp-register-client
(make-lsp-client
:new-connection (lsp-stdio-connection "/usr/bin/zls")
:major-modes '(zig-mode)
:server-id 'zls))
:hook
(zig-mode . (lambda ()
(setq-local fill-column 100)
(setq-local tab-width 4))))
;;; File format/markup support
(use-package markdown-mode)
(use-package markdown-mode
:commands (markdown-mode))
(use-package toml-mode)
(use-package yaml-pro)
(use-package yaml-pro
:hook (yaml-ts-mode . yaml-pro-ts-mode))
;;; init.el ends here