(setq gc-cons-threshold 100000000) (add-to-list 'load-path "~/.emacs.d/lisp/") (add-to-list 'load-path "~/git/d-ts-mode/") (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) (savehist-mode -1) (global-hl-line-mode) (column-number-mode) ;; undo-tree (package-install 'undo-tree) (global-undo-tree-mode) ;; basic 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) (global-set-key (kbd "C-c k") 'kill-current-buffer) (defun reindent-buffer (start end &optional column) "Reindent the current buffer." (interactive "r\nP") (save-excursion (mark-whole-buffer) (indent-region start end column))) (global-set-key (kbd "C-c C-r") 'reindent-buffer) (defun edit-init-file () "Switch to a buffer visiting your user's init file. One will be created if none exist." (interactive) (find-file user-init-file)) (global-set-key (kbd "C-c e i") 'edit-init-file) ;; variables (setq compilation-scroll-output t ; M-x compile dictionary-server "dict.org" ; M-x dictionary-search fill-column 72 ; M-x auto-fill-mode wdired-allow-to-change-permissions t) ; M-x dired C-x C-q ;; some packages (package-install 'nerd-icons) (package-install 'pdf-tools) ;; modes (require 'cc-mode) (require 'd-ts-mode) (package-install 'git-modes) (package-install 'json-mode) (package-install 'lua-mode) (package-install 'markdown-mode) (package-install 'nix-mode) (package-install 'yaml-mode) ;; hooks (defun indent-common-hook () ;; set indent width to 4 spaces (setq-local tab-width 4 c-basic-offset 4 c-syntactic-indentation nil c-ts-mode-indent-offset 4 lua-indent-level 4)) (defun indent-tab-hook () (indent-common-hook) (setq-local indent-tabs-mode t)) (defun indent-spc-hook () (indent-common-hook) (setq-local 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 'sgml-mode-hook 'indent-spc-hook) (add-hook 'nix-mode-hook #'(lambda () (indent-spc-hook) (setq-local tab-width 2))) (defun lisp-hook () (indent-spc-hook) (keymap-local-set "C-c l" 'common-lisp-hyperspec) (setq-local tab-width 2)) (add-hook 'lisp-mode-hook 'lisp-hook) (add-hook 'lisp-data-mode-hook 'lisp-hook) (add-hook 'mail-mode-hook 'auto-fill-mode) (add-hook 'markdown-mode-hook 'auto-fill-mode) (add-hook 'nroff-mode-hook 'auto-fill-mode) (add-hook 'nroff-mode-hook 'variable-pitch-mode) ;; file extensions (add-to-list 'auto-mode-alist '("\\.yuck\\'" . lisp-mode)) (add-to-list 'auto-mode-alist '("\\.eml\\'" . mail-mode)) (add-to-list 'auto-mode-alist '("\\.scd\\'" . markdown-mode)) (add-to-list 'auto-mode-alist '("\\.3lua\\'" . nroff-mode)) ;; 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\\|Runtime\\|Thread\\)\\>" . 'font-lock-type-face))) ;; highlight colours (package-install 'rainbow-mode) (add-hook 'prog-mode-hook 'rainbow-mode) ;; rainbow parens in lisp-mode (package-install 'rainbow-delimiters) (add-hook 'lisp-mode-hook 'rainbow-delimiters-mode) (add-hook 'lisp-data-mode-hook 'rainbow-delimiters-mode) ;; modernize org-mode (package-install 'org-modern) (add-hook 'org-mode-hook 'org-modern-mode) ;; create a TOC on saving an org document (package-install 'toc-org) (add-hook 'org-mode-hook 'toc-org-mode) ;; enable spell checking in org mode (add-hook 'org-mode-hook #'(lambda () (flyspell-mode))) ;; slime (package-install 'slime) (setq inferior-lisp-program "sbcl") (add-hook 'slime-repl-mode-hook #'(lambda () (keymap-local-set "C-c l" 'slime-hyperspec-lookup))) ;; minibuffer completion (package-install 'marginalia) (package-install 'vertico) (marginalia-mode) (vertico-mode) ;; company completion (package-install 'company) (require 'company) (add-hook 'after-init-hook 'global-company-mode) (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 read-buffer-completion-ignore-case t read-file-name-completion-ignore-case t completion-ignore-case t) ;; eglot (require 'eglot) (add-hook 'c-ts-mode-hook 'eglot-ensure) (add-hook 'c++-ts-mode-hook 'eglot-ensure) (add-to-list 'eglot-server-programs `(d-ts-mode . ("serve-d"))) ;; 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 (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 " ") ;; image-dired (package-install 'image-dired) (global-set-key (kbd "C-c i") 'image-dired) (add-hook 'image-dired-thumbnail-mode-hook #'(lambda () (keymap-local-set "M-RET" 'image-dired-display-this))) ;; magit (package-install 'magit) (global-set-key (kbd "C-c b") 'magit-blame) ;; fonts (let ((font-fixed "Roboto Mono") (font-varpt "Roboto")) (add-to-list 'default-frame-alist '(font . "Roboto Mono")) (set-face-attribute 'default t :height 140) (set-face-attribute 'fixed-pitch t :family font-fixed) (set-face-attribute 'variable-pitch t :family font-varpt) (set-face-attribute 'fixed-pitch-serif t :family font-fixed :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-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"))))) '(info-menu-star ((t nil))) '(info-xref ((t (:inherit link :background "#181825" :foreground "#cdd6f4")))) '(link ((t (:foreground "#89b4fa" :underline t)))) '(widget-field ((t (:extend t :background "#181825" :box (:line-width (1 . 1) :color "#11111b")))))) (custom-set-variables) ;; catppuccin theme (package-install 'catppuccin-theme) (setq catppuccin-flavor 'mocha) (setq treesit-font-lock-level 4) (load-theme 'catppuccin :no-confirm) ;; alpha (add-to-list 'default-frame-alist '(alpha-background . 96)) ;; nyan-mode (package-install 'nyan-mode) (setq nyan-animate-nyancat t) (nyan-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)))))) ;; dashboard (package-install 'dashboard) (defun make-quote () (interactive) (let ((quotes '("At its core is an interpreter for Emacs Lisp." "Only one segfault in the default install, in a heck of a long time!" "Merely an interface to your code." "M-x eglot" "“We don't use the term ‘corelibs,’ and I am not sure what that would mean.”" "50 years and Dired is still the best file manager on the planet"))) (nth (random (length quotes)) quotes))) (setq dashboard-banner-logo-title "Welcome to GNU Emacs, one component of the GNU/Linux operating system." dashboard-startup-banner "~/pix/jemacs-book.png" dashboard-center-content t dashboard-vertically-center-content t dashboard-items '((bookmarks . 8) (recents . 4)) dashboard-footer-messages `(,(make-quote)) initial-buffer-choice (lambda () (get-buffer-create dashboard-buffer-name))) (add-hook 'after-init-hook 'dashboard-insert-startupify-lists) (add-hook 'after-init-hook 'dashboard-initialize) (dashboard-setup-startup-hook) ;; 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) ;; show opening paren context if it's offscreen (setq show-paren-context-when-offscreen 'overlay) ;; frames/windows resize pixelwise (setq frame-resize-pixelwise t window-resize-pixelwise t) (put 'dired-find-alternate-file 'disabled nil) (put 'downcase-region 'disabled nil) (put 'upcase-region 'disabled nil)