dotfiles/emacs.d/init.el

488 lines
13 KiB
EmacsLisp
Raw Normal View History

;; Disable package.el early so it won't start loading packages before init is loaded
(setq package-enable-at-startup nil)
2021-12-17 23:02:45 -05:00
;; No thanks
2022-04-08 11:26:11 -04:00
(setq inhibit-startup-message t) ; Disable startup message
(scroll-bar-mode -1) ; Disable visible scrollbar
(tool-bar-mode -1) ; Disable the toolbar
(tooltip-mode -1) ; Disable tooltips
(set-fringe-mode 10) ; Give some breathing room
(menu-bar-mode -1) ; Disable the menu bar
2021-12-17 23:02:45 -05:00
(setq-default custom-file null-device) ; Write customizations not in this file to the null device (AKA stop littering in my init.el)
;; Visible bell
(setq visible-bell t)
; Font
2022-04-13 12:05:49 -04:00
(set-face-attribute 'default nil :font "Hack" :height 110)
2021-12-17 23:02:45 -05:00
;; Make ESC quit prompts
(global-set-key (kbd "<escape>") 'keyboard-escape-quit)
;; paren/bracket pairs
(show-paren-mode t)
(setq-default show-paren-style 'parenthesis)
(electric-pair-mode 1)
;; Profile emacs startup
(add-hook 'emacs-startup-hook
(lambda ()
(message "*** Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done)))
;; Change the user-emacs-directory to keep ~/.emacs.d clean
(setq user-emacs-directory (expand-file-name "~/.cache/emacs/")
url-history-file (expand-file-name "url/history" user-emacs-directory))
;; No annoying Windows errors
(set-default-coding-systems 'utf-8)
;; Disable suspend-frame shortcut
(define-key global-map "\C-z" nil)
;; 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)
2022-04-08 11:26:11 -04:00
;; Improve scrolling
(setq mouse-wheel-scroll-amount '(1 ((shift) . 1))) ; one line at a time
(setq mouse-wheel-progressive-speed nil) ; don't accelerate scrolling
(setq mouse-wheel-follow-mouse 't) ; scroll window under mouse
(setq scroll-step 1) ; keyboard scroll one line at a time
2021-12-17 23:02:45 -05:00
;; Tabs
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq indent-line-function 'insert-tab)
;;Line numbers
(setq column-number-mode t)
(dolist (mode '(text-mode-hook
prog-mode-hook
conf-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 1))))
;; Show vertical line at column 80 to keep code clean in prog-mode
(setq-default fill-column 80)
(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode)
; Override some modes which derive from the above
(dolist (mode '(org-mode-hook))
(add-hook mode (lambda () (display-line-numbers-mode 0))))
;; Install and load straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;;;;;;;;;;;;;; Not needed when using straight.el ;;;;;;;;;;;;;;
2021-12-17 23:02:45 -05:00
;; Initialize package sources
;(require 'package)
2021-12-17 23:02:45 -05:00
;(setq package-archives '(("melpa" . "https://melpa.org/packages/")
; ("org" . "https://orgmode.org/elpa/")
; ("elpa" . "https://elpa.gnu.org/packages/")))
2021-12-17 23:02:45 -05:00
;(package-initialize)
;(unless package-archive-contents
; (package-refresh-contents))
2021-12-17 23:02:45 -05:00
;; Initialize use-package on non-Linux platforms
;(unless (package-installed-p 'use-package)
; (package-install 'use-package))
;(require 'use-package)
;(setq use-package-always-ensure t)
;;;;;;;;;;;;;;
2021-12-17 23:02:45 -05:00
;; Install use-package
(straight-use-package 'use-package)
2021-12-17 23:02:45 -05:00
;; Make use-package use straight.el
(use-package straight
:custom (straight-use-package-by-default t))
2021-12-17 23:02:45 -05:00
;; Theme
2022-01-19 16:11:29 -05:00
(setq custom-safe-themes t)
;; (use-package everforest
;; :straight (:type git :repo "https://git.sr.ht/~theorytoe/everforest-theme")
;; :config
;; (load-theme 'everforest-hard-dark t))
;; (use-package gruvbox-theme
;; :config
;; (load-theme 'gruvbox-dark-soft t))
(add-to-list 'custom-theme-load-path "~/.cache/emacs/custom/everforest-theme")
(load-theme 'everforest-hard-dark t)
2022-04-08 11:26:11 -04:00
;; Help distinguish work buffers from others like sidebars and terminal
2021-12-17 23:02:45 -05:00
(use-package solaire-mode
:init
2022-01-19 16:11:29 -05:00
(solaire-global-mode t))
2021-12-17 23:02:45 -05:00
;; Icons
(use-package all-the-icons)
;; Modeline
2022-01-20 16:09:19 -05:00
2021-12-17 23:02:45 -05:00
(use-package minions
2022-01-20 16:09:19 -05:00
:hook (doom-modeline-mode . minions-mode)
(simple-modeline-mode . minions-mode))
2021-12-17 23:02:45 -05:00
(use-package doom-modeline
:init (doom-modeline-mode)
:custom
(doom-modeline-height 30)
(doom-modeline-bar-width .75)
2021-12-17 23:02:45 -05:00
(doom-modeline-window-width-limit fill-column)
(doom-modeline-lsp t)
(doom-modeline-minor-modes t)
(doom-modeline-persp-name nil)
(doom-modeline-buffer-file-name-style 'truncate-upto-project)
(doom-modeline-major-mode-icon t)
(doom-modeline-major-mode-color-icon t)
(doom-modeline-enable-word-count t)
(doom-modeline-env-version t)
(doom-modeline-env-load-string "..."))
;; Don't remind me about some minor modes
(use-package diminish)
;; Automatically set paths to the new user-emacs-directory
(use-package no-littering)
;; Automatically clean whitespace
(use-package ws-butler
:hook ((text-mode . ws-butler-mode)
(prog-mode . ws-butler-mode)))
;; Overview of keybindings available based on prefix keys
(use-package which-key
:init (which-key-mode)
:config
(setq which-key-idle-delay 0.3))
;; Navigation: Ivy/Counsel/Swiper
(use-package ivy
:init
(ivy-mode 1)
:config
(setq ivy-use-virtual-buffers t)
(setq ivy-wrap t)
(setq ivy-count-format "(%d/%d) ")
(setq enable-recursive-minibuffers t))
(use-package ivy-rich
:after ivy
:hook (counsel-mode . ivy-rich-mode)
:config
(setq ivy-rich-parse-remote-buffer nil))
(use-package counsel
:after ivy
:config
(counsel-mode 1)
(setq ivy-initial-inputs-alist nil))
(use-package swiper
:after ivy
:bind (("C-s" . swiper)))
(use-package treemacs
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t B" . treemacs-bookmark)
("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag)))
(use-package lsp-treemacs
:config
(lsp-treemacs-sync-mode 1))
;; Git
2021-12-17 23:02:45 -05:00
(use-package magit
: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))
;; Project management
(use-package projectile
:init
(projectile-mode +1)
:bind-keymap
(("C-M-p" . projectile-find-file)
("C-c p" . projectile-command-map))
:bind (:map projectile-mode-map
("C-c p" . projectile-command-map)))
2021-12-17 23:02:45 -05:00
;; LSP & debugging
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
:commands (lsp lsp-deferred)
:hook
2022-04-08 11:26:11 -04:00
((c-mode . lsp)
(c++-mode . lsp)
2022-06-28 05:00:40 -04:00
(go-mode . lsp)
2022-04-08 11:26:11 -04:00
(java-mode . lsp)
(js-mode . lsp)
(latex-mode . lsp)
(python-mode . lsp)
(rust-mode . lsp)
(tex-mode . lsp)
2022-03-25 22:09:02 -04:00
(typescript-mode . lsp)
2022-04-08 11:26:11 -04:00
(web-mode . lsp)
(zig-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration))
2021-12-17 23:02:45 -05:00
:config
2022-01-20 16:09:19 -05:00
(setq lsp-prefer-flymake nil)) ;prefer lsp-ui (flycheck) to flymake
2021-12-17 23:02:45 -05:00
; :bind
; (:map lsp-mode-map
; ("TAB" . completion-at-point)))
(use-package lsp-ui
:requires lsp-mode flycheck
:hook (lsp-mode . lsp-ui-mode)
:commands lsp-ui-mode
:config
(setq lsp-ui-doc-enable t)
(setq lsp-ui-doc-use-childframe t)
(setq lsp-ui-doc-position 'bottom-and-right)
(setq lsp-ui-doc-include-signature t)
(setq lsp-ui-sideline-enable t)
(setq lsp-ui-sideline-show-hover nil)
(setq lsp-ui-flycheck-enable t)
(setq lsp-ui-flycheck-list-position 'right)
(setq lsp-ui-flycheck-live-reporting t)
(setq lsp-ui-peek-enable t)
(setq lsp-ui-peek-list-width 60)
(setq lsp-ui-peek-peek-height 25)
(lsp-ui-doc-show))
(use-package dap-mode
:after lsp-mode
:commands dap-debug
2021-12-17 23:02:45 -05:00
:config
2022-04-03 22:24:40 -04:00
(dap-ui-mode 1)
(dap-tooltip-mode 1)
(eval-when-compile
(require 'cl-lib))
(require 'dap-python)
2022-05-16 23:54:19 -04:00
(require 'dap-node)
:bind
(:map dap-mode-map
2022-05-17 11:20:38 -04:00
("<f5>" . dap-debug)
("<f10>" . dap-next)
("<f11>" . dap-step-in)
("S-<f5>" . dap-disconnect)
("C-S-<f5>" . dap-debug-restart)))
2021-12-17 23:02:45 -05:00
(use-package company
:config
(global-company-mode 1)
:custom
(company-idle-delay 0)
(company-minimum-prefix-length 1)
(company-tooltip-align-annotations t)
:bind
(:map company-active-map
2022-05-16 23:54:19 -04:00
("RET" . nil)
2021-12-17 23:02:45 -05:00
("[return]" . nil)
2022-05-16 23:54:19 -04:00
("TAB" . company-complete-selection)
("<tab>" . company-complete-selection)
("C-n" . company-select-next)
("C-p" . company-select-previous)))
2021-12-17 23:02:45 -05:00
;;; Languages/Tools
;; Highlighting/Formatting
2021-12-17 23:02:45 -05:00
(use-package apheleia
:init
(apheleia-global-mode +1))
(use-package tree-sitter
:config
(global-tree-sitter-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode))
(use-package tree-sitter-langs
:after tree-sitter)
2021-12-17 23:02:45 -05:00
;; C/C++
2022-03-25 22:09:02 -04:00
2022-04-08 11:26:11 -04:00
;(setq-default c-default-style "k&r")
;(setq-default c-basic-offset 2)
2021-12-17 23:02:45 -05:00
;(use-package ccls
; :hook ((c-mode c++-mode objc-mode cuda-mode) .
; (lambda () (require 'ccls) (lsp))))
;(use-package modern-cpp-font-lock
; :config
2022-06-28 05:00:40 -04:00
; (modern-c++-font-lock-global-mode))
;; Golang
(use-package go-mode
:config
(add-hook 'before-save-hook #'lsp-organize-imports))
2021-12-17 23:02:45 -05:00
2022-06-30 22:48:51 -04:00
;; Go
(use-package go-mode)
2021-12-17 23:02:45 -05:00
;; Java
;(use-package lsp-java)
;; JavaScript/TypeScript, HTML, CSS
2022-03-25 22:09:02 -04:00
(setq css-indent-level 2)
(setq css-indent-offset 2)
2022-03-25 22:09:02 -04:00
(setq js-indent-level 2)
2022-05-10 19:58:13 -04:00
(add-to-list 'auto-mode-alist '("\\.mjs\\'" . js-mode))
2022-03-25 22:09:02 -04:00
(use-package js2-mode
:config
2022-03-25 23:37:52 -04:00
(add-to-list 'interpreter-mode-alist '("#!/usr/bin/env node" . js2-mode))
;(setq js2-strict-missing-semi-warning t)
(setq js2-mode-show-strict-warnings t)
:hook (js-mode . js2-minor-mode))
2022-03-25 22:09:02 -04:00
(use-package typescript-mode
:config
(setq typescript-indent-level 2)
:mode ("\\.ts\\'" . typescript-mode)
("\\.tsx\\'" . typescript-mode))
(use-package restclient
:init
(use-package company-restclient)
:mode ("\\.http\\'" . restclient-mode))
(use-package rainbow-mode
:hook
((js-mode . rainbow-mode)
(typescript-mode . rainbow-mode)
(web-mode . rainbow-mode)))
;; (use-package skewer-mode
;; :init
;; (setq httpd-port 8080)
;; :hook
;; (('js-mode-hook 'skewer-mode)
;; ('css-mode-hook 'skewer-css-mode)
;; ('html-mode-hook 'skewer-html-mode)))
;; (use-package skewer-reload-stylesheets
;; :hook
;; (('css-mode-hook 'skewer-reload-stylesheets-start-editing)
;; ('scss-mode-hook 'skewer-reload-stylesheets-start-editing)))
;; (use-package simple-httpd)
(use-package web-mode
:config
(setq web-mode-code-indent-offset 2)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-attribute-indent-offset 2)
:mode
(("\\.phtml\\'" . web-mode)
("\\.tpl\\.php\\'" . web-mode)
("\\.jsp\\'" . web-mode)
("\\.as[cp]x\\'" . web-mode)
("\\.erb\\'" . web-mode)
("\\.mustache\\'" . web-mode)
("\\.djhtml\\'" . web-mode)
("\\.jst.ejs\\'" . web-mode)
("\\.html?\\'" . web-mode)))
(use-package jsdoc
:straight (jsdoc :type git :host github :repo "isamert/jsdoc.el")
:bind ("C-c C-n" . jsdoc))
2021-12-17 23:02:45 -05:00
;; LaTeX
(use-package lsp-latex)
(setq lsp-tex-server 'digestif)
;; Protocol Buffers
(use-package protobuf-mode)
2021-12-17 23:02:45 -05:00
;; Python
2022-03-02 14:56:12 -05:00
(setq dap-python-debugger 'debugpy)
2022-02-25 14:54:20 -05:00
2021-12-17 23:02:45 -05:00
(use-package lsp-pyright
:hook (python-mode . (lambda ()
(require 'lsp-pyright)
(lsp)))) ; or lsp-deferred
(use-package numpydoc
2022-04-08 11:26:11 -04:00
:after python
:bind (:map python-mode-map
("C-c C-n" . numpydoc-generate))
:config
(setq numpydoc-insert-examples-block nil))
2021-12-17 23:02:45 -05:00
;; Rust
;(use-package rust-mode)
;; Zig
;(use-package zig-mode
; :custom (zig-format-on-save nil)
; :config
; (add-to-list 'lsp-language-id-configuration '(zig-mode . "zig"))
; (make-lsp-client
; :new-connection (lsp-stdio-connection "/usr/bin/zls")
; :major-modes '(zig-mode)
; :server-id 'zls))
;; Syntax checking
(use-package flycheck
:hook (lsp-mode . flycheck-mode))
;; Templating
(use-package yasnippet
:bind
("C-c y s" . yas-insert-snippet)
("C-c y v" . yas-visit-snippet-file)
:config
(add-to-list 'yas-snippet-dirs "~/.emacs.d/snippets")
(yas-reload-all)
(yas-global-mode))
(use-package yasnippet-snippets)
;;; End init.el