diff --git a/.config.d/00-preserve-between-restarts.el b/.config.d/00-preserve-between-restarts.el new file mode 100644 index 0000000..bd1fc7a --- /dev/null +++ b/.config.d/00-preserve-between-restarts.el @@ -0,0 +1,33 @@ +;;; 00-preserve-between-restarts.el --- -*- no-byte-compile: t; lexical-binding: t; -*- + +;;; Description: +;; This file contains some modes that allow the user to preserve their +;; session between restarts, such as recentf, savehist and save-place +;; modes. This file also includes global-auto-revert mode, which +;; automatically updates the contents of a buffer to reflect changes +;; made to the underlying file on disk. + +;;; Code: + +;; Auto-revert in Emacs is a feature that automatically updates the +;; contents of a buffer to reflect changes made to the underlying file +;; on disk. +(add-hook 'after-init-hook #'global-auto-revert-mode) + +;; recentf is an Emacs package that maintains a list of recently +;; accessed files, making it easier to reopen files you have worked on +;; recently. +(add-hook 'after-init-hook #'recentf-mode) + +;; savehist is an Emacs feature that preserves the minibuffer history between +;; sessions. It saves the history of inputs in the minibuffer, such as commands, +;; search strings, and other prompts, to a file. This allows users to retain +;; their minibuffer history across Emacs restarts. +(add-hook 'after-init-hook #'savehist-mode) + +;; save-place-mode enables Emacs to remember the last location within a file +;; upon reopening. This feature is particularly beneficial for resuming work at +;; the precise point where you previously left off. +(add-hook 'after-init-hook #'save-place-mode) + +;;; 00-preserve-between-restarts.el ends here diff --git a/.config.d/05-basic.el b/.config.d/05-basic.el new file mode 100644 index 0000000..893182e --- /dev/null +++ b/.config.d/05-basic.el @@ -0,0 +1,91 @@ +;;; 05-basic.el --- Setup some basics. -*- no-byte-compile: t; lexical-binding: t; -*- + +;; Setup the font +(set-face-attribute 'default nil :height 140 :font "Iosevka Nerd Font" :weight 'normal) + +;; This package provides which-key, which is a minor mode for Emacs +;; that displays the key bindings following your currently entered +;; incomplete command (a prefix) in a popup. +(use-package which-key + :ensure t + :config + (which-key-mode)) + +;; Pixel perfect scrolling +(pixel-scroll-precision-mode) +;; Display time +(display-time-mode) +(show-paren-mode +1) ; Paren match highlighting +;; Winner mode is a global minor mode that records the changes in the +;; window configuration (i.e. how the frames are partitioned into +;; windows) so that the changes can be "undone" using the command +;; ‘winner-undo’. +(winner-mode 1) + +;; Configure Emacs to ask for confirmation before exiting +(setq confirm-kill-emacs 'y-or-n-p) + +;; This package provides a complete git integration +(use-package magit + :ensure t + :defer t + :commands (magit)) + +(use-package reverse-im + :ensure t + :defer nil) + +(setq reverse-im-char-fold t) ; use lax matching +(setq reverse-im-read-char-advice-function #'reverse-im-read-char-include) +(setq reverse-im-input-methods '("russian-computer")) ; translate these methods + +(reverse-im-mode t) + +(electric-indent-mode) +(electric-pair-mode) + +(use-package modus-themes + :ensure t + :defer nil + :config + (load-theme 'modus-operandi-tinted t)) + +(use-package hbdh + :straight (hbdh :type git :host github :repo "zzhjerry/hbdh-mode") + :config (hbdh-mode)) + +(defun my/hbdh-highlight-line () + "Activate hbdh, dim text outside of current line" + (interactive) + (let ((point-beginning (line-beginning-position)) + (point-end (line-end-position))) + ;; note that those are internal functions + ;; probably should use hbdh activation commands instead of this + (hbdh--activate-overlay point-beginning point-end) + (hbdh--rewrite-region-face))) + +(setq hbdh-mode-map (make-sparse-keymap)) +(define-key hbdh-mode-map "a" 'hbdh-activate-on-region) +(define-key hbdh-mode-map "d" 'hbdh-deactivate) +(define-key hbdh-mode-map "l" 'my/hbdh-highlight-line) + +(global-set-key "\C-ch" hbdh-mode-map) + +;; A must have for any NixOS user +(use-package direnv + :ensure t + :defer nil + :config (direnv-mode)) + +;; RSS reader +(use-package elfeed + :ensure t + :defer t + :commands (elfeed) + :init + (setq elfeed-feeds + '("https://sachachua.com/blog/category/emacs-news/feed" + "https://planet.emacslife.com/atom.xml")) + :bind (("C-c f" . elfeed))) + +;;; 05-basic.el ends here diff --git a/.config.d/07-org.el b/.config.d/07-org.el new file mode 100644 index 0000000..f14fa3c --- /dev/null +++ b/.config.d/07-org.el @@ -0,0 +1,37 @@ +;;; 07-org.el --- Setup org-mode. -*- no-byte-compile: t; lexical-binding: t; -*- + +(use-package org + :ensure nil + :defer t + :commands (org-mode)) +(use-package org-roam + :ensure t + :defer t + :commands (org-roam-node-insert + org-roam-node-find + org-roam-capture)) + +(add-hook 'org-mode-hook 'auto-fill-mode) +(setq org-cite-global-bibliography + '("/home/dizzar/data2/Notes/references/bibliography.bib")) + +(setq org-roam-directory (file-truename "~/data2/Notes")) +(org-roam-db-autosync-mode) + +(setq global-roam-map (make-sparse-keymap "Roam Keys")) +(global-set-key "\C-cr" global-roam-map) +(define-key global-roam-map "i" 'org-roam-node-insert) +(define-key global-roam-map "f" 'org-roam-node-find) +(define-key global-roam-map "c" 'org-roam-capture) + +(setq global-org-map (make-sparse-keymap "Org Keys")) +(global-set-key "\C-co" global-org-map) +(define-key global-org-map "c" 'org-capture) +(define-key global-org-map "\C-c" 'org-capture) + +(setq org-capture-templates + ;; other capture templates + `(("s" "Slipbox" entry (file "~/data2/Notes/inbox.org") + "* %?\n"))) + +;;; 07-org.el ends here diff --git a/.config.d/10-completion.el b/.config.d/10-completion.el new file mode 100644 index 0000000..d01bda4 --- /dev/null +++ b/.config.d/10-completion.el @@ -0,0 +1,219 @@ +;;; 10-completion.el --- Setup completion. -*- no-byte-compile: t; lexical-binding: t; -*- + +;;; Description: +;; This file contains code setting up all the completion packages, +;; such as corfu, vertico, marginalia, orderless, etc. + +;;; Code: + +;; COmpletion in Region FUnction. Corfu enhances in-buffer completion +;; with a small completion popup. Corfu is the minimalistic in-buffer +;; completion counterpart of the Vertico minibuffer UI. +(use-package corfu + :ensure t + :defer nil + :commands (corfu-mode global-corfu-mode) + + :hook ((prog-mode . corfu-mode) + (shell-mode . corfu-mode) + (eshell-mode . corfu-mode)) + + :custom + ;; Hide commands in M-x which do not apply to the current mode. + (read-extended-command-predicate #'command-completion-default-include-p) + ;; Disable Ispell completion function. As an alternative try `cape-dict'. + (text-mode-ispell-word-completion nil) + (tab-always-indent 'complete) + + :init + (setq corfu-auto t) + (setq tab-always-indent 'complete) + (setq corfu-preview-current 'insert) + (setq corfu-echo-documentation nil) + (setq corfu-popupinfo-delay '(1.0 . 0.5)) + + ;; Enable Corfu + :config + (global-corfu-mode t) + (corfu-popupinfo-mode t)) + + +;; Cape provides Completion At Point Extensions which can be used in +;; combination with Corfu, Company or the default completion UI. The +;; completion backends used by completion-at-point are so called +;; completion-at-point-functions (Capfs). +(use-package cape + :ensure t + :defer t + :commands (cape-dabbrev cape-file cape-elisp-block) + :bind ("C-c p" . cape-prefix-map) + :init + ;; Add to the global default value of `completion-at-point-functions' which is + ;; used by `completion-at-point'. + (add-hook 'completion-at-point-functions #'cape-dabbrev) + (add-hook 'completion-at-point-functions #'cape-file) + (add-hook 'completion-at-point-functions #'cape-elisp-block)) + +;; VERTical Interactive COmpletion. Vertico provides a performant and +;; minimalistic vertical completion UI based on the default completion +;; system. +(use-package vertico + ;; (Note: It is recommended to also enable the savehist package.) + :ensure t + :defer t + :commands vertico-mode + :hook (after-init . vertico-mode)) + +;; This package provides an orderless completion style that divides +;; the pattern into space-separated components, and matches candidates +;; that match all of the components in any order. +(use-package orderless + ;; Vertico leverages Orderless' flexible matching capabilities, allowing users + ;; to input multiple patterns separated by spaces, which Orderless then + ;; matches in any order against the candidates. + :ensure t + :custom + (completion-styles '(orderless basic)) + (completion-category-defaults nil) + (completion-category-overrides '((file (styles partial-completion))))) + +;; This package provides marginalia-mode which adds marginalia to the +;; minibuffer completions. Marginalia are marks or annotations placed +;; at the margin of the page of a book or in this case helpful +;; colorful annotations placed at the margin of the minibuffer for +;; your completion candidates. +(use-package marginalia + ;; Marginalia allows Embark to offer you preconfigured actions in more contexts. + ;; In addition to that, Marginalia also enhances Vertico by adding rich + ;; annotations to the completion candidates displayed in Vertico's interface. + :ensure t + :defer t + :commands (marginalia-mode marginalia-cycle) + :hook (after-init . marginalia-mode) + :init + (define-key minibuffer-local-map "\M-A" 'marginalia-cycle)) + +;; Emacs Mini-Buffer Actions Rooted in Keymaps. Embark makes it easy +;; to choose a command to run based on what is near point, both during +;; a minibuffer completion session (in a way familiar to Helm or +;; Counsel users) and in normal buffers. +(use-package embark + ;; Embark is an Emacs package that acts like a context menu, allowing + ;; users to perform context-sensitive actions on selected items + ;; directly from the completion interface. + :ensure t + :defer t + :commands (embark-act + embark-dwim + embark-export + embark-collect + embark-bindings + embark-prefix-help-command) + :bind + (("C-." . embark-act) ;; pick some comfortable binding + ("C-;" . embark-dwim) ;; good alternative: M-. + ("C-h B" . embark-bindings)) ;; alternative for `describe-bindings' + + :init + (setq prefix-help-command #'embark-prefix-help-command) + + :config + ;; Hide the mode line of the Embark live/completions buffers + (add-to-list 'display-buffer-alist + '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" + nil + (window-parameters (mode-line-format . none))))) + +;; This package provides some integrations between the emabrk and +;; consult packages. +(use-package embark-consult + :ensure t + :hook + (embark-collect-mode . consult-preview-at-point-mode)) + +;; Consulting completing-read. Consult provides search and navigation +;; commands based on the Emacs completion function +;; completing-read. Completion allows you to quickly select an item +;; from a list of candidates. +(use-package consult + :ensure t + :bind (;; C-c bindings in `mode-specific-map' + ("C-c M-x" . consult-mode-command) + ("C-c C-h" . consult-history) + ("C-c k" . consult-kmacro) + ("C-c m" . consult-man) + ("C-c i" . consult-info) + ([remap Info-search] . consult-info) + ;; C-x bindings in `ctl-x-map' + ("C-x M-:" . consult-complex-command) + ("C-x b" . consult-buffer) + ("C-x 4 b" . consult-buffer-other-window) + ("C-x 5 b" . consult-buffer-other-frame) + ("C-x t b" . consult-buffer-other-tab) + ("C-x r b" . consult-bookmark) + ("C-x p b" . consult-project-buffer) + ;; Custom M-# bindings for fast register access + ("M-#" . consult-register-load) + ("M-'" . consult-register-store) + ("C-M-#" . consult-register) + ;; Other custom bindings + ("M-y" . consult-yank-pop) + ;; M-g bindings in `goto-map' + ("M-g e" . consult-compile-error) + ("M-g f" . consult-flymake) + ("M-g g" . consult-goto-line) + ("M-g M-g" . consult-goto-line) + ("M-g o" . consult-outline) + ("M-g m" . consult-mark) + ("M-g k" . consult-global-mark) + ("M-g i" . consult-imenu) + ("M-g I" . consult-imenu-multi) + ;; M-s bindings in `search-map' + ("M-s d" . consult-find) + ("M-s c" . consult-locate) + ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s k" . consult-keep-lines) + ("M-s u" . consult-focus-lines) + ;; Isearch integration + ("M-s e" . consult-isearch-history) + :map isearch-mode-map + ("M-e" . consult-isearch-history) + ("M-s e" . consult-isearch-history) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ;; Minibuffer history + :map minibuffer-local-map + ("M-s" . consult-history) + ("M-r" . consult-history)) + + ;; Enable automatic preview at point in the *Completions* buffer. + :hook (completion-list-mode . consult-preview-at-point-mode) + + :init + ;; Optionally configure the register formatting. This improves the register + (setq register-preview-delay 0.5 + register-preview-function #'consult-register-format) + + ;; Optionally tweak the register preview window. + (advice-add #'register-preview :override #'consult-register-window) + + ;; Use Consult to select xref locations with preview + (setq xref-show-xrefs-function #'consult-xref + xref-show-definitions-function #'consult-xref) + + :config + (consult-customize + consult-theme :preview-key '(:debounce 0.2 any) + consult-ripgrep consult-git-grep consult-grep + consult-bookmark consult-recent-file consult-xref + consult--source-bookmark consult--source-file-register + consult--source-recent-file consult--source-project-recent-file + ;; :preview-key "M-." + :preview-key '(:debounce 0.4 any)) + (setq consult-narrow-key "<")) + +;;; 10-completion.el ends here diff --git a/.config.d/15-lsp.el b/.config.d/15-lsp.el new file mode 100644 index 0000000..c8072f1 --- /dev/null +++ b/.config.d/15-lsp.el @@ -0,0 +1,69 @@ +;;; 15-lsp.el --- Setup LSP -*- no-byte-compile: t; lexical-binding: t; -*- + +;;; Description: +;; Despite the name, this file not only sets up LSP integration, but +;; also native emacs modes for various programming lanuguages, such as +;; Prolog, that do not use LSP. + +;;; Code: + +;; Eglot is the built-in LSP client. +(use-package eglot + :ensure nil + :defer t + :commands (eglot + eglot-rename + eglot-ensure + eglot-rename + eglot-format-buffer) + + :custom + (eglot-report-progress nil) ; Prevent minibuffer spam + + :config + (add-to-list 'eglot-server-programs '((rust-mode) . ("rust-analyzer"))) + ;; Optimizations + (fset #'jsonrpc--log-event #'ignore) + (setq jsonrpc-event-hook nil)) + +;; This package provides syntax highlighting and some utilities for +;; working with rust code. +(use-package rust-mode + :ensure t + :defer t + :commands (rust-mode)) + +;; This package provides integration with Prolog (SWI). +(use-package sweeprolog + :straight (sweeprolog :type git + :host nil + :repo "https://git.sr.ht/~eshel/sweep" + :branch "main" + :files ("*.el" "sweep.pl" "sweep.texi")) ; Custom recipe because + ; the normal one did not + ; build properly. + :ensure t + :defer t + :commands (sweeprolog-mode + sweeprolog-top-level) + :init + (setq sweeprolog-swipl-path "swipl") + (add-to-list 'auto-mode-alist '("\\.plt?\\'" . sweeprolog-mode))) + +(add-hook 'rust-mode-hook #'eglot) + +;; Nix language +(use-package nix-mode + :ensure t + :defer t + :commands (nix-mode)) + +;; Common Lisp +(use-package sly + :ensure t + :defer t + :commands (sly) + :init + (setq inferior-lisp-program "sbcl")) + +;;; 15-lsp.el end here