diff options
| -rw-r--r-- | .emacs.d/custom-vars.el | 15 | ||||
| -rw-r--r-- | .emacs.d/early-init.el | 6 | ||||
| -rw-r--r-- | .emacs.d/init.el | 59 | ||||
| -rw-r--r-- | .emacs.d/modules/et-appearance.el | 38 | ||||
| -rw-r--r-- | .emacs.d/modules/et-keys.el | 5 | ||||
| -rw-r--r-- | .emacs.d/modules/et-package.el | 33 | ||||
| -rw-r--r-- | .emacs.d/modules/et-vc.el | 83 |
7 files changed, 211 insertions, 28 deletions
diff --git a/.emacs.d/custom-vars.el b/.emacs.d/custom-vars.el new file mode 100644 index 0000000..bf04d9f --- /dev/null +++ b/.emacs.d/custom-vars.el @@ -0,0 +1,15 @@ +;;; -*- lexical-binding: t -*- +(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 + '(doom-modeline ivy marginalia nord-theme surround vertico xclip)) + '(safe-local-variable-values '((Lexical-binding . t)))) +(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. + ) diff --git a/.emacs.d/early-init.el b/.emacs.d/early-init.el new file mode 100644 index 0000000..2f887b9 --- /dev/null +++ b/.emacs.d/early-init.el @@ -0,0 +1,6 @@ +;; Temporarily increase GC threshold during startup +(setq gc-cons-threshold most-positive-fixnum) + +;; Restore to normal value after startup (e.g. 50MB) +(add-hook 'emacs-startup-hook + (lambda () (setq gc-cons-threshold (* 50 1024 1024)))) diff --git a/.emacs.d/init.el b/.emacs.d/init.el index c391857..b082145 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -1,45 +1,48 @@ -;; Setup package.el for installing packages. -;; Use M-x list-packages to see what's available. -(require 'package) -(setq package-archives '(("melpa" . "https://melpa.org/packages/") - ("melpa-stable" . "https://stable.melpa.org/packages/") - ("elpa" . "https://elpa.gnu.org/packages/"))) -(package-initialize) - -(unless (package-installed-p 'use-package) - (package-refresh-contents) - (package-install 'use-package)) +;; Add configuration modules to load path +(add-to-list 'load-path '"~/.dotfiles/.emacs.d/modules") + +;; --------- Core Variables --------------------- +(defvar et/monospace-font "Hack Nerd Font Mono" + "The font used by default and for any monospaced font usage.") +(defvar et/monospace-font-size 128) + +;; --------- Modules ---------------------------- +(require 'et-package) +(require 'et-appearance) +(require 'et-vc) (use-package which-key - :ensure t :config (which-key-mode 1)) -(use-package nord-theme - :ensure t - :config - (load-theme 'nord t)) (use-package eglot - :ensure t :hook (python-mode . eglot-ensure) :config (add-to-list 'eglot-server-programs '(python-mode . ("ty" "server")))) (use-package surround - :ensure t :bind-keymap ("M-'" . surround-keymap)) -;; Move auto-generated Customize code to custom.el -(setq custom-file (expand-file-name "custom.el" user-emacs-directory)) -(when (file-exists-p custom-file) - (load custom-file)) +(use-package vertico + :custom + (vertico-cycle t) + :init + (vertico-mode)) + +(use-package savehist + :init + (savehist-mode)) -(menu-bar-mode -1) ; Remove the menu bar (File Edit Options...) -(tool-bar-mode -1) ; Remove the tool bar (if using GUI) -(setq inhibit-startup-screen t) ; Skip the welcome screen +(use-package marginalia + :after vertico + :custom + (marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil)) + :init + (marginalia-mode)) -;; Line numbers -(setq display-line-numbers-type 'relative) -(global-display-line-numbers-mode 1) +(setq custom-file (expand-file-name "custom-vars.el" user-emacs-directory)) +(when (file-exists-p custom-file) + (load custom-file)) +(setq messages-log-max t) diff --git a/.emacs.d/modules/et-appearance.el b/.emacs.d/modules/et-appearance.el new file mode 100644 index 0000000..06fa44d --- /dev/null +++ b/.emacs.d/modules/et-appearance.el @@ -0,0 +1,38 @@ +; 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) + +;; 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) + +;; Setup our monospace font +(set-face-attribute 'default nil + :font (symbol-value 'et/monospace-font) + :height (symbol-value 'et/monospace-font-size)) + +;; Use line numbers globally +;; (setq display-line-numbers-type 'relative) +(global-display-line-numbers-mode 1) + +(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) diff --git a/.emacs.d/modules/et-keys.el b/.emacs.d/modules/et-keys.el new file mode 100644 index 0000000..2b3b5d1 --- /dev/null +++ b/.emacs.d/modules/et-keys.el @@ -0,0 +1,5 @@ +;; Make ESC quit prompts. M-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) diff --git a/.emacs.d/modules/et-package.el b/.emacs.d/modules/et-package.el new file mode 100644 index 0000000..230a335 --- /dev/null +++ b/.emacs.d/modules/et-package.el @@ -0,0 +1,33 @@ +;; 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/") + ("melpa-stable" . "https://stable.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) diff --git a/.emacs.d/modules/et-vc.el b/.emacs.d/modules/et-vc.el new file mode 100644 index 0000000..107ebf9 --- /dev/null +++ b/.emacs.d/modules/et-vc.el @@ -0,0 +1,83 @@ +;;; -*- Lexical-binding:t -*- +(require 'vc-git) + +(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." + (interactive) + + (if (not buffer-file-name) + (message "Not visiting a file.") + (let* ((git-remote-url-cmd "git config --get remote.origin.url") + (remote-url (string-trim + (shell-command-to-string git-remote-url-cmd))) + (git-head-sha-cmd "git rev-parse HEAD") + (head-sha (string-trim (shell-command-to-string git-head-sha-cmd))) + (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 github.com url." 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. + + Supported providers: + - github + - sourcehut + + Otherwise, if the url corresponds to an unsupported provider, + nil 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 + ((string-match-p "github" provider) + (et--gh-generate-remote-git-url remote-url head-sha relative-file-path line-num)) + ((string-match-p "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--extract-repo-path (base-url remote-url) + (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) + (string-prefix-p "git@" url)) + +(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)) + +(provide 'et-vc) |