-
Notifications
You must be signed in to change notification settings - Fork 0
/
.emacs
executable file
·354 lines (290 loc) · 11.1 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
;; config --- kyukhin's Emacs config
;;; Commentary:
;;; A custom flag set
(setq-default display-fill-column-indicator-column 80)
(global-display-fill-column-indicator-mode 1)
;; Activate installed packages
(require 'package)
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives
'("gnu" . "http://elpa.gnu.org/packages/")
'("org" . "http://orgmode.org/elpa/")))
(defun ensure-package-installed (&rest packages)
"Assure every package is installed, ask for installation if it’s not.
Return a list of installed packages or nil for every skipped package."
(mapcar
(lambda (package)
;; (package-installed-p 'evil)
(if (package-installed-p package)
nil
(if (y-or-n-p (format "Package %s is missing. Install it? " package))
(package-install package)
package)))
packages))
;; make sure to have downloaded archive description.
;; Or use package-archive-contents as suggested by Nicolas Dudebout
(or (file-exists-p package-user-dir)
(package-refresh-contents))
(ensure-package-installed 'buffer-move
'mo-git-blame
'solarized-theme
'whitespace
'magit
'irony
'company
'company-irony
'flycheck
'flycheck-irony
)
;; Enable speller
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'prog-mode-hook 'flyspell-prog-mode)
;; Auto complete
(add-hook 'c++-mode-hook 'company-mode)
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'company-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'company-mode)
(add-hook 'objc-mode-hook 'irony-mode)
;; Start rdm server if it isn't
(add-hook 'c-mode-hook 'rtags-start-process-unless-running)
(add-hook 'c++-mode-hook 'rtags-start-process-unless-running)
(add-hook 'objc-mode-hook 'rtags-start-process-unless-running)
(defun my-cdb-load ()
(irony-cdb-json-add-compile-commands-path "/export/kyukhin/tarantool/src" "/export/kyukhin/tarantool/bld/compile_commands.json")
)
(my-cdb-load)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options)
(require 'rtags)
(rtags-enable-standard-keybindings)
;
; Company mode: autocompletion
(defvar company-backends)
(eval-after-load 'company
'(add-to-list 'company-backends 'company-irony))
;; Show function in status
(which-function-mode 1)
;; Indent
;(defvar blank-style)
(defun maybe-sqlite-style ()
(c-set-style "Linux")
(company-mode)
(irony-cdb-json-select-most-recent)
(irony-mode))
;)
(add-hook 'c-mode-hook 'maybe-sqlite-style)
(add-hook 'c++-mode-hook 'maybe-sqlite-style)
(display-time-mode 1)
;; only run this if rtags is installed
(defvar c-mode-base-map)
(when (require 'rtags nil :noerror)
;; make sure you have company-mode installed
(define-key c-mode-base-map (kbd "M-.")
(function rtags-find-symbol-at-point))
(define-key c-mode-base-map (kbd "M-,")
(function rtags-find-references-at-point))
(define-key c-mode-base-map (kbd "M-u")
(function rtags-location-stack-back))
;; install standard rtags keybindings. Do M-. on the symbol below to
;; jump to definition and see the keybindings.
(rtags-enable-standard-keybindings))
;; IRC client.
(defvar erc-log-channels-directory)
(setq erc-log-channels-directory "~/.erc/logs/")
(defvar erc-save-buffer-on-part)
(setq erc-save-buffer-on-part t)
(defvar erc-hide-timestamps)
(setq erc-hide-timestamps t)
(defvar conf-shell nil "No shell mode")
(defvar erc-autojoin-channels-alist)
(defun erc-fn (switch)
(message "IRC mode for emacs.")
(setq erc-autojoin-channels-alist
'(("freenode.net" "#maria" "#maria-dev")
("oftc.net" "#gcc")))
(erc :server "irc.freenode.net" :port 6667 :nick "kyukhin")
(erc :server "irc.oftc.net" :port 6667 :nick "kyukhin"))
(defun shell-fn (switch)
(message "Shells will start")
(setq conf-shell t))
(add-to-list 'command-switch-alist '("-erc" . erc-fn))
(add-to-list 'command-switch-alist '("-shell" . shell-fn))
(require 'buffer-move)
(load-theme 'solarized-light t)
(add-to-list 'auto-mode-alist '("/mutt" . mail-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . lisp-mode))
;; mo-git-blame
(autoload 'mo-git-blame-file "mo-git-blame" nil t)
(autoload 'mo-git-blame-current "mo-git-blame" nil t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq keyboard-type 'xterm-color)
(defun tabs-on () (setq indent-tabs-mode t))
(defun tabs-off () (setq indent-tabs-mode nil))
(defvar lua-indent-level)
(setq lua-indent-level 4)
(add-hook 'lua-mode-hook 'tabs-off)
(setq make-backup-files nil)
(setq column-number-mode 1)
(normal-erase-is-backspace-mode 0)
(if (fboundp 'scroll-bar-mode ) (scroll-bar-mode -1))
(if (fboundp 'tool-bar-mode ) (tool-bar-mode -1))
(if (fboundp 'menu-bar-mode ) (menu-bar-mode -1))
(if (fboundp 'global-font-lock-mode) (global-font-lock-mode 1))
(setq scroll-preserve-screen-position 1 )
(setq scroll-step 1 )
(setq scroll-conservatively 20)
(global-set-key "\C-s" 'isearch-forward-regexp )
(global-set-key "\C-r" 'isearch-backward-regexp)
;;; View tags other window
(defun view-tag-other-window (tagname &optional next-p regexp-p)
"Same as `find-tag-other-window' but doesn't move the point"
(interactive (find-tag "View tag other window: "))
(let ((window (get-buffer-window)))
(find-tag-other-window tagname next-p regexp-p)
(recenter 0)
(select-window window)))
(global-set-key [f1] 'revert-buffer)
(global-set-key [f2] 'buf-move-down)
(global-set-key [f3] 'whitespace-mode)
(global-set-key [f4] 'view-tag-other-window)
(global-set-key [f5] 'goto-line)
(global-set-key [f6] 'compile)
; (global-set-key [f6] 'ispell-region)
; (global-set-key [f7] 'ispell-buffer)
(global-set-key [f8] 'delete-trailing-whitespace)
(global-set-key [f9] 'comment-region)
(global-set-key [f10] 'uncomment-region)
(global-set-key [f11] 'magit-status)
(global-set-key [f12] 'search-word-under-cursor-forward)
; Swapping buffers
(global-set-key (kbd "<S-up>") 'buf-move-up)
(global-set-key (kbd "<S-down>") 'buf-move-down)
(global-set-key (kbd "<S-left>") 'buf-move-left)
(global-set-key (kbd "<S-right>") 'buf-move-right)
; Kill whole line w/ Alt+k
(global-set-key (kbd "M-k") 'kill-whole-line)
(defun search-word-under-cursor-backward ()
(interactive)
(search-backward (current-word)))
(defun search-word-under-cursor-forward ()
(interactive)
(search-forward (current-word)))
(defun kyukhin-remove-dos-eol ()
"Removes the disturbing '^M' showing up in files containing mixed UNIX and DOS line endings."
(interactive)
(setq buffer-display-table (make-display-table))
(aset buffer-display-table ?\^M []))
(put 'upcase-region 'disabled nil)
(eval-after-load 'diff-mode
'(progn
(set-face-foreground 'diff-added "green4")
(set-face-foreground 'diff-removed "red3")))
;; Usage: emacs -diff file1 file2
(defun command-line-diff (switch)
(let ((file1 (pop command-line-args-left))
(file2 (pop command-line-args-left)))
(ediff file1 file2)))
(add-to-list 'command-switch-alist '("diff" . command-line-diff))
(add-hook 'perl-mode-hook 'n-cperl-mode-hook t)
(defvar cperl-indent-level)
(defvar cperl-continued-statement-offset)
(defvar cperl-extra-newline-before-brace)
(defun n-cperl-mode-hook ()
(setq cperl-indent-level 4)
(setq indent-tabs-mode nil)
(setq cperl-continued-statement-offset 0)
(setq cperl-extra-newline-before-brace t)
)
;; Команды емаксу в русской раскладке.
(defvar quail-keyboard-layout)
(defun reverse-input-method (input-method)
"Build the reverse mapping of single letters from INPUT-METHOD."
(interactive
(list (read-input-method-name "Use input method (default current): ")))
(if (and input-method (symbolp input-method))
(setq input-method (symbol-name input-method)))
(let ((current current-input-method)
(modifiers '(nil (control) (meta) (control meta))))
(when input-method
(activate-input-method input-method))
(when (and current-input-method quail-keyboard-layout)
(dolist (map (cdr (quail-map)))
(let* ((to (car map))
(from (quail-get-translation
(cadr map) (char-to-string to) 1)))
(when (and (characterp from) (characterp to))
(dolist (mod modifiers)
(define-key local-function-key-map
(vector (append mod (list from)))
(vector (append mod (list to)))))))))
(when input-method
(activate-input-method current))))
(reverse-input-method "russian-computer")
(defun start-shells-fn ()
"Starts shells if launched with -shell option."
(if conf-shell
(progn
(split-window-vertically)
(select-window (next-window (selected-window)))
(shell "*shell*")
;; Don't ask about active buffers upon exit.
(set-process-query-on-exit-flag (get-process "shell") nil)
(rename-buffer "bld")
(shell "*shell*")
(set-process-query-on-exit-flag (get-process "shell<1>") nil)
(rename-buffer "aux")
;;(switch-to-buffer-other-window "aux")
(add-hook 'comint-exec-hook
(lambda () (set-process-query-on-exit-flag (get-buffer-process (current-buffer)) nil)))
)
)
)
(add-hook 'emacs-startup-hook 'start-shells-fn)
(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.
'(custom-safe-themes
'("8aebf25556399b58091e533e455dd50a6a9cba958cc4ebb0aab175863c25b9a4" "d677ef584c6dfc0697901a44b885cc18e206f05114c8a3b7fde674fce6180879" default))
'(grep-command "grep --color -nH -r -e ")
'(package-selected-packages
'(flycheck-clang-analyzer flycheck-clang-tidy flycheck-clangcheck rtags lua-mode magit solarized-theme mo-git-blame buffer-move)))
(setq split-height-threshold 1200)
(setq split-width-threshold 2000)
(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.
)
(provide '.emacs)
;;; .emacs ends here
;; Flycheck
(require 'flycheck-clangcheck)
(require 'flycheck-clang-tidy)
(require 'flycheck-clang-analyzer)
(eval-after-load 'flycheck
'(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))
(add-hook 'after-init-hook #'global-flycheck-mode)
;; Flycheck -- clang-tidy
;; To enable all checks:
;; rm .emacs.d/elpa/flycheck-clang-tidy*/flycheck-clang-tidy.elc
;; Find "flycheck-define-checker c/c++-clang-tidy" in
;; .emacs.d/elpa/flycheck-clang-tidy*/flycheck-clang-tidy.el
;; Add "--checks=*" berfore "source)"
(setq flycheck-clang-tidy-extra-options "-extra-arg=-Wno-unknown-warning-option")
(defun my-select-clang-tidy-for-checker ()
"Select clang-tidy for flycheck's checker."
(flycheck-select-checker 'c/c++-clang-tidy))
(add-hook 'c-mode-hook #'my-select-clang-tidy-for-checker)
(add-hook 'c++-mode-hook #'my-select-clang-tidy-for-checker)
;; Flycheck -- clangcheck>
(setq flycheck-clangcheck-dbname "/export/tarantool/bld/compile_commands.json")
(setq flycheck-clangcheck-analyze t)
;; Flycheck -- clang-analyzer
(flycheck-clang-analyzer-setup)