-
Notifications
You must be signed in to change notification settings - Fork 0
/
.emacs
338 lines (278 loc) · 14 KB
/
.emacs
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
;; absolute path of ~/.emacs.d
(setq emacs-home (expand-file-name (concat (getenv "HOME") "/.emacs.d/")))
;; disable welcome screen
(setq inhibit-startup-screen t)
;; =============================================================================
;; =========================== melpa package manager ===========================
;; =============================================================================
;; melpa package repository for extra packages
(require 'package)
;; run 'M-x package-refresh-contents RET' to get the melpa packages
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
;; =============================================================================
;; ============================== auto generated ===============================
;; =============================================================================
;; 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.
(package-initialize)
(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-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(custom-enabled-themes '(tsdh-dark))
'(package-selected-packages
'(yasnippet company-rtags company-quickhelp use-package grip-mode cmake-ide undo-fu highlight-indent-guides conda blacken company-web web-mode impatient-mode clang-format multi-term company-irony-c-headers helm-rtags flycheck-rtags rtags ein diff-hl neotree flycheck-irony flycheck-mypy pylint flycheck magit helm-projectile ggtags company-irony irony projectile yaml-mode s dash dictcc helm-gtags helm-themes helm cmake-mode company company-jedi jedi epc markdown-mode flyspell-popup xclip)))
(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.
'(ediff-current-diff-A ((t (:foreground "White" :background "brown"))))
'(ediff-even-diff-A ((t (:background "blue"))))
'(ediff-even-diff-Ancestor ((t (:background "blue"))))
'(ediff-even-diff-B ((t (:background "blue"))))
'(ediff-even-diff-C ((t (:background "blue"))))
'(ediff-odd-diff-A ((t (:background "blue"))))
'(ediff-odd-diff-Ancestor ((t (:background "blue"))))
'(ediff-odd-diff-B ((t (:background "blue"))))
'(ediff-odd-diff-C ((t (:background "blue"))))
'(term-color-blue ((t (:background "deep sky blue" :foreground "deep sky blue")))))
;; =============================================================================
;; =================== install packages via package manager ====================
;; =============================================================================
;; all packages, which have to installed via emacs package manager
(setq my-package-list '(blacken clang-format cmake-ide cmake-mode company company-irony company-irony-c-headers company-jedi
company-rtags company-quickhelp company-web conda dictcc diff-hl dash ein epc ggtags grip-mode
flycheck flycheck-irony flycheck-mypy flycheck-rtags
flymake-shellcheck
flyspell-popup helm helm-gtags helm-rtags helm-projectile
helm-themes highlight-indent-guides
impatient-mode irony yasnippet jedi magit markdown-mode
multi-term neotree projectile
rtags s undo-fu use-package web-mode yaml-mode xclip))
;; The file run_melpa contains the variable run-melpa. If the variable is true,
;; new packages must be installed.
;; The var is set by the setup.py script.
(load (concat emacs-home "run_melpa.el"))
(when run-melpa
(progn
(unless package-archive-contents
(package-refresh-contents))
(dolist (my-package my-package-list)
(unless (package-installed-p my-package)
(progn
(package-install my-package)
(message "install package: %s" my-package)
)))
;; Set the variable to nil, otherwise all packages will be checked at
;; every start, which unnecessarily increases the start time.
(write-region "(setq run-melpa nil)\n" nil (concat emacs-home "run_melpa.el")
)))
;; =============================================================================
;; ================ load emacs lisp functions from extra files ================
;; =============================================================================
;; the directory contains packages which are not available at the package manager
(setq load-path (cons (concat emacs-home "lisp") load-path))
;; self-defined general functions
(load-file (concat emacs-home "lisp/help_function/autoload.el"))
;; configuration for different modes
(dolist (config (directory-files (concat emacs-home "modes") t ".el"))
(load-file config))
;; loads host-dependent configurations, which are generated by the setup.py script
(load-file (concat emacs-home "setup_generated.el"))
;; loads host-dependent configurations, e.g. paths to executables
(if (file-exists-p (concat emacs-home "local-vars.el"))
(load-file (concat emacs-home "local-vars.el")))
;; =============================================================================
;; =============================== enable modes ================================
;; =============================================================================
(require 'use-package)
;; the ido mode improve the path navigation in the mini buffer
(require 'ido)
(ido-mode t)
;; add llvm ir highlighting
;; from offical repo: https://github.com/llvm-mirror/llvm/tree/e74acf4ba7bb2df0b2a04548061b4c886efc368a/utils/emacs
(require 'llvm-mode)
;; symon is a hardware monitor, which display cpu, memory usage and more in the mini-buffer
;; https://github.com/zk-phi/symon
(require 'symon)
;; helm is a framework, which improve the UI of emacs
;; https://github.com/emacs-helm/helm
(require 'helm)
(helm-mode t)
;; company is a backend for auto completion in different modes (https://company-mode.github.io/)
(require 'company)
(add-hook 'after-init-hook 'global-company-mode)
;; register different company backends
(let ((company-backends-to-enable
'(company-cmake
;; add new backend
)))
(dolist (backend company-backends-to-enable)
(add-to-list 'company-backends backend))
(eval-after-load 'company 'company-backends)
)
;; this package enables a function to display the function documentation during running company completion
;; run `M-x company-show-doc-buffer` to verify if your company backend supports this
(company-quickhelp-mode)
;; library to managing projects, e.g a git repo is a project
(require 'projectile)
(setq projectile-indexing-method 'hybrid)
(setq projectile-sort-order 'recentf)
;; enable helm extension for projectile
(require 'helm-projectile)
(helm-projectile-on)
;; flycheck allows to highlight warnings and errors in the source code using external tools
(require 'flycheck)
(add-hook 'after-init-hook #'global-flycheck-mode)
;; diff-hl is a plugin which show git diff inside the buffer
;; highlight works just in GUI mode, navigation also in terminal
(require 'diff-hl)
(global-diff-hl-mode)
;; use flycheck to update highlight without saving file
(diff-hl-flydiff-mode)
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
;; emacs ipython notebook (ein)
;; the polymode allows to display markdown cells in notebooks
(setq ein:polymode t)
(add-hook 'rst-mode-hook 'sphinx-build-mode)
(require 'conda)
;; add indentation highlighting in buffers
(require 'highlight-indent-guides)
;; configure style
(set-face-background 'highlight-indent-guides-odd-face "darkgray")
(set-face-background 'highlight-indent-guides-even-face "dimgray")
(set-face-foreground 'highlight-indent-guides-character-face "dimgray")
(setq highlight-indent-guides-method 'character)
;; setup modes with indentation highlighting
(add-hook 'yaml-mode-hook 'highlight-indent-guides-mode)
(add-hook 'python-mode-hook 'highlight-indent-guides-mode)
;; enable yasnippet
(require 'yasnippet)
(yas-global-mode 1)
;; =============================================================================
;; =========================== configure main usage ============================
;; =============================================================================
;; enable c++-mode at cuda cu.files
(add-to-list 'auto-mode-alist '("\\.cu\\'" . c++-mode))
;; enable sh-mode at singularity .def recipe
(add-to-list 'auto-mode-alist '("\\.def\\'" . sh-mode))
;; enable copy/paste between emacs and x11
;; to install use following command in emcas (RET means key enter): M-x package-install RET xclip RET
;; the enable_xclip variable is generated by the setup.py script and located in setup_generated.el
(if (= enable_xclip 1)
(progn
(xclip-mode 1)
(setq select-enable-clipboard t)
)
()
)
;; show cursor position within line
(column-number-mode 1)
(if (= flyspell-enable 1)
(progn
;; enable on the fly spellcheck
;; spellcheck for the complete text
(add-hook 'text-mode-hook 'flyspell-mode)
;; spellcheck just for comments and strings (depends on the prog language)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
;; when this mode is enabled, the spellchecker pop menu opens if the cursor stays on the wrong word for more than one second
(add-hook 'flyspell-mode-hook #'flyspell-popup-auto-correct-mode)
))
(setq ediff-split-window-function 'split-window-horizontally)
;; disable scroll bar in GUI mode
(scroll-bar-mode -1)
;; allows to load every .dir-locals.el
;; can be a secure problem
;; by default, safe (system-dependent) variables are stored in the .emacs.
(setq enable-local-variables :all)
;; =============================================================================
;; ============================ global key bindings ============================
;; =============================================================================
;; replace the default emacs functions and do the same things without kill-ring
;; bind them to emacs's default shortcut keys:
(global-set-key (kbd "C-j") 'my-delete-line-backward) ; Ctrl+Shift+k
(global-set-key (kbd "C-k") 'my-delete-line)
(global-set-key (kbd "<C-delete>") 'my-delete-word)
(global-set-key (kbd "<M-DEL>") 'my-backward-delete-word)
;; swap shortcut of move to begin and move to indentation
(global-set-key (kbd "M-m") 'move-beginning-of-line)
(global-set-key (kbd "C-a") 'back-to-indentation)
;; shortcut to open the spellcheck pop-menu
(global-set-key (kbd "M-$") 'flyspell-popup-correct)
;; open company completion popup
(global-set-key (kbd "M-#") 'company-complete)
;; windmove is a built-in function that allows you to change the window selectively
;; it improves the functionality of 'C-x o'.
(global-set-key (kbd "C-c <left>") 'windmove-left)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <up>") 'windmove-up)
(global-set-key (kbd "C-c <down>") 'windmove-down)
;; if the C-c bindings are overwritten by another mode
(global-set-key (kbd "C-x C-<left>") 'windmove-left)
(global-set-key (kbd "C-x C-<right>") 'windmove-right)
(global-set-key (kbd "C-x C-<up>") 'windmove-up)
(global-set-key (kbd "C-x C-<down>") 'windmove-down)
;; the original shortcut is M-|
;; but some German keyboards are too cheep to execute this combination
(global-set-key (kbd "M-_") 'shell-command-on-region)
;; original shortcut is C-x z
(global-set-key (kbd "M-<f3>") 'repeat)
;; another shortcut for switching framework
(global-set-key (kbd "C-x <down>") 'other-frame)
;; another shortcut for comment-line
(global-set-key (kbd "C-x ;") 'comment-line)
;; add shortcut to the dired-mode
(add-hook
'dired-mode-hook
(lambda()
(define-key dired-mode-map "J" 'ido-dired)))
;; replace default emacs functions with helm functions
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-x r b") #'helm-filtered-bookmarks)
(global-set-key (kbd "C-x C-f") #'helm-find-files)
(global-set-key (kbd "C-x b") #'helm-buffers-list)
;; run dictcc translation
(global-set-key (kbd "M-ü") 'dictcc)
;; allow smart completion with <TAB>
(define-key helm-map (kbd "TAB") 'helm-execute-persistent-action)
;; set prefix key binding for every projectile command
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
(projectile-mode +1)
;; run magit status command
(global-set-key (kbd "C-x g") 'magit-status)
(global-set-key (kbd "<f8>") 'neotree-toggle)
(global-unset-key (kbd "C-_"))
(global-set-key (kbd "C-_") 'undo-fu-only-undo)
(global-set-key (kbd "C-:") 'undo-fu-only-redo)
;; =============================================================================
;; =================================== other ===================================
;; =============================================================================
;; save all backup files to a central directory
(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
backup-by-copying t ; Don't delink hardlinks
version-control t ; Use version numbers on backups
delete-old-versions t ; Automatically delete excess backups
kept-new-versions 20 ; how many of the newest versions to keep
kept-old-versions 5 ; and how many of the old
)
;; remove trailing whitespaces in source code files
(defun nuke_traling ()
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
(add-hook 'prog-mode-hook #'nuke_traling)
(add-hook 'markdown-mode-hook #'nuke_traling)
(add-hook 'rst-mode-hook #'nuke_traling)
;; =============================================================================
;; ================================== Macros ===================================
;; =============================================================================
;; load macros from file and maybe bind to key
;; (load-file "~/.emacs.d/macros/gen.macs")
;; (global-company-mode "\C-x\C-kT" 'myMacro)