Source

.emacs.d / 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
;; created 2008


;; .emacs就是一个程序,这意味着:
;; * 如果太大,就需要拆开,分成多个函数,甚至多个文件
;; * 它也要有自己的配置文件(将变动部分与不变部分分离)
;; * 需要进行版本控制


;; .emacs作为一个程序的目标:
;; * 跨平台(windows,linux,cygwin)
;; * 环境自适应(有什么包配什么包,不要配不存在的包而导致出错;用户可以启用或禁用某个包;用户可以选择用该包的哪个版本)
;; * 启动快速: 按需加载插件
;; * 易扩充,易维护


;; 本.emacs的功能汇总:
;; C-f8		insert key sequence
;; C-f7		(epm) compile current C++ file
;; f7		(epm) build project
;; f4		rebuild and reload BROWSE generated by ebrowse
;; f2		切换行间距大小


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  以下是实现部分  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; 为了加快启动速度,注释掉,需要时再通过C-x C-e执行吧
;; (require 'package)
;; (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
;; (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))

;; 确保在配置各个包之前先加载这些包
(setq package-enable-at-startup nil)
(package-initialize)

;; 程序主入口(main entry)在本文件最后


;; 一些外部包所在位置的默认值:
;; 可根据实际情况在~/.emacs.d/env.el中对这些位置进行调整(此文件在各个机子间不进行同步)。
;; 如果一个包的.el文件有自己独立的目录,就指向该目录;
;; 如果一个包的.el文件与其他包的.el文件共享同一个目录,则指向能表明该包存在的某个.el文件。
(defvar epm-path "~/work/epm/")
(defvar ibus-path "~/.emacs.d/packages/ibus.el/")
(defvar haskell-mode-path "~/.emacs.d/packages/haskell-mode/") ; http://www.haskell.org/haskellwiki/Haskell_mode_for_Emacs
(defvar cscope-path "/usr/share/emacs/site-lisp/xcscope.el") ; 从源里安装的话xcscope.el就位于此处
(defvar auctex-path "/usr/local/share/emacs/site-lisp/auctex.el")
(defvar org-path "~/.emacs.d/packages/org-mode/") ; git clone git://orgmode.org/org-mode.git
(defvar color-theme-path "~/.emacs.d/packages/color-theme/") ; http://www.nongnu.org/color-theme/
(defvar ntcmd-path "~/.emacs.d/packages/ntcmd.el") ; http://www.emacswiki.org/emacs/DosScripts
(defvar powershell-path "~/.emacs.d/packages/Powershell.el") ; http://www.emacswiki.org/emacs/PowerShell
(defvar powershell-mode-path "~/.emacs.d/packages/powershell-mode.el") ; http://www.emacswiki.org/emacs/PowerShell
(defvar auto-complete-path "~/.emacs.d/packages/auto-complete") ; 此包光解开不行,还要安装,这里是安装所至目录。http://cx4a.org/software/auto-complete/manual.html
(defvar yasnippet-path "~/.emacs.d/packages/yasnippet/") ; http://www.emacswiki.org/emacs/Yasnippet
(defvar visual-basic-mode-path "~/.emacs.d/packages/visual-basic-mode.el") ; http://xahlee.org/visual_basic/emacs_visualbasic_mode.html
(defvar markdown-mode-path "~/.emacs.d/packages/markdown-mode.el") ; http://jblevins.org/projects/markdown-mode/
(defvar paredit-path "~/.emacs.d/packages/paredit.el") ; http://emacswiki.org/emacs/ParEdit
(defvar ace-jump-mode-path "~/.emacs.d/packages/ace-jump-mode.el") ; https://github.com/winterTTr/ace-jump-mode/wiki
(defvar yaml-mode-path "~/.emacs.d/packages/yaml-mode/") ; https://github.com/yoshiki/yaml-mode
(defvar cmake-mode-path "/usr/share/emacs/site-lisp/cmake-mode.el")



;;;; ~/.emacs.d/env.el就相当于.emacs这个程序的配置文件。
(when (file-exists-p "~/.emacs.d/env.el")
  (load-file "~/.emacs.d/env.el"))
;; 如果想禁用某个package,可在env.el中让其path指向一个不存在的位置,如(setq color-theme-path "~/non-exist")


(defun add-to-load-path (dir-or-file-path)
  (if (file-directory-p dir-or-file-path)
      (add-to-list 'load-path dir-or-file-path)
    (add-to-list 'load-path (file-name-directory dir-or-file-path))))


;; elpa中的包优先,然后是自己下载的包(这个顺序好吗?)
;; elpa管理下的包地位仅次于built-in的包,可看作emacs的一部分。
;; 如果该包已经通过elpa安装并加载了,啥也不用做
;; 否则检测该包是否存在,若在就添加到load-path中,否则输出一行信息
(defun add-package (package dir-or-file-path)
  (cond ((package-installed-p package) t)
        ((file-exists-p dir-or-file-path) (add-to-load-path dir-or-file-path) t)
        (t (message "no %s" (symbol-name package)) nil))
  )


;;;; 甄别宿主平台

;; (equal system-name "DYN-ASUS")

(defun is-term ()
  (not initial-window-system))


(defun is-win2k ()
  (and
   (equal system-type 'windows-nt)
   (eq (car (w32-version)) 5)
   (eq (cadr (w32-version)) 0)))


(defun is-winxp ()
  (and
   (equal system-type 'windows-nt)
   (eq (car (w32-version)) 5)
   (eq (cadr (w32-version)) 1)))


(defun is-vista ()
  (and
   (equal system-type 'windows-nt)
   (eq (car (w32-version)) 6)
   (eq (cadr (w32-version)) 0)))


(defun is-win7 ()
  (and
   (equal system-type 'windows-nt)
   (eq (car (w32-version)) 6)
   (eq (cadr (w32-version)) 1)))


(defun is-ubuntu ()
  (if (equal system-type 'gnu/linux)
      t
    nil))


(defun is-cygwin ()
  (if (equal system-type 'cygwin)
      t
    nil))


;;;; 加载设置(以load打头),短而简单的配置,就直接在
;;;; load函数中做了;长而复杂的配置,在load中调用相应的configure函数。
;;;; 对路径的检测放在configure函数中,因为同一个configure函数会被多处调用。
;;;; 检测路径时,如果一个插件有自己独立的目录,检测该目录是否存在即可;如与其他插件共享目录,则检测其主要文件是否存在。
(defun load-common-settings ()

  (setq frame-title-format '("%b"
                             (:eval
                              (if (buffer-file-name)
                                  (concat " ("
                                          (directory-file-name
                                           (file-name-directory
                                            (abbreviate-file-name
                                             (buffer-file-name))))
                                          ")")
                                ""))
                             " - Emacs"))

  (add-to-list 'load-path "~/.emacs.d/")
  (add-to-list 'load-path "~/.emacs.d/ws/")
  (add-to-list 'load-path "~/.emacs.d/packages/")
  (add-to-list 'image-load-path "~/.emacs.d/images/")


  (when (file-exists-p "~/share/emacs/lisp/")
    (add-to-load-path "~/share/emacs/lisp/"))


  (require 'string-operations)
  (load "general-helper")
  (load "font-helper")
  (autoload 'bc-eval-region "bc" "bc" t)

  (require 'debug-log)
  (require 'ws)                         ; 中文分词
  (require 'pmh)
  (require 'smart-kill)


  (setq inhibit-startup-screen t)
  (setq column-number-mode t)
  (setq scroll-bar-mode-explicit t)
  (set-scroll-bar-mode 'right)
  (setq show-paren-mode t)
  (put 'narrow-to-region 'disabled nil)
  (require 'uniquify)
  (setq uniquify-buffer-name-style 'forward)

  ;; cua
  ;;(cua-mode)
  ;;(setq cua-prefix-override-inhibit-delay 0.1) ; default 0.2

  (iswitchb-mode t)
  ;; (which-func-mode 1) 不稳定,时而就无显示了。
  (setq read-file-name-completion-ignore-case t)
  (windmove-default-keybindings)
  (setq make-backup-files nil)
  (column-number-mode t)
  (show-paren-mode t)
  (global-set-key (kbd "C-z") 'undo)
  (global-set-key (kbd "C-/") 'suspend-emacs)
  (global-set-key (kbd "C-c w") 'delete-region)
  (global-set-key (kbd "C-c k") 'server-edit)
  (setq-default indicate-empty-lines t)

  ;; tab and space
  ;; when true, emacs use mixture of tab and space to achieve offset
  (setq-default indent-tabs-mode nil)
  ;; control length used to offset.
  ;;(setq-default c-basic-offset 4)

  (setq c-default-style
        '((c++-mode . "stroustrup")
          (java-mode . "java")
          (awk-mode . "awk")
          (other . "gnu")))

  ;; control how emacs explain TAB.
  (setq-default tab-width 4)
  ;; (defun my-java-mode-hook ()
  ;;   (setq c-basic-offset 4))
  ;; (add-hook 'java-mode-hook 'my-java-mode-hook)

  ;; (add-hook 'before-save-hook 'delete-trailing-whitespace)

  (global-set-key (kbd "<C-f8>") 'insert-key-sequence)

  ;; 这种方法不行,按钮添加上去了,可是过一会就消失了,而且按钮在最左边。
  ;; (define-key global-map [tool-bar new-untitled-button]
  ;;   '(menu-item "New untitled" new-untitled
  ;;               :help "New untitled!"
  ;;               :image (image :type xpm :file "new.xpm")))

  ;; 得用这种方法
  (tool-bar-add-item "new-untitled" 'new-untitled 'new-untitled-button :help "New untitled")
  (tool-bar-add-item "home" 'open-init-file 'open-init-file-button :help "Open init-file")
  (tool-bar-add-item "delete-other-windows" 'delete-other-windows 'delete-other-windows-button :help "Maximize")


  (configure-org-mode)
  (configure-color-theme)
  (configure-c++-mode)
  (configure-python-mode)
  (configure-emacs-lisp-mode)
  (configure-haskell-mode)
  (configure-auto-complete)
  (configure-yasnippet)
  (configure-markdown-mode)
  (configure-yaml-mode)
  (configure-cmake-mode)
  (configure-paredit)
  (configure-ace-jump-mode)
  (configure-calendar/diary))


(defun load-win-common-settings ()
  (load-common-settings)
  (server-start)
  (when (fboundp 'ime-save-and-set-status)
    (require 'smart-ime)
    (smart-ime-mode 1))

  ;;(w32-register-hot-key [M-tab]) ; win7下无效
  ;;(w32-unregister-hot-key [M-tab])
  (configure-ntcmd-mode)
  (configure-powershell)
  (configure-powershell-mode)
  (configure-visual-basic-mode)
  (global-set-key (kbd "<C-wheel-up>") 'text-scale-increase)
  (global-set-key (kbd "<C-wheel-down>") 'text-scale-decrease))


(defun load-winxp-settings ()
  (load-win-common-settings)
  (load-winxp-font-settings))


(defun load-win7-settings ()

  ;;(make-frame-invisible)
  (load-win-common-settings)
  (load-win7-font-settings)
  ;;(tool-bar-mode 1)
  ;;(tool-bar-mode -1) ; 有了这行,frame最大化就有问题。http://stackoverflow.com/questions/815239/how-to-maximize-emacs-on-windows-at-startup  可通过注册去除工具栏
  ;;(w32-send-sys-command 61488)          ; frame最大化

  ;;(make-frame-visible)
)


(defun load-linux-common-settings ()

  (load-common-settings)

  ;; add the line below to ~/.bashrc
  ;;alias emacs='XMODIFIERS=@im=none emacs'

  (configure-gdb)

  (setq bookmark-save-flag 1)

  (configure-xcscope)

  (configure-epm)

  ;;(configure-edect) ; emacs自带的已经很好用了。
  (configure-semantic)

  (global-set-key (kbd "<C-mouse-4>") 'text-scale-increase)
  (global-set-key (kbd "<C-mouse-5>") 'text-scale-decrease))


(defun load-ubuntu-settings ()

  (load-linux-common-settings)
  (load-ubuntu-font-settings)
  (configure-ibus)                 ; 并非所有linux系统的输入法都是ibus

  ;; 使得能够在emacs跟其他程序之间复制粘贴
  (setq x-select-enable-clipboard t)

  (configure-auctex))


(defun load-cygwin-settings ()
  (load-linux-common-settings)

  ;; need emacs compiled with smart-ime supports
  (when (fboundp 'ime-save-and-set-status)
    (require 'smart-ime)
    (smart-ime-mode 1))
)


(defun load-term-settings ()
  (load-linux-common-settings))

  ;; (when (file-exists-p org-path)
  ;;   (add-to-list 'load-path (concat org-path "lisp"))
  ;;   (add-to-list 'load-path (concat org-path "contrib/lisp")))


;;;; 一次性的设置(以configure打头)
(defun configure-org-mode ()
  (when (add-package 'org (concat org-path "lisp"))
    (add-package 'org-plus-contrib (concat org-path "contrib/lisp"))

    (setq org-replace-disputed-keys t)

    ;; (when (file-exists-p org-path)
    ;;   (require 'org-install))

    (global-set-key (kbd "C-c l") 'org-store-link)
    (global-set-key (kbd "C-c c") 'org-capture)
    (global-set-key (kbd "C-c a") 'org-agenda)
    (global-set-key (kbd "C-c b") 'org-iswitchb)

    ;; Setting up Remember for Org
    (org-remember-insinuate)
    (setq org-directory "~/orgfiles/")
    (setq org-default-notes-file (concat org-directory "notes.org"))
    (define-key global-map "\C-cr" 'org-remember)


    (add-to-list 'auto-mode-alist '("\\.txt\\'" . org-mode))
    (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
    ;;(add-to-list 'auto-mode-alist '("\\.txt\\'" . orgtbl-mode))
    ;; (add-to-list 'auto-mode-alist '("\\.txt\\'" . orgstruct-mode))
    ;; (add-to-list 'auto-mode-alist '("\\.txt\\'" . orgstruct++-mode))

    ;; (global-set-key "\C-c L" 'org-insert-link-global)
    ;; (global-set-key "\C-c o" 'org-open-at-point-global)



    (setq org-src-fontify-natively t)

    (add-hook 'org-mode-hook 'tweak-org-mode)

    ;; (add-to-list 'load-path "~/org-7.5/contrib/lisp")
    ;; (require 'org-toc)
    ;; (global-set-key "\C-cs" 'org-toc-show)
    (setq org-ctrl-k-protect-subtree 'error)
    (require 'doc-struct)

    )
  )


(defun configure-ibus ()
  (if (not (file-exists-p ibus-path))
      (message "no ibus.el")
    (add-to-load-path ibus-path)
    (if (file-exists-p (concat ibus-path "ibus.el"))
        (require 'ibus)
      (require 'ibus "ibus-dev.el"))    ; bzr库中的名为ibus-dev.el,而非ibus.el。
    ;; Turn on ibus-mode automatically after loading .emacs
    (add-hook 'after-init-hook 'ibus-mode-on)
    ;; Use C-SPC for Set Mark command
    (ibus-define-common-key ?\C-\s nil)
    ;; Use C-/ for Undo command
    ;;(ibus-define-common-key ?\C-/ nil)
    (ibus-define-common-key ?\C-z nil)
    ;; Change cursor color depending on IBus status
    (setq ibus-cursor-color '("red" "blue" "limegreen"))

    ;; use C-; to toggle IBus
    (global-set-key [(control ?\;)] 'ibus-toggle)
    ;; Enable C-; key only for preediting
    (ibus-define-common-key [(control ?\;)] nil)
    (ibus-define-preedit-key [(control ?\;)] t)))


(defun configure-gdb ()
  (setq gdb-many-windows t)
  ;;(setq gdb-show-main t)
  )


(defun configure-semantic ()
  ;; 参考emacs手册Programs/Semantic一节,以及更全面的semantic手册

  (semantic-mode 1)


  ;; Idle Scheduler
  (global-semantic-idle-scheduler-mode 1)
  ;;(global-semantic-idle-completions-mode) ; 空闲时自动补全。自动补全后可按M-p或M-n在候选之间切换。回车接受。TAB切换并接受。C-g退出。


  ;; MRU Bookmarks mode,给最近使用的tag加书签,以便返回
  ;;(global-semantic-mru-bookmark-mode 1)


  ;; Sticky Function mode,就算函数或类的名字被翻页翻上去了,仍然用一行显示出来,让你知道你在哪个函数中。
  ;; 相比which-func-mode,好处在于which-func-mode显示的名字一旦横向切分窗口可能就看不见了。
  (global-semantic-stickyfunc-mode 1)


  ;; Highlight Func Mode,不喜欢
  ;;(global-semantic-highlight-func-mode 1)


  ;; Tag Decoration Mode,把屏幕弄得花花绿绿的,不喜欢
  ;; (global-semantic-decoration-mode 1)
  ;; (semantic-toggle-decoration-style 'semantic-tag-boundary t)
  ;; (semantic-toggle-decoration-style 'semantic-decoration-on-private-members t)
  ;; (semantic-toggle-decoration-style 'semantic-decoration-on-protected-members t)
  ;; (semantic-toggle-decoration-style 'semantic-decoration-on-includes t)

  )


(defun configure-cedect ()
  ;; according to http://alexott.net/en/writings/emacs-devenv/EmacsCedet.html
  (load-file "~/cedet-1.0/common/cedet.el")

  ;;; 工程管理。我不用它,我用我自己的epm。
  ;; (global-ede-mode 1)


  ;; 下边这5个,都是预先定义的设置。一个比一个功能多,可通过(C-h f)查看其区别。
  ;; 但这些都不符合我的需求,有些缺我要的功能,有些虽有我要的,但却包含我不想要的。
  ;; 因此,我从最小功能集合出发,然后自行定义。
  ;; (semantic-load-enable-minimum-features)
  (semantic-load-enable-code-helpers)
  ;; (semantic-load-enable-gaudy-code-helpers) ;
  ;; (semantic-load-enable-excessive-code-helpers)
  ;; (semantic-load-enable-semantic-debugging-helpers)


  ;; semantic-ia这个包能在使用时自动加载。但我们提前加载。在
  ;; (semantic-load-enable-minimum-features)及以上,semantic-ia中的命令
  ;; 就可以正常工作。
  (require 'semantic-ia)


  ;;; 在菜单栏上添加一个TAGS菜单,该功能在(semantic-load-enable-code-helpers)及以上都是默认打开的。
  ;; (add-hook 'semantic-init-hooks
  ;;           '(lambda ()
  ;;              (imenu-add-to-menubar "TAGS")))



  ;;; 名字补全。有两种途径:第一种,用semantic-ia这个包。第二种,用
  ;; Senator这个包。前者更精确,后者速度更快。(semantic-load-enable-code-helpers)会使用Senator。
  ;; 分别如下:

  ;; semantic-ia提供的三种补全方式:
  ;; M-x semantic-ia-complete-symbol 以buffer方式呈现候选名字
  ;; M-x semantic-ia-complete-symbol-menu 以菜单方式呈现候选名字
  ;; M-x semantic-ia-complete-tip 以tooltip方式呈现候选名字

  ;; Senator提供的三种补全方式
  ;; M-x senator-complete-symbol 以buffer方式呈现候选名字 (C-c , TAB)
  ;; M-x senator-completion-menu-popup 以菜单方式呈现候选名字 (C-c , SPC)

  ;; 我想把本来绑定在Senator身上的两个键(C-c , TAB)和(C-c , SPC)绑定到semantic-ia中的对应物上,但是改不了。
  ;; 可能是受emacs自带的cedet功能影响吧。于是绑到(C-c TAB)和(C-c SPC)上。感觉效果并没有想象中的好。
  ;; (add-hook 'c-mode-common-hook
  ;;           '(lambda ()
  ;;              (local-set-key (kbd "C-c TAB") 'semantic-ia-complete-symbol)
  ;;              ;(local-set-key (kbd "C-c SPC") 'semantic-ia-complete-tip)
  ;;              (local-set-key (kbd "C-c SPC") 'semantic-ia-complete-symbol-menu)))



  ;; c模式下,按.或>之后,呈现补全候选
  (add-hook 'c-mode-common-hook
            '(lambda ()
               (local-set-key "." 'semantic-complete-self-insert)
               (local-set-key ">" 'semantic-complete-self-insert)))



  ;;; 打开srecode小模式,以便插入代码模板
  ;(global-srecode-minor-mode 1)            ; Enable template insertion menu

  )


(defun configure-auctex ()
  (if (not (file-exists-p auctex-path))
      (message "no auctex")
    (add-to-load-path auctex-path)
    (load "auctex.el" nil t t)
    (load "preview-latex.el" nil t t)
    (setq TeX-auto-save t)
    (setq TeX-parse-self t)
    (setq-default TeX-master nil)


    ;; 用xetex引擎而不是默认的引擎(xetex对中文字体的支持好)
    (setq TeX-engine 'xetex)

    ;; 产生pdf而不是dvi
    (setq TeX-PDF-mode t)

    (add-hook 'TeX-mode-hook 'tweak-TeX-mode)



    ;; ubuntu 10.04的evince版本太老,不支持从pdf切换到latex中对应点。
    ;; 而又无法为其安装高版本的evince。所以用来自KDE的okular作为pdf阅读器。
    ;; okular命令行选项
    ;; --unique让okular复用同一个进程。
    ;; %打头的占位符的含义请参考变量TeX-expand-list的文档
    ;; %n TeX-current-line
    ;; %b TeX-current-file-name-master-relative
    (setq TeX-view-program-list '(("Okular"
                                   ("okular"
                                    (mode-io-correlate " --unique %o#src:%n%b")))))


    ;; 把上边定义的okular程序放在列表最前面,如果输出是pdf,就使用okular
    ;; (setq TeX-view-program-selection
    ;;       (cons '(output-pdf "Okular") TeX-view-program-selection))
    (setq TeX-view-program-selection '((output-pdf "Okular")))


    ))


(defun configure-color-theme ()
  ;; (load-theme 'adwaita t)
  ;; (load-theme 'deeper-blue t)           ;
  ;; (load-theme 'dichromacy t)
  (load-theme 'light-blue t)            ;
  ;; (load-theme 'manoj-dark t)
  ;; (load-theme 'misterioso t)
  ;; (load-theme 'tango t)
  ;; (load-theme 'tango-dark t)            ;
  ;; (load-theme 'tsdh-dark t)             ;
  ;; (load-theme 'tsdh-light t)
  ;; (load-theme 'wheatgrass t)            ;
  ;; (load-theme 'whiteboard t)
  ;; (load-theme 'wombat t)                ;

  )
;; for emacs 23
;; (defun configure-color-theme ()
;;   (if (not (file-exists-p color-theme-path))
;;       (message "no color-theme")
;;     (add-to-load-path color-theme-path)
;;     (require 'color-theme)

;;     ;; 我自己收集的color themes都放在~/.emacs.d/packages/my-color-themes/下,或者有其独立目录,或者没有,通通加入laod-path。
;;     (add-to-list 'load-path "~/.emacs.d/packages/my-color-themes/")
;;     (let ((default-directory "~/.emacs.d/packages/my-color-themes/"))
;;       (normal-top-level-add-subdirs-to-load-path)) ; http://emacswiki.org/emacs/LoadPath#toc2

;;     ;; http://blog.jdhuntington.com/2008/11/emacs-color-theme-blackboard.html
;;     (autoload 'color-theme-blackboard "color-theme-blackboard" "color theme blackboard" t)
;;     ;; https://github.com/sellout/emacs-color-theme-solarized
;;     (autoload 'color-theme-solarized-light "color-theme-solarized" "color-theme-solarized-light" t)
;;     (autoload 'color-theme-solarized-dark "color-theme-solarized" "color-theme-solarized-dark" t)

;;     (eval-after-load "color-theme"
;;       '(progn
;;          (color-theme-initialize)
;;          (fset 'color-theme-snapshot (color-theme-make-snapshot))
;;          ;;(color-theme-hober)
;;          ;;(color-theme-blackboard)
;;          (color-theme-deep-blue)
;;          ))
;;     (autoload 'use-color-theme "color-theme-helper" "use specified color theme" t)
;;     ))


(defun configure-auto-complete ()
  (when (add-package 'auto-complete auto-complete-path)
    
    
    (require 'auto-complete-config)
    (add-to-list 'ac-dictionary-directories (concat auto-complete-path "ac-dict"))
    (ac-config-default)
    )
  )


(defun configure-yasnippet ()
  (when (add-package 'yasnippet yasnippet-path)
    (require 'yasnippet)
    (yas/global-mode 1)
    )
  )


(defun configure-visual-basic-mode ()
  (if (not (file-exists-p visual-basic-mode-path))
      (message "no visual-basic-mode")
    (add-to-load-path visual-basic-mode-path)
    (autoload 'visual-basic-mode "visual-basic-mode" "Visual Basic mode." t)
    (add-to-list 'auto-mode-alist '("\\.vbs\\'" . visual-basic-mode))
    (add-to-list 'auto-mode-alist '("\\.vb\\'" . visual-basic-mode))
    (add-to-list 'auto-mode-alist '("\\.bas\\'" . visual-basic-mode))
    (add-to-list 'auto-mode-alist '("\\.frm\\'" . visual-basic-mode))
    (add-to-list 'auto-mode-alist '("\\.cls\\'" . visual-basic-mode))))


(defun configure-c++-mode ()
  (load "c++-helper.el" nil t t)
  (autoload 'make-guard "c++-helper" "make guard in C++ header" t)
  (autoload 'rebuild-and-reload-BROWSE "c++-helper" "rebuild and reload BROWSE" t)
  (autoload 'fix-enum-class "c++-helper" "Setup `c++-mode' to better handle \"class enum\"." t)
  (add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
  (add-hook 'c++-mode-hook 'tweak-c++-mode))


(defun configure-python-mode ()
  (add-hook 'python-mode-hook
            '(lambda ()
               (define-key python-mode-map "\C-c\C-c" 'comment-region))))


(defun configure-emacs-lisp-mode ()
  (add-hook 'emacs-lisp-mode-hook 'tweak-emacs-lisp-mode))


(defun configure-haskell-mode ()
  (if (not (file-exists-p haskell-mode-path))
      (message "no haskell-mode")
    (add-to-load-path haskell-mode-path)
    (autoload 'haskell-mode "haskell-site-file" "haskell mode." t)
    (add-to-list 'auto-mode-alist '("\\.hs\\'" . haskell-mode))
    (add-hook 'haskell-mode-hook 'tweak-haskell-mode)))


(defun configure-ntcmd-mode ()
  (if (not (file-exists-p ntcmd-path))
      (message "no ntcmd-mode")
    (add-to-load-path ntcmd-path)
    (add-to-list 'auto-mode-alist '("\\.bat\\'" . ntcmd-mode))
    (autoload 'ntcmd-mode "ntcmd" "ntcmd-mode" t)))


(defun configure-powershell ()
  ;; 在emacs中运行powershell
  ;; M-x powershell 即可
  (if (not (file-exists-p powershell-path))
      (message "no powershell")
    (add-to-load-path powershell-path)
    (autoload 'powershell "Powershell" "powershell" t)))


(defun configure-powershell-mode ()
  ;; powershell脚本模式
  (if (not (file-exists-p powershell-mode-path))
      (message "no powershell-mode")
    (add-to-load-path powershell-mode-path)
    (autoload 'powershell-mode "powershell-mode" "powershell-mode" t)
    (add-to-list 'auto-mode-alist '("\\.ps1\\'" . powershell-mode))))


(defun configure-markdown-mode ()
  (if (not (file-exists-p markdown-mode-path))
      (message "no markdown-mode")
    (add-to-load-path markdown-mode-path)
    (autoload 'markdown-mode "markdown-mode.el" "Major mode for editing Markdown files" t)
    (add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
    (add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))))


(defun configure-yaml-mode ()
  (when (add-package 'yaml-mode yaml-mode-path)
    (autoload 'yaml-mode "yaml-mode.el" "Major mode for editing YAML files" t)
    (add-to-list 'auto-mode-alist '("\\.yaml\\'" . yaml-mode))
    (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
    (add-hook 'yaml-mode-hook
              '(lambda ()
                 (define-key yaml-mode-map "\C-c\C-c" 'comment-region))))
  
  )


(defun configure-cmake-mode ()
  (if (not (file-exists-p cmake-mode-path))
      (message "no cmake-mode")
    (add-to-load-path cmake-mode-path)
    (autoload 'cmake-mode "cmake-mode.el" "Major mode for editing CMake listfiles." t)
    (add-to-list 'auto-mode-alist '("CMakeLists\\.txt\\'" . cmake-mode))
    (add-to-list 'auto-mode-alist '("\\.cmake\\'" . cmake-mode))
    (add-hook 'cmake-mode-hook
              '(lambda ()
                 (define-key cmake-mode-map "\C-c\C-c" 'comment-region)))
    )
  )


(defun configure-ace-jump-mode ()
  (if (not (file-exists-p ace-jump-mode-path))
      (message "no ace-jump-mode")
    (require 'ace-jump-mode)
    (define-key global-map (kbd "C-c SPC") 'ace-jump-mode)))

;; 例子
;; (defun foo ()
;;    (if (f 5)
;;        (let ((a 1))
;;          |(bar a)) ;; M-x paredit-convolute-sexp, | stands for the cursor
;;      (qux 2))) 
;; 变成
;; (defun foo ()
;;   (let ((a 1))
;;     (if (f 5) 
;;         (bar a)
;;       (qux 2))))
(defun configure-paredit ()
  (when (add-package 'paredit paredit-path)
    (autoload 'paredit-mode "paredit"
      "Minor mode for pseudo-structurally editing Lisp code." t))
  )


(defun configure-xcscope ()
  (if (not (file-exists-p cscope-path))
      (message "no xcscope")
    (add-to-load-path cscope-path)
    (require 'xcscope)))


(defun configure-epm ()
  (if (not (file-exists-p epm-path))
      (message "no epm")
    (load (concat epm-path "epmacs"))
    (global-set-key [f7] 'epm-build)
    (global-set-key [C-f7] 'epm-compile)
    (global-set-key [f5] 'epm-run-gdb)))


(defun configure-calendar/diary ()
  (setq appt-display-format 'window)
  (appt-activate)
  ;; appt-audible
  ;; appt-display-duration
  ;; appt-disp-window-function
  ;; appt-delete-window-function
  ;; appt-message-warning-time
  ;; (setq appt-display-diary nil)
  )


;;;; 挂在hook上的各种微调(以tweak打头)。如果短而简单,
;;;; 就直接放在configure函数中的lambda中;如果长而复杂,才在此处建立专
;;;; 门的tweak函数。

(defun tweak-org-mode ()
  (visual-line-mode)

  ;; (require 'smart-kill)
  ;; (turn-on-smart-kill)

  (ws-mode 1)

  ;; handle conflict between smart-kill-mode and ws-mode on M-d
  ;; (define-key smart-kill-mode-map "\M-d" 'ws-smart-kill-word)
  ;; (define-key ws-mode-map "\M-d" 'ws-smart-kill-word)

  )

(defun tweak-TeX-mode ()
  (TeX-source-correlate-mode)
  ;;TeX-source-correlate-method


  ;; reftex的toc远比outline模式好用
  ;;(outline-minor-mode 1)
  (turn-on-reftex)

  (visual-line-mode)

  ;; (require 'smart-kill)
  ;; (turn-on-smart-kill)

  (ws-mode 1)

  ;; ;; handle conflict between smart-kill-mode and ws-mode on M-d
  ;; (define-key smart-kill-mode-map "\M-d" 'ws-smart-kill-word)
  ;; (define-key ws-mode-map "\M-d" 'ws-smart-kill-word)

  (define-key TeX-mode-map (kbd "<f12>") 'toggle-line-spacing)

  )


(defun tweak-emacs-lisp-mode ()
  (define-key emacs-lisp-mode-map "\C-c\C-c" 'comment-region)
  (ws-mode)                             ; 中文分词

  (when (file-exists-p paredit-path)
    (paredit-mode +1)  
    (pmh-mode t)
    ;; 在汉字中启用ws-mode,在英文中启用paredit-mode 
    ;; todo: paredit-mode非自带,需要先检测
    (add-hook 'pmh-hook '(lambda ()
                           (if (looking-at "\\cc")
                               (progn
                                 (setq paredit-mode nil)
                                 (setq ws-mode t)
                                 )
                             (setq paredit-mode +1)
                             (setq ws-mode nil)))
              nil
              t
              )
    )
  )


(defun tweak-c++-mode ()
  ;;(buffer-face-mode -1)
  ;;(buffer-face-set 'c++mode)



  ;;HelloWorld
  ;; glass-mode

  ;;我要按照<<Code Complete>>的建议在缩进的注释中写伪代码,/会导致当前行被自动缩进
  (c-toggle-electric-state -1)
  ;;(setq c-syntactic-indentation nil)

  (fix-enum-class)


  (subword-mode 1)           ; 视大写字母为word的边界,helloWorldChina
  (ws-mode)                  ; 中文分词
  (pmh-mode)
  ;; 在汉字中启用ws-mode,在英文中启用subword-mode
  (add-hook 'pmh-hook '(lambda ()
                         (if (looking-at "\\cc")
                             (progn
                               (setq subword-mode nil)
                               (setq ws-mode t)
                             )
                           (setq subword-mode t)
                           (setq ws-mode nil)))
            nil
            t
            )


  ;; ws-mode可以和我的smart-kill-mode共存
  ;; subword-mode可以和我的smart-kill-mode共存
  ;; 但不要在同一个buffer中同时启用ws-mode与subword-mode
  ;; smart-kill-mode conflicts with subword-mode
  ;; reason: kill-word-without-kill-ring uses kill-word
  ;; (require 'smart-kill)
  ;; (turn-on-smart-kill)
  ;; ;; handle conflict between smart-kill-mode and subword-mode on M-d
  ;; (define-key smart-kill-mode-map "\M-d" 'smart-kill-subword)
  ;; (define-key subword-mode-map "\M-d" 'smart-kill-subword)

  (local-set-key (kbd "<f4>") 'rebuild-and-reload-BROWSE)



  )

(defun tweak-haskell-mode ()
  (define-key haskell-mode-map "\C-c\C-c" 'comment-region)

  (turn-on-haskell-doc-mode)

  ;; 三种不同的缩进模式,只能启用一种
  ;;(turn-on-haskell-indentation)
  (turn-on-haskell-indent)
  ;;(turn-on-haskell-simple-indent)


  (subword-mode 1)  
  (ws-mode)                             ; 中文分词
  (pmh-mode)
  ;; 在汉字中启用ws-mode,在英文中启用subword-mode 
  (add-hook 'pmh-hook '(lambda ()
                         (if (looking-at "\\cc")
                             (progn
                               (setq subword-mode nil)
                               (setq ws-mode t))
                           (setq subword-mode t)
                           (setq ws-mode nil)))
            nil
            t)

  )


;;;; 待整理
;; 还需要以下这些东西
;; pymacs
;; simsum form windows
;; locate-library



;;;; 下面是M-x customize生产的

(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.
 '(column-number-mode t)
 '(org-agenda-files (quote ("f:/womacs-dev/womacs/开发手记.txt" "f:/投稿/盘点.txt")))
 '(show-paren-mode t))
(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.
 '(default ((t (:family "Consolas" :foundry "outline" :slant normal :weight normal :height 143 :width normal))))
 '(table-cell ((t (:background "pale goldenrod" :foreground "black" :inverse-video nil))) t))
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)


;; ;;; This was installed by package-install.el.
;; ;;; This provides support for the package system and
;; ;;; interfacing with ELPA, the package archive.
;; ;;; Move this code earlier if you want to reference
;; ;;; packages in your .emacs.
;; (when
;;     (load
;;      (expand-file-name "~/.emacs.d/elpa/package.el"))
;;   (package-initialize))



;; 调整默认字体大小后再最大化窗口,所以将主入口放在自动生成的配置之后。
;;;; 主入口(main entry)
(cond 
 ((is-ubuntu) (load-ubuntu-settings))  ; Ubuntu
 ((is-winxp) (load-winxp-settings))    ; Windows XP
 ((is-win7) (load-win7-settings))      ; Windows 7
 ((is-cygwin) (load-cygwin-settings))  ; Cygwin
 ((is-term) (load-term-settings))      ; character only terminal
 )
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.