dotfiles/emacs.d/init.el

497 lines
13 KiB
EmacsLisp

;; Disable package.el early so it won't start loading packages before init is loaded
(setq package-enable-at-startup nil)
;; No thanks
(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) ; Add come extra space to the left/right sides
(menu-bar-mode -1) ; Disable the menu bar
(setq-default custom-file null-device) ; Write customizations not in this file to the null device (AKA stop littering in my init.el)
(setq confirm-kill-processes nil) ; Stop asking about running processes on exit
;; Visible bell
(setq visible-bell t)
; Font
(set-face-attribute 'default nil :font "Hack" :height 110)
;; 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)
;; 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
;; 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 in prog-mode
(setq-default fill-column 80)
(add-hook 'prog-mode-hook #'display-fill-column-indicator-mode)
; No line numbers in org-mode
(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 ;;;;;;;;;;;;;;
;; Initialize package sources
;(require 'package)
;(setq package-archives '(("melpa" . "https://melpa.org/packages/")
; ("org" . "https://orgmode.org/elpa/")
; ("elpa" . "https://elpa.gnu.org/packages/")))
;(package-initialize)
;(unless package-archive-contents
; (package-refresh-contents))
;; 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)
;;;;;;;;;;;;;;
;; Install use-package
(straight-use-package 'use-package)
;; Make use-package use straight.el
(use-package straight
:custom (straight-use-package-by-default t))
;; Theme
(setq custom-safe-themes t)
;; (use-package everforest
;; :straight (:type git :repo "https://git.sr.ht/~theorytoe/everforest-theme"))
;; (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)
;; Help distinguish work buffers from others like sidebars and terminal
(use-package solaire-mode
:init
(solaire-global-mode t))
;; Icons
(use-package all-the-icons)
;; Modeline
(use-package minions
:hook (doom-modeline-mode . minions-mode)
(simple-modeline-mode . minions-mode))
(use-package doom-modeline
:init (doom-modeline-mode)
:custom
(doom-modeline-height 30)
(doom-modeline-bar-width .75)
(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
(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)))
;; LSP & debugging
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-c l")
:commands (lsp lsp-deferred)
:hook
((c-mode . lsp)
(c++-mode . lsp)
(go-mode . lsp)
(java-mode . lsp)
(js-mode . lsp)
(latex-mode . lsp)
(python-mode . lsp)
(rust-mode . lsp)
(tex-mode . lsp)
(typescript-mode . lsp)
(web-mode . lsp)
(zig-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration))
:config
(setq lsp-prefer-flymake nil)) ;prefer lsp-ui (flycheck) to flymake
; :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
:config
(dap-ui-mode 1)
(dap-tooltip-mode 1)
(eval-when-compile
(require 'cl-lib))
(require 'dap-python)
;(require 'dap-node)
(require 'dap-lldb)
: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)))
(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
("RET" . nil)
("[return]" . nil)
("TAB" . company-complete-selection)
("<tab>" . company-complete-selection)
("C-n" . company-select-next)
("C-p" . company-select-previous)))
;;; Languages/Tools
;; Highlighting/Formatting
(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)
;; C/C++
(setq dap-lldb-debug-program '("/usr/bin/lldb-vscode"))
(setq-default c-default-style "k&r")
(setq-default c-basic-offset 2)
;(use-package ccls
; :hook ((c-mode c++-mode objc-mode cuda-mode) .
; (lambda () (require 'ccls) (lsp))))
;(use-package modern-cpp-font-lock
; :config
; (modern-c++-font-lock-global-mode))
;; Golang
;; (use-package go-mode
;; :config
;; (add-hook 'before-save-hook #'lsp-organize-imports))
;; Java
;(use-package lsp-java)
;; JavaScript/TypeScript, HTML, CSS
;; (setq css-indent-level 2)
;; (setq css-indent-offset 2)
;; (setq js-indent-level 2)
;; (add-to-list 'auto-mode-alist '("\\.mjs\\'" . js-mode))
;; (use-package js2-mode
;; :config
;; (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))
;; (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))
;; LaTeX
;; (use-package lsp-latex)
;; (setq lsp-tex-server 'digestif)
;; Protocol Buffers
;; (use-package protobuf-mode)
;; Python
(setq dap-python-debugger 'debugpy)
(use-package lsp-pyright
:hook (python-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
:init
(setq conda-anaconda-home (expand-file-name "/opt/miniconda3"))
(setq 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)))))
;; 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)
:config
(setq flycheck-python-flake8-executable "flake8"))
;; 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