aboutsummaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/init.el
blob: 11026691d32b69193670dc92c8e286ed08bef5c6 (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
;;; init.el --- Tom-Emacs Interface                  -*- lexical-binding: t; -*-

;; Copyright (C) 2018  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: local

;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;; This is my Emacs configuration. It has gone through many iterations
;; before and may yet go through many more iterations.

;;; Code:

;;;; Load path and autoloads

(eval-and-compile
  (let ((load-directory
         (file-name-directory
          (or load-file-name byte-compile-current-file))))
    (add-to-list 'load-path (format "%sinit/" load-directory))
    (add-to-list 'load-path (format "%ssite-lisp/" load-directory))
    (add-to-list 'load-path (format "%sos-lisp/" load-directory))

    (mapc (lambda (d) (add-to-list 'load-path d))
          (directory-files
           (format "%svendor-lisp/" load-directory) t "^[^.]"))))

(load "oni-site-autoloads" :noerror :nomessage)

(require 'package)

(eval-and-compile (package-initialize))

;;;; Dependencies

(require 'counsel)
(require 'destroy-trailing-whitespace)
(require 'diff-hl)
(require 'diminish)
(require 'ivy)
(require 'ivy-hydra)
(require 'projectile)
(require 'shackle)

;;;; Settings

;;; Put backup and auto save files in their own directories so they
;;; don't clutter the rest of the filesystem.
(setq backup-directory-alist
      `((".*" . ,(concat user-emacs-directory "data/backup-files"))))

(add-to-list
 'auto-save-file-name-transforms
 `(".*" ,(concat user-emacs-directory "data/auto-save-files/") t)
 :append)

(setq auto-save-list-file-prefix
      (concat user-emacs-directory "data/" "auto-save-list/.saves-"))

(setq abbrev-file-name
      (concat user-emacs-directory "data/abbrev_defs"))

(with-eval-after-load 'forge
  (setq forge-database-file
        (concat user-emacs-directory "data/forge-database.sqlite")))

(with-eval-after-load 'projectile
  (setq projectile-cache-file
        (concat user-emacs-directory "data/projectile.cache")
        projectile-known-projects-file
        (concat user-emacs-directory "data/projectile-bookmarks.eld")))

(with-eval-after-load 'tramp-cache
  (setq tramp-persistency-file-name
        (concat user-emacs-directory "data/tramp")))

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

(global-set-key (kbd "C-M-SPC") 'er/expand-region)
(global-set-key (kbd "M-+") 'mc/mark-next-like-this)
(global-set-key (kbd "C-c (") 'embrace-commander)
(global-set-key (kbd "C-c o") 'oni-hydra-org/body)
(global-set-key (kbd "C-c v") 'oni-hydra-magit/body)
(global-set-key (kbd "C-x f") 'ffap)
(global-set-key (kbd "C-x C-b") 'ibuffer)

(global-destroy-trailing-whitespace-mode)

(setq require-final-newline t)

(setq-default indent-tabs-mode nil)

(setq-default tab-width 4)

(setq sentence-end-double-space nil)

(setq inhibit-startup-screen t)

(setq-default truncate-lines t)

(setq-default fill-column 80)

(global-unset-key (kbd "C-z"))

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

(show-paren-mode)

(diminish 'ivy-mode)

(ivy-mode)

(setq counsel-find-file-ignore-regexp
      (rx (or (and bos ".")
              (and ".zwc" eos))))

(counsel-mode)

(diminish 'counsel-mode)

(eval-when-compile (require 'bookmark))
(setq bookmark-default-file
      (concat user-emacs-directory "data/bookmarks"))

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

(eval-when-compile (require 'browse-url))

(with-eval-after-load 'browse-url
  (setq browse-url-browser-function 'browse-url-firefox))

(add-hook 'minibuffer-setup-hook 'electric-pair-local-mode)

(shackle-mode)

(with-eval-after-load 'shr (load "oni-shr-init"))

(with-eval-after-load 'paredit
  (diminish 'paredit-mode))

(electric-indent-mode -1)

(defun oni: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"))))

(add-hook 'electric-indent-local-mode-hook #'oni:switch-newline-keys)

(global-diff-hl-mode)
(blink-cursor-mode -1)

(defun oni:with-diff-hl-p4-args (orig-fun &rest args)
  "Add Perforce-specific command-line arguments to `diff-hl-mode'.

ORIG-FUN is the function being wrapped, ARGS are the arguments specified"
  (let ((p4-lowlevel-diff-switches '("-du0")))
    (apply orig-fun args)))

(with-eval-after-load 'vc-p4
  (add-function :around (symbol-function 'diff-hl-changes-buffer)
                #'oni:with-diff-hl-p4-args))

(setq projectile-known-projects-file
      (concat user-emacs-directory "data/projectile-bookmarks.eld"))

(with-eval-after-load 'projectile
  (setq projectile-mode-line
        '(:eval
          (if (file-remote-p default-directory)
              " P"
            (let ((name (projectile-project-name)))
              (if (string= "-" name)
                  ""
                (format " P[%s]" name)))))))

(setq projectile-cache-file
      (concat user-emacs-directory "data/projectile.cache"))

(projectile-mode)

(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)

(setq projectile-completion-system 'ivy)

(add-to-list 'projectile-project-root-files "yarn.lock")
(add-to-list 'projectile-project-root-files "fabfile.py")

;; (with-eval-after-load 'server
;;   (diminish 'server-buffer-clients
;;             (propertize (concat "  " (char-to-string #xf233))
;;                         'face '(:family "Font Awesome" :height 0.75))))

(with-eval-after-load 'cider (load "oni-cider-init"))
(with-eval-after-load 'align (load "oni-align"))
(with-eval-after-load 'cc-mode (load "oni-cpp-init"))
(with-eval-after-load 'circe (load "oni-circe-init"))
(with-eval-after-load 'cmake-mode (load "oni-cmake-init"))
(with-eval-after-load 'compile (load "oni-compilation-init"))
(with-eval-after-load 'css-mode (load "oni-css-mode-init"))
(with-eval-after-load 'dired (load "oni-dired-init"))
(with-eval-after-load 'ediff (load "oni-ediff-init"))
(with-eval-after-load 'elec-pair (load "oni-elec-pair-init"))
(with-eval-after-load 'eshell (load "oni-eshell-init"))
(with-eval-after-load 'gnus (load "oni-gnus-init"))
(with-eval-after-load 'jabber (load "oni-jabber-init"))
(with-eval-after-load 'js (load "oni-js-mode-init"))
(with-eval-after-load 'lui (load "oni-lui-init"))
(with-eval-after-load 'magit (load "oni-magit-init"))
(with-eval-after-load 'php-mode (load "oni-php-mode-init"))
(with-eval-after-load 'ruby-mode (load "oni-ruby-init"))
(with-eval-after-load 'scheme (load "oni-scheme-init"))
(with-eval-after-load 'sh-mode (load "oni-sh-mode-init"))
(with-eval-after-load 'shackle (load "oni-shackle-init"))
(with-eval-after-load 'slack (load "oni-slack-init"))
(with-eval-after-load 'slime (load "oni-slime-init"))
(with-eval-after-load 'yasnippet (load "oni-yasnippet-init"))
(with-eval-after-load 'rust-mode (load "oni-rust-init"))

(add-hook 'ielm-mode-hook 'paredit-mode)
(add-hook 'prog-mode-hook 'goto-address-prog-mode)

(autoload 'mbsync-conf-mode "mbsync-conf-mode"
  "Major mode for editing mbsync configuration files."
  :interactive)

(autoload 'msmtprc-mode "msmtprc-mode"
  "Major mode for editing msmtp configuration files."
  :interactive)

(add-to-list 'auto-mode-alist '("\\.blade\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.inc\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("\\.mbsyncrc\\'" . mbsync-conf-mode))
(add-to-list 'auto-mode-alist '("\\.module\\'" . php-mode))
(add-to-list 'auto-mode-alist '("\\.msmtprc\\'" . msmtprc-mode))
(add-to-list 'auto-mode-alist '("\\.targets\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.proj\\'" . nxml-mode))

(add-hook 'git-commit-mode-hook 'electric-quote-local-mode)

(add-hook 'makefile-mode-hook 'whitespace-only-tabs-mode)

(add-hook 'makefile-mode-hook 'electric-pair-local-mode)

(with-eval-after-load 'clojure-mode
  (require 'clojure-mode-extra-font-locking))

(add-hook 'clojure-mode-hook 'paredit-mode)

(add-hook 'clojure-mode-hook 'rainbow-delimiters-mode)

(eval-when-compile (require 'inf-lisp))

(defun oni:clojure-set-inferior-lisp ()
  (setq inferior-lisp-program "lein repl"))

(add-hook 'clojure-mode-hook 'oni-clojure-add-font-lock)
(add-hook 'clojure-mode-hook 'oni-clojure-add-indent)

(add-hook 'c-mode-hook 'electric-pair-local-mode)

(add-hook 'c-mode-hook 'electric-indent-local-mode)

(add-hook 'c-mode-hook 'flycheck-mode)

(add-hook 'c-mode-hook 'fci-mode)

(add-hook 'html-mode-hook 'electric-pair-local-mode)

(add-to-list 'grep-files-aliases '("js" . "*.js *.jsx *.json"))
(add-to-list 'grep-files-aliases '("css" . "*.css *.less *.sass *.scss"))
(add-to-list 'grep-files-aliases '("php" . "*.php *.inc *.module"))
(add-to-list 'grep-files-aliases '("msbuild" . "*.targets *.proj"))

(add-hook 'before-save-hook 'time-stamp)

(if (eq system-type 'windows-nt)
    (require 'oni-windows-nt))

(setq custom-file (concat user-emacs-directory "custom.el"))
(load custom-file t)

(provide 'init)
;;; init.el ends here