feat(emacs): basic setup
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 1m3s

This commit is contained in:
Price Hiller 2024-07-09 22:59:31 -05:00
parent 12ce2a09e4
commit c6baf97dd9
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB
2 changed files with 445 additions and 7 deletions

View File

@ -3,16 +3,456 @@
#+EMAIL: price@orion-technologies.io
#+OPTIONS: num:nil
* General.el
* Auto Compile
#+begin_src emacs-lisp
;; General for keybindings
(use-package general
(use-package auto-compile
:custom
(load-prefer-newer t)
:defer nil
:config
(auto-compile-on-load-mode)
(auto-compile-on-save-mode))
#+end_src
* Add Additional Package Archives
#+begin_src emacs-lisp
#+end_src
* Core
** Font Settings
#+begin_src emacs-lisp
(set-face-attribute 'default nil :family "Fira Code" :height 130)
#+end_src
** Splash Screen
Remove splash screen and use a *scratch* buffer instead
#+begin_src emacs-lisp
(setq inhibit-startup-message t
inhibit-startup-echo-area-message t)
#+end_src
** Line Numbers
Default to enabling line numbers in all buffers
#+begin_src emacs-lisp
(setq display-line-numbers-type 'relative
column-number-mode t)
(global-display-line-numbers-mode t)
#+end_src
** Improved Tabs/Indentation
#+begin_src emacs-lisp
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
#+end_src
** Improved default visuals
#+begin_src emacs-lisp
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode t)
(setq visible-bell nil)
(global-hl-line-mode t)
(blink-cursor-mode 0)
#+end_src
** Improve yes or no prompt
#+begin_src emacs-lisp
(fset 'yes-or-no-p 'y-or-n-p)
#+end_src
* Appearance / Themeing
** Kanagawa Theme
#+begin_src emacs-lisp
(use-package kanagawa-theme
:ensure t
:demand t)
(elpaca-wait)
:config
(load-theme 'kanagawa t))
#+end_src
* Evil Mode
#+begin_src emacs-lisp
(use-package evil
:defer nil
:custom
(evl-kbd-macro-suppress-motion-error t)
(evil-want-C-u-scroll t)
(evil-want-integration t)
(evil-want-keybinding 'nil)
(which-key-allow-evil-operators t)
(evil-undo-system 'undo-redo)
(evil-want-fine-undo t)
(evil-emacs-state-modes nil)
(evil-insert-state-modes nil)
(evil-motion-state-modes nil)
:config
(evil-mode 1))
#+end_src
* General.el
Used for keybindings
#+begin_src emacs-lisp
(use-package general
:ensure (:wait t)
:after evil
:demand t)
(general-create-definer key-leader
:states 'normal
:keymaps 'override
:prefix "SPC")
;; Make hitting escape work more like vim
(general-def
"<escape>" #'keyboard-escape-quit)
#+end_src
* Which Key
#+begin_src emacs-lisp
(use-package which-key
:defer nil
:config
:general
(key-leader
:states 'normal
"w w" #'which-key-show-top-level)
:custom
(which-key-idle-delay 1)
(which-key-max-description-length 50)
:init
(which-key-mode))
#+end_src
* Auto Revert
#+begin_src emacs-lisp
(global-auto-revert-mode t)
#+end_src
* Treesitter
** Auto setup
#+begin_src emacs-lisp
(use-package treesit-auto
:custom
(treesit-auto-install 'prompt)
:config
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
#+end_src
** Nix Integration
#+begin_src emacs-lisp
(use-package nix-ts-mode
:mode "\\.nix\\'")
#+end_src
* Completion
** Orderless w/ Hotfuzz
#+begin_src emacs-lisp
(use-package hotfuzz
:ensure (:host github
:depth 1
:repo "axelf4/hotfuzz"
:pre-build (("cmake" "-DCMAKE_C_FLAGS='-O3 -march=native'" ".") ("cmake" "--build" "."))))
(use-package orderless
:after hotfuzz
:demand t
:config
(defun +orderless--consult-suffix ()
"Regexp which matches the end of string with Consult tofu support."
(if (and (boundp 'consult--tofu-char) (boundp 'consult--tofu-range))
(format "[%c-%c]*$"
consult--tofu-char
(+ consult--tofu-char consult--tofu-range -1))
"$"))
;; Recognizes the following patterns:
;; * .ext (file extension)
;; * regexp$ (regexp matching at end)
(defun +orderless-consult-dispatch (word _index _total)
(cond
;; Ensure that $ works with Consult commands, which add disambiguation suffixes
((string-suffix-p "$" word)
`(orderless-regexp . ,(concat (substring word 0 -1) (+orderless--consult-suffix))))
;; File extensions
((and (or minibuffer-completing-file-name
(derived-mode-p 'eshell-mode))
(string-match-p "\\`\\.." word))
`(orderless-regexp . ,(concat "\\." (substring word 1) (+orderless--consult-suffix))))))
(defun flex-if-twiddle (pattern _index _total)
(when (string-suffix-p "~" pattern)
`(orderless-flex . ,(substring pattern 0 -1))))
(defun first-initialism (pattern index _total)
(if (= index 0) 'orderless-initialism))
(defun not-if-bang (pattern _index _total)
(cond
((equal "!" pattern)
#'ignore)
((string-prefix-p "!" pattern)
`(orderless-not . ,(substring pattern 1)))))
(setq
completion-ignore-case t
completion-styles '(hotfuzz orderless basic)
completion-category-defaults nil
completion-category-overrides nil
orderless-component-separator #'orderless-escapable-split-on-space
orderless-style-dispatchers (list #'+orderless-consult-dispatch
#'orderless-affix-dispatch)
orderless-matching-styles
'(orderless-prefixes
orderless-initialism
orderless-literal
orderless-regexp)))
#+end_src
** Corfu
#+begin_src emacs-lisp
(use-package corfu
:custom
(corfu-min-width 60)
(corfu-max-width corfu-min-width)
(corfu-cycle t)
(corfu-auto t)
(corfu-auto-prefix 1)
(corfu-on-exact-match nil)
(corfu-preselect 'prompt)
(read-extended-command-predicate #'command-completion-default-include-p)
(completion-cycle-threshold 0)
(corfu-separator ?\s)
(tab-always-indent 'complete)
(corfu-scroll-margin 5)
(corfu-popupinfo-delay 0.1)
:general
(:keymaps 'corfu-map
"TAB" 'corfu-next
"S-TAB" 'corfu-previous
"S-SPC" 'corfu-insert-separator
"<escape>" 'corfu-quit
"<return>" 'corfu-insert
"M-d" 'corfu-show-documentation
"M-d" 'corfu-show-location)
:init
(global-corfu-mode)
(corfu-history-mode)
(corfu-popupinfo-mode))
#+end_src
** Cape
#+begin_src emacs-lisp
(use-package cape
:ensure (:host github
:repo "minad/cape"
:depth 1)
:init
;; Add to the global default value of `completion-at-point-functions' which is
;; used by `completion-at-point'. The order of the functions matters, the
;; first function returning a result wins. Note that the list of buffer-local
;; completion functions takes precedence over the global list.
(add-to-list 'completion-at-point-functions #'cape-dabbrev)
(add-to-list 'completion-at-point-functions #'cape-file)
(add-to-list 'completion-at-point-functions #'cape-elisp-block)
(add-to-list 'completion-at-point-functions #'cape-keyword)
(add-to-list 'completion-at-point-functions #'cape-elisp-symbol)
(add-to-list 'completion-at-point-functions #'cape-elisp-block)
(add-to-list 'completion-at-point-functions #'cape-tex)
(add-to-list 'completion-at-point-functions #'cape-emoji))
#+end_src
** Marginalia
#+begin_src emacs-lisp
(use-package marginalia
; :ensure (:host github
; :depth 1
; :repo "minad/marginalia")
:general
(:keymaps 'minibuffer-local-map
"M-A" #'marginalia-cycle)
:custom
(marginalia-max-relative-age 0)
(marginalia-align #'center)
:init
(marginalia-mode))
#+end_src
** Completion Icons
#+begin_src emacs-lisp
(use-package kind-icon
:ensure t
:after corfu nerd-icons
:custom
(kind-icon-use-icons nil)
(kind-icon-default-face 'corfu-default) ; to compute blended backgrounds correctly
(kind-icon-mapping
`(
(array ,(nerd-icons-codicon "nf-cod-symbol_array") :face font-lock-type-face)
(boolean ,(nerd-icons-codicon "nf-cod-symbol_boolean") :face font-lock-builtin-face)
(class ,(nerd-icons-codicon "nf-cod-symbol_class") :face font-lock-type-face)
(color ,(nerd-icons-codicon "nf-cod-symbol_color") :face success)
(command ,(nerd-icons-codicon "nf-cod-terminal") :face default)
(constant ,(nerd-icons-codicon "nf-cod-symbol_constant") :face font-lock-constant-face)
(constructor ,(nerd-icons-codicon "nf-cod-triangle_right") :face font-lock-function-name-face)
(enummember ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
(enum-member ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
(enum ,(nerd-icons-codicon "nf-cod-symbol_enum") :face font-lock-builtin-face)
(event ,(nerd-icons-codicon "nf-cod-symbol_event") :face font-lock-warning-face)
(field ,(nerd-icons-codicon "nf-cod-symbol_field") :face font-lock-variable-name-face)
(file ,(nerd-icons-codicon "nf-cod-symbol_file") :face font-lock-string-face)
(folder ,(nerd-icons-codicon "nf-cod-folder") :face font-lock-doc-face)
(interface ,(nerd-icons-codicon "nf-cod-symbol_interface") :face font-lock-type-face)
(keyword ,(nerd-icons-codicon "nf-cod-symbol_keyword") :face font-lock-keyword-face)
(macro ,(nerd-icons-codicon "nf-cod-symbol_misc") :face font-lock-keyword-face)
(magic ,(nerd-icons-codicon "nf-cod-wand") :face font-lock-builtin-face)
(method ,(nerd-icons-codicon "nf-cod-symbol_method") :face font-lock-function-name-face)
(function ,(nerd-icons-codicon "nf-cod-symbol_method") :face font-lock-function-name-face)
(module ,(nerd-icons-codicon "nf-cod-file_submodule") :face font-lock-preprocessor-face)
(numeric ,(nerd-icons-codicon "nf-cod-symbol_numeric") :face font-lock-builtin-face)
(operator ,(nerd-icons-codicon "nf-cod-symbol_operator") :face font-lock-comment-delimiter-face)
(param ,(nerd-icons-codicon "nf-cod-symbol_parameter") :face default)
(property ,(nerd-icons-codicon "nf-cod-symbol_property") :face font-lock-variable-name-face)
(reference ,(nerd-icons-codicon "nf-cod-references") :face font-lock-variable-name-face)
(snippet ,(nerd-icons-codicon "nf-cod-symbol_snippet") :face font-lock-string-face)
(string ,(nerd-icons-codicon "nf-cod-symbol_string") :face font-lock-string-face)
(struct ,(nerd-icons-codicon "nf-cod-symbol_structure") :face font-lock-variable-name-face)
(text ,(nerd-icons-codicon "nf-cod-text_size") :face font-lock-doc-face)
(typeparameter ,(nerd-icons-codicon "nf-cod-list_unordered") :face font-lock-type-face)
(type-parameter ,(nerd-icons-codicon "nf-cod-list_unordered") :face font-lock-type-face)
(unit ,(nerd-icons-codicon "nf-cod-symbol_ruler") :face font-lock-constant-face)
(value ,(nerd-icons-codicon "nf-cod-symbol_field") :face font-lock-builtin-face)
(variable ,(nerd-icons-codicon "nf-cod-symbol_variable") :face font-lock-variable-name-face)
(t ,(nerd-icons-codicon "nf-cod-code") :face font-lock-warning-face)))
:config
(add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter))
(use-package nerd-icons-completion
:after marginalia
:config
(nerd-icons-completion-mode)
(add-hook 'marginalia-mode-hook #'nerd-icons-completion-marginalia-setup))
#+end_src
** Vertico
#+begin_src emacs-lisp
(use-package vertico
:general
(:keymaps '(normal insert visual motion)
"M-." #'vertico-repeat) ; Perfectly return to the state of the last Vertico minibuffer usage
(:keymaps 'vertico-map
"C-<return>" #'vertico-insert
"M-s" #'vertico-next-group
"M-a" #'vertico-previous-group
"TAB" #'vertico-next
[tab] #'vertico-next
"S-TAB" #'vertico-previous
[backtab] #'vertico-previous
"<backspace>" #'vertico-directory-delete-char
"C-<backspace>" #'vertico-directory-delete-word
"<return>" #'vertico-directory-enter
"M-j" #'vertico-quick-insert)
:hook (minibuffer-setup . vertico-repeat-save) ; Make sure vertico state is saved for `vertico-repeat'
:custom
(vertico-count 15)
(vertico-resize t)
(vertico-cycle nil)
(enable-recursive-minibuffers t)
(vertico-grid-lookahead 50)
(vertico-buffer-display-action '(display-buffer-reuse-window))
(vertico-multiform-categories
'((file reverse)
(consult-ripgrep buffer)
(consult-location)
(imenu buffer)
(library reverse indexed)
(org-roam-node reverse indexed)
(t reverse)))
(vertico-multiform-commands
'(("flyspell-correct-*" grid reverse)
(org-refile grid reverse indexed)
(consult-yank-pop indexed)
(consult-lsp-diagnostics)
))
:init
(defun crm-indicator (args)
(cons (format "[CRM%s] %s"
(replace-regexp-in-string
"\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
crm-separator)
(car args))
(cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
(setq read-extended-command-predicate
#'command-completion-default-include-p)
(vertico-mode)
(vertico-mouse-mode))
#+end_src
* Modeline
#+begin_src emacs-lisp
(use-package doom-modeline
:custom
(doom-modeline-height 25)
(doom-modeline-bar-width 5)
(doom-modeline-icon t)
(doom-modeline-major-mode-icon t)
(doom-modeline-major-mode-color-icon t)
(doom-modeline-buffer-file-name-style 'truncate-upto-project)
(doom-modeline-buffer-state-icon t)
(doom-modeline-buffer-modification-icon t)
(doom-modeline-minor-modes nil)
(doom-modeline-enable-word-count nil)
(doom-modeline-buffer-encoding t)
(doom-modeline-indent-info nil)
(doom-modeline-checker-simple-format t)
(doom-modeline-vcs-max-length 12)
(doom-modeline-env-version t)
(doom-modeline-irc-stylize 'identity)
(doom-modeline-github-timer nil)
(doom-modeline-gnus-timer nil)
:config
(doom-modeline-mode))
#+end_src
* Org Mode
#+begin_src emacs-lisp
(use-package org
:hook (org-mode . org-indent-mode)
:ensure nil
:defer nil
:general
(key-leader
:states 'normal
"o" '(nil :which-key "Org"))
:custom
(org-agenda-files '("~/Notes" "~/Git/College"))
(org-hide-emphasis-markers t))
(use-package org-modern
:after org
:config
(global-org-modern-mode))
#+end_src

View File

@ -37,11 +37,9 @@
(load "./elpaca-autoloads")))
(add-hook 'after-init-hook #'elpaca-process-queues)
(elpaca `(,@elpaca-order))
(setq package-enable-at-startup nil)
(elpaca elpaca-use-package
(elpaca-use-package-mode)
(setq use-package-always-ensure t))
;; Load in the config via org babel
(package-initialize)
(org-babel-load-file "~/.config/emacs/config.org")