-
Notifications
You must be signed in to change notification settings - Fork 0
/
flycheck_init.el
1401 lines (1224 loc) · 50 KB
/
flycheck_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
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;; melpa
(require 'package)
; Add package-archives
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
; Initialize
(package-initialize)
; melpa.el
(require 'melpa)
;; emacs 設定ファイル
(require 'cl)
;;;;;;;;;;;;;;;;;; 初期処理 ;;;;;;;;;;;;;;;;;;;;;;;;
;; OSのタイプを格納
(defvar os-type nil)
(cond ((string-match "apple-darwin" system-configuration) ;; Mac
(setq os-type 'mac))
((string-match "linux" system-configuration) ;; Linux
(setq os-type 'linux))
((string-match "freebsd" system-configuration) ;; FreeBSD
(setq os-type 'bsd))
((string-match "mingw" system-configuration) ;; Windows
(setq os-type 'win)))
;; OSのタイプを判別する
(defun mac? ()
(eq os-type 'mac))
(defun linux? ()
(eq os-type 'linux))
(defun bsd? ()
(eq os-type 'freebsd))
(defun win? ()
(eq os-type 'win))
;; load-pathをサブディレクトリごと追加する関数を定義
(defun add-to-load-path (&rest paths)
(let (path)
(dolist (path paths paths)
(let ((default-directory (expand-file-name (concat user-emacs-directory path))))
(add-to-list 'load-path default-directory)
(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
(normal-top-level-add-subdirs-to-load-path))))))
;; elispとconfディレクトリをサブディレクトリごとload-pathに追加
(add-to-load-path "elisp" "conf")
(when (win?)
(add-to-list 'load-path "C:/opt/emacs/site-lisp/apel")
(add-to-list 'load-path "C:/opt/emacs/site-lisp/emu"))
;; http://pastelwill.jp/wiki/doku.php?id=emacs:org-mode
;; org-mode の開発版、安定板を切り替える
(setq load-path (append '(
"~/Dropbox/.emacs.d/public_repos/org-mode/head/lisp" ; The latest org-mode
"~/Dropbox/.emacs.d/public_repos/org-mode/head/contrib/lisp"
;; "~/Dropbox/.emacs.d/public_repos/org-mode/org-8.2.2/lisp"
;; "~/Dropbox/.emacs.d/public_repos/org-mode/org-8.2.2/contrib/lisp"
) load-path))
;; 文字コード
(prefer-coding-system 'utf-8)
(if (win?)
(progn
(set-file-name-coding-system 'cp932)
;; 参考 http://skalldan.wordpress.com/2011/11/09/ntemacs-%E3%81%A7-utf-8-%E3%81%AA%E7%92%B0%E5%A2%83%E6%A7%8B%E7%AF%89%E3%82%92%E8%A9%A6%E8%A1%8C%E9%8C%AF%E8%AA%A4/
;; Setenv
(setenv "LANG" "ja_JP.UTF-8")
;; 言語環境
(set-language-environment "Japanese")
;; 文字コード
(set-buffer-file-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(set-selection-coding-system 'utf-16le-dos)
;; Shell Mode
(setq shell-mode-hook
(function (lambda()
(set-buffer-process-coding-system 'utf-8-unix
'utf-8-unix))))
;; Grep
(defadvice grep (around grep-coding-setup activate)
(let ((coding-system-for-read 'utf-8))
ad-do-it))))
;;;;;;;;;;;;;;;;; 画面の基本設定 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if window-system (progn
;; 文字の色を設定
(add-to-list 'default-frame-alist '(foreground-color . "green"))
;; フォントの設定
(if (linux?)
;; プログラミング用フォント Ricty
(add-to-list 'default-frame-alist '(font . "ricty-12")))
;; (add-to-list 'default-frame-alist '(font . "-unknown-VL ゴシック-normal-normal-normal-*-13-*-*-*-*-0-iso10646-1"))
;; 背景色を設定します。
(add-to-list 'default-frame-alist '(background-color . "black"))
;; 背景の透過
(add-to-list 'default-frame-alist '(alpha . (1.00 1.00)))
(defun set-frame-parameter-alpha (alpha)
"set frame parameter to argument alpha"
(interactive "nInput alpha value(0~100):")
(set-frame-parameter nil 'alpha alpha))
(global-set-key (kbd "C-x C-a") 'set-frame-parameter-alpha)
;; カ-ソルの色を設定します。
(add-to-list 'default-frame-alist '(cursor-color . "SlateBlue2"))
;; マウスポインタの色を設定します。
(add-to-list 'default-frame-alist '(mouse-color . "SlateBlue2"))
(if (linux?)
(add-to-list 'default-frame-alist '(width . 160))
(add-to-list 'default-frame-alist '(width . 140)))
(if (linux?)
(add-to-list 'default-frame-alist '(height . 40))
(add-to-list 'default-frame-alist '(height . 30)))
;; モ-ドライン(アクティブでないバッファ)の文字色を設定します。
(set-face-foreground 'mode-line-inactive "gray30")
;; モ-ドライン(アクティブでないバッファ)の背景色を設定します。
(set-face-background 'mode-line-inactive "gray85")
))
;; emacs 24.3 になってエラーになってしまった
;;;;モ-ド行の背景, 文字の色を変更
(set-face-background 'mode-line "grey10")
(set-face-foreground 'mode-line "SkyBlue")
(set-face-background 'highlight "grey10")
(set-face-foreground 'highlight "red")
;; ツールバーは非表示
(tool-bar-mode -1)
;; 対応する括弧を光らせる
(show-paren-mode 1)
;; リージョンに色を付ける
(setq transient-mark-mode t)
;; モードラインに桁数を表示
(column-number-mode 1)
;; モードラインにファイルサイズ表示
(size-indication-mode 1)
;; タイトルバーにファイルのフルパスを表示
(setq frame-title-format (format "emacs@%s : %%f" (system-name)))
;; 全角スペース/タブ文字を可視化
(setq whitespace-style
'(tabs tab-mark spaces space-mark))
(setq whitespace-space-regexp "\\(\x3000+\\)")
(setq whitespace-display-mappings
'((space-mark ?\x3000 [?\□])
(tab-mark ?\t [?\xBB ?\t])
))
(require 'whitespace)
(global-whitespace-mode 1)
(set-face-foreground 'whitespace-space "LightSlateGray")
(set-face-background 'whitespace-space "DarkSlateGray")
(set-face-foreground 'whitespace-tab "LightSlateGray")
(set-face-background 'whitespace-tab "DarkSlateGray")
(setq-default tab-width 4 indent-tabs-mode nil)
;; 行末の空白を削除する
(global-set-key (kbd "C-x C-s") 'delete-trailing-whitespace)
;; Windows専用設定
(if (win?)
(progn
;; 日本語フォント設定
(cond
(window-system
(set-default-font "Courier New-11")
;; Japanese(japanese-jisx0208)font
(set-fontset-font
(frame-parameter nil 'font)
'japanese-jisx0208
(font-spec :family "Meiryo"))
(set-fontset-font "fontset-default"
'katakana-jisx0201
'("MS ゴシック" . "jisx0201-katakana"))
))
;; フレームの最大化、切り替え
(defvar w32-window-state nil)
(defun w32-fullscreen-switch-frame ()
(interactive)
(setq w32-window-state (not w32-window-state))
(if w32-window-state
(w32-fullscreen-restore-frame)
(w32-fullscreen-maximize-frame)
))
(defun w32-fullscreen-maximize-frame ()
"Maximize the current frame (windows only)"
(interactive)
(w32-send-sys-command 61488))
(defun w32-fullscreen-restore-frame ()
"Restore a minimized/maximized frame (windows only)"
(interactive)
(w32-send-sys-command 61728))
(global-set-key [f11] 'w32-fullscreen-switch-frame)
;; cygwinのbash使用
(setq explicit-shell-file-name "c:\\cygwin\\bin\\bash.exe")
(modify-coding-system-alist 'process "shell" '(undecided-dos . sjis-unix))
;;; cygwin の find を使う
;;; あらかじめ findcyg.exe に rename しておく
;; 参考 http://antoine.st/MeadowSettings.html
;; cons の第2引数はカーソルの初期位置(''の間にくるよう設定)
(setq grep-find-command
(cons (concat "findcyg ./ -type f -name '*'"
" | xargs grep -n -e '' {} nul \\;")
50))
))
;; Linux用設定
(if (linux?)
(progn
;; http://d.hatena.ne.jp/khiker/20090711/emacsfullscreen
;;上記リンクから引用
(defun my-fullscreen ()
(interactive)
(let ((fullscreen (frame-parameter (selected-frame) 'fullscreen)))
(cond
((null fullscreen)
(set-frame-parameter (selected-frame) 'fullscreen 'fullboth))
(t
(set-frame-parameter (selected-frame) 'fullscreen 'nil))))
(redisplay))
(global-set-key [f11] 'my-fullscreen)
(setq grep-find-command
(cons (concat "find . -type f -print0"
" | ""xargs"" -0 -e grep -nH -e ''")
51))))
;; フレームサイズ切替
;; (load-file "~/.emacs.d/util/my-screen.el")
;; (global-set-key [f11] 'my-fullscreen)
;; フレームの操作性を向上する
(defun other-window-or-split ()
(interactive)
(when (one-window-p)
(split-window-horizontally))
(other-window 1))
;; C-oで次のwindowへカーソルを移す
(global-set-key (kbd "C-o") 'other-window-or-split)
;; cua-mode の設定
(cua-mode t)
(setq cua-enable-cua-keys nil)
;; 'pop-mark' C-u C-SPC C-SPC C-SPC... のように
;; C-SPC を連続で入力するだけで,連続でマークを辿れるようになる
(setq set-mark-command-repeat-pop t)
;; ;; バックアップとオートセーブファイルを保存する
;; (add-to-list 'backup-directory-alist
;; (cons "." "~/Dropbox/backups/"))
;; (setq auto-save-file-name-transforms
;; `((".*" ,(expand-file-name "~/Dropbox/backups/") t)))
;; (setq auto-save-intarval 60)
;; バックアップファイルを作成しない
(setq make-backup-files nil)
;; オートセーブファイルを作らない
(setq auto-save-default nil)
;; (global-set-key "\M-g" 'goto-line)
(global-set-key (kbd "C-M-g") 'igrep)
(global-set-key (kbd "C-x g") 'grep-find)
(global-set-key (kbd "C-M-e") 'ediff-merge-files)
(global-set-key "\M-o" 'occur-by-moccur)
(global-set-key (kbd "C-M-o") 'moccur)
(global-set-key (kbd "C-x C-o") 'moccur-grep-find)
;; (global-set-key [\C-\tab] 'dabbrev-expand)
(global-set-key (kbd "C-c C-i") 'indent-region)
(global-set-key (kbd "C->") 'comment-region)
(global-set-key (kbd "C-<") 'uncomment-region)
;; 改行と同時にインデント
(global-set-key (kbd "C-m") 'newline-and-indent)
;; (global-set-key (kbd "C-h") 'delete-backward-char)
;; (global-set-key (kbd "C-c h") 'help-command)
;; 文字の拡大、縮小、元に戻す
(global-set-key (kbd "C-M-;") (lambda () (interactive) (text-scale-increase 1)))
;; 文字の縮小
(global-set-key (kbd "C-M--") (lambda () (interactive) (text-scale-decrease 1)))
;; 文字のサイズを元に戻す
(global-set-key (kbd "C-M-0") (lambda () (interactive) (text-scale-increase 0)))
;; http://www.gentei.org/~yuuji/software/euc/instamp.el
;; 現在時刻挿入
(autoload 'instamp
"instamp" "Insert TimeStamp on the point" t)
(define-key global-map "\M-s" 'instamp)
(setq instamp-date-format-list-private
'("%Y%m%d"))
;; M-wやC-kでコピーしたものを、他のアプルケーションで貼り付け可能にする
(cond (window-system
(setq x-select-enable-clipboard t)
))
;; 対応する括弧等を自動挿入する。以下を評価してインストール
;; (auto-install-from-url "https://github.com/uk-ar/skeleton-pair-dwim/raw/master/skeleton-pair-dwim.el")
;; (require 'skeleton-pair-dwim)
;; (skeleton-pair-dwim-load-default)
;; ;; < >でエラーが出るためキーバインドを再定義
;; (define-key (current-global-map) (kbd "<") 'self-insert-command)
;; (define-key (current-global-map) (kbd ">") 'self-insert-command)
;; (define-key (current-global-map) (kbd "`") 'self-insert-command)
;; (define-key (current-global-map) (kbd "'") 'self-insert-command)
;; (skeleton-pair-dwim-global-set-key '("{" "(" "\"" "'" "`" "<" "[") 'self-insert-command);;unload default
;; (skeleton-pair-dwim-define-key
;; '(global-map lisp-mode-map) '("{" "\"" "[") 'skeleton-pair-insert-dwim)
;; 参考
;; http://d.hatena.ne.jp/uk-ar/20111208/1322572618%3E
(require 'key-combo)
(key-combo-load-default)
(key-combo-define-global (kbd "(") "(`!!')")
(key-combo-define-global (kbd "\"") "\"`!!'\"")
(key-combo-define-global (kbd "[") "[`!!']")
;; 古い設定2013/11/22時点
;; (key-combo-define-global (kbd "(") '("(`!!')"))
;; (key-combo-define-global (kbd "()") "()")
;; (key-combo-define-global (kbd "((") "((`!!'))")
;; (key-combo-define-global (kbd "\"") '("\"`!!'\""))
;; (key-combo-define-global (kbd "\"\"") "\"\"")
;; (key-combo-define-global (kbd "{") '("{`!!'}"))
;; (key-combo-define-global (kbd "{}") "{}")
;; (key-combo-define-global (kbd "[") '("[`!!']"))
;; (key-combo-define-global (kbd "[]") "[]")
;; 英和辞書
(when (require 'sdic nil t)
(global-set-key "\C-cw" 'sdic-describe-word)
(global-set-key "\C-cp" 'sdic-describe-word-at-point))
;; 動作と見掛けを調節するための設定
(setq sdic-window-height 10
sdic-disable-select-window t)
(if (win?)
(progn
;; 使用する辞書ファイルの設定
(setq sdic-eiwa-dictionary-list '((sdicf-client "~/Dropbox/.emacs.d/dict/gene.sdic")))
(setq sdic-waei-dictionary-list '((sdicf-client "~/Dropbox/.emacs.d/dict/jedict.sdic")))
)
)
;; 単語の意味をツールチップで表示する
(defun temp-cancel-read-only (function &optional jaspace-off)
"eval temporarily cancel buffer-read-only
&optional t is turn of jaspace-mode"
(let ((read-only-p nil)
(jaspace-mode-p nil))
(when (and jaspace-off jaspace-mode)
(jaspace-mode)
(setq jaspace-mode-p t))
(when buffer-read-only
(toggle-read-only)
(setq read-only-p t))
(eval function)
(when read-only-p
(toggle-read-only))
(when jaspace-mode-p
(jaspace-mode))))
(defun my-sdic-describe-word-with-popup (word &optional search-function)
"Display the meaning of word."
(interactive
(let ((f (if current-prefix-arg (sdic-select-search-function)))
(w (sdic-read-from-minibuffer)))
(list w f)))
(let ((old-buf (current-buffer))
(dict-data))
(set-buffer (get-buffer-create sdic-buffer-name))
(or (string= mode-name sdic-mode-name) (sdic-mode))
(erase-buffer)
(let ((case-fold-search t)
(sdic-buffer-start-point (point-min)))
(if (prog1 (funcall (or search-function
(if (string-match "\\cj" word)
'sdic-search-waei-dictionary
'sdic-search-eiwa-dictionary))
word)
(set-buffer-modified-p nil)
(setq dict-data (buffer-string))
(set-buffer old-buf))
(temp-cancel-read-only
'(popup-tip dict-data :scroll-bar t :truncate nil))
(message "Can't find word, \"%s\"." word))))
)
(defadvice sdic-describe-word-at-point (around sdic-popup-advice activate)
(letf (((symbol-function 'sdic-describe-word) (symbol-function 'my-sdic-describe-word-with-popup)))
ad-do-it))
;; wdired
;; http://at-aka.blogspot.com/2006/12/emacs-dired-wdired.html
;; (eval-after-load "dired"
;; '(lambda ()
;; (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)))
(require 'dired)
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
;; ワンキーで dired のソートタイプを切り替える
;; 参考 http://d.hatena.ne.jp/mooz/20091207/p1
;; "s" で順送り切り替え
;; "c" でワンクリック切り替え
(defvar dired-various-sort-type
'(("S" . "size")
("X" . "extension")
("v" . "version")
("t" . "date")
("" . "name")))
(defun dired-various-sort-change (sort-type-alist &optional prior-pair)
(when (eq major-mode 'dired-mode)
(let* (case-fold-search
get-next
(options
(mapconcat 'car sort-type-alist ""))
(opt-desc-pair
(or prior-pair
(catch 'found
(dolist (pair sort-type-alist)
(when get-next
(throw 'found pair))
(setq get-next (string-match (car pair) dired-actual-switches)))
(car sort-type-alist)))))
(setq dired-actual-switches
(concat "-l" (dired-replace-in-string (concat "[l" options "-]")
""
dired-actual-switches)
(car opt-desc-pair)))
(setq mode-name
(concat "Dired by " (cdr opt-desc-pair)))
(force-mode-line-update)
(revert-buffer))))
(defun dired-various-sort-change-or-edit (&optional arg)
"Hehe"
(interactive "P")
(when dired-sort-inhibit
(error "Cannot sort this dired buffer"))
(if arg
(dired-sort-other
(read-string "ls switches (must contain -l): " dired-actual-switches))
(dired-various-sort-change dired-various-sort-type)))
(defvar anything-c-source-dired-various-sort
'((name . "Dired various sort type")
(candidates . (lambda ()
(mapcar (lambda (x)
(cons (concat (cdr x) " (" (car x) ")") x))
dired-various-sort-type)))
(action . (("Set sort type" . (lambda (candidate)
(dired-various-sort-change dired-various-sort-type candidate)))))
))
(add-hook 'dired-mode-hook
'(lambda ()
(define-key dired-mode-map "s" 'dired-various-sort-change-or-edit)
(define-key dired-mode-map "c"
'(lambda ()
(interactive)
(anything '(anything-c-source-dired-various-sort))))
))
;; サイズ表示が 69913580 から 67M といったようにちょっと分かりやすくなる
(setq dired-listing-switches "-alh")
;; ;; Visual Basicモード
;; (auto-install-from-url "http://www.emacswiki.org/emacs/download/visual-basic-mode.el")
(autoload 'visual-basic-mode "visual-basic-mode" "Visual Basic mode." t)
(setq auto-mode-alist (append '(("\\.\\(frm\\|FRM\\|BAS\\|bas\\|cls\\|vb\\)$" .
visual-basic-mode)) auto-mode-alist))
;; コードの折り畳み
(add-hook 'visual-basic-mode-hook
'(lambda ()
(hs-minor-mode 1)))
;; file名の補完で大文字小文字を区別しない
(setq completion-ignore-case t)
;; バッファ自動再読み込み
(global-auto-revert-mode 1)
;; 現在行をハイライト表示する
(defface hlline-face
'((((class color)
(background dark))
(:background "dark slate gray"))
(((class color)
(background light))
(:background "#98FB98"))
(t
()))
"*Face used by hl-line.")
(setq hl-line-face 'hlline-face)
(global-hl-line-mode)
;;;;;;;;;;;;;;;;; Emacsテクニックバイブルより ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 14. org-mode
(require 'org)
;; 14.4 M-x org-remember
;; (org-remember-insinuate) ;; org-mode を最新にしたらエラーが出たのでコメントアウト2013/11/8
(setq org-directory "~/Dropbox/org/")
(setq org-mobile-directory "~/Dropbox/mobileorg/")
(setq org-mobile-inbox-for-pull "~/Dropbox/org/mobile_todo.org")
(setq org-default-notes-file (expand-file-name "agenda/agenda.org" org-directory))
(setq org-remember-templates
'(("Memo" ?m "** %?\n %i %a\n %t" nil "Inbox")
;; ("Todo" ?t "** TODO %?\n %i %a\n %t" nil "Inbox")
("Twitter" ?t "** %?\n %i %t" nil "Twitter")))
;; (global-set-key (kbd "C-,") 'org-remember)
;; 14.6 TODOリストを作成する
(setq org-use-fast-todo-selection t)
(setq org-todo-keywords
'((sequence "TODO(t)" "STARTED(s)" "WAITING(w)" "|" "DONE(d)" "CANCEL(c)")))
;; 14.14 予定表を見る
;; アジェンダ表示の対象ファイル
(setq org-agenda-files (list org-directory))
(global-set-key (kbd "C-c a") 'org-agenda)
(setq org-agenda-custom-commands
'(("x" "My agenda view"
((agenda)
(todo "TODO")
(tags-todo "movie")
(tags-todo "music")))))
;; Googleカレンダーへエスクポート
;; ネタ元
;; http://d.hatena.ne.jp/t0m0_tomo/20100103/1262537012
(setq org-combined-agenda-icalendar-file "~/Dropbox/calendar/org.ics")
(setq org-icalendar-include-todo t)
;; (setq org-icalendar-use-deadline '(event-if-todo event-if-not-todo))
;; (setq org-icalendar-use-scheduled '(event-if-todo event-if-not-todo))
(setq org-icalendar-use-deadline '(event-if-todo))
(setq org-icalendar-use-scheduled '(event-if-todo event-if-not-todo))
(defun start-process-org ()
(interactive)
(start-process-shell-command "org-sync-gcal" "*org-sync-gcal*" "emacs" "--script" "~/Dropbox/.emacs.d/elisp/org-sync-gcal.el"))
(define-key global-map [f12] 'start-process-org)
;; Emacs 起動時に mobileorg から pull
(org-mobile-pull)
(if (linux?)
(progn
;; (start-process-org)
;; Emacs 終了時に mobileorg に push
(add-hook 'kill-emacs-hook 'org-mobile-push)))
;; サブタスクが残っているときに親タスクをDONEにできないようにする
(setq org-enforce-todo-dependencies t)
;; サブタスクが全て DONE になったら親タスクも自動的に DONE になり
;; サブタスクをひとつでも TODO にしたら 親タスクも TODO になる
(defun org-summary-todo (n-done n-not-done)
"Switch entry to DONE when all subentries are done, to TODO otherwise."
(let (org-log-done org-log-states) ; turn off logging
(org-todo (if (= n-not-done 0) "DONE" "TODO"))))
(add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
;; カーソル位置のステータスを取得する関数
;; 返り値 :item, :headline, :headline-stars
(defun org-position-status(context-list)
(if (not (cdr context-list))
;; context-list の末尾に到達
(caar context-list)
(org-position-status (cdr context-list))))
(add-hook
'org-mode-hook
(lambda ()
;; elscreen で<C-tab>をタブの切り換えに割り当てたいので無効にする
(define-key org-mode-map (kbd "<C-tab>") nil)
(local-set-key (kbd "<M-return>") (lambda () (interactive)
(if (not (eq (org-position-status (org-context)) :item))
(progn
(org-insert-heading-after-current)
(insert (format "%s" "TODO [0/1] ")))
(org-insert-heading))))
(local-set-key (kbd "<M-S-return>") (lambda () (interactive)
(message "%s" (org-context))))
;; 自作の M-return の動きに干渉するので key-combo-mode をオフにする
(key-combo-mode -1)
(auto-complete-mode t)
))
;; org-babel
(org-babel-do-load-languages ;;; org7.5/doc/org.pdf p162
'org-babel-load-languages
'((R . t)
(sh . t)
(C . t)))
;; org ファイル読み込み時に自動的に画像をインライン表示する
;; 読み込み後、編集中の画像リンクには影響しない
(setq org-startup-with-inline-images t)
;; 常に画像を表示
;; リンク記述後 C-l で即表示
(add-hook 'org-mode-hook 'turn-on-iimage-mode)
(require 'ox-freemind)
;; anything初期設定
(require 'anything-startup)
;; 15.5 anything-for-files
(global-set-key (kbd "C-x C-.") 'anything-for-files)
(define-key global-map (kbd "M-y") 'anything-show-kill-ring)
;; (auto-install-from-url "http://www.emacswiki.org/cgi-bin/emacs/download/descbinds-anything.el")
(when (require 'descbinds-anything nil t)
;; describe-bindings を Anything に置き換える
(descbinds-anything-install))
;; ;;; helm
;; (require 'helm-config)
;; (helm-descbinds-mode)
;; (require 'helm-migemo)
;; (setq helm-use-migemo t)
;; (define-key global-map (kbd "C-.") 'helm-for-files)
;; (define-key global-map (kbd "C-x b") 'helm-for-files)
;; (define-key global-map (kbd "M-y") 'helm-show-kill-ring)
;; 2.1 ddskk
(defun skk-latin-toggle()
(interactive)
(if skk-mode
(if skk-latin-mode
(skk-mode t)
(progn
(skk-latin-mode t)
(key-combo-mode t)))))
(global-set-key "\C-\\" 'skk-mode)
(global-set-key "\C-xj" 'skk-auto-fill-mode)
(global-set-key "\C-xt" 'skk-tutorial)
(global-set-key (kbd "C-t") 'skk-latin-toggle)
(autoload 'skk-mode "skk" nil t)
(autoload 'skk-tutorial "skk-tut" nil t)
(autoload 'skk-check-jisyo "skk-tools" nil t)
(autoload 'skk-merge "skk-tools" nil t)
(autoload 'skk-diff "skk-tools" nil t)
;;;; "「"を入力したら"」"も自動で挿入
(setq skk-auto-insert-paren t)
;;;; 句読点は , . を使う
(setq skk-kuten-touten-alist
'(
(jp . ("。" . "、" ))
(en . ("." . ","))
))
;;;; jp にすると「。、」を使います
(setq-default skk-kutouten-type 'jp)
;;;; @で挿入する日付表示を半角に
(setq skk-number-style nil)
;;;; 変換のときEnterを押しても確定のみで改行しない。
(setq skk-egg-like-newline t)
;; skk で日本語入力時に \ 押下で skk-list-chars が起動しないようにする
(defun skk-list-chars (&optional arg)
(interactive "P")
;; skk-list-chars が呼ばれた時点で元の▽モードが終了してしまうので、再度▽モードを呼び出す
(skk-set-henkan-point-subr)
)
(add-hook 'skk-mode-hook
(lambda ()
(key-combo-mode -1)))
;; 2.2 auto-install.el
(require 'auto-install)
(auto-install-update-emacswiki-package-name t)
(auto-install-compatibility-setup)
(setq auto-install-use-wget t)
(auto-install-compatibility-setup)
(setq auto-install-directory "~/Dropbox/.emacs.d/elisp/")
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
;; 3.9 key-chord.el
;; (require 'key-chord)
;; (setq key-chord-two-keys-delay 0.04)
;; (key-chord-mode 1)
;; 4.2 uniquify.el
(require 'uniquify)
(setq uniquify-buffer-name-style 'post-forward-angle-brackets)
(setq uniqify-ignore-buffers-re "*[^*]+*")
;; 4.4 recentf.el
;; (setq recentf-max-saved-items 500)
;; (setq recentf-exclude '("/TAGS$" "/var/tmp/"))
(require 'recentf-ext)
;; (define-key global-map (kbd "C-x f") 'recentf-open-files)
;; 4.6 emacsclient
;; (server-start)
;; (defun iconify-emacs-when-server-is-done ()
;; (unless server-clients (iconify-frame)))
;; ;; 編集が終了したらEmacsをアイコン化する
;; (add-hook 'server-done-hook 'iconify-emacs-when-server-is-done)
;; ;;
;; (global-set-key (kbd "C-x C-c") 'server-edit)
;; (defalias 'exit 'save-buffers-kill-emacs)
;; 4.8 auto-save-buffers.el
;; ファイルを自動保存する
;; M-x install-elisp http://homepage3.nifty.com/oatu/emacs/archives/auto-save-buffers.el
(require ' auto-save-buffers)
(run-with-idle-timer 2 t 'auto-save-buffers)
(when (executable-find "cmigemo")
;; 5.5 migemo.el
(setq migemo-command "cmigemo")
(setq migemo-options '("-q" "--emacs" "-i" "\g"))
;; migemo-dictのパスを指定
(if (linux?)
(setq migemo-dictionary "/usr/share/cmigemo/utf-8/migemo-dict")
(setq migemo-dictionary (expand-file-name "~/Dropbox/.emacs.d/elisp/migemo/cp932/migemo-dict")))
(setq migemo-user-dictionary nil)
(setq migemo-regex-dictionary nil)
;; キャッシュ機能を利用する
(setq migemo-use-pattern-alist t)
(setq migemo-use-frequent-pattern-alist t)
(setq migemo-pattern-alist-length 1024)
;; 辞書の文字コードを指定.
(if (linux?)
(setq migemo-coding-system 'utf-8-unix)
(setq migemo-coding-system 'cp932-unix))
(load-library "migemo")
(migemo-init)
)
(when (not (executable-find "cmigemo"))
(setq migemo-isearch-enable-p nil))
;; 5.6 point-undo.el
;; カーソル位置を戻す
;; (require 'point-undo)
;; (define-key global-map (kbd "C--") 'point-undo)
;; (define-key global-map (kbd "C-=") 'point-redo)
;; 5.8 goto-chg.el
;; 最後の変更箇所にジャンプする
(require 'goto-chg)
(define-key global-map (kbd "<f8>") 'goto-last-change)
(define-key global-map (kbd "S-<f8>") 'goto-last-change-reverse)
;; ;; 6.2 redo+.el
;; (require 'redo+)
;; (global-set-key (kbd "C-M-/") 'redo)
;; (setq undo-no-redo t)
;; (setq undo-limit 600000)
;; (setq undo-strong-limit 900000)
(when (require 'undo-tree nil t)
(global-undo-tree-mode t)
(global-set-key (kbd "C-M-/") 'undo-tree-redo))
;; 6.6 yasnippet.el
(require 'yasnippet) ;; not yasnippet-bundle
(yas/initialize)
(yas/load-directory "~/Dropbox/.emacs.d/elisp/plugins/yasnippet-0.6.1c/snippets")
;; 6.14 auto-complete.el
;; M-x auto-install-batch auto-complete TAB
(require 'auto-complete-config)
(global-auto-complete-mode 1)
;; C-n/C-p で候補を選択
(define-key ac-complete-mode-map "\C-n" 'ac-next)
(define-key ac-complete-mode-map "\C-p" 'ac-previous)
;; 大文字、小文字を区別する
(setq ac-ignore-case nil)
;; auto-complete の候補に日本語を含む単語が含まれないようにする
;; http://d.hatena.ne.jp/IMAKADO/20090813/1250130343
(defadvice ac-word-candidates (after remove-word-contain-japanese activate)
(let ((contain-japanese (lambda (s) (string-match (rx (category japanese)) s))))
(setq ad-return-value
(remove-if contain-japanese ad-return-value))))
;; 7.6 color-moccur.el
(require 'color-moccur)
(setq moccur-split-word 1) ; スペースで区切られた複数の単語にマッチさせる
(setq moccur-use-migemo 1)
;; 7.7 moccur-edit.el
(require 'moccur-edit)
;; 7.9 igrep.el
(require 'igrep)
;; lgrepに-0u8オプションをつけると出力がUTF-8になる
(igrep-define lgrep (igrep-use-zgrep nil) (igrep-regex-option "-n -0u8"))
(igrep-find-define lgrep (igrep-use-zgrep nil) (igrep-regex-option "-n -0u8"))
;; 7.10 grep-a-lot.el
(require 'grep-a-lot)
(grep-a-lot-setup-keys)
;; igrepを使う人向け
(grep-a-lot-advise igrep)
;; grep-a-lot-buffer-name の定義を上書き
;; 参考 http://d.hatena.ne.jp/kitokitoki/20110213/p1
(setq my-grep-a-lot-search-word nil)
(defun grep-a-lot-buffer-name (position)
"Return name of grep-a-lot buffer at POSITION."
(if (not (null my-grep-a-lot-search-word))
(concat "*grep*<" my-grep-a-lot-search-word ">")
(concat "*grep*<" (number-to-string position) ">")))
(defadvice rgrep (before my-rgrep (regexp &optional files dir) activate)
(setq my-grep-a-lot-search-word regexp))
(defadvice lgrep (before my-lgrep (regexp &optional files dir) activate)
(setq my-grep-a-lot-search-word regexp))
(defadvice grep (before my-lgrep (regexp &optional files dir) activate)
(if (string-match "|.+'\\(.+\\)'" regexp)
;; 検索ワードが '(シングルクォート)に囲まれていることを期待
(setq my-grep-a-lot-search-word
(subseq regexp (match-beginning 1) (match-end 1)))))
;; 7.11 grep-edit.el
(require 'grep-edit)
;; 8.4 w3m.el
;; (if (linux?)
;; (require 'w3m-load))
;; 8.6 gist.el
;(require 'gist)
;; 11.1 view-mode
;; view-minor-modeの設定
(setq view-read-only t)
(add-hook 'view-mode-hook
'(lambda()
(progn
;; C-b, ←
(define-key view-mode-map "h" 'backward-char)
;; C-n, ↓
(define-key view-mode-map "j" 'next-line)
;; C-p, ↑
(define-key view-mode-map "k" 'previous-line)
;; C-f, →
(define-key view-mode-map "l" 'forward-char)
)))
;; 12.3 paredit.el
;(require 'paredit)
;(add-hook 'emacs-lisp-mode-hook 'enable-paredit-mode)
;(add-hook 'lisp-interaction-mode 'enable-paredit-mode)
;(add-hook 'lisp-mode-hook 'enable-paredit-mode)
;(add-hook 'ielm-mode-hook 'enable-paredit-mode)
;; kiwanamiさん作成関連
;; (autoload 'id-manager "id-manager" nil t)
;; (global-set-key (kbd "M-7") 'id-manager) ; キーバインド
;; (setenv "GPG_AGENT_INFO" nil) ; minibufferでパスワードを入力する場合
;;;;;;;;;;;;;;;;; VCS関連 ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; (install-elisp "https://raw.github.com/byplayer/egg/master/egg.el")
;; (install-elisp "https://raw.github.com/byplayer/egg/master/egg-grep.el")
(when (executable-find "git")
(require 'egg nil t))
;; (install-elisp "http://www.xsteve.at/prg/emacs/psvn.el")
;; 上記ファイルでは svn 1.7 で使えなかった(2012/6/22時点)
;; (install-elisp "http://www.eaflux.com/psvn/psvn.el.new")
(when (executable-find "svn")
(setq svn-status-verbose nil)
(autoload 'svn-status "psvn" "Run 'svn status'." t))
(when (win?)
(setq process-coding-system-alist '(("svn" . utf-8)))
(setq default-file-name-coding-system 'sjis)
(setq svn-status-svn-file-coding-system 'utf-8)
(setq svn-status-svn-process-coding-system 'utf-8)
(setenv "CYGWIN" "nodosfilewarning")
(setenv "LC_ALL" "en_US.UTF-8")
(setenv "LANG" "en_US.UTF-8")
)
;;; ctags.el の設定(Emacs 実践入門 p191より)
(require 'ctags nil t)
(setq tags-revert-without-query t)
;; (setq ctags-command "ctags -e -R ")
;; ctagsを呼び出すコマンドライン
(setq ctags-command "ctags -R --fields=\"+afikKlmnsSzt\" ")
(global-set-key (kbd "<f5>") 'ctags-create-or-update-tags-table)
;; 定義ジャンプできるようにする
(when (require 'anything nil t)
(require 'anything-exuberant-ctags)
)
(global-set-key (kbd "C-;") (lambda () (interactive)
(ring-insert find-tag-marker-ring (point-marker))
(anything-exuberant-ctags-select-from-here)))
(global-set-key (kbd "C-.") (lambda () (interactive)
(ring-insert find-tag-marker-ring (point-marker))
(anything-exuberant-ctags-select)))
;; ジャンプ元に戻る
(global-set-key (kbd "C--") 'pop-tag-mark)
;;;;;;;;;;;;;;;;; 言語モード ;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; プログラミング全般
;; 参考
;; http://moimoitei.blogspot.jp/2010/05/flymake-in-emacs.html
(require 'flymake)
;; GUIの警告は表示しない
(setq flymake-gui-warnings-enabled nil)
;; 全てのファイルで flymakeを有効化
(add-hook 'find-file-hook 'flymake-find-file-hook)
;; M-p/M-n で警告/エラー行の移動
(global-set-key "\M-p" 'flymake-goto-prev-error)
(global-set-key "\M-n" 'flymake-goto-next-error)
;; 警告エラー行の表示
(global-set-key "\C-cd" 'my-flymake-display-err-popup.el-for-current-line)
;; popup.el を使って tip として表示
(defun my-flymake-display-err-popup.el-for-current-line ()
"Display a menu with errors/warnings for current line if it has errors and/or warnings."
(interactive)
(let* ((line-no (flymake-current-line-no))
(line-err-info-list (nth 0 (flymake-find-err-info flymake-err-info line-no)))
(menu-data (flymake-make-err-menu-data line-no line-err-info-list)))
(if menu-data
(popup-tip (mapconcat '(lambda (e) (nth 0 e))
(nth 1 menu-data)
"\n")))
))
;; 参考
;; http://d.hatena.ne.jp/CortYuming/20110920/p1
(when (load "flymake" t)
;; JavaScript with Google Closure
;; http://www.emacswiki.org/emacs/FlymakeJavaScript
;; http://code.google.com/intl/ja/closure/utilities/docs/linter_howto.html
;; http://d.hatena.ne.jp/Ehren/20101006/1286386194
;; http://d.hatena.ne.jp/Ehren/20110912/1315804158
(defun flymake-gjslint-init ()
"Initialize flymake for gjslint"
(let* ((temp-file (flymake-init-create-temp-buffer-copy
'flymake-create-temp-inplace)))
(list "/usr/local/bin/gjslint" (list temp-file "--nosummary"))))
(add-to-list 'flymake-allowed-file-name-masks
'(".+\\.js$"
flymake-gjslint-init
flymake-simple-cleanup
flymake-get-real-file-name))
(add-to-list 'flymake-err-line-patterns
'("^Line \\([[:digit:]]+\\), E:[[:digit:]]+: "
nil 1 nil))
(add-hook 'js-mode-hook (lambda () (flymake-mode t)))
;; FlymakeHtml
;; http://www.emacswiki.org/emacs/FlymakeHtml
(delete '("\\.html?\\'" flymake-xml-init) flymake-allowed-file-name-masks)
(defun flymake-html-init ()
(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 "tidy" (list local-file))))
(list "tidy" (list "-utf8" local-file))))
(add-to-list 'flymake-allowed-file-name-masks