-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathinit.el
436 lines (366 loc) · 20 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
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
;;; init.el --- Make Emacs useful!
;;; Author: Vedang Manerikar
;;; Created on: 10 Jul 2016
;;; Commentary:
;; This file is a bare minimum configuration file to enable working
;; with Emacs for Helpshift newcomers.
;;; Code:
(when (version< emacs-version "27")
(error "Unsupported Emacs Version! Please upgrade to a newer Emacs. Emacs installation instructions: https://www.gnu.org/software/emacs/download.html"))
(defvar emacs-up--version "v3.5.0"
"The current version of the Emacs Up Starter Kit.")
(defun emacs-up-version ()
"Return the current version of the Emacs Up Starter Kit."
(interactive)
(message "Emacs Up %s" emacs-up--version))
;; Set a directory for temporary/state related files.
(defvar dotfiles-dirname
(file-name-directory (or load-file-name
(buffer-file-name)))
"The directory where this code is running from.
Ideally, this will be ~/.emacs.d.")
(defvar tempfiles-dirname
(concat dotfiles-dirname "temp-files/")
"A sub-directory to hold temporary files generated by Emacs.")
;; Create the temp-files folder if necessary.
(make-directory tempfiles-dirname t)
;;; El-Get for great good.
(defvar el-get-dir
(concat dotfiles-dirname "el-get/")
"The sub-directory where el-get packages are installed.")
(defvar el-get-user-package-directory
(concat dotfiles-dirname "el-get-config/")
"The sub-directory where optional user-configuration for various packages, and user-defined recipes live.")
(defvar el-get-my-recipes
(concat el-get-user-package-directory "personal-recipes/")
"The sub-directory where user-defined recipes live, if the user needs to define and install his/her own recipes.")
;; Make the el-get directories if required
(make-directory el-get-dir t)
(make-directory el-get-my-recipes t)
;; Add el-get to the load-path. From this point onward, we're plugged
;; into the el-get package management system.
(add-to-list 'load-path (concat el-get-dir "el-get"))
;; Install el-get if it isn't already present
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.github.com/dimitri/el-get/master/el-get-install.el")
(let ((el-get-git-install-url "https://github.com/vedang/el-get.git")
(el-get-install-branch "rcp/add-update-rcps")
el-get-install-skip-emacswiki-recipes)
(goto-char (point-max))
(eval-print-last-sexp))))
;; Add our personal recipes to el-get's recipe path
(add-to-list 'el-get-recipe-path el-get-my-recipes)
(with-eval-after-load 'info
(progn
(info-initialize)
(add-to-list 'Info-directory-list
(concat el-get-dir "el-get/"))))
;;; Load packaging info for clojure
(defvar clj-packages-file
(concat dotfiles-dirname "hs-clj-packages.el")
"Information about packages to be installed for Clojure development.
Also contains along with versions and other config.")
(load clj-packages-file)
;;; This is the order in which the packages are loaded. Changing this
;;; order can sometimes lead to nasty surprises: eg: when you are
;;; overshadowing some in-built libraries or when you expect a package
;;; to already be loaded in order to fix system paths (*cough*
;;; `exec-path-from-shell' *cough*)
(setq el-get-sources
(append
(when (and (eq system-type 'darwin)
(eq window-system 'ns))
;; Emacs plugin for dynamic PATH loading - Fix Emacs's
;; understanding of the the Path var on Mac.
'((:name exec-path-from-shell
:after (progn (exec-path-from-shell-initialize)))))
'(;; Jump to things in Emacs tree-style.
(:name avy
:after (progn (global-set-key (kbd "M-g C-j") 'avy-resume)
(global-set-key (kbd "M-g g") 'avy-goto-line)
(global-set-key (kbd "M-g SPC") 'avy-goto-word-1)
(avy-setup-default)))
;; Fixing weird quirks and poor defaults
(:name better-defaults)
(:name plantuml-mode
:after (progn (setq plantuml-default-exec-mode 'jar)
(add-to-list 'auto-mode-alist
'("\\.puml$" . plantuml-mode))))
;; A low contrast color theme for Emacs.
(:name color-theme-zenburn)
;; Modular in-buffer completion framework for Emacs
(:name company-mode
:after (progn (require 'company)
(add-hook 'after-init-hook #'global-company-mode)
(setq company-require-match nil
company-tooltip-align-annotations t)
(with-eval-after-load 'company
(setq-default company-lighter " cmp")
(define-key company-active-map
(kbd "TAB") 'company-complete))))
;; an Emacs jump to definition package for 40+ languages
(:name dumb-jump
:after (progn (dumb-jump-mode)
(add-hook 'xref-backend-functions #'dumb-jump-xref-activate)
(define-key dumb-jump-mode-map (kbd "C-c d g") 'dumb-jump-go)
(define-key dumb-jump-mode-map (kbd "C-c d b") 'dumb-jump-back)
;; Don't mess with the default indentation
;; keybinding
(define-key dumb-jump-mode-map (kbd "C-M-q") nil)
(define-key dumb-jump-mode-map (kbd "C-M-p") nil)
(setq dumb-jump-selector 'popup
dumb-jump-prefer-searcher 'rg)))
;; On-the-fly syntax checking
(:name flycheck
:after (progn (setq flycheck-global-modes '(not org-mode)
flycheck-emacs-lisp-load-path 'inherit)
(global-flycheck-mode)))
(:name flycheck-inline
:after (with-eval-after-load 'flycheck
(add-hook 'flycheck-mode-hook #'flycheck-inline-mode)))
;; Emacs incremental completion and narrowing framework
(:name helm
:after (progn
(require 'helm-config)
(setq helm-reuse-last-window-split-state t
helm-move-to-line-cycle-in-source t
helm-ff-file-name-history-use-recentf t
helm-buffers-fuzzy-matching t
helm-recentf-fuzzy-match t
helm-mini-default-sources '(helm-source-buffers-list
helm-source-recentf
helm-source-bookmarks
helm-source-buffer-not-found)
helm-grep-ag-command
"rg --color=always --colors 'match:style:underline' --colors 'match:bg:black' --colors 'match:fg:white' --smart-case --no-heading --line-number %s %s %s")
(helm-define-key-with-subkeys global-map
(kbd "C-c n") ?n 'helm-cycle-resume)
(helm-mode +1)
;; Add `ido-completing-read' functions for
;; things that don't have default values in
;; `helm-completing-read-handlers-alist'.
(push '(describe-function . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(describe-variable . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(describe-symbol . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(debug-on-entry . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(find-function . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(disassemble . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(trace-function . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(trace-function-foreground . ido-completing-read)
helm-completing-read-handlers-alist)
(push '(trace-function-background . ido-completing-read)
helm-completing-read-handlers-alist)
;; Remember helm candidate preferences.
(require 'helm-adaptive)
(setq helm-adaptive-history-file nil)
(helm-adaptive-mode +1)
(require 'helm-utils)
(helm-popup-tip-mode +1)
(setq helm-highlight-matches-around-point-max-lines '(30 . 30)
helm-window-show-buffers-function #'helm-window-mosaic-fn)
(add-hook 'find-file-hook #'helm-save-current-pos-to-mark-ring)
(require 'helm-info)
(global-set-key (kbd "C-h r") #'helm-info-emacs)
;; I want to use `helm-mini' and
;; `helm-find-files' as my primary entry
;; point into helm.
(global-set-key (kbd "C-x b") 'helm-mini)
(global-set-key (kbd "C-x C-f") 'helm-find-files)
;; Useful Helm Defaults: C-x c i, C-x c I
;; unset this because I plan to use it as a prefix key.
(global-set-key (kbd "C-x c r") nil)
(global-set-key (kbd "C-x c r b") 'helm-filtered-bookmarks)
(global-set-key (kbd "C-x c r r") 'helm-regexp)
(global-set-key (kbd "M-y") 'helm-show-kill-ring)
(global-set-key (kbd "C-x c SPC") 'helm-all-mark-rings)
(global-set-key (kbd "C-h SPC") 'helm-all-mark-rings)
(global-set-key (kbd "C-x c r i") 'helm-register)
;; I want to use <C-x c p> for helm-projectile
(global-set-key (kbd "C-x c P") 'helm-list-emacs-process)
;; rebind tab to run persistent action. now
;; <tab> and <C-j> will both perform
;; persistent actions
(define-key helm-map (kbd "<tab>")
'helm-execute-persistent-action)
(when (executable-find "curl")
(setq helm-net-prefer-curl t))
(with-eval-after-load 'projectile
(defun helm-do-grep-project-root (&optional with-types)
"Search in current project with. With WITH-TYPES, ask for file
types to search in. Uses `projectile'."
(interactive "P")
(let ((default-directory (projectile-project-root)))
(call-interactively 'helm-do-grep-ag)))
(global-set-key (kbd "C-x c g a") 'helm-do-grep-project-root)
(global-set-key (kbd "C-c s") 'helm-do-grep-project-root))
(defun helm-do-grep-ag-with-directory (dir)
"Do `helm-do-grep-ag' with `default-directory' set to DIR."
(interactive "DDirectory to search in: ")
(let ((default-directory dir))
(call-interactively 'helm-do-grep-ag)))
(global-set-key (kbd "C-x c g s") 'helm-do-grep-ag)
(global-set-key (kbd "C-x c g g") 'helm-do-grep-ag-with-directory)))
(:name helm-descbinds
:after (progn (require 'helm-descbinds)
(helm-descbinds-mode)))
(:name helm-projectile
:before (progn (setq projectile-keymap-prefix (kbd "C-x c p")))
:after (progn (require 'helm-projectile)
(projectile-mode)
(setq projectile-completion-system 'helm
projectile-switch-project-action 'helm-projectile
projectile-enable-caching t
projectile-cache-file (concat tempfiles-dirname "projectile.cache")
projectile-known-projects-file (concat tempfiles-dirname "projectile-bookmarks.eld")
projectile-mode-line '(:eval (if (file-remote-p default-directory)
" "
(format " Ptl[%s]"
(projectile-project-name)))))
(helm-projectile-on)))
;; Use ido (nearly) everywhere
;; settings for this package are loaded below in the ido section.
(:name ido-completing-read-plus)
;; It's Magit! An Emacs mode for Git.
(:name magit
:after (progn (global-set-key (kbd "C-x g") 'magit-status)
(setq magit-completing-read-function
#'helm--completing-read-default
magit-diff-refine-hunk t
magit-diff-refine-ignore-whitespace nil)
(with-eval-after-load 'info
(info-initialize)
(add-to-list 'Info-directory-list
(concat el-get-dir "magit/")))))
;; Minor mode for editing parentheses
(:name paredit
:after (progn (defvar paredit-major-modes
'(emacs-lisp-mode lisp-mode clojure-mode
cider-repl-mode ielm-mode)
"List of modes where I want paredit to always work.")
;; hideshow.el does not have anything to
;; do with paredit, but I want the
;; minor-mode to be loaded in exactly
;; the same places as paredit. Hence
;; adding the coniguration here.
(load-library "hideshow")
(require 'hideshow)
(load-library "paren")
(require 'paren)
(require 'paredit)
(defun turn-on-paredit ()
"Utility function to turn on Paredit."
(paredit-mode 1)
(show-paren-mode 1)
(hs-minor-mode 1))
(setq show-paren-style 'mixed)
(dolist (m paredit-major-modes)
(add-hook `,(intern (concat (symbol-name m) "-hook"))
#'turn-on-paredit))
(with-eval-after-load 'paredit
(define-key paredit-mode-map (kbd "C-o") 'paredit-open-round))
(with-eval-after-load 'hideshow
;; Unbind `C-h' this should only be used for help.
(define-key hs-minor-mode-map (kbd "C-c @ C-h") nil)
(define-key hs-minor-mode-map (kbd "C-c @ @") 'hs-toggle-hiding)
(define-key hs-minor-mode-map (kbd "C-c @ 2") 'hs-toggle-hiding))))
;; Major mode for plantUML
(:name plantuml-mode
:after (progn (setq plantuml-default-exec-mode 'jar)
(add-to-list 'auto-mode-alist
'("\\.puml$" . plantuml-mode))))
;; Format JS, JSX files on save event.
;; Prerequisite: npm install -g prettier`
(:name prettier-js
:after (add-hook 'rjsx-mode-hook #'prettier-js-mode))
;; Major mode for JSX and JS files
(:name rjsx-mode
:after (progn (add-to-list 'auto-mode-alist '("\\.js\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . rjsx-mode))
(add-to-list 'auto-mode-alist '("\\.json\\'" . rjsx-mode))
(setq js2-basic-offset 2
js-switch-indent-offset 2)))
;; M-x interface with Ido-style fuzzy matching.
(:name smex
:after (progn (smex-initialize)
(global-set-key (kbd "M-x") 'smex)))
;; A collection of snippets for repetitive stuff
(:name yasnippet
:after (progn (yas-global-mode 1)
(add-to-list 'hippie-expand-try-functions-list
'yas-hippie-try-expand)))
(:name yasnippet-snippets)
(:name yatemplate
:after (progn (auto-insert-mode +1))))
(cond
;; Set up recipes to support development against older
;; Clojure versions
((equal "clj16-" clj-version)
(progn (hs-cleanup-previous-install-if-necessary)
(hs-clojure16-env)))
;; Set up recipes to support development against Clojure
;; version 1.7
((equal "clj17" clj-version)
(progn (hs-cleanup-previous-install-if-necessary)
(hs-clojure17-env)))
;; Latest Clojure
((equal "clj18+" clj-version)
(progn (hs-cleanup-previous-install-if-necessary)
(hs-latest-stable-clojure-env))))))
(el-get 'sync
(mapcar 'el-get-source-name el-get-sources))
(hs-store-clojure-env-ver)
;; Modify the CMD key to be my Meta key
(setq mac-command-modifier 'meta)
;;; Recentf settings
;; Use recentf via helm, invoke it with <C-x c C-c f>
(require 'recentf)
(setq recentf-exclude (list (concat tempfiles-dirname "*"))
recentf-save-file (concat tempfiles-dirname "recentf")
recentf-max-saved-items 1000
recentf-max-menu-items 1000
recentf-menu-filter 'recentf-show-basenames)
(recentf-mode 1)
;;; Interactively Do Things
;; Ido settings
(require 'ido)
(require 'ido-completing-read+)
(setq ido-enable-flex-matching t
ido-use-virtual-buffers t
ido-create-new-buffer 'always
ido-save-directory-list-file (concat tempfiles-dirname "ido.last"))
(add-hook 'ido-make-buffer-list-hook 'ido-summary-buffers-to-end)
;;; Saveplace Settings
(require 'saveplace)
(require 'savehist)
(setq save-place-file (concat tempfiles-dirname "places"))
(save-place-mode 1)
(savehist-mode 1)
;;; Desktop Settings
(require 'desktop)
(add-to-list 'desktop-path tempfiles-dirname)
;; Move Emacs state into the temp folder we've created.
(setq backup-directory-alist `(("." . ,(concat tempfiles-dirname "backups"))))
;; Turn off the anoying bell sound
(setq visible-bell t)
;; Theme and Look
;; This should load after `custom-safe-themes' to avoid Emacs
;; panicking about whether it is safe or not.
(load-theme 'zenburn t)
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(require 'package)
(package-initialize)
(server-start)
(provide 'init)
;;; init.el ends here