aboutsummaryrefslogtreecommitdiff
path: root/share/home
diff options
context:
space:
mode:
authorMiran Bastaja <miran.bastaja04@gmail.com>2023-12-16 23:36:07 +0100
committerMiran Bastaja <miran.bastaja04@gmail.com>2023-12-16 23:36:07 +0100
commite56561405ff9da0cc9f0ffdbc72d42c1161fdafe (patch)
tree913f3fcf834ba43ef433441659630df2097ffdd2 /share/home
parentf7f69e10eb07e74b6895ff9b3e1aab1062ae42c5 (diff)
parent3688356e33753001519d89e83d800c5e9016529a (diff)
Merge branch 'emacs'
Diffstat (limited to 'share/home')
-rw-r--r--share/home/emacs/early-init.el6
-rw-r--r--share/home/emacs/emacs.el265
2 files changed, 174 insertions, 97 deletions
diff --git a/share/home/emacs/early-init.el b/share/home/emacs/early-init.el
new file mode 100644
index 0000000..bbfc354
--- /dev/null
+++ b/share/home/emacs/early-init.el
@@ -0,0 +1,6 @@
+;;; early-init.el --- Early Initalization -*- lexical-binding: t; -*-
+;; All our packages come from Nix
+(setq package-enable-at-startup nil
+ package-archives nil)
+(provide 'early-init)
+;;; early-init.el ends here
diff --git a/share/home/emacs/emacs.el b/share/home/emacs/emacs.el
index 3baa19b..76d7f9f 100644
--- a/share/home/emacs/emacs.el
+++ b/share/home/emacs/emacs.el
@@ -1,20 +1,113 @@
-;; -*- lexical-binding: t -*-
-;;; emacs-config --- My emacs config
+;;; init.el --- Initalization -*- lexical-binding: t; -*-
+;;;
;;; Commentary:
+;;; Various resources were used to hack together this config:
+;;; - https://sanemacs.com/
+;;; - https://rossabaker.com/configs/emacs/
+;;;
;;; Code:
-;; Lots of stuff copied from Sanemacs version 0.3.2
-;; https://sanemacs.com/
-;;; For performance
-(setq gc-cons-threshold 100000000)
-(setq read-process-output-max (* 1024 1024)) ;; 1mb
+;;;;;;;;;;;;;;;;;;;;;;;
+;;; Startup ;;;
+;;;;;;;;;;;;;;;;;;;;;;;
+;;; Startup - Use package ;;;
-(add-hook 'after-init-hook #'(lambda ()
- ;; restore after startup
- (setq gc-cons-threshold 800000)))
+;; Most of this config is broken down into [[https://github.com/jwiegley/use-package][~use-package~]] stanzas. All
+;; dependencies are managed by [[https://nixos.org/][Nix]]. Any package with a true ~:ensure~
+;; keyword is found by [[https://github.com/nix-community/emacs-overlay#extra-library-functionality][~emacsWithPackagesFromUsePackage~]] to generate
+;; the set of Emacs packages to install with Nix.
+;;
+;; In the brutish non-Nix world, ~:ensure~ triggers Emacs' own package
+;; manager with willy nilly downloads. To prevent this, we tell
+;; ~use-package~ to assume the package is there and merely look for its
+;; autoloads.
-;;; Disable menu-bar, tool-bar, and scroll-bar.
+(defun ross/use-package-ensure-already-installed
+ (name _ensure state &optional _context)
+ "Value for `use-package-ensure-function` that assumes the package
+ is already installed. This is true in our Nix environment."
+ (let ((autoloads-file-name (format "%s-autoloads" name)))
+ (with-demoted-errors "Error loading autoloads: %s"
+ (load autoloads-file-name t t))))
+
+(setq use-package-ensure-function #'ross/use-package-ensure-already-installed)
+
+;; ~use-package~ also by default appends ~"-hook"~ to all its hooks.
+;; This impairs ripgreppability. Let's be explicit:
+
+(setq use-package-hook-name-suffix nil)
+
+;; use-package doesn't use itself. (Well, I think it could, but this
+;; is the recommended approach...)
+
+(eval-when-compile
+ (require 'use-package))
+
+;; some packages complain if I don't have this
+(use-package bind-key
+ :demand t
+ :bind
+ (:prefix-map rab/files-map
+ :prefix "C-c f")
+ :bind
+ (:prefix-map rab/toggles-map
+ :prefix "C-c t"))
+
+;;; Startup - Benchmarking ;;;
+
+(use-package benchmark-init
+ :ensure t
+ :demand t
+ :hook (after-init . benchmark-init/deactivate)
+ :config
+ (benchmark-init/activate))
+
+;;; Startup - Garbage collection ;;;
+
+(use-package gcmh
+ :ensure t
+ :diminish
+ :init (setq gc-cons-threshold (* 80 1024 1024))
+ :hook (emacs-startup . gcmh-mode))
+
+;;; Startup - Better cache location ;;;
+(use-package no-littering
+ :ensure t
+ :init
+ (setq no-littering-etc-directory "~/.cache/emacs/etc/"
+ no-littering-var-directory "~/.cache/emacs/var/")
+ (when (fboundp 'startup-redirect-eln-cache)
+ (startup-redirect-eln-cache
+ (convert-standard-filename
+ (expand-file-name "eln-cache/" no-littering-var-directory)))))
+
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Customization ;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Customization - Scrolling ;;;
+;; TODO: Smooth scroll
+
+;;; Customization - Theme ;;;
+
+(use-package doom-themes
+ :ensure t
+ :config
+ ;; Global settings (defaults)
+ (setq doom-themes-enable-bold t ; if nil, bold is universally disabled
+ doom-themes-enable-italic t) ; if nil, italics is universally disabled
+ (load-theme 'doom-one t)
+
+ ;; Enable flashing mode-line on errors
+ (doom-themes-visual-bell-config)
+ ;; Corrects (and improves) org-mode's native fontification.
+ (doom-themes-org-config))
+
+;;; Customization - General settings ;;;
+
+;; Disable menu-bar, tool-bar, and scroll-bar.
(if (fboundp 'menu-bar-mode)
(menu-bar-mode -1))
(if (fboundp 'tool-bar-mode)
@@ -22,26 +115,7 @@
(if (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1))
-;;; Fix this bug:
-;;; https://www.reddit.com/r/emacs/comments/cueoug/the_failed_to_download_gnu_archive_is_a_pretty/
-(when (version< emacs-version "26.3")
- (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3"))
-
-;;; Setup package.el
-(require 'package)
-(setq package-enable-at-startup nil)
-(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
-(unless package--initialized (package-initialize))
-
-;;; Setup use-package
-(unless (package-installed-p 'use-package)
- (package-refresh-contents)
- (package-install 'use-package))
-(eval-when-compile
- (require 'use-package))
-(setq use-package-always-ensure t)
-
-;;; Useful Defaults
+;; Useful Defaults
(setq-default cursor-type 'bar) ; Line-style cursor similar to other text editors
(setq inhibit-startup-screen t) ; Disable startup screen
(setq initial-scratch-message "") ; Make *scratch* buffer blank
@@ -49,92 +123,89 @@
(setq ring-bell-function 'ignore) ; Disable bell sound
(fset 'yes-or-no-p 'y-or-n-p) ; y-or-n-p makes answering questions faster
(show-paren-mode 1) ; Show closing parens by default
-(setq linum-format "%4d ") ; Line number format
-(delete-selection-mode 1) ; Selected text will be overwritten when you start typing
(global-auto-revert-mode t) ; Auto-update buffer if file has changed on disk
-(use-package undo-tree ; Enable undo-tree, sane undo/redo behavior
- :init (global-undo-tree-mode)
- :config (setq-default undo-tree-auto-save-history nil))
-(add-hook 'before-save-hook
- 'delete-trailing-whitespace) ; Delete trailing whitespace on save
-(add-hook 'prog-mode-hook ; Show line numbers in programming modes
- (if (and (fboundp 'display-line-numbers-mode) (display-graphic-p))
- #'display-line-numbers-mode
- #'linum-mode))
+(setopt create-lockfiles nil) ; Don't create lockfiles
+(electric-pair-mode 1) ; Autopairs
-(defun sanemacs/backward-kill-word ()
- (interactive "*")
- (push-mark)
- (backward-word)
- (delete-region (point) (mark)))
+;;; Customization - Highlight current line ;;;
-;;; Keybindings
-(global-set-key [mouse-3] 'mouse-popup-menubar-stuff) ; Gives right-click a context menu
-(global-set-key (kbd "C->") 'indent-rigidly-right-to-tab-stop) ; Indent selection by one tab length
-(global-set-key (kbd "C-<") 'indent-rigidly-left-to-tab-stop) ; De-indent selection by one tab length
-(global-set-key (kbd "M-DEL") 'sanemacs/backward-kill-word) ; Kill word without copying it to your clipboard
-(global-set-key (kbd "C-DEL") 'sanemacs/backward-kill-word) ; Kill word without copying it to your clipboard
+(use-package hl-line
+ :hook (on-first-buffer . global-hl-line-mode))
-;;; Offload the custom-set-variables to a separate file
-;;; This keeps your init.el neater and you have the option
-;;; to gitignore your custom.el if you see fit.
-(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
-(unless (file-exists-p custom-file)
- (write-region "" nil custom-file))
-;;; Load custom file. Don't hide errors. Hide success message
-(load custom-file nil t)
+;;; Customization - Evil ;;;
-;;; Put Emacs auto-save and backup files to /tmp/ or C:/Temp/
-(defconst emacs-tmp-dir (expand-file-name (format "emacs%d" (user-uid)) temporary-file-directory))
-(setq
- backup-by-copying t ; Avoid symlinks
- delete-old-versions t
- kept-new-versions 6
- kept-old-versions 2
- version-control t
- auto-save-list-file-prefix emacs-tmp-dir
- auto-save-file-name-transforms `((".*" ,emacs-tmp-dir t)) ; Change autosave dir to tmp
- backup-directory-alist `((".*" . ,emacs-tmp-dir)))
+;; Set up vi keybinds
+(use-package evil
+ :config
+ (evil-mode 1))
-;;; Lockfiles unfortunately cause more pain than benefit
-(setq create-lockfiles nil)
+;;; Customization - Direnv support ;;;
-;;; Load wheatgrass as the default theme if one is not loaded already
+(use-package envrc
+ :ensure t
+ :hook (on-first-file . envrc-global-mode))
-(if (not custom-enabled-themes)
- (load-theme 'wheatgrass t))
+;;; Customziation - Completion framework ;;;
-(defun reload-config ()
- (interactive)
- (load-file (expand-file-name "init.el" user-emacs-directory)))
+(use-package helm
+ :init
+ (helm-mode 1)
+ :config
+ (setq helm-completion-style 'emacs))
+(use-package fussy
+ :config
+ (push 'fussy completion-styles)
+ (setq
+ ;; For example, project-find-file uses 'project-files which uses
+ ;; substring completion by default. Set to nil to make sure it's using
+ ;; flx.
+ completion-category-defaults nil
+ completion-category-overrides nil))
-;; Autopairs
-(electric-pair-mode 1)
+;;; Customization - Project management ;;;
-;; Set up vi keybinds
-(use-package evil
+(use-package projectile
+ :bind-keymap ("C-c p" . projectile-command-map)
:config
- (evil-mode 1))
+ (projectile-mode +1))
+
+;;; Customization - Completions ;;;
+
+(use-package company
+ :init (global-company-mode))
+
+;;; Customization - Syntax checking ;;;
+
+(use-package flycheck
+ :init (global-flycheck-mode))
+
+;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Languages ;;;
+;;;;;;;;;;;;;;;;;;;;;;;;;
+
+;;; Langauges - Emacs lisp ;;;
+
+;; Preserve indentation in org mode source blocks
+(dolist (pair '((org-src-preserve-indentation . t) (org-src-tab-acts-natively . t)))
+ (add-to-list 'safe-local-variable-values pair))
+
+;;; Languages - Nix ;;;
(use-package nix-mode
:mode "\\.nix\\'")
-;; Set up proof general for working with coq
+;;; Languages - Coq ;;;
+
(use-package proof-general
:mode ("\\.v\\'" . coq-mode))
-(use-package flycheck
- :init (global-flycheck-mode))
-
-(use-package company
- :init (global-company-mode))
+;; ----------------------------------------------------------------------- ;;
-(use-package projectile
- :init
- (projectile-mode +1))
+;; (use-package display-line-numbers
+;; :custom
+;; (display-line-numbers-widen t)
+;; :hook
+;; ((prog-mode conf-mode) . display-line-numbers-mode))
-(use-package helm
- :init
- (helm-mode 1))
;;; emacs.el ends here