-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
406 lines (352 loc) · 14 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; emacs-pervasives ver. 1.00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Include ~/.emacs.d in the load path
;; ~/.emacs.d下に入れたファイルをload,require等で読み込めるようにする
(setq load-path (cons "~/.emacs.d" load-path))
;; Include (sub-)directories under ~/.emacs.d/site-lisp in the load path
;; ~/.emacs.d/site-lisp下に入れたファイルを(サブディレクトリ内のものも
;; 含め)load,require等で読み込めるようにする
(when (fboundp 'normal-top-level-add-subdirs-to-load-path)
(let* ((dir "~/.emacs.d/site-lisp")
(default-directory dir))
(when (file-directory-p dir)
(setq load-path (cons dir load-path))
(normal-top-level-add-subdirs-to-load-path))))
;; Do not show startup messages
;; 起動時に表示されるメッセージ, *scratch*バッファのメッセージ等を表示しない
(setq inhibit-startup-message t
inhibit-startup-screen t
initial-scratch-message nil)
;; Ask y/n instead of yes/no
;; yes/noではなくy/nで訊くようにする
(fset 'yes-or-no-p 'y-or-n-p)
;; Show row and column of the cursor position
;; カーソル位置の行番号と桁数を表示する
(setq column-number-mode t)
;; Hide toolbar
;; ツールバーを非表示にする
;(setq tool-bar-mode nil)
;; Hide menubar
;; メニューバーを非表示にする
;(setq menu-bar-mode nil)
;; Highlight matching parenthesis
;; 対応する括弧をハイライトする
(show-paren-mode t)
;; Highlight selected region
;; 選択範囲を表示する
(setq transient-mark-mode t)
;; Kill selected region by BS
;; 範囲選択中にバックスペースで選択範囲を削除する
(delete-selection-mode t)
;; Show line number
;; 行番号を(常に)表示する
(global-linum-mode)
;; Highlight the current line
;; カーソル位置の行をハイライトする
;(global-hl-line-mode)
;; Do not blink cursor
;; カーソルを点滅しない
(blink-cursor-mode nil)
;; Show special character (») for wrapped line end
;; 長い行を折り返したときに記号(»)を表示する
(defface wrap-face
'((((class color) (min-colors 88) (background dark))
:foreground "aquamarine4")
(((class color) (min-colors 88) (background light))
:foreground "aquamarine2")
(((class color) (min-colors 16))
:foreground "DarkCyan")
(((class color) (min-colors 8))
:foreground "gray")
(((type tty) (class mono))
:inverse-video t))
"Face of the wrap."
:group 'convenience)
(set-display-table-slot standard-display-table 'wrap
(make-glyph-code #xbb 'wrap-face))
;; Highlight whitespace at EOL
;; 行末の空白をハイライトする
(setq-default show-trailing-whitespace t)
;; Show buffer boundary indicator
;; バッファの範囲を示すマークを表示する
(setq-default indicate-buffer-boundaries 'left)
;; C-x C-b shows buffer selector
;; C-x C-bでバッファ選択画面を開く
(global-set-key (kbd "C-x C-b") 'bs-show)
;; Put directory names for the same name of different files
;; 同じ名前のファイルを開いたときにfile<2>ではなくdir/fileという表示にする
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
;; Auto completion like IntelliSense
;; [Key Bindings]
;; M-n next candidate
;; M-p previous candidate
;; TAB do complete
;; C-m do complete
;; IntelliSenseのような自動補完
;; [補完候補のキーバインド]
;; M-n 次の候補
;; M-p 前の候補
;; TAB 候補の確定
;; C-m 候補の確定
(when (require 'auto-complete nil t)
(global-auto-complete-mode t)
(setq ac-auto-show-menu 0.5))
;; Selecting candidates in a sophisticated way
;; [Key Bindings]
;; C-n next candidate
;; Down next candidate
;; C-p previous candidate
;; Up previous candidate
;; Left next source
;; Right previous source
;; 様々なものの選択を賢くする
;; [候補選択のキーバインド]
;; C-n 次の候補
;; Down 次の候補
;; C-p 前の候補
;; Up 前の候補
;; Left 次の生成元
;; Right 前の生成元
(when (require 'anything-config nil t)
(setq dired-bind-jump nil) ; prevent binding to C-x C-j
;; Source of file list
;; ファイル選択で使うファイルリストの生成元
(setq anything-for-files-prefered-list
'(anything-c-source-buffers+
anything-c-source-ffap-line
anything-c-source-ffap-guesser
anything-c-source-recentf
anything-c-source-bookmarks
anything-c-source-files-in-current-dir+
anything-c-source-locate))
;; Replace switch-to-buffer with anything-for-files
;; バッファ選択(switch-to-buffer)の代わりにanythingを使う
(global-set-key (kbd "C-x b") 'anything-for-files)
;; Enable anything on M-x
;; M-xでanythingを有効にする
(when (require 'anything-complete nil t)
(setq anything-complete-sort-candidates t)
(substitute-key-definition 'execute-extended-command
'anything-execute-extended-command global-map))
;; Enable anything on M-x describe-bindings
;; M-x describe-bindingsでanythingを有効にする
(when (require 'descbinds-anything nil t)
(descbinds-anything-install)))
;; Use 4-space soft tab by default
;; デフォルトタブ幅4, タブはスペースを挿入
(setq-default tab-width 4
indent-tabs-mode nil)
;; Treat undo history as a tree
;; [Key Bindings]
;; C-/ undo
;; M-_ redo
;; C-x u show history as a tree
;; p go up the tree (undo)
;; n go down the tree (redo)
;; f select right branch of the tree
;; b select left branch of the tree
;; 元に戻す/やり直しをツリー状に管理
;; [キーバインド]
;; C-/ 元に戻す
;; M-_ やり直し
;; C-x u 編集履歴ツリーを表示
;; p ツリーを上る (元に戻す)
;; n ツリーを下る (やり直し)
;; f 右の枝を選択
;; b 左の枝を選択
;; q ツリーを閉じる
(when (require 'undo-tree nil t)
(global-undo-tree-mode)
(setq undo-tree-mode-lighter nil))
;; Highlight the current line on GDB source buffer
;; GDBで実行中の行をハイライト
(defadvice gdb-display-source-buffer
(after ad-hl-line-source-buffer (buffer) activate)
(with-current-buffer buffer (hl-line-mode 1)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; flymake
;; Compile background and show errors on the fly
;; 裏で自動コンパイルしてエラー箇所を表示
(require 'flymake)
;; Compilation runs when it is idle for 3 seconds
;; 3秒間操作しなかったらコンパイルする
(setq flymake-no-change-timeout 3)
;; colors
;; 色設定
(set-face-background 'flymake-errline "red4")
(set-face-foreground 'flymake-errline "black")
(set-face-background 'flymake-warnline "yellow")
(set-face-foreground 'flymake-warnline "black")
;; Shows errors on the minibuffer
;; エラーをミニバッファに表示
;; http://d.hatena.ne.jp/xcezx/20080314/1205475020
(defun flymake-display-err-minibuf ()
"Displays the error/warning for the current line in the minibuffer"
(interactive)
(let* ((line-no (flymake-current-line-no))
(line-err-info-list
(nth 0 (flymake-find-err-info flymake-err-info line-no)))
(count
(length line-err-info-list)))
(while (> count 0)
(when line-err-info-list
(let* ((file
(flymake-ler-file (nth (1- count) line-err-info-list)))
(full-file
(flymake-ler-full-file (nth (1- count) line-err-info-list)))
(text (flymake-ler-text (nth (1- count) line-err-info-list)))
(line
(flymake-ler-line (nth (1- count) line-err-info-list))))
(message "[%s] %s" line text)))
(setq count (1- count)))))
;; Automatically show errors on the minibuffer
;; エラーをミニバッファに表示するのを自動的にやる
(defadvice flymake-post-syntax-check
(after flymake-display-err-minibuf-auto last activate)
(flymake-display-err-minibuf))
;; Do nothing if visiting something other than a file
;; ファイル以外を編集中は何もしない
(defadvice flymake-get-init-function
(around flymake-ignore-non-file (file-name) activate)
(if file-name ad-do-it '(lambda () nil)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C/C++
;; Compiler paths
;; コンパイラのパス
(setq flymake-c-command "/usr/bin/gcc")
(setq flymake-cc-command "/usr/bin/g++")
;; Compiler options
;; コンパイラに渡すオプション
(setq flymake-cc-command-opt
'("-fsyntax-only"
;; "-std=c++98" "-pedantic-errors"
"-Wall" "-Wextra"
;; "-Wcast-qual" "-Wwrite-strings"
;; "-Wno-missing-field-initializers" "-Wnon-virtual-dtor"
;; "-Weffc++" "-Wold-style-cast" "-Woverloaded-virtual"
))
;; Pass include directory settings in Makefile to the compiler
;; Makefileにインクルード設定があったらそれもコンパイラに渡す関数
;; (ライブラリの利用のためにインクルードディレクトリを追加した場合に必要)
(defun flymake-extract-includes-from-makefile ()
(let ((buf (current-buffer))
(dir (file-name-directory (or (buffer-file-name) ""))))
(with-temp-buffer
(if (file-readable-p (concat dir "Makefile"))
(progn
(insert-file-contents (concat dir "Makefile") nil nil nil t)
(goto-char 0)
(if (re-search-forward "^INCLUDE\\s-*=\\s-*\\(.*\\)$" nil t nil)
(let ((includes (split-string (match-string 1) " \t\r\n")))
(with-current-buffer buf
(set (make-local-variable 'flymake-cc-command-opt)
(append includes flymake-cc-command-opt))))))))))
;; Initialization for C/C++
;; C/C++用にflymakeを初期化する関数
(defun flymake-cc-init ()
(let ((cmd (cond
((eq major-mode 'c-mode) flymake-c-command)
((eq major-mode 'c++-mode) flymake-cc-command)
(t nil))))
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace))
(local-file (file-relative-name
temp-file
(file-name-directory buffer-file-name))))
(list cmd (append flymake-cc-command-opt (list local-file))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C
;; Enable c-mode and flymake automatically for the specific file extensions
;; C言語用モードを特定の拡張子で有効にする
(autoload 'c-mode "cc-mode")
(setq auto-mode-alist
(append '(("\\.h$" . c-mode)
("\\.c$" . c-mode))
auto-mode-alist))
(push '("\\.c$" flymake-cc-init) flymake-allowed-file-name-masks)
;; c-mode initialization
;; C言語用モード起動時にやること
(add-hook 'c-mode-hook
'(lambda ()
;; indentation styles
;; インデントスタイル
(c-set-style "stroustrup")
(c-set-offset 'innamespace 0)
(setq c-basic-offset 2)
;; activate flymake
;; flymakeを有効にする
(flymake-extract-includes-from-makefile)
(flymake-mode t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C++
;; Enable cc-mode and flymake automatically for the specific file extensions
;; C++用モードを特定の拡張子で有効にする
(autoload 'c++-mode "cc-mode")
(setq auto-mode-alist
(append '(;("\\.h$" . c++-mode)
("\\.hpp$" . c++-mode)
("\\.cpp$" . c++-mode)
("\\.hxx$" . c++-mode)
("\\.cxx$" . c++-mode))
auto-mode-alist))
(push '("\\.cpp$" flymake-cc-init) flymake-allowed-file-name-masks)
;; cc-mode initialization
;; C++用モード起動時にやること
(add-hook 'c++-mode-hook
'(lambda ()
;; indentation styles
;; インデントスタイル
(c-set-style "stroustrup")
(c-set-offset 'innamespace 0)
(setq c-basic-offset 2)
;; activate flymake
;; flymakeを有効にする
(flymake-extract-includes-from-makefile)
(flymake-mode t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; LaTeX
;; Set default-buffer-file-coding-system according to file name
;; ファイル名に従ってdefault-buffer-file-coding-systemを設定する
(defvar default-file-coding-system-alist nil
"List of pairs of a file name regexp and a coding system.")
(add-hook 'find-file-hook
'(lambda ()
(let ((code (assoc-default buffer-file-name
default-file-coding-system-alist
'string-match nil)))
(when code
(progn
(make-local-variable 'default-buffer-file-coding-system)
(setq default-buffer-file-coding-system code))))))
;; Default TeX mode
;; デフォルトのTeXモード
(unless (boundp 'TeX-default-mode)
(setq TeX-default-mode 'latex-mode))
(when (string= current-language-environment "Japanese")
;; 日本語用のモードを使う
(when (featurep 'tex-site) ;; AUCTeX
(setq TeX-default-mode 'japanese-latex-mode))
;; 日本語用TeXコマンド
(setq japanese-TeX-command-default "pTeX")
(setq japanese-LaTeX-command-default "pLaTeX")
;; TeX関係のファイルはEUC-JPにする
(setq default-file-coding-system-alist
(append
'(("\\.tex$" . euc-jp-unix)
("\\.sty$" . euc-jp-unix)
("\\.bib$" . euc-jp-unix))
default-file-coding-system-alist)))
;; Activate TeX-mode automatically
;; 自動的にTeX-modeを起動する
(setq auto-mode-alist
(append
`(("\\.sty$" . ,TeX-default-mode)
("\\.tex$" . ,TeX-default-mode))
auto-mode-alist))
;; Enable reftex
;; reftexを有効にする
(add-hook 'TeX-mode-hook 'turn-on-reftex)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
;; emacs-pervasives ends here