nixos-config/modules/programs/emacs/dotemacs

225 lines
6.0 KiB
Plaintext

(defconst dd/using-native-comp-p (fboundp 'native-comp-available-p))
(when dd/using-native-comp-p
(setq comp-async-query-on-exit t)
(setq comp-async-jobs-number 8)
(setq comp-async-report-warnings-errors nil)
(setq comp-deferred-compilation t))
(setq redisplay-dont-pause t)
(setq jit-lock-defer-time 0)
(setq fast-but-imprecise-scrolling t)
(setq make-backup-files nil) (setq create-lockfiles nil)
;; A trick for faster startup is to just disable GC for the init phase
;;; See: https://github.com/nilcons/emacs-use-package-fast#a-trick-less-gc-during-startup
(setq gc-cons-threshold 64000000)
(add-hook 'after-init-hook #'(lambda ()
;; restore after startup
(setq gc-cons-threshold 800000)))
(require 'package)
; Visual things
(defvar emacs-font "SourceCodePro:style=Light-7")
(add-to-list 'default-frame-alist `(font . ,emacs-font))
(set-face-attribute 'default t :height 150 :font emacs-font)
(tool-bar-mode -1)
(menu-bar-mode -1)
(toggle-scroll-bar -1)
(setq inhibit-startup-screen t)
(add-to-list 'custom-theme-load-path (expand-file-name "themes" user-emacs-directory))
(load-theme 'weyland-yutani t)
(use-package rainbow-delimiters
:config
(add-hook 'prog-mode-hook
#'rainbow-delimiters-mode))
(use-package hl-todo
:config
(add-hook 'prog-mode-hook
#'hl-todo-mode))
(global-hl-line-mode 1)
(use-package nlinum
:config
(add-hook 'prog-mode-hook
(lambda ()
(nlinum-mode 1))))
(add-hook 'prog-mode-hook
(lambda ()
(show-paren-mode 1)
(setq show-parens-delay 0)))
(use-package ivy
:config
(defvar ivy-use-virtual-buffers t)
(ivy-mode 1))
(setq enable-recursive-minibuffers t)
; This function allows us to exit EVIL states with C-c
; (https://www.emacswiki.org/emacs/Evil#toc16)
(defun escape (prompt)
(cond ((or (evil-insert-state-p) (evil-normal-state-p) (evil-replace-state-p) (evil-visual-state-p)) [escape])
(t (kbd "C-g"))))
(use-package evil
:init
(setq evil-want-keybinding nil)
:config
(define-key key-translation-map (kbd "C-c") 'escape)
(evil-mode 1))
(use-package evil-collection
:after evil
:ensure t
:config
(evil-collection-init))
; Vim-like buffer navigation
(global-set-key (kbd "C-h") 'windmove-left)
(global-set-key (kbd "C-l") 'windmove-right)
(global-set-key (kbd "C-k") 'windmove-up)
(global-set-key (kbd "C-j") 'windmove-down)
(use-package rainbow-delimiters
:config
(add-hook 'prog-mode-hook
#'rainbow-delimiters-mode))
(use-package highlight-parentheses
:config
(highlight-parentheses-mode))
(use-package smartparens
:config
(smartparens-global-mode t))
(use-package undo-tree
:config
(global-undo-tree-mode))
(setq-default indent-tab-mode t)
(setq tab-width 4)
;(use-package perspective
; :bind
; ("C-x C-b" . (lambda (arg)
; (interactive "P")
; (if (fboundp 'persp-bs-show)
; (persp-bs-show arg)
; (bs-show "all"))))
; :config
; (message "Persp-mode")
; (persp-mode))
;; mu4e config
(unless (string= (system-name) "miku")
; I don't need mu4e on my desktop
(load-file (expand-file-name "mu4e.el" user-emacs-directory))
(use-package mu4e
:config
(ptw/init-mu4e)))
;; Org mode stuff
;(use-package org-evil)
(use-package graphviz-dot-mode)
(use-package org
:bind
("C-x P" . (lambda ()
(interactive)
(org-babel-execute-src-block)
(org-redisplay-inline-images)))
:config
(org-babel-do-load-languages
'org-babel-load-languages
'((dot . t)))
(add-hook 'org-mode-hook
(lambda ()
(local-set-key
(kbd "C-x q")
(lambda ()
(interactive)
(org-present-quit)))
(local-set-key
(kbd "C-x p")
(lambda ()
(interactive)
(org-present))))))
(use-package org-present
:config
(add-hook 'org-present-mode-hook
(lambda ()
(org-present-big)
(org-display-inline-images)
(org-present-hide-cursor)
(org-present-read-only)
(org-hide-block-all)
; Disable evil, but bind left (prev) and right (next)
(turn-off-evil-mode)
(local-set-key
(kbd "l")
(lambda ()
(interactive)
(org-present-next)
;; NOTE: Workaround for images not being shown wen
;; the slide has been changed
(org-redisplay-inline-images)))
(local-set-key
(kbd "h")
(lambda ()
(interactive)
(org-present-prev)
;; NOTE: Workaround for images not being shown wen
;; the slide has been changed
(org-redisplay-inline-images)))
;; Disable the modeline. But save it before so that we
;; can restore it
(set (make-local-variable 'saved-mode-line-format) mode-line-format)
(setq mode-line-format nil)))
(add-hook 'org-present-mode-quit-hook
(lambda ()
(org-present-small)
(org-remove-inline-images)
(org-present-show-cursor)
(org-present-read-write)
(org-show-all)
(turn-on-evil-mode)
(local-unset-key (kbd "h"))
(local-unset-key (kbd "l"))
;; Restore the modeline.
;; NOTE: We need to call redraw-display or else the modeline
;; won't be complete
(setq mode-line-format saved-mode-line-format)
(redraw-display))))
;; Development
(use-package tide
:config
(defun setup-tide-mode ()
(interactive)
(tide-setup)
(tide-hl-identifier-mode +1))
(add-hook 'typescript-mode-hook #'setup-tide-mode)
(add-hook 'web-mode-hook
(lambda ()
(when (string-equal "tsx" (file-name-extension buffer-file-name))
(setup-tide-mode))))
(add-to-list 'auto-mode-alist '("\\.tsx\\'" . web-mode)))
(use-package nix-mode)
(use-package go-mode)
(use-package json-mode)
(use-package rust-mode)
(use-package yaml-mode)
(add-hook 'dart-mode-hook 'lsp)
(setq lsp-lens-enable t
lsp-signature-auto-activate nil
company-minimum-prefix-length 1
read-process-output-max (* 1024 1024))
;; Debugging
;(use-package explain-pause-mode
; :straight
; (explain-pause-mode
; :type git
; :host github
; :repo "lastquestion/explain-pause-mode")
; :config
; (explain-pause-mode))