diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-04-06 07:34:05 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-04-06 07:34:05 -0400 |
| commit | d4f779d7d43bef2c655c1b3c44e5d92644989dca (patch) | |
| tree | b893c9da85b9d76414000095f6b476c527a0488b /.emacs.d/lisp | |
| parent | Replace slime with sly (diff) | |
| download | dotfiles-d4f779d7d43bef2c655c1b3c44e5d92644989dca.zip | |
Update emacs config to use project.el
Diffstat (limited to '.emacs.d/lisp')
| -rw-r--r-- | .emacs.d/lisp/et-appearance.el | 56 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-completion.el | 83 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-format.el | 12 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-keys.el | 12 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-lsp.el | 13 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-navigation.el | 39 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-package.el | 38 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-utils.el | 35 | ||||
| -rw-r--r-- | .emacs.d/lisp/et-vc.el | 103 |
9 files changed, 391 insertions, 0 deletions
diff --git a/.emacs.d/lisp/et-appearance.el b/.emacs.d/lisp/et-appearance.el new file mode 100644 index 0000000..7034d9a --- /dev/null +++ b/.emacs.d/lisp/et-appearance.el @@ -0,0 +1,56 @@ +;;; et-appearance --- Configuration for the "Look" of Emacs -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;;; Code: +(require 'et-utils) + +(defvar et-monospace-font "Hack Nerd Font Mono" + "The font used by default and for any monospaced font usage.") +(defvar et-monospace-font-size (if (et-is-desktop-p) 192 160)) +(set-face-attribute 'default nil + :font (symbol-value 'et-monospace-font) + :height (symbol-value 'et-monospace-font-size)) + +;; Start emacs in full screen +;; +;; The t parameter appends to the hook, instead of prepending. +;; This means it'll be run after other hooks that might fiddle +;; with the frame size. +(add-hook 'window-setup-hook 'toggle-frame-maximized t) + +; Remove the menu bar (File Edit Options...) +(menu-bar-mode -1) + +; Remove the tool bar (if using the GUI) +(tool-bar-mode -1) + +; Skip the welcome screen +(setq inhibit-startup-screen t) + +;; Rather than an auditory noise, use a visual +;; flash instead. +(setq visible-bell t) + +;; Default to using line numbers in all modes +;; and turn them off one by one in the particular +;; modes where they don't make as much sense. +(global-display-line-numbers-mode 1) +(dolist (mode '(text-mode-hook + org-mode-hook + term-mode-hook + eshell-mode-hook + shell-mode-hook + special-mode-hook)) + (add-hook mode (lambda () (display-line-numbers-mode 0)))) + +(use-package nord-theme + :config + (load-theme 'nord t)) + +(use-package nerd-icons) +(use-package doom-modeline + :init (doom-modeline-mode 1)) + +(provide 'et-appearance) +;;; et-appearance.el ends here diff --git a/.emacs.d/lisp/et-completion.el b/.emacs.d/lisp/et-completion.el new file mode 100644 index 0000000..e0fc230 --- /dev/null +++ b/.emacs.d/lisp/et-completion.el @@ -0,0 +1,83 @@ +;;; et-completion.el --- Enhance the Emacs completion behavior -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;;; Code: + +;; Add a vertical completion UI +(use-package vertico + :custom + (vertico-cycle t) + :init + (vertico-mode)) + +;; Adjust completion search behavior +(use-package orderless + :ensure t + :custom + (completion-styles '(orderless basic)) + (completion-category-overrides '((file (styles partial-completion)))) + (completion-pcm-leading-wildcard t)) + +;; Persist history over emacs restarts. +;; This allows vertico to sort by history position. +(use-package savehist + :init + (savehist-mode)) + +;; Add documentation alongside the completion items +(use-package marginalia + :init + (marginalia-mode)) + +(use-package corfu + :custom + (corfu-cycle t) ;; Enable cycling for `corfu-next/previous' + ;; (corfu-quit-at-boundary nil) ;; Never quit at completion boundary + ;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match + ;; (corfu-preview-current nil) ;; Disable current candidate preview + ;; (corfu-preselect 'prompt) ;; Preselect the prompt + ;; (corfu-on-exact-match 'insert) ;; Configure handling of exact matches + (corfu-popupinfo-delay '(0.5 . 0.2)) ;; (first-show . subsequent) + (corfu-popupinfo-max-height 15) + (corfu-auto t) + (corfu-auto-delay 0.2) + (corfu-auto-trigger ".") + (corfu-quit-no-match 'separator) + + :init + (global-corfu-mode) + (corfu-history-mode) + (corfu-popupinfo-mode)) + +(use-package dabbrev + ;; Swap M-/ and C-M-/ + :bind (("M-/" . dabbrev-completion) + ("C-M-/" . dabbrev-expand)) + :config + (add-to-list 'dabbrev-ignored-buffer-regexps "\\` ") + (add-to-list 'dabbrev-ignored-buffer-modes 'authinfo-mode) + (add-to-list 'dabbrev-ignored-buffer-modes 'doc-view-mode) + (add-to-list 'dabbrev-ignored-buffer-modes 'pdf-view-mode) + (add-to-list 'dabbrev-ignored-buffer-modes 'tags-table-mode)) + +(use-package emacs + :custom + ;; TAB cycle if there are only few candidates + ;; (completion-cycle-threshold 3) + + ;; Enable indentation+completion using the TAB key. + ;; `completion-at-point' is often bound to M-TAB. + (tab-always-indent 'complete) + + ;; Emacs 30 and newer: Disable Ispell completion function. + ;; Try `cape-dict' as an alternative. + (text-mode-ispell-word-completion nil) + + ;; Hide commands in M-x which do not apply to the current mode. Corfu + ;; commands are hidden, since they are not used via M-x. This setting is + ;; useful beyond Corfu. + (read-extended-command-predicate #'command-completion-default-include-p)) + +(provide 'et-completion) +;;; et-completion.el ends here diff --git a/.emacs.d/lisp/et-format.el b/.emacs.d/lisp/et-format.el new file mode 100644 index 0000000..be4b9ac --- /dev/null +++ b/.emacs.d/lisp/et-format.el @@ -0,0 +1,12 @@ +;;; et-format.el --- Code formatting configuration ;; -*- lexical-binding: t; -*- +;;; Commentary: +;; +;;; Code: + +(use-package flycheck + :init (global-flycheck-mode)) + +(setq-default flycheck-emacs-lisp-load-path 'inherit) + +(provide 'et-format) +;;; et-format.el ends here diff --git a/.emacs.d/lisp/et-keys.el b/.emacs.d/lisp/et-keys.el new file mode 100644 index 0000000..2b5a640 --- /dev/null +++ b/.emacs.d/lisp/et-keys.el @@ -0,0 +1,12 @@ +;;; et-keys.el --- Set misc. custom keybindings -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;;; Code: + +;; Make ESC quit prompts. C-g will also do this, but it's +;; a convienence for my vim-pilled brain. +(global-set-key (kbd "<escape>") 'keyboard-escape-quit) + +(provide 'et-keys) +;;; et-keys.el ends here diff --git a/.emacs.d/lisp/et-lsp.el b/.emacs.d/lisp/et-lsp.el new file mode 100644 index 0000000..8560c46 --- /dev/null +++ b/.emacs.d/lisp/et-lsp.el @@ -0,0 +1,13 @@ +;;; et-lsp.el --- Setup LSP servers for necessary languages -*- lexical-binding: t; -*- +;;; Commentary: +;;; Code: + +(use-package eglot + :defer t + :hook ((python-mode . eglot-ensure) + (go-mode . eglot-ensure)) + :config + (add-to-list 'eglot-server-programs '(python-mode . ("ty" "server")))) + +(provide 'et-lsp) +;;; et-lsp.el ends here diff --git a/.emacs.d/lisp/et-navigation.el b/.emacs.d/lisp/et-navigation.el new file mode 100644 index 0000000..e434ade --- /dev/null +++ b/.emacs.d/lisp/et-navigation.el @@ -0,0 +1,39 @@ +;;; et-navigation.el --- Emacs navigation utiltiies -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;; This module overrides the "scroll up page" and "scroll down page" +;; default Emacs key mappings to only scroll up and down half a page. +;; +;;; Code: + +(global-set-key (kbd "C-v") + 'et-scroll-down-half-page) + +(global-set-key (kbd "M-v") + 'et-scroll-up-half-page) + +(defun et-scroll-down-half-page () + "Scroll down half a page while keeping the cursor centered." + (interactive) + (let ((ln (line-number-at-pos)) + (lmax (line-number-at-pos (point-max)))) + (cond ((= ln 1) (move-to-window-line nil)) + ((= ln lmax) (recenter (window-end))) + (t (progn + (move-to-window-line -1) + (recenter)))))) + +(defun et-scroll-up-half-page () + "Scroll up half a page while keeping the cursor centered." + (interactive) + (let ((ln (line-number-at-pos)) + (lmax (line-number-at-pos (point-max)))) + (cond ((= ln 1) nil) + ((= ln lmax) (move-to-window-line nil)) + (t (progn + (move-to-window-line 0) + (recenter)))))) + +(provide 'et-navigation) +;;; et-navigation.el ends here diff --git a/.emacs.d/lisp/et-package.el b/.emacs.d/lisp/et-package.el new file mode 100644 index 0000000..1a99b12 --- /dev/null +++ b/.emacs.d/lisp/et-package.el @@ -0,0 +1,38 @@ +;;; et-package.el --- Bootstrap Emacs package management and use-package -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;;; Code: + +;; First, we want to setup package.el for installing packages. +;; This is emac's built-in package manager, and we'll use it +;; to install use-package itself. +;; +;; To list the packages and see what is avaiable, we can use +;; M-x list-packages. +(require 'package) + +;; Package archives are where we want to install packages from. +;; It is expected that we setup this variable before we call +;; package-initialize. +(setq package-archives '(("melpa" . "https://melpa.org/packages/") + ("org" . "https://orgmode.org/elpa/") + ("elpa" . "https://elpa.gnu.org/packages/"))) +(package-initialize) + +;; If use package isn't installed on the current system, +;; we want to build the package contents and install use-package. +;; +;; Do note that the package contents can get out of date, and there +;; is no automatic process here for refreshing them. Instead, we'll +;; need to do M-x package-refresh-contents occasionally. +(unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) + +(require 'use-package) +;; Always ensure anything used via use-package is installed. +(setq use-package-always-ensure t) + +(provide 'et-package) +;;; et-package.el ends here diff --git a/.emacs.d/lisp/et-utils.el b/.emacs.d/lisp/et-utils.el new file mode 100644 index 0000000..d14bc17 --- /dev/null +++ b/.emacs.d/lisp/et-utils.el @@ -0,0 +1,35 @@ +;;; et-utils.el --- Utilities for my Emacs configuration -*- lexical-binding: t; -*- +;; +;;; Commentary: +;; +;;; Code: + +(defun et-is-desktop-p () + "Check if the current system is my desktop system." + (string-match-p "desktop" (system-name))) + +(defun et-insert-elisp-template (summary) + "Insert a elisp template into the buffer. + +SUMMARY will be inserted into the header docstring +as the file summary." + (interactive (list (read-string "summary: "))) + (let ((move-to-center-of-code-section (lambda () (forward-line -3))) + (get-current-file-name (lambda () (file-name-sans-extension (file-name-nondirectory buffer-file-name)))) + (get-module-template (lambda (module-name summary) + (format ";;; %s.el --- %s -*- lexical-binding: t; -*- +;;; Commentary: +;;; Code: + + + +(provide '%s) +;;; %s.el ends here" module-name summary module-name module-name)))) + (if (not (buffer-file-name)) + (message "No file visited.") + (progn + (insert (funcall get-module-template (funcall get-current-file-name) summary)) + (funcall move-to-center-of-code-section))))) + +(provide 'et-utils) +;;; et-utils.el ends here diff --git a/.emacs.d/lisp/et-vc.el b/.emacs.d/lisp/et-vc.el new file mode 100644 index 0000000..fc78138 --- /dev/null +++ b/.emacs.d/lisp/et-vc.el @@ -0,0 +1,103 @@ +;;; et-vc.el --- Version control configuration -*- lexical-binding:t -*- +;; +;;; Commentary: +;; +;;; Code: +(require 'vc-git) + +(use-package magit) + +(global-set-key (kbd "C-c gu") + 'et-generate-remote-git-url) + +(defun et-generate-remote-git-url () + "Generate a remote URL for the current buffer file and line number. + +* The remote URL can be HTTPS or SSH. +* The git hosting provider is determined via the git remote `origin` url. +* Only Github and SourceHut are supported as a hosting provider. + +For example, if the point is on line 12 of example.el on head SHA +abc123, and the git remote origin url is set to a github URL, then a +URL such https://github.com/myuser/myrepo/blob/abc123/example.el#L12 +would be added to the kill ring." + (interactive) + + (if (not buffer-file-name) + (message "Not visiting a file.") + (let* ((remote-url (vc-git-repository-url buffer-file-name "origin")) + (head-sha (vc-git-working-revision buffer-file-name)) + (relative-file-path (file-relative-name buffer-file-name + (vc-git-root buffer-file-name))) + (line-num (line-number-at-pos))) + + (if (et--is-supported-provider-p remote-url) + (progn + (kill-new (et--generate-remote-git-url remote-url head-sha relative-file-path line-num)) + (message "Copied remote git URL")) + (message (format "%s is not a supported git hosting provider." remote-url)))))) + +(defun et--is-supported-provider-p (url) + "Check whether URL is a supported git hosting provider for URL generation." + (not (null (et--get-git-hosting-provider url)))) + +(defun et--get-git-hosting-provider (url) + "Get the git hosting provider for the given URL. + +The supported providers are github and sourcehut. If the URL +corresponds to an unsupported provider, null is returned." + (cond + ((string-match-p "github\\.com" url) 'github) + ((string-match-p "git\\.sr\\.ht" url) 'sourcehut))) + +(defun et--generate-remote-git-url (remote-url head-sha relative-file-path line-num) + (let ((provider (et--get-git-hosting-provider remote-url))) + (cond + ((eq 'github provider) + (et--gh-generate-remote-git-url remote-url head-sha relative-file-path line-num)) + ((eq 'sourcehut provider) + (et--sh-generate-remote-git-url remote-url head-sha relative-file-path line-num))))) + +(defun et--gh-generate-remote-git-url (remote-url head-sha relative-file-path line-num) + (format "https://github.com/%s/blob/%s/%s#L%d" + (et--extract-repo-path "https://github.com" remote-url) + head-sha + relative-file-path + line-num)) + +(defun et--sh-generate-remote-git-url (remote-url head-sha relative-file-path line-num) + (format "https://git.sr.ht/%s/tree/%s/item/%s#L%d" + (et--extract-repo-path "https://git.sr.ht" remote-url) + head-sha + relative-file-path + line-num)) + +(defun et--extract-repo-path (base-url remote-url) + "Extract the repository path from the REMOTE-URL. + +BASE-URL is used to determine where the repository part of the +REMOTE-URL starts if the REMOTE-URL is a http URL. + +Example: + (et--extract-repo-path + \"https://github.com\" + \"https://github.com/user/repo\") + => \"user/repo\" + + (et--extract-repo-path + \"https://git.sr.ht\" + \"git@git.sr.ht:~eugenetriguba/repo\") + => \"~eugenetriguba/repo\"" + (if (et--git-ssh-url-p remote-url) + (substring remote-url (+ 1 (string-match ":" remote-url))) + (replace-regexp-in-string + (format "%s/\\(.*?\\)\\(.git\\)?$" base-url) + "\\1" + remote-url))) + +(defun et--git-ssh-url-p (url) + "Check whether URL is a SSH-based Git origin URL." + (string-prefix-p "git@" url)) + +(provide 'et-vc) +;;; et-vc.el ends here |