dotfiles/.config/emacs/init.el

215 lines
5.9 KiB
EmacsLisp

(load-file ".config/emacs/init-elpaca.el")
(use-package emacs
:elpaca nil
:bind (("C-z" . nil)
("C-z i" . (lambda () (interactive) (find-file user-init-file))))
:config
(defalias 'yes-or-no-p 'y-or-n-p)
(display-time-mode)
(display-battery-mode)
(put 'dired-find-alternate-file 'disabled nil)
(set-default-file-modes #o750)
(windmove-default-keybindings 'super)
:custom
(column-number-mode t)
(dired-dwim-target 'dired-dwim-target-next)
(display-time-day-and-date t)
(display-time-24hr-format t)
(inhibit-startup-screen t)
(global-auto-revert-mode t)
(global-auto-revert-non-file-buffers t))
(use-package better-defaults
:elpaca (:repo "https://git.sr.ht/~technomancy/better-defaults"))
(use-package treemacs-icons-dired
:hook (dired-mode . treemacs-icons-dired-mode))
(use-package undo-tree
:init (global-undo-tree-mode)
:custom
(undo-tree-history-directory-alist '(("." . "~/.config/emacs/undo-tree"))))
(use-package magit
:bind (("C-x g" . magit-status)
("C-x M-g" . magit-list-repositories))
:custom
(magit-repository-directories
'(("~/" . 0)
("~/Projects/" . 1))))
(use-package nyan-mode
:init
(nyan-mode 1)
:custom
(nyan-animate-nyancat t)
(nyan-wavy-trail t))
(use-package mozc
:bind (("C-c m" . mozc-mode)))
(use-package material-theme
:config
(load-theme 'material t))
(use-package windmove
:elpaca nil
:bind (("s-w" . windmove-up)
("s-a" . windmove-left)
("s-s" . windmove-down)
("s-d" . windmove-right)))
(use-package counsel
:bind (("C-s" . swiper-isearch)
("M-x" . counsel-M-x)
("M-y" . counsel-yank-pop)
("<f1> f" . counsel-describe-function)
("<f1> v" . counsel-describe-variable)
("C-x C-f" . counsel-find-file)
("C-x b" . ivy-switch-buffer)
("C-x d" . counsel-dired)
("C-c u" . counsel-unicode-char)
("C-c v" . ivy-push-view)
("C-c V" . ivy-pop-view)
:map ivy-minibuffer-map
("C-<return>" . ivy-immediate-done))
:config
(setq ivy-re-builders-alist
'((t . ivy--regex-ignore-order)))
:custom
(ivy-mode 1)
(ivy-count-format "(%d/%d) "))
(use-package org
:elpaca nil
:bind (("C-c l" . org-store-link)
("C-c c" . org-capture)
("C-c a" . org-agenda)
("C-c b" . org-switchb)
:map org-mode-map
("M-." . org-open-at-point)
("M-," . org-mark-ring-goto))
:custom
(org-agenda-start-on-weekday 0)
(org-agenda-weekend-days '(5 6))
(org-default-notes-file "~/Documents/notes.org")
(org-agenda-files (list org-default-notes-file))
(org-capture-templates
'(
("i" "Thoughts on Debugging and Research" entry
(file+headline org-default-notes-file "Inquiries")
"** %?\n %U\n*** Failures and possible solutions")
("t" "Task" entry
(file+headline org-default-notes-file "Tasks")
"** TODO %?\n %U")
)))
(use-package org-contrib)
(use-package org-contacts
:after org-contrib)
;; EPUB reader
(use-package nov
:init
(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode)))
(use-package company
:init (global-company-mode))
(use-package apt-mode
:disabled t)
(use-package docker
:bind ("C-c d" . docker))
(use-package iedit)
(use-package wgrep)
(use-package lsp-mode
:init
(setq lsp-keymap-prefix "C-z l")
:custom
(lsp-pylsp-plugins-flake8-enabled nil))
(use-package flycheck
:init (global-flycheck-mode)
:bind (:map flycheck-mode-map
("C-c C-n" . flycheck-next-error)
("C-c C-p" . flycheck-previous-error)
("C-c C-l" . flycheck-list-errors)))
; Requires poetry to be installed
(use-package poetry)
(defun load-python-env ()
"Set up the Python IDE in the current project"
(interactive)
(progn
(poetry-venv-workon)
(lsp)))
(defun symbols-at-point ()
(let* ((lsp--document-symbols-request-async t)
(symbols (lsp--get-document-symbols))
(symbols-hierarchy (lsp--symbols->document-symbols-hierarchy symbols)))
(mapcar (lambda (symb)
(list (gethash "name" symb) (lsp--get-symbol-type symb)))
symbols-hierarchy)))
(defun python-test-at-point ()
(let ((symbols (symbols-at-point)))
(pcase symbols
(`((,class "Class") (,method "Method") . ,_)
(if (equal "test_" (substring method 0 5))
`(,class ,method)
`(,class)))
(`((,class "Class") . ,_) `(,class))
(_ ()))))
(defun python-test-name-at-point ()
(let* ((path (mapcar #'substring-no-properties lsp-headerline--path-up-to-project-segments))
(filename (f-no-ext (f-filename (buffer-file-name)))))
(string-join (append path (list filename) (python-test-at-point)) ".")))
(defun python-run-test-at-point (debug)
(interactive "P")
(let ((python (executable-find "python"))
(test-name (python-test-name-at-point)))
(if debug
(pdb (concat python " -m pdb -m unittest " test-name))
(compile (concat python " -m unittest " test-name)))))
(use-package python
:bind (:map python-mode-map
("C-c C-p" . nil)
("C-c C-l" . nil)
("C-c C-t" . python-run-test-at-point)
("C-M-t" . recompile))
:hook (python-mode . load-python-env))
; Requires the Python package "black"
(use-package blacken
:hook (python-mode . blacken-mode))
; Requires the Python package "isort"
(use-package py-isort
:hook (before-save . (lambda ()
(when (bound-and-true-p blacken-mode)
(py-isort-before-save))))
:config
(setq py-isort-options '("--profile" "black")))
;; Jupyter notebook integration
(use-package ein
:bind (("C-z j" . ein:run)
:map ein:notebook-mode-map
("C-c C-x k" . ein:notebook-switch-kernel))
:config
(require 'ein-notebook)
:custom
(ein:jupyter-default-notebook-directory "~/Projects/notebooks")
(ein:output-area-inlined-images t))
(use-package direnv
:config
(direnv-mode))