dotfiles/emacs.d/init.el

441 lines
11 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
(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
(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
(set-face-attribute 'default nil :font "Hack" :height 120)
;; 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)
;; Improved 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 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/raxod502/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 zenburn-theme
; :config
; (load-theme `zenburn t))
(use-package everforest-hard-dark-theme
:straight (everforest-hard-dark-theme :type git :repo "https://git.sr.ht/~theorytoe/everforest-hard-dark-theme")
2022-01-19 16:11:29 -05:00
:config
(load-theme 'everforest-hard-dark))
2021-12-17 23:02:45 -05:00
2022-01-20 11:07:30 -05:00
;; (use-package base16-theme
;; :config
;; (load-theme 'gruvbox-dark-soft t))
2021-12-17 23:02:45 -05:00
2022-01-20 12:16:49 -05:00
;; Help distinguish between work from others like sidebars and terminal
2021-12-17 23:02:45 -05:00
(use-package solaire-mode
:diminish
: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
:diminish
: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
:defer t
: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
:defer t
: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
((c-mode . lsp)
(c++-mode . lsp)
(java-mode . lsp)
2022-03-25 22:09:02 -04:00
(js-mode . lsp)
(latex-mode . lsp)
2021-12-17 23:02:45 -05:00
(python-mode . lsp)
(rust-mode . lsp)
(tex-mode . lsp)
2022-03-25 22:09:02 -04:00
(typescript-mode . lsp)
(web-mode . lsp)
2021-12-17 23:02:45 -05:00
(zig-mode . lsp)
(lsp-mode . lsp-enable-which-key-integration))
: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
:hook ((python-mode . dap-ui-mode)
(python-mode . dap-mode))
2021-12-17 23:02:45 -05:00
:config
2022-02-25 14:54:20 -05:00
;(dap-ui-mode 1)
;(dap-tooltip-mode 1)
(eval-when-compile
(require 'cl-lib))
2022-03-02 14:56:12 -05:00
(require 'dap-python))
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
("RET" . nil)
("[return]" . nil)
("TAB" . company-complete-selection)
("<tab>" . company-complete-selection)
("C-n" . company-select-next)
("C-p" . company-select-previous)))
;;; Languages
(use-package apheleia
:init
(apheleia-global-mode +1))
2021-12-17 23:02:45 -05:00
;; C/C++
2022-03-25 22:09:02 -04:00
2021-12-17 23:02:45 -05:00
(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))
;; 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)
(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))
2022-03-25 22:09:02 -04:00
(setq js2-mode-show-strict-warnings nil)
2022-03-25 23:37:52 -04:00
:hook ('js-mode-hook '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))
(use-package restclient
:init
(use-package company-restclient))
(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 8123)
:hook
(('js2-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 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)))
2021-12-17 23:02:45 -05:00
;; LaTeX
(use-package lsp-latex)
(setq lsp-tex-server 'digestif)
;; 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
: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