-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
417 lines (353 loc) · 12.9 KB
/
init.el
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
;; .emacs
;;; uncomment this line to disable loading of "default.el" at startup
;(setq inhibit-default-init t)
;; PuTTY fix
(define-key global-map "\M-[1~" 'beginning-of-line)
(define-key global-map [select] 'end-of-line)
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "https://stable.melpa.org/packages/"))
(package-initialize)
;; Remove security vulnerability
(eval-after-load "enriched"
'(defun enriched-decode-display-prop (start end &optional param)
(list start end)))
;; Set path to dependencies
(setq site-lisp-dir
(expand-file-name "site-lisp" user-emacs-directory))
(setq settings-dir
(expand-file-name "settings" user-emacs-directory))
;; Set up load path
(add-to-list 'load-path settings-dir)
(add-to-list 'load-path site-lisp-dir)
;; Keep emacs Custom-settings in separate file
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)
;; Set up appearance early
(require 'appearance)
;; Settings for currently logged in user
(setq user-settings-dir
(concat user-emacs-directory "users/" user-login-name))
(add-to-list 'load-path user-settings-dir)
;; Add external projects to load path
(dolist (project (directory-files site-lisp-dir t "\\w+"))
(when (file-directory-p project)
(add-to-list 'load-path project)))
;; Put backup files neatly away
(let ((backup-dir "~/.cache/tmp/emacs/backups")
(auto-saves-dir "~/.cache/tmp/emacs/auto-saves/"))
(dolist (dir (list backup-dir auto-saves-dir))
(when (not (file-directory-p dir))
(make-directory dir t)))
(setq backup-directory-alist `(("." . ,backup-dir))
auto-save-file-name-transforms `((".*" ,auto-saves-dir t))
tramp-backup-directory-alist `((".*" . ,backup-dir))
tramp-auto-save-directory auto-saves-dir))
(setq backup-by-copying t ; Don't delink hardlinks
delete-old-versions t ; Clean up the backups
version-control t ; Use version numbers on backups,
kept-new-versions 5 ; keep some new versions
kept-old-versions 2) ; and some old ones, too
;; Save point position between sessions
(require 'saveplace)
(setq-default save-place t)
(setq save-place-file (expand-file-name ".places" user-emacs-directory))
;; Setup packages
(require 'setup-package)
;(unless (version< emacs-version "24.4")
;; Install extensions if they're missing
(defun init--install-packages ()
(packages-install
'(wgrep
hydra
; paredit
move-text
htmlize
visual-regexp
markdown-mode
; fill-column-indicator
; flycheck
; flycheck-pos-tip
flx
f
flx-ido
; dired-details
; css-eldoc
; yasnippet
ido-vertical-mode
ido-at-point
simple-httpd
guide-key
; nodejs-repl
; restclient
highlight-escape-sequences
whitespace-cleanup-mode
elisp-slime-nav
; dockerfile-mode
groovy-mode
; prodigy
string-edit
; beginend
)))
(condition-case nil
(init--install-packages)
(error
(package-refresh-contents)
(init--install-packages)))
;; Lets start with a smattering of sanity
(require 'sane-defaults)
;; guide-key
(require 'guide-key)
(setq guide-key/guide-key-sequence '("C-x r" "C-x 4" "C-x v" "C-x 8" "C-x +"))
(guide-key-mode 1)
(setq guide-key/recursive-key-sequence-flag t)
(setq guide-key/popup-window-position 'bottom)
;; Setup extensions
(message "ido stuff")
(eval-after-load 'ido '(require 'setup-ido))
(eval-after-load 'org '(require 'setup-org))
;(eval-after-load 'dired '(require 'setup-dired))
(eval-after-load 'shell '(require 'setup-shell))
(require 'setup-rgrep)
(require 'setup-hippie)
;(require 'setup-perspective)
(require 'setup-ffip)
(require 'setup-html-mode)
;(unless (version< emacs-version "24.4")
; (eval-after-load 'magit '(require 'setup-magit))
; (beginend-global-mode))
;(require 'prodigy)
;(global-set-key (kbd "C-x M-m") 'prodigy)
; Font lock dash.el
(eval-after-load "dash" '(dash-enable-font-lock))
;(unless (version< emacs-version "24.4")
;; Default setup of smartparens
;(require 'smartparens-config)
;(setq sp-autoescape-string-quote nil)
;(--each '(css-mode-hook
; restclient-mode-hook
; js-mode-hook
; java-mode
; ruby-mode
; markdown-mode
; groovy-mode
; scala-mode)
; (add-hook it 'turn-on-smartparens-mode))
;)
;; Language specific setup files
;(eval-after-load 'markdown-mode '(require 'setup-markdown-mode))
;; Load stuff on demand
;(autoload 'skewer-start "setup-skewer" nil t)
;(autoload 'skewer-demo "setup-skewer" nil t)
;(autoload 'auto-complete-mode "auto-complete" nil t)
;(eval-after-load 'flycheck '(require 'setup-flycheck))
;; Map files to modes
(require 'mode-mappings)
(unless (version< emacs-version "24.4")
;; Visual regexp
(require 'visual-regexp)
(define-key global-map (kbd "M-&") 'vr/query-replace)
(define-key global-map (kbd "M-/") 'vr/replace)
)
;; Functions (load all files in defuns-dir)
(setq defuns-dir (expand-file-name "defuns" user-emacs-directory))
(dolist (file (directory-files defuns-dir t "\\w+"))
(when (file-regular-p file)
(load file)))
(require 'expand-region)
;(require 'multiple-cursors)
(require 'delsel)
;(require 'jump-char)
;(require 'eproject)
;(require 'smart-forward)
;(require 'change-inner)
;(require 'multifiles)
;; Don't use expand-region fast keys
(setq expand-region-fast-keys-enabled nil)
;; Show expand-region command used
(setq er--show-expansion-message t)
;; Fill column indicator
;(require 'fill-column-indicator)
;(setq fci-rule-color "#111122")
;; Browse kill ring
(require 'browse-kill-ring)
(setq browse-kill-ring-quit-action 'save-and-restore)
(message "loading smex")
; Smart M-x is smart
;(require 'smex)
;(smex-initialize)
;; Elisp go-to-definition with M-. and back again with M-,
(autoload 'elisp-slime-nav-mode "elisp-slime-nav")
(add-hook 'emacs-lisp-mode-hook (lambda () (elisp-slime-nav-mode t) (eldoc-mode 1)))
(message "dealing with server")
;; Emacs server
(require 'server)
(unless (server-running-p)
(server-start))
;; Run at full power please
(message "run at full power")
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
;; Conclude init by setting up specifics for the current user
(when (file-exists-p user-settings-dir)
(mapc 'load (directory-files user-settings-dir nil "^[^#].*el$")))
(message "eshell stuff")
(require 'eshell)
(require 'em-smart)
(setq eshell-where-to-jump 'begin)
(setq eshell-review-quick-commands nil)
(setq eshell-smart-space-goes-to-end t)
; eshell beginning of line fix
(defun eshell-maybe-bol ()
(interactive)
(let ((p (point)))
(eshell-bol)
(if (= p (point))
(beginning-of-line))))
(add-hook 'eshell-mode-hook
'(lambda () (define-key eshell-mode-map [home] 'eshell-maybe-bol)))
(message "global font lock")
;; turn on font-lock mode
(when (fboundp 'global-font-lock-mode)
(global-font-lock-mode t))
;; enable visual feedback on selections
(setq transient-mark-mode t)
;; default to better frame titles
(setq frame-title-format
(concat "%b - emacs@" (system-name)))
;; default to unified diffs
(setq diff-switches "-u")
;; always end a file with a newline
;(setq require-final-newline 'query)
(message "custom set variables")
(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.
'(ansi-color-names-vector
; ["black" "red" "green" "yellow" "blue" "magenta" "cyan" "white"])
["#212526" "#ff4b4b" "#b4fa70" "#fce94f" "#729fcf" "#ad7fa8" "#8cc4ff" "#eeeeec"]))
; '(custom-enabled-themes nil))
(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.
'(default ((t (:inherit nil :stipple nil :background "color-233" :foreground "color-251" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 1 :width normal :foundry "defaul\
;t" :family "default"))))
'(font-lock-comment-face ((t (:foreground "color-245"))))
'(font-lock-keyword-face ((t (:foreground "color-72"))))
;'(link ((t (:foreground "color-39" :underline t))))
'(minibuffer-prompt ((t (:foreground "color-41")))))
(message "auto mode alist")
(setq auto-mode-alist
(cons '("\\.m$" . octave-mode) auto-mode-alist))
(add-hook 'octave-mode-hook
(lambda ()
(abbrev-mode 1)
(auto-fill-mode 1)
(if (eq window-system 'x)
(font-lock-mode 1))))
(add-hook 'inferior-octave-mode-hook
(lambda ()
(turn-on-font-lock)
(define-key inferior-octave-mode-map [up]
'comint-previous-input)
(define-key inferior-octave-mode-map [down]
'comint-next-input)))
(defun RET-behaves-as-LFD ()
(let ((x (key-binding "C-j")))
(local-set-key "\C-m" x)))
(add-hook 'octave-mode-hook 'RET-behaves-as-LFD)
(autoload 'run-octave "octave-inf" nil t)
;; Make the shell open in the same window
(add-to-list 'display-buffer-alist
`(,(regexp-quote "*shell") display-buffer-same-window))
(require 'cl)
(message "gdb stuff")
;; For the consistency of gdb-select-window's calling convention...
(defun gdb-comint-buffer-name ()
(buffer-name gud-comint-buffer))
(defun gdb-source-buffer-name ()
(buffer-name (window-buffer gdb-source-window)))
(defun gdb-select-window (header)
"Switch directly to the specified GDB window.
Moves the cursor to the requested window, switching between
`gdb-many-windows' \"tabs\" if necessary in order to get there.
Recognized window header names are: 'comint, 'locals, 'registers,
'stack, 'breakpoints, 'threads, and 'source."
(interactive "Sheader: ")
(let* ((header-alternate (case header
('locals 'registers)
('registers 'locals)
('breakpoints 'threads)
('threads 'breakpoints)))
(buffer (intern (concat "gdb-" (symbol-name header) "-buffer")))
(buffer-names (mapcar (lambda (header)
(funcall (intern (concat "gdb-"
(symbol-name header)
"-buffer-name"))))
(if (null header-alternate)
(list header)
(list header header-alternate))))
(window (if (eql header 'source)
gdb-source-window
(or (get-buffer-window (car buffer-names))
(when (not (null (cadr buffer-names)))
(get-buffer-window (cadr buffer-names)))))))
(when (not (null window))
(let ((was-dedicated (window-dedicated-p window)))
(select-window window)
(set-window-dedicated-p window nil)
(when (member header '(locals registers breakpoints threads))
(switch-to-buffer (gdb-get-buffer-create buffer))
(setq header-line-format (gdb-set-header buffer)))
(set-window-dedicated-p window was-dedicated))
t)))
;; Use global keybindings for the window selection functions so that they
;; work from the source window too...
(mapcar (lambda (setting)
(lexical-let ((key (car setting))
(header (cdr setting)))
(global-set-key (concat "\C-c\C-g" key) #'(lambda ()
(interactive)
(gdb-select-window header)))))
'(("c" . comint)
("l" . locals)
("r" . registers)
("u" . source)
("s" . stack)
("b" . breakpoints)
("t" . threads)))
;; GTAGS stuff
;(setq load-path (cons "/usr/bin/global" load-path))
;(setq load-path (cons "/usr/bin/gtags" load-path))
;(setq load-path (cons "settings" load-path))
;(autoload 'gtags-mode "gtags" "" t)
(defun my-ido-find-tag ()
"Find a tag using ido"
(interactive)
(tags-completion-table)
(let* ((initial-input
(funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default)))
(initial-input-regex (concat "\\(^\\|::\\)" initial-input "$")))
(find-tag (ido-completing-read
"Tag: "
(sort
(remove nil
(mapcar (lambda (tag) (unless (integerp tag)
(prin1-to-string tag 'noescape)))
tags-completion-table))
;; put those matching initial-input first:
(lambda (a b) (string-match initial-input-regex a)))
nil
'require-match
initial-input))))
(eval-after-load 'shell
'(define-key shell-mode-map (kbd "M-?") 'ignore))
(ido-mode 0)
(ido-mode 1)