aboutsummaryrefslogtreecommitdiffstats
path: root/oni-core.el
blob: 4f6725601c740efcf85adc32052abe11c14b8e30 (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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
;;; oni-core.el --- Core Emacs configuration         -*- lexical-binding: t; -*-

;; Copyright (C) 2019  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local
;; Version: 2021.1123.003634
;; Package-Requires: (oni-data-dir oni-embrace oni-hydra expand-region multiple-cursors gcmh diminish ws-butler which-key insert-char-preview dashboard mixed-pitch)

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; Core Emacs configuration, doesn't need any requires from within
;; Emacs. These settings don't seem to go anywhere else. Add the following to
;; your init file in case you want to use this configuration:
;;
;;     (require 'oni-core)

;;; Code:

(require 'auth-source)
(require 'diminish)
(require 'gcmh)
(require 'hydra)
(require 'package)
(require 'recentf)
(require 'which-key)
(require 'ws-butler)

(require 'oni-data-dir)

(defconst oni-core--auto-save-directory (oni-data-dir-locate "auto-save-files/")
  "Directory where auto-saves go.")

(defalias 'yes-or-no-p 'y-or-n-p)

(defvar oni-core--recentf-idle-timer nil
  "Internal variable keeping track of a timer started for ‘recentf-save-list’.")

(defun oni-core--switch-newline-keys ()
  "Switch the ‘C-j’ and ‘RET’ keys in the local buffer."
  (if electric-indent-mode
      (progn
        (local-set-key (kbd "C-j") 'newline)
        (local-set-key (kbd "RET") 'electric-newline-and-maybe-indent))
    (local-unset-key (kbd "C-j"))
    (local-unset-key (kbd "RET"))))

(defun oni-core--ensure-autosave-directory-exists ()
  "Create the autosave directory if doesn't exist."
  (mkdir oni-core--auto-save-directory t))

(defun oni-core-move-beginning-of-dwim ()
  "Move to beginning of line either after indentation or before."
  (interactive)
  (let ((start (point)))
    (back-to-indentation)
    (unless (/= start (point))
      (move-beginning-of-line 1))))

(defun oni-core-move-end-of-dwim ()
  "Move to end of line, either before any comments or after."
  (interactive)
  (let ((start (point))
        (eolpos (line-end-position)))
    (beginning-of-line)
    (if (and comment-start
             (not (looking-at (regexp-quote comment-start)))
             (comment-search-forward eolpos t))
        (progn
          (search-backward-regexp (concat "[^ \t" comment-start "]"))
          (forward-char)
          (when (or (bolp)
                    (= start (point)))
            (end-of-line)))
      (end-of-line))))

;;; From Bastien Guerry’s Emacs configuraiton:
;;; https://github.com/bzg/dotemacs/blob/master/emacs.org
(defun oni-core-unfill-paragraph ()
  "Make a multi-line paragraph into a single line of text."
  (interactive)
  (let ((fill-column (point-max)))
    (fill-paragraph nil)))

(defun oni-core-recentf-save-list-silently ()
  "Call ‘recentf-save-list’ but without showing a message about it."
  (let ((inhibit-message t))
    (recentf-save-list)))

(defhydra oni-sort-and-align-hydra (:color teal :hint nil)
  "
     ^Sort^
^^--------------
_l_: Lines
_p_: Paragraph
_s_: String list"
  ("l" sort-lines)
  ("p" (save-excursion
         (sort-lines
          nil
          (progn (start-of-paragraph-text) (point))
          (progn (end-of-paragraph-text) (point)))))
  ("s" (sort-regexp-fields
        nil
        (rx "\"" (one-or-more (not "\"")) "\"")
        (rx (one-or-more (not "\"")))
        (region-beginning)
        (region-end))))

(add-to-list 'auto-save-file-name-transforms
	         `(".*" ,oni-core--auto-save-directory t)
	         :append)

(setq backup-directory-alist
      `((".*" . ,(oni-data-dir-locate "backup-files"))))

(setq auto-save-list-file-prefix
      (oni-data-dir-locate "auto-save-list/.saves-"))

(setq abbrev-file-name (oni-data-dir-locate "abbrev_defs"))

(setq recentf-save-file (oni-data-dir-locate "recentf"))

;;; Get rid of the default help tooltip on the mode-line.
(setq mode-line-default-help-echo nil)

(setq user-full-name "Tom Willemse"
      user-mail-address "tom@ryuslash.org")

(setq delete-old-versions t)
(setq kept-new-versions 20)
(setq kept-old-versions 20)
(setq vc-make-backup-files t)
(setq version-control t)
(setq require-final-newline t)
(setq sentence-end-double-space nil)
(setq inhibit-startup-screen t)
(setq electric-pair-skip-whitespace 'chomp)
(setq fit-window-to-buffer-horizontally t)

(require 'dashboard)
(setq dashboard-footer-messages
      '("Play more in order to learn more"
        "Learn from similarities, unlearn from differences"
        "Explore, invent, and apply in your environment - safely"
        "See without judging and then act"
        "Give yourself permission to fail; it’s the path to success"
        "Groove your mind for success"
        "Learn to focus"
        "Make thinking time"
        "Use a wiki to manage information and knowledge"
        "Establish rules of engagement to manage interruptions"
        "Send less email, and you’ll receive less email"
        "Choose your own tempo for an email conversation"
        "Mask interrupts to maintain focus"
        "Use multiple monitors to avoid context switching"
        "Optimize your personal workflow to maximize context"
        "Grab the wheel. You can’t steer on autopilot"
        "Can it be simpler?"))
(dashboard-setup-startup-hook)
(setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))

;; Increase the threshold for garbage collection for increased performance.
;; Apparently there are some (lsp-mode for example) packages that generate a lot
;; of garbage.
(setq gc-cons-threshold 100000000)

;;; Remove ~/.authinfo from the auth sources since it’s an unencripted file and
;;; I don’t want to accidentally store anything in there.
(setq auth-sources
      (cons "secrets:Login"
            (remove "~/.netrc"
                    (remove "~/.authinfo" auth-sources))))

(setq read-mail-command 'gnus)

(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
(setq-default truncate-lines t)
(setq-default fill-column 80)

(add-hook 'Info-mode-hook 'mixed-pitch-mode)
(add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
(add-hook 'auto-save-hook #'oni-core--ensure-autosave-directory-exists)
(add-hook 'before-save-hook 'time-stamp)
(add-hook 'electric-indent-local-mode-hook #'oni-core--switch-newline-keys)
(add-hook 'minibuffer-setup-hook 'electric-pair-local-mode)
(add-hook 'prog-mode-hook 'goto-address-prog-mode)

(global-set-key (kbd "C-M-SPC") 'er/expand-region)
(global-set-key (kbd "C-S-b") 'windmove-left)
(global-set-key (kbd "C-S-f") 'windmove-right)
(global-set-key (kbd "C-S-n") 'windmove-down)
(global-set-key (kbd "C-S-p") 'windmove-up)
(global-set-key (kbd "C-c (") 'embrace-commander)
(global-set-key (kbd "C-c q") #'oni-core-unfill-paragraph)
(global-set-key (kbd "C-c s") #'oni-sort-and-align-hydra/body)
(global-set-key (kbd "C-c l") 'imenu)
(global-set-key (kbd "C-x C-b") 'ibuffer-jump)
(global-set-key (kbd "C-x M-f") 'ffap)
(global-set-key (kbd "M-+") 'mc/mark-next-like-this)
(global-set-key [remap insert-char] 'insert-char-preview)
(global-set-key [remap move-beginning-of-line] #'oni-core-move-beginning-of-dwim)
(global-set-key [remap move-end-of-line] #'oni-core-move-end-of-dwim)

(global-set-key (kbd "C-<left>") 'winner-undo)
(global-set-key (kbd "C-<right>") 'winner-redo)

(unless oni-core--recentf-idle-timer
  (setq oni-core--recentf-idle-timer
        (run-with-idle-timer 10 t #'oni-core-recentf-save-list-silently)))

(with-eval-after-load 'gcmh (diminish 'gcmh-mode))
(with-eval-after-load 'ws-butler (diminish 'ws-butler-mode))
(with-eval-after-load 'which-key (diminish 'which-key-mode))

(add-to-list 'display-buffer-alist
             `(,(rx string-start
                    "*" (any ?h ?H) "elp")
               display-buffer-in-side-window
               (side . bottom)
               (slot . 0)
               (window-height . 0.33)))

(when (eql system-type 'windows-nt)
  (add-to-list 'load-path (locate-user-emacs-file "vendor/p4-vc"))
  (add-to-list 'exec-path "c:/Program Files/Git/bin")
  (add-to-list 'exec-path "C:/Program Files/Git/usr/bin")
  (add-to-list 'exec-path "c:/cygwin64/bin")

  (setq delete-by-moving-to-trash t)

  (setq-default buffer-file-coding-system 'utf-8-unix))

;; Set up autoloads for all of my configuration files so that when they get
;; installed they get loaded automatically, but don’t require them to be
;; installed.

(with-eval-after-load 'ahk-mode (require 'oni-autohotkey))
(with-eval-after-load 'alert (require 'oni-alert))
(with-eval-after-load 'bat-mode (require 'oni-bat))
(with-eval-after-load 'bats (require 'oni-bats))
(with-eval-after-load 'bookmark (require 'oni-bookmark))
(with-eval-after-load 'browse-url (require 'oni-browse-url))
(with-eval-after-load 'cc-mode (require 'oni-c nil t))
(with-eval-after-load 'cc-mode (require 'oni-cpp nil t))
(with-eval-after-load 'cc-mode (require 'oni-java nil t))
(with-eval-after-load 'cider (require 'oni-clojure))
(with-eval-after-load 'circe (require 'oni-circe))
(with-eval-after-load 'clojure-mode (require 'oni-clojure))
(with-eval-after-load 'cmake-mode (require 'oni-cmake))
(with-eval-after-load 'company (require 'oni-company))
(with-eval-after-load 'compile (require 'oni-compilation))
(with-eval-after-load 'conf-mode (require 'oni-conf))
(with-eval-after-load 'counsel (require 'oni-counsel))
(with-eval-after-load 'csharp-mode (require 'oni-csharp))
(with-eval-after-load 'css-mode (require 'oni-css))
(with-eval-after-load 'diff-hl (require 'oni-diff-hl))
(with-eval-after-load 'dired (require 'oni-dired))
(with-eval-after-load 'ediff (require 'oni-ediff))
(with-eval-after-load 'elfeed (require 'oni-elfeed))
(with-eval-after-load 'elisp-mode (require 'oni-elisp))
(with-eval-after-load 'elm-mode (require 'oni-elm))
(with-eval-after-load 'embrace (require 'oni-embrace))
(with-eval-after-load 'eshell (require 'oni-eshell))
(with-eval-after-load 'fish-mode (require 'oni-fish))
(with-eval-after-load 'flycheck (require 'oni-flycheck))
(with-eval-after-load 'git-commit (require 'oni-git-commit))
(with-eval-after-load 'gnus (require 'oni-gnus))
(with-eval-after-load 'grep (require 'oni-grep))
(with-eval-after-load 'groovy-mode (require 'oni-groovy))
(with-eval-after-load 'haskell-mode (require 'oni-haskell))
(with-eval-after-load 'highlight-indent-guides (require 'oni-highlight-indent-guides))
(with-eval-after-load 'hydra (require 'oni-hydra))
(with-eval-after-load 'ielm (require 'oni-elisp))
(with-eval-after-load 'ivy (require 'oni-ivy))
(with-eval-after-load 'jabber (require 'oni-jabber))
(with-eval-after-load 'js2-mode (require 'oni-js))
(with-eval-after-load 'json-mode (require 'oni-json))
(with-eval-after-load 'lisp-mode (require 'oni-common-lisp))
(with-eval-after-load 'log-edit (require 'oni-log-edit))
(with-eval-after-load 'lsp (require 'oni-lsp))
(with-eval-after-load 'lua-mode (require 'oni-lua))
(with-eval-after-load 'lui (require 'oni-lui))
(with-eval-after-load 'magit (require 'oni-magit))
(with-eval-after-load 'make-mode (require 'oni-makefile))
(with-eval-after-load 'nov (require 'oni-epub))
(with-eval-after-load 'org (require 'oni-org))
(with-eval-after-load 'org-roam (require 'oni-org-roam))
(with-eval-after-load 'package (require 'oni-package))
(with-eval-after-load 'package-x (require 'oni-package))
(with-eval-after-load 'paredit (require 'oni-paredit))
(with-eval-after-load 'php-mode (require 'oni-php))
(with-eval-after-load 'prescient (require 'oni-prescient))
(with-eval-after-load 'projectile (require 'oni-projectile))
(with-eval-after-load 'python (require 'oni-python))
(with-eval-after-load 'ruby-mode (require 'oni-ruby))
(with-eval-after-load 'rust-mode (require 'oni-rust))
(with-eval-after-load 'scheme (require 'oni-scheme))
(with-eval-after-load 'sgml-mode (require 'oni-html))
(with-eval-after-load 'sh (require 'oni-sh))
(with-eval-after-load 'shr (require 'oni-shr))
(with-eval-after-load 'smartparens (require 'oni-smartparens))
(with-eval-after-load 'sort (require 'oni-sort))
(with-eval-after-load 'tramp (require 'oni-tramp))
(with-eval-after-load 'vc (require 'oni-vc))
(with-eval-after-load 'vterm (require 'oni-vterm))
(with-eval-after-load 'web-mode (require 'oni-web))
(with-eval-after-load 'yaml-mode (require 'oni-yaml))

(with-eval-after-load 'yasnippet
  (require 'oni-yasnippet)
  (when (and (package-installed-p 'oni-yasnippet)
             (not yas-global-mode))
    (yas-global-mode)))

(eval-when-compile
  (require 'calendar))

(with-eval-after-load 'calendar
  ;; I’m used to working with Monday as the starting day.
  (setq calendar-week-start-day 1))

(defun oni-core-in-word-p ()
  "Check whether the character just typed was part of a word."
  (save-excursion
    (backward-char)
    (looking-back (rx word) (1- (point)))))

(with-eval-after-load 'electric
  (add-hook 'electric-quote-inhibit-functions #'oni-core-in-word-p))

(eval-when-compile (require 'ispell))
(with-eval-after-load 'ispell
  (setq ispell-program-name "hunspell"
        ispell-really-hunspell t))

;; Enable any modes that I want to have turned on right away.

(electric-indent-mode -1)
(winner-mode)
(recentf-mode)
(gcmh-mode)
(ws-butler-global-mode)
(which-key-mode)
(auto-insert-mode)
(counsel-mode)
(global-diff-hl-mode)

(provide 'oni-core)
;;; oni-core.el ends here