emacs/init.el

275 lines
9 KiB
EmacsLisp
Raw Normal View History

2022-11-25 23:05:07 +00:00
;;;; Appearance
2022-11-28 23:38:20 +00:00
(defun apply-appearance ()
;; Set theme
(load-theme 'my-theme +1)
2023-01-17 03:20:09 +00:00
;; Use JBMono
(set-frame-font "-JB-JetBrainsMonoNL Nerd Font-normal-normal-normal-*-13-*-*-*-m-0-iso10646-1" nil t)
2022-11-28 23:38:20 +00:00
;; Hide GTK scroll bar
(toggle-scroll-bar -1))
(apply-appearance)
(add-hook 'after-make-frame-functions
(lambda (frame)
(with-selected-frame frame
(apply-appearance))))
;; Hide ribbon, menu bar
2022-11-25 23:05:07 +00:00
(menu-bar-mode -1)
(tool-bar-mode -1)
;; Show colum number in status bar
(column-number-mode +1)
;; Show line numbers
(global-display-line-numbers-mode +1)
;; Highlight current line
2022-11-29 08:55:04 +00:00
(global-hl-line-mode +1)
2022-11-25 23:05:07 +00:00
;; Replace yes/no prompts with y/n prompts
(fset #'yes-or-no-p #'y-or-n-p)
;; Fix jumpy scrolling
(setq mouse-wheel-scroll-amount '(3 ((shift) . 1))
mouse-wheel-progressive-speed nil
mouse-wheel-follow-mouse +1
scroll-step 1) ;; C-n C-p scroll step
;; Highlight matching parens faster
(setq show-paren-delay 0)
2023-01-13 21:46:45 +00:00
(setq tab-width 2)
2022-11-28 22:12:01 +00:00
(defun disable-tabs ()
(indent-tabs-mode -1))
(defun enable-tabs ()
2023-01-13 21:46:45 +00:00
(indent-tabs-mode +1))
2022-11-28 22:12:01 +00:00
(add-hook 'prog-mode-hook 'enable-tabs)
(add-hook 'lisp-mode-hook 'disable-tabs)
(add-hook 'emacs-lisp-mode-hook 'disable-tabs)
2023-01-17 03:21:10 +00:00
(let ((savedir (concat (file-name-as-directory (getenv "XDG_DATA_HOME")) "emacs/autosave/")))
(make-directory savedir t)
(setq backup-directory-alist `(("." . ,savedir)))
(setq auto-save-list-file-prefix (concat savedir ".saves-"))
(setq auto-save-file-name-transforms `((".*" ,savedir t)))
(setq tramp-auto-save-directory savedir))
(setq backup-by-copying t
delete-old-versions t
version-control t
kept-new-versions 2
kept-old-versions 2)
2023-01-14 10:26:58 +00:00
;; Packages
(require 'use-package)
2022-11-25 23:05:07 +00:00
2023-01-04 23:31:52 +00:00
;; Evil (Vim Emulation)
(use-package evil
:init
(setq evil-want-C-u-scroll t
evil-mode-beyond-eol t
evil-mode-fine-undo t
evil-default-state 'emacs
evil-undo-system 'undo-redo
evil-want-keybinding nil)
:config
(add-hook 'evil-local-mode-hook (lambda ()
(setq-local interprogram-cut-function nil)
(setq-local interprogram-paste-function nil)))
(evil-set-initial-state 'prog-mode 'normal)
(evil-set-initial-state 'text-mode 'normal)
(evil-mode +1))
(use-package evil-collection
:config
(evil-collection-init 'magit))
2022-11-25 23:05:07 +00:00
;; Avy (jump to char)
2022-11-25 23:22:16 +00:00
(use-package avy
:bind (("C-;" . avy-goto-char)
("C-:" . avy-goto-word-1)
("M-g g" . avy-goto-line)))
2022-11-25 23:05:07 +00:00
;; Magit (git frontend)
(use-package magit)
2022-11-28 22:12:01 +00:00
;; Rainbow-Mode (show hex strings in color)
(use-package rainbow-mode)
2022-11-29 08:55:04 +00:00
2022-12-08 08:30:59 +00:00
;; Vertico (completion helper)
(use-package vertico
:config
(vertico-mode))
;; Editorconfig support
(use-package editorconfig
:config
(editorconfig-mode 1))
2022-12-01 20:54:23 +00:00
;; Remove trailing whitespace
(use-package ws-butler
:config
(add-hook 'prog-mode-hook #'ws-butler-mode))
2022-12-02 00:26:49 +00:00
;; Code folding
2023-01-14 10:26:58 +00:00
(use-package ts-fold)
2022-12-02 00:26:49 +00:00
2022-12-09 22:58:46 +00:00
;; Markdown
(use-package markdown-mode
:init
(setq markdown-fontify-code-blocks-natively t))
;; Treesitter
(use-package tree-sitter
:config
(use-package tree-sitter-langs
:config
(tree-sitter-require 'rust)
2022-12-02 11:47:12 +00:00
(tree-sitter-require 'java)
(tree-sitter-require 'nix))
2022-12-02 00:26:49 +00:00
(add-hook 'tree-sitter-after-on-hook #'ts-fold-mode)
(add-hook 'tree-sitter-after-on-hook #'tree-sitter-hl-mode)
(global-tree-sitter-mode +1))
;; Rust support
(use-package rustic)
2022-12-02 11:47:12 +00:00
;; Nix support
(use-package nix-mode
2023-01-13 21:46:45 +00:00
:mode "\\.nix\\'"
:config
(add-hook 'nix-mode-hook 'disable-tabs))
2022-12-02 11:47:12 +00:00
;; Treesitter based navigation
(use-package evil-textobj-tree-sitter
:config
(let ((define-scope (lambda (key outer inner)
(define-key evil-outer-text-objects-map key outer)
(define-key evil-inner-text-objects-map key inner)))
(define-jumps (lambda (key name)
(let ((key key) (name name))
(define-key evil-normal-state-map (kbd (concat "]" key))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer"))))
(define-key evil-normal-state-map (kbd (concat "[" key))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer") t)))
(define-key evil-normal-state-map (kbd (concat "]" (upcase key)))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer") nil t)))
(define-key evil-normal-state-map (kbd (concat "[" (upcase key)))
`(lambda () (interactive)
(evil-textobj-tree-sitter-goto-textobj (concat ',name ".outer") t t)))))
))
;; Define new scope symbols for use with i and a
(funcall define-scope "c"
(evil-textobj-tree-sitter-get-textobj "class.outer")
(evil-textobj-tree-sitter-get-textobj "class.inner"))
(funcall define-scope "f"
(evil-textobj-tree-sitter-get-textobj "function.outer")
(evil-textobj-tree-sitter-get-textobj "function.inner"))
;; Define jumps with ] and [
(funcall define-jumps "c" "class")
(funcall define-jumps "f" "function")))
2022-12-01 10:40:05 +00:00
;; Highlight operations
(use-package evil-goggles
:init
(setq evil-goggles-duration 0.15)
:config
(evil-goggles-mode +1))
2022-12-01 10:40:05 +00:00
;; Project
(use-package projectile
:config
(define-key prog-mode-map (kbd "C-c p") 'projectile-command-map)
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(projectile-mode +1))
;; File tree (+ related integrations)
(use-package treemacs
:init
(setq treemacs-tag-follow-delay 0.5)
:config
(treemacs-resize-icons 15)
(treemacs-follow-mode +1)
(treemacs-tag-follow-mode +1)
(treemacs-project-follow-mode +1))
(use-package treemacs-evil)
(use-package treemacs-projectile)
(use-package treemacs-magit)
;; Explanations for keybindings
(use-package which-key
:config
(which-key-mode +1))
;; On the fly syntax checking
(use-package flycheck)
;; Completions
(use-package company
:init
(setq company-minimum-prefix-length 1
company-idle-delay 0
company-selection-wrap-around t
company-tooltip-align-annotations t
company-tooltip-flip-when-above t
company-tooltip-margin 0
company-show-quick-access 'left)
:config
(setq company-transformers '(delete-consecutive-dups
company-sort-prefer-same-case-prefix
company-sort-by-backend-importance
company-sort-by-occurrence))
2022-12-02 00:26:49 +00:00
(define-key company-active-map (kbd "<return>") nil)
2022-12-08 08:30:09 +00:00
(define-key company-active-map (kbd "RET") nil)
(define-key company-active-map (kbd "M-`") #'company-complete-selection)
(define-key company-active-map (kbd "M-n") #'company-select-next)
(define-key company-active-map (kbd "M-p") #'company-select-previous)
(define-key company-active-map (kbd "M-j") #'company-select-next)
(define-key company-active-map (kbd "M-k") #'company-select-previous)
(global-company-mode +1))
;; Fuzzy forawrd search in completions
(setq completion-styles '(flex basic))
;; Lsp
(use-package lsp-mode
:init
(setq lsp-headerline-breadcrumb-enable nil
lsp-signature-auto-activate nil
lsp-signature-doc-lines 0)
:config
(add-hook 'lsp-mode-hook #'lsp-enable-which-key-integration)
(add-hook 'evil-insert-state-entry-hook #'lsp-signature-activate)
(add-hook 'evil-insert-state-exit-hook #'lsp-signature-stop))
(use-package lsp-ui
:init
2022-12-28 05:33:10 +00:00
(setq lsp-ui-doc-position 'at-point
lsp-ui-doc-delay 0.5)
:config
(define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions)
(define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references)
(define-key evil-normal-state-map (kbd "SPC l d") #'lsp-ui-peek-find-definitions)
(define-key evil-normal-state-map (kbd "SPC l u") #'lsp-ui-peek-find-references)
(define-key evil-normal-state-map (kbd "SPC l r") #'lsp-rename)
(define-key evil-normal-state-map (kbd "SPC l a") #'lsp-execute-code-action)
(define-key evil-normal-state-map (kbd "SPC l = =") #'lsp-format-buffer)
(define-key evil-normal-state-map (kbd "SPC l = r") #'lsp-format-region)
(define-key evil-normal-state-map (kbd "SPC l s q") #'lsp-workspace-shutdown)
(define-key evil-normal-state-map (kbd "SPC l s r") #'lsp-workspace-restart)
2023-01-04 23:44:28 +00:00
(define-key evil-normal-state-map (kbd "SPC l i") #'lsp-ui-doc-glance)
;; Controls inside references popup
(define-key lsp-ui-peek-mode-map (kbd "j") #'lsp-ui-peek--select-next)
(define-key lsp-ui-peek-mode-map (kbd "k") #'lsp-ui-peek--select-prev)
(define-key lsp-ui-peek-mode-map (kbd "J") #'lsp-ui-peek--select-next-file)
(define-key lsp-ui-peek-mode-map (kbd "K") #'lsp-ui-peek--select-prev-file)
(define-key lsp-ui-peek-mode-map (kbd "o") #'lsp-ui-peek--goto-xref))
2022-12-02 01:17:08 +00:00
(use-package lsp-treemacs)
(setq gc-cons-threshold (* 1024 1024 100)
read-process-output-max (* 1024 1024))