aboutsummaryrefslogtreecommitdiff
path: root/share/home/emacs/emacs.el
blob: 7959f6d502f5b9de20de2b7bd8fe00be479c0d64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
;;; 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:

;;;;;;;;;;;;;;;;;;;;;;;
;;;     Startup     ;;;
;;;;;;;;;;;;;;;;;;;;;;;

;;; Startup - Use package ;;;

;; 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.

(defun ross/use-package-ensure-already-installed
    (name _ensure state &optional _context)
  "Assumes the package is already installed.
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))))
  :config
  (no-littering-theme-backups))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;     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)
    (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode)
    (scroll-bar-mode -1))

;; 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
(setq-default frame-title-format '("%b")) ; Make window title the buffer name
(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
(global-auto-revert-mode t)               ; Auto-update buffer if file has changed on disk
(setopt create-lockfiles nil)             ; Don't create lockfiles
(electric-pair-mode 1)                    ; Autopairs

;;; Customization - Highlight current line ;;;

(use-package hl-line
  :hook (on-first-buffer . global-hl-line-mode))

;;; Customization - Evil ;;;

;; Set up vi keybinds
(use-package evil
  :config
  (evil-mode 1))

;;; Customization - Direnv support ;;;

(use-package envrc
  :ensure t
  :hook (on-first-file . envrc-global-mode))

;;; Customziation - Completion framework ;;;

(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))

;;; Customization - Project management ;;;

(use-package projectile
  :bind-keymap ("C-c p" . projectile-command-map)
  :config
  (projectile-mode +1))

;;; Customization - Completions ;;;

(use-package company
  :init (global-company-mode))

;;; Customization - Syntax checking ;;;

(use-package flycheck
  :init (global-flycheck-mode))

;;; Customization - Line numbers ;;;

(when (version<= "26.0.50" emacs-version )
  (global-display-line-numbers-mode))

;;; Customization - Which key ;;;

(use-package which-key
  :init (which-key-mode +1))

;;;;;;;;;;;;;;;;;;;;;;;;;
;;;     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\\'")

;;; Languages - Coq ;;;

(use-package proof-general
  :mode ("\\.v\\'" . coq-mode))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;     Useful modes     ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; Useful modes - magit ;;;

(use-package magit)

;;; emacs.el ends here