commit ae5643c66d00e13903cc1cd42a0e234d399e26c4 Author: Jeremy Baxter Date: Mon Mar 4 11:47:59 2024 +1300 emacs: init config diff --git a/.emacs.d/init.el b/.emacs.d/init.el new file mode 100644 index 0000000..2bb8106 --- /dev/null +++ b/.emacs.d/init.el @@ -0,0 +1,226 @@ +(setq gc-cons-threshold 100000000) + +(require 'package) +(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) +(package-initialize) +(add-to-list 'load-path "~/.emacs.d/lisp/") + +;; disable menu bar, tool bar, scroll bar and savehist +(menu-bar-mode -1) +(tool-bar-mode -1) +(scroll-bar-mode -1) +(savehist-mode -1) + +;; evil + undo-tree +(package-install 'evil) +(package-install 'undo-tree) +(evil-mode) +(global-undo-tree-mode) +(evil-set-undo-system 'undo-tree) + +;; key binds +(global-set-key (kbd "C-`") 'other-window) +(global-set-key (kbd "C-c c") 'compile) +(global-set-key (kbd "C-c r") 'recompile) + +;; some packages +(package-install 'nerd-icons) +(package-install 'sudo-edit) + +;; modes +(require 'cc-mode) +(package-install 'd-mode) +(package-install 'git-modes) +(package-install 'json-mode) +(package-install 'lua-mode) +(package-install 'markdown-mode) +(package-install 'nix-mode) +(package-install 'rainbow-mode) +(package-install 'yaml-mode) +(package-install 'org-modern) +(package-install 'toc-org) + +;; hooks +(defun indent-common-hook () + ;; set indent width to 4 spaces + (setq tab-width 4 + c-basic-offset 4 + c-syntactic-indentation nil + c-ts-mode-indent-offset 4 + lua-indent-level 4) + ;; turn off smart indent + (electric-indent-mode -1)) +(defun indent-tab-hook () + (indent-common-hook) + (setq indent-tabs-mode t)) +(defun indent-spc-hook () + (indent-common-hook) + (setq indent-tabs-mode nil)) + +(add-hook 'prog-mode-hook 'display-line-numbers-mode) +(add-hook 'text-mode-hook 'hl-line-mode) + +(add-hook 'prog-mode-hook 'indent-tab-hook) +(add-hook 'lisp-mode-hook 'indent-spc-hook) + +;; treesitter modes +(setq major-mode-remap-alist + '((c-mode . c-ts-mode) + (c++-mode . c++-ts-mode) + (sh-mode . bash-ts-mode))) +;; fix to make d-mode highlight primitive types properly +(font-lock-add-keywords 'd-mode + '(("\\<\\(bool\\|byte\\|ubyte\\|char\\|delegate\\|double\\|float\\|function\\|int\\|long\\|short\\|uint\\|ulong\\|ushort\\|cent\\|ucent\\|real\\|ireal\\|idouble\\|ifloat\\|creal\\|cfloat\\|cdouble\\|wchar\\|dchar\\|void\\|string\\|wstring\\|dstring\\|__vector\\|Thread\\)\\>" . 'font-lock-type-face))) + +;; highlight colours +(add-hook 'prog-mode-hook 'rainbow-mode) + +;; modernize org-mode +(add-hook 'org-mode-hook 'org-modern-mode) +;; create a TOC on saving an org document +(add-hook 'org-mode-hook 'toc-org-mode) +;; enable spell checking in org mode +(add-hook 'org-mode-hook '(lambda () (flyspell-mode))) + +;; minibuffer completion +(package-install 'marginalia) +(package-install 'vertico) +(marginalia-mode) +(vertico-mode) + +;; company completion with eglot +(package-install 'company) +(require 'company) +(require 'eglot) +(add-hook 'after-init-hook 'global-company-mode) +(add-hook 'prog-mode-hook 'eglot-ensure) +(add-to-list 'eglot-server-programs `(d-mode . ("~/.local/bin/serve-d"))) +(setq company-begin-commands '(self-insert-command) + company-idle-delay .1 + company-minimum-prefix-length 2 + company-show-numbers t + company-tooltip-align-annotations 't) +(setq read-buffer-completion-ignore-case t + read-file-name-completion-ignore-case t + completion-ignore-case t) + +;; diff information in the gutter +(package-install 'diff-hl) +(global-diff-hl-mode) +(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh) +(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh) + +;; editorconfig +(package-install 'editorconfig) +(editorconfig-mode) + +;; which-key +;; shows available key binds +(package-install 'which-key) +(which-key-mode) +(setq which-key-side-window-location 'bottom + which-key-sort-order 'which-key-key-order-alpha + which-key-sort-uppercase-first nil + which-key-add-column-padding 1 + which-key-max-display-columns nil + which-key-min-display-lines 6 + which-key-side-window-slot -10 + which-key-side-window-max-height 0.25 + which-key-idle-delay 0.8 + which-key-max-description-length 25 + which-key-allow-imprecise-window-fit t + which-key-separator " ") + +;; magit +(package-install 'magit) + +;; fonts +(add-to-list 'default-frame-alist '(font . "Iosevka")) +(set-face-attribute 'default t :height 140) +(set-face-attribute 'fixed-pitch t :family "Iosevka") +(set-face-attribute 'variable-pitch t :family "Roboto") +(set-face-attribute 'fixed-pitch-serif t :family "Roboto Mono" :weight 'regular) +;; make comments italic +(set-face-attribute 'font-lock-comment-face t :slant 'italic) +(set-face-attribute 'font-lock-keyword-face t :slant 'italic) + +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(package-selected-packages + '(forge elcord nix-mode vterm breadcrumb nyan-mode simple-modeline catppuccin-theme which-key treesit-auto editorconfig diff-hl company vertico marginalia toc-org org-modern yaml-mode rainbow-mode markdown-mode lua-mode json-mode git-modes d-mode sudo-edit nerd-icons magit undo-tree evil))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(custom-button ((t (:background "#181825" :foreground "white" :box (:line-width (1 . 1) :color "#11111b" :style flat-button))))) + '(custom-button-mouse ((t (:background "#11111b" :foreground "white")))) + '(custom-button-pressed ((t (:inherit custom-button-mouse :box (:line-width (1 . 1) :color "#11111b"))))) + '(help-key-binding ((t (:inherit fixed-pitch :background "#181825" :foreground "#89b4fa" :box (:line-width (-1 . -1) :color "#11111b"))))) + '(link ((t (:foreground "#89b4fa" :underline t)))) + '(widget-field ((t (:extend t :background "#181825" :box (:line-width (1 . 1) :color "#11111b")))))) + +;; catppuccin theme +(package-install 'catppuccin-theme) +(setq catppuccin-flavor 'mocha) +(load-theme 'catppuccin :no-confirm) + +(package-install 'simple-modeline) +(package-install 'nyan-mode) +(simple-modeline-mode) +(column-number-mode) +;; nyan-mode +(nyan-mode) +(setq nyan-animate-nyancat t) + +;; modeline segments +(setq simple-modeline-segments + ;; left side + (let ((separator (lambda () (format " ")))) + '((simple-modeline-segment-modified + simple-modeline-segment-buffer-name + simple-modeline-segment-position + separator + nyan-create + (lambda () (format " ")) + (lambda () (format "%d" (count-lines (point-min) (point-max))))) + ;; right side + (simple-modeline-segment-vc + separator + simple-modeline-segment-encoding + simple-modeline-segment-eol + separator + simple-modeline-segment-major-mode)))) + +;; breadcrumbs +(package-install 'breadcrumb) +(setq breadcrumb-project-crumb-separator "  " + breadcrumb-imenu-crumb-separator "  ") +(add-hook 'prog-mode-hook '(lambda () + (setq header-line-format '( + " " (:eval (breadcrumb-project-crumbs)) + " : " (:eval (breadcrumb-imenu-crumbs)))))) + +;; vterm, a terminal emulator +(package-install 'vterm) +(add-hook 'vterm-mode-hook (lambda () + (evil-local-mode -1) + (hl-line-mode -1))) + +;; misc + +;; guess the major mode from file name +(setq-default major-mode (lambda () +(unless buffer-file-name (let ((buffer-file-name (buffer-name))) + (set-auto-mode))))) + +;; save files and your position in them +(save-place-mode) +(recentf-mode) + +;; frames/windows resize pixelwise +(setq frame-resize-pixelwise t + window-resize-pixelwise t)