/
gnu-emacs
1300 lines (1078 loc) · 46.4 KB
/
gnu-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
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
;;; gnu-emacs --- initialization file for Gnu Emacs
;;; Commentary:
;;; Code:
(require 'init-path
(expand-file-name "init-path.el"
(concat (getenv "HOME") "/config/emacs-init")))
(require 'init-version)
(require 'init-package)
;;=============================================================================
;; Set geometry on Mac; darwin emacs does not like -g 80x50
;;=============================================================================
(if running-darwin-gnuemacs
(progn
(set-frame-width (selected-frame) 88)
(set-frame-height (selected-frame) 55)
(setq locate-command "mdfind")
))
(require 'init-keybind)
;;=============================================================================
;; semantic really is a cow
;;=============================================================================
(setq max-specpdl-size 8000)
(setq max-lisp-eval-depth 22000)
;;=============================================================================
;; Start the Emacs server
;;=============================================================================
;;(require 'gnuserv)
;;(gnuserv-start)
(require 'init-ui)
(require 'init-edit)
(require 'init-search)
;;=============================================================================
;; Setup dired mode
;;=============================================================================
(require 'dired-x)
(setq diredp-hide-details-initially-flag nil)
;; -a list all files
;; -l long format
;; -D help emacs dired mode
;; -G enable colorized output
(if running-darwin-gnuemacs
(setq dired-listing-switches "-a -l -G")
(setq dired-listing-switches "-a -l -D -G"))
;; reuse current buffer by pressing 'a'
(put 'dired-find-alternate-file 'disabled nil)
;; allow dired to be able to delete or copy a whole dir.
(setq dired-recursive-copies (quote always)) ; “always” means no asking
(setq dired-recursive-deletes (quote top)) ; “top” means ask once
;; if there is a dired buffer displayed in the next window, use its
;; current subdir, instead of the current subdir of this dired buffer
(setq dired-dwim-target t)
(add-hook 'dired-load-hook
(lambda () (load "dired-x")))
(add-hook 'dired-mode-hook 'diff-hl-dired-mode)
;;=============================================================================
;; Setup ispell and flyspell
;;=============================================================================
(require 'ispell)
;; (progn
;; (let (mac-portsaspell-prg "/opt/local/bin/aspell")
;; (if (file-exists-p aspell-prg)
;; (setq-default ispell-program-name aspell-prg))))
;; (let ((gnuwin32-grep "c:/gnuwin32/bin/grep.exe")
;; (msys-grep "c:/MinGW/msys/1.0/bin/grep.exe"))
;; (cond ((file-exists-p gnuwin32-grep)
;; (setq-default ispell-grep-command gnuwin32-grep))
;; ((file-exists-p msys-grep)
;; (setq-default ispell-grep-command msys-grep))))
;; (setq-default ispell-grep-options "-E")
;; (setq-default ispell-program-name "aspell")))
(if (file-exists-p "/opt/local/bin/aspell")
(progn
(setq-default ispell-program-name "aspell")
(setq ispell-list-command "--list")))
(when (executable-find ispell-program-name)
(autoload 'flyspell-mode "flyspell" "On-the-fly spelling checker." t))
;;=============================================================================
;; Make editing this file easier. Put the file name in the register 'e'.
;; To edit this file: C-x r j e or f5 (jump-to-register)
;;
;; Now ~/config/emacs and ~/config/gnu-emacs are bookmarked
;; To visit: C-x r b (jump-to-bookmark)
;;
;; C-x r m set a bookmark
;; C-x r b jump to bookmark
;; C-x r l list bookmarks
;;=============================================================================
;;(set-register ?e '(file . "~/config/gnu-emacs"))
;; Open the bookmark list
(require 'bookmark)
(bookmark-bmenu-list)
(switch-to-previous-buffer)
;;=============================================================================
;; Setup text mode
;;=============================================================================
(add-hook 'text-mode-hook 'turn-on-auto-fill)
(add-hook 'text-mode-hook 'turn-on-flyspell)
;;=============================================================================
;; Setup Org mode
;;=============================================================================
(require 'org)
(define-key global-map "\C-cl" 'org-store-link)
(define-key global-map "\C-ca" 'org-agenda)
(setq org-log-done t)
;;=============================================================================
;;=============================================================================
;; Setup CEDET
;;=============================================================================
;; While Emacs 24 comes with cedet built in, that version of cedet does not
;; have a semantic-load that jde (as of 2.4.0.1) expects. So we will load a
;; non-built-in version
;;(let* ((site-lisp-path
;; (cond (running-ntemacs "c:/cygwin/usr/local/share/emacs/site-lisp")
;; (t "/usr/local/share/emacs/site-lisp")))
;; (cedet-elisp-canidate-list
;; (list
;; (expand-file-name
;; "cedet.el"
;; (concat site-lisp-path "/" "cedet-1.1" "/common"))
;; (expand-file-name
;; "cedet.el"
;; (concat site-lisp-path "/" "cedet-1.0pre4" "/common"))
;; (expand-file-name
;; "cedet.el"
;; (concat site-lisp-path "/" "cedet-1.0beta3b" "/common")))))
;; (dolist (cedet-elisp cedet-elisp-canidate-list)
;; (if (file-exists-p cedet-elisp)
;; (load-file cedet-elisp))))
;;
;;(setq semanticdb-default-save-directory "~/.semantic")
(require 'init-help)
(require 'init-vc)
(setq auto-mode-alist
(append '(("emacs" . emacs-lisp-mode)
("gnu-emacs" . emacs-lisp-mode)
("SConstruct" . python-mode)
("SConscript" . python-mode)
("bourne_common_startup" . sh-mode)
("korn_common_startup" . sh-mode)
("korn_common_aliases" . sh-mode)
("bash_aliases" . sh-mode)
("bash_functions" . sh-mode))
auto-mode-alist))
;;=============================================================================
;; Setup ggtags mode - GNU Global tags system
;;=============================================================================
(autoload 'gtags-mode "gtags" "" t)
;;=============================================================================
;; Setup shell mode
;;=============================================================================
(cond (system-is-w32
(setq binary-process-input t)
(setq shell-file-name "bash")
(setenv "SHELL" shell-file-name)
(setq explicit-shell-file-name "bash")
(setq process-coding-system-alias
(cons '("bash" . undecided-unix) process-coding-system-alist))
(defun my-shell-setup ()
"For bash (cygwin) under NT Emacs 21"
(setq comint-scroll-show-maximum-output 'this)
(setq comint-completion-addsuffix t)
(setq comint-process-echoes t) ;; reported this is no longer needed
(setq comint-eol-on-send t)
(setq shell-completion-execonly nil)
(setq shell-pushd-tohome t)
(setq w32-quote-process-args ?\")
(make-variable-buffer-local 'comint-completion-addsuffix)
;; move to beginning of line, after prompt
(local-set-key [home] 'comint-bol)
;; cycle backward through command history
(local-set-key [up]
(lambda () (interactive)
(if (comint-after-pmark-p)
(comint-previous-input 1)
(previous-line 1))))
(local-set-key [down]
'(lambda () (interactive)
(if (comint-after-pmark-p)
(comint-next-input 1)
(forward-line 1)))))
(setq shell-mode-hook 'my-shell-setup)
;;
;; This removes unsightly ^M characters that would otherwise
;; appear in the output of java applications.
;;
(add-hook 'comint-output-filter-functions
'comint-strip-ctrl-m)))
;;=============================================================================
;; Setup eshell mode
;;=============================================================================
(cond (system-is-w32
(setenv "CDPATH" ".")))
(defun my-eshell-prompt-function ()
"Set the prompt in eshell to last directory name followed by # or $."
(let ((pwd (eshell/pwd))
(prompt-char (if (= (user-uid) 0) " # " " $ ")))
(concat (if (string-match "^.*/" pwd)
(substring pwd (match-end 0))
pwd)
prompt-char)))
(setq eshell-prompt-function 'my-eshell-prompt-function)
;; Tell eshell's file completion to ignore:
;; emacs backup files, java class files and object files
(setq eshell-cmpl-file-ignore "~\\'\\|\\.class$\\|\\.o$")
;; Don't add input matching the last to histoty input ring
(setq eshell-hist-ignoredups t)
;; Don't ask to save the history; just save it
(setq eshell-ask-to-save-history 'always)
;; Don't ask to save the last-dir-ring; just save it
(setq eshell-ask-to-save-last-dir 'always)
;; make pushd with no arg behave as 'pushd ~' (like `cd')
(setq eshell-pushd-tohome t)
;; make pushd only add unique directories to the stack
(setq eshell-pushd-dunique t)
;; List file sizes in human readable terms
(setq eshell-ls-initial-args "-h")
(setq eshell-ls-dired-initial-args "-h")
(setq eshell-ls-exclude-regexp "~\\'")
(setq eshell-ls-product-regexp
"\\.\\(elc\\|o\\(bj\\)?\\|class\\|a\\||lib\\|res\\)\\'")
;;=============================================================================
;; Setup ange-ftp mode
;;=============================================================================
(if running-ntemacs
(setq ange-ftp-ftp-program-name "c:/cygwin/bin/ftp.exe"))
(setq ange-ftp-generate-anonymous-password "lee@leebrinton.net")
;;=============================================================================
;; Setup TRAMP mode
;;=============================================================================
(require 'tramp)
(setq tramp-default-method "ssh")
;;=============================================================================
;; Setup browse-url
;;=============================================================================
(require 'browse-url)
(setq browse-url-new-window-p t)
(add-to-list
'browse-url-filename-alist
'("/\\[scp/elrond\\]/usr/local/www/data.elrond/" . "http://elrond/"))
(cond
((eq system-type 'darwin)
(setq browse-url-browser-function 'browse-url-default-macosx-browser))
(system-is-unix
(setq browse-url-generic-program "mozilla"))
(system-is-w32
(setq browse-url-generic-program
"c:/Program Files/Internet Explorer/iexplore.exe")))
;;----------------------------------------------------------------------------
;; Browse current HTML file
;;----------------------------------------------------------------------------
(defun browse-current-file ()
"Open the current file as a URL using `browse-url'."
(interactive)
(let ((file-name (buffer-file-name)))
(if (tramp-tramp-file-p file-name)
(error "Cannot open tramp file")
(browse-url (concat "file://" file-name)))))
;;=============================================================================
;; Setup abbrev mode
;;=============================================================================
(abbrev-mode t)
(setq dabbrev-case-replace nil)
;; load abbrevs from ~/.abbrev_defs
(setq abbrev-file-name
(expand-file-name "abbrev_defs" user-emacs-directory))
(if (file-exists-p abbrev-file-name)
(quietly-read-abbrev-file))
(setq hippie-expand-try-functions-list
'(try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-complete-file-name-partially
try-complete-file-name
try-expand-all-abbrevs
try-expand-list
try-expand-line
try-complete-lisp-symbol-partially
try-complete-lisp-symbol))
;;=============================================================================
;; Setup auto-insert
;;=============================================================================
(add-hook 'find-file-hooks 'auto-insert)
(setq auto-insert-directory "~/.auto-insert/")
;(setq auto-insert-alist
; (append
; (list
; '(html-helper-mode . "html-helper.html"))
; auto-insert-alist))
;;=============================================================================
;; Setup fly-check - automatic syntax checker
;;=============================================================================
(add-hook 'after-init-hook #'global-flycheck-mode)
;; Override default flycheck triggers
(setq flycheck-check-syntax-automatically '(save idle-change mode-enabled)
flycheck-idle-change-delay 0.8)
(setq flycheck-display-errors-function
#'flycheck-display-error-messages-unless-error-list)
(add-hook 'prog-mode-hook 'flycheck-mode)
;;=============================================================================
;; Setup make-mode - mode for editing make files
;;=============================================================================
(load "make-mode")
(add-to-list 'auto-mode-alist '("Makefile" . makefile-mode))
;;=============================================================================
;; Setup cmake-mode - mode for editing CMake files
;;=============================================================================
(require 'cmake-mode)
(setq auto-mode-alist
(append '(("CMakeLists\\.txt\\'" . cmake-mode)
("\\.cmake\\'" . cmake-mode))
auto-mode-alist))
;;=============================================================================
;; Setup compile mode
;;=============================================================================
(defun prelude-colorize-compilation-buffer ()
"Colorize a compilation mode buffer."
(interactive)
;; we don't want to mess with child modes such as grep-mode, ack, ag, etc
(when (eq major-mode 'compilation-mode)
(let ((inhibit-read-only t))
(ansi-color-apply-on-region (point-min) (point-max)))))
(require 'compile)
;; Colorize output of Compilation Mode, see
;; http://stackoverflow.com/a/3072831/355252
(require 'ansi-color)
(add-hook 'compilation-filter-hook #'prelude-colorize-compilation-buffer)
(defun my-compilation-mode-setup ()
;; Automatically save any modified buffers on a compile
(setq compilation-ask-about-save nil)
;; Just kill old compile processes before starting the new one
(setq compilation-always-kill t)
;; Always give an audible signal upon compilation completion
(setq compilation-always-signal-completion t)
;; Automatically scroll to first error
(setq compilation-scroll-output 'first-error))
(add-hook 'compilation-mode-hook 'my-compilation-mode-setup)
(defun turn-off-compilation-read-command ()
(make-local-variable 'compilation-read-command)
(setq compilation-read-command nil))
;;=============================================================================
;; Some utility functions
;;=============================================================================
(defun tabify-buffer ()
"tabify an entire buffer"
(interactive)
(tabify (point-min) (point-max)))
(defun untabify-buffer ()
"untabify an entire buffer"
(interactive)
(untabify (point-min) (point-max)))
(defun ascii-table ()
"Print the ascii table. Based on a defun by Alex Schroeder <asc@bsiag.com>"
(interactive)
(switch-to-buffer "*ASCII*")
(erase-buffer)
(insert (format "ASCII characters up to number %d.\n" 254))
(let ((i 0))
(while (< i 254)
(setq i (+ i 1))
(insert (format "%4d %c\n" i i))))
(beginning-of-buffer))
(defun insert-date ()
"Insert date at point."
(interactive)
(insert (format-time-string "%a %b %e, %Y %l:%M %p")))
(defun dos-unix ()
(interactive)
(goto-char (point-min))
(while (search-forward "\r" nil t) (replace-match "")))
(defun unix-dos ()
(interactive)
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match "\r\n")))
(defun google ()
"Google the selected region if any, display a query prompt otherwise."
(interavtive)
(browse-url
(concat
"http://www.google.com/search?ie=utf-8&oe=utf-8&q="
(url-hexify-string (if mark-active
(buffer-substring (region-beginning) (region-end))
(read-string "Google: "))))))
(defun yas/advise-indent-function (function-symbol)
(eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
,(format
"Try to expand a snippet before point, then call `%s' as usual"
function-symbol)
(let ((yas-fallback-behavior nil))
(unless (and (interactive-p)
(yas-expand))
ad-do-it)))))
;;=============================================================================
;; Enable yasnippit mode
;;=============================================================================
(require `yasnippet)
(yas-global-mode 1)
;; java-mode snippets from
;; git clone https://github.com/nekop/yasnippet-java-mode.git.
(setq yassnippet-dirs '("/usr/local/share/emacs/site-lisp/snippets"
"~/.emacs.d/elpa/yasnippet-20140929.240/snippets"
"~/.emacs.d/snippets"))
;;=============================================================================
;; Setup auto-complete
;;=============================================================================
(require 'auto-complete-config)
(global-auto-complete-mode t)
;; (setq-default ac-expand-on-auto-complete nil)
(setq-default ac-auto-start nil)
(setq-default ac-dwim nil) ; To get pop-ups with docs even if a word is uniquely completed
;;----------------------------------------------------------------------------
;; Use Emacs' built-in TAB completion hooks to trigger AC (Emacs >= 23.2)
;;----------------------------------------------------------------------------
(setq tab-always-indent 'complete) ;; use 't when auto-complete is disabled
(add-to-list 'completion-styles 'initials t)
;; Stop completion-at-point from popping up completion buffers so eagerly
(setq completion-cycle-threshold 5)
;; ;; TODO: find solution for php, haskell and other modes where TAB always does something
;; (setq c-tab-always-indent nil
;; c-insert-tab-function 'indent-for-tab-command)
;; hook AC into completion-at-point
(defun sanityinc/auto-complete-at-point ()
(when (and (not (minibufferp))
(fboundp 'auto-complete-mode)
auto-complete-mode)
(auto-complete)))
;; (defun sanityinc/never-indent ()
;; (set (make-local-variable 'indent-line-function) (lambda () 'noindent)))
(defun set-auto-complete-as-completion-at-point-function ()
(setq completion-at-point-functions
(cons 'sanityinc/auto-complete-at-point
(remove 'sanityinc/auto-complete-at-point completion-at-point-functions))))
(add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
(set-default 'ac-sources
'(ac-source-imenu
ac-source-dictionary
ac-source-words-in-buffer
ac-source-words-in-same-mode-buffers
ac-source-words-in-all-buffer))
(dolist (mode '(magit-log-edit-mode
log-edit-mode org-mode text-mode haml-mode
git-commit-mode
sass-mode yaml-mode csv-mode haskell-mode
html-mode nxml-mode sh-mode smarty-mode clojure-mode
lisp-mode textile-mode markdown-mode tuareg-mode
js2-mode css-mode sql-mode
sql-interactive-mode
inferior-emacs-lisp-mode))
(add-to-list 'ac-modes mode))
;;=============================================================================
;; company-mode
;;=============================================================================
(autoload 'company-mode "company" nil t)
;;=============================================================================
;; Configure emacs lisp mode
;;=============================================================================
(defun prelude-start-or-switch-to (function buffer-name)
"Invoke FUNCTION if there is no buffer with BUFFER-NAME.
Otherwise switch to the buffer named BUFFER-NAME. Don't clobber
the current buffer."
(if (not (get-buffer buffer-name))
(progn
(split-window-sensibly (selected-window))
(other-window 1)
(funcall function))
(switch-to-buffer-other-window buffer-name)))
(defun prelude-visit-ielm ()
"Switch to default `ielm' buffer.
Start `ielm' if it's not already running."
(interactive)
(prelude-start-or-switch-to 'ielm "*ielm*"))
(define-key emacs-lisp-mode-map (kbd "C-c C-z") 'prelude-visit-ielm)
(define-key emacs-lisp-mode-map (kbd "C-c C-c") 'eval-defun)
(define-key emacs-lisp-mode-map (kbd "C-c C-b") 'eval-buffer)
(defun my-lisp-coding-defaults ()
;; (smartparens-strict-mode +1)
(rainbow-delimiters-mode +1))
(setq my-lisp-codeing-hook 'my-lisp-coding-defaults)
(defun prelude-conditional-emacs-lisp-checker ()
"Don't check doc style in Emacs Lisp test files."
(let ((file-name (buffer-file-name)))
(when (and file-name (string-match-p ".*-tests?\\.el\\'" file-name))
(setq-local flycheck-checkers '(emacs-lisp)))))
(defun my-emacs-lisp-mode-defaults ()
"Defaults for `emacs-lisp-mode'."
(run-hooks 'my-lisp-coding-hook)
(turn-on-eldoc-mode)
(rainbow-mode +1)
(prelude-conditional-emacs-lisp-checker))
(setq my-emacs-lisp-mode-hook 'my-emacs-lisp-mode-defaults)
(add-hook 'emacs-lisp-mode-hook (lambda ()
(run-hooks 'my-emacs-lisp-mode-hook)))
;; ielm is an interactive Emacs Lisp shell
(defun my-ielm-mode-defaults ()
"Defaults for `ielm'."
(run-hooks 'my-lisp-coding-hook)
(turn-on-eldoc-mode))
(setq my-ielm-mode-hook 'my-ielm-mode-defaults)
(add-hook 'ielm-mode-hook (lambda ()
(run-hooks 'my-ielm-mode-hook)))
(eval-after-load "elisp-slime-nav"
'(diminish 'elisp-slime-nav-mode))
(eval-after-load "rainbow-mode"
'(diminish 'rainbow-mode))
(eval-after-load "eldoc"
'(diminish 'eldoc-mode))
(eval-after-load "ielm"
'(progn
(define-key ielm-map (kbd "M-(") (prelude-wrap-with "("))
(define-key ielm-map (kbd "M-\"") (prelude-wrap-with "\""))))
;; enable elisp-slime-nav-mode
(dolist (hook '(emacs-lisp-mode-hook ielm-mode-hook))
(add-hook hook 'elisp-slime-nav-mode))
;; (defun conditionally-enable-smartparens-mode ()
;; "Enable `smartparens-mode' in the minibuffer, during `eval-expression'."
;; (if (eq this-command 'eval-expression)
;; (smartparens-mode 1)))
;; (add-hook 'minibuffer-setup-hook 'conditionally-enable-smartparens-mode)
;;=============================================================================
;; Configure cc-mode
;;=============================================================================
(require 'cc-mode)
(setq c-hanging-comment-starter-p nil)
(setq c-hanging-comment-ender-p nil)
;;-----------------------------------------------------------------------------
;;c-mode-common-hook
;;-----------------------------------------------------------------------------
(defvar c-mode-tags-menu)
(defvar my-make-command "make -k ")
(defvar my-c-compile-single-file-command "gcc -Wall -pedantic -W -c ")
(defun find-next-tag ()
"find next alternate definition of last tag specified"
(interactive)
(setq tagname (car find-tag-history))
(find-tag tagname t))
(defun find-next-tag-regexp ()
"find the next tag whose name matches the last pattern used"
(interactive)
(setq tagname (car find-tag-history))
(find-tag-regexp tagname t))
(defun my-c-mode-tags-menu (c-like-lang-mode-map)
"insert a tags menu in c-mode"
(condition-case nil
(progn
(require 'easymenu)
(easy-menu-define
c-mode-tags-menu c-like-lang-mode-map "Tags menu in c mode"
'("Tags"
["Find Tag" find-tag t]
["Find Tag regex" find-tag-regexp t]
["Find Tag Other Window" find-tag-other-window t]
["Find Tag Other Frame" find-tag-other-frame t]
"----"
["Next Tag" find-next-tag t]
["Next Tag regex" find-next-tag-regexp t]
["Next File" next-file t]
"----"
["Tags Search..." tags-search t]
["Tags Replace..." tags-query-replace t]
["Continue Search/Replace" tags-loop-continue t]
"----"
["Pop stack" pop-tag-mark t]
["List Tags in File" list-tags t]
["Apropros..." tags-apropos t]
["Set Tags Table File" visit-tags-table t])))))
(defun indent-or-complete ()
"Complete if point is at end of a word, otherwise indent line."
(interactive)
(if (looking-at "\\>")
(dabbrev-expand nil)
(indent-for-tab-command)))
(defconst my-c-style
'((c-basic-offset . 4)
;; Comments get no special indentation
(c-comment-only-line-offset . 0)
;; Tab always means indent
(c-tab-always-indent . t)
;; Never use tabs in my indentation
(c-indent-tabs-mode . nil)
;; Turn on auto newlines
(c-toggle-auto-state . 1)
;; Turn on hungury deletion
(c-toggle-hungry-state . 1)
(c-offsets-alist
(access-label . -)
(topmost-intro . 0)
(topmost-intro-cont . 0)
(knr-argdecl-intro . +)
(label . 0)
(statement-cont . +)
(substatement-open . 0)
(substatement . +)
(block-open . +)
(inline-open . 0)
(defun-open . 0)
(defun-block-intro . +)
(brace-list-open . +)
(case-label . +)
(class-open . 0)
(inclass . +)
(class-close . 0)
(inexpr-class . 0)
(extern-lang-open . +)
(extern-lang-close . +)
(namespace-open . +)
(namespace-close . +)))
"My C Programming Style")
(defun my-c-mode-common-setup ()
(c-add-style "lb" my-c-style t)
;; Set the cc-mode style to my own personal style
(c-set-style "lb")
;; When I open a file that uses [TAB]s, make [TAB] mean 4 spaces
(setq tab-width 4)
;; Never use tabs in my indentation
(setq indent-tabs-mode nil)
;; Convert tabs to spaces
(if (not buffer-read-only) (untabify-buffer))
;; Have compile always use the contents of compile-command
(turn-off-compilation-read-command)
(local-set-key "[" 'self-insert-command)
;; Have tab key perform completion when at the end of a word
(yas/advise-indent-function 'indent-or-complete)
(local-set-key (kbd "<tab>") 'indent-or-complete)
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
(ggtags-mode 1)))
(add-hook 'c-mode-common-hook 'my-c-mode-common-setup)
;;c-mode-hook
(defun my-c-mode-setup ()
;; Add a tags menu
(my-c-mode-tags-menu c-mode-map)
;; set compile-command
(make-local-variable 'compile-command)
(if (or (file-exists-p "makefile")
(file-exists-p "Makefile"))
(setq compile-command my-make-command)
(setq compile-command (concat my-c-compile-single-file-command
buffer-file-name))))
(add-hook 'c-mode-hook 'my-c-mode-setup)
;;c++-mode-hook
(defun my-c++-mode-setup ()
;; Add a tags menu
(my-c-mode-tags-menu c++-mode-map))
(add-hook 'c++-mode-hook 'my-c++-mode-setup)
;;=============================================================================
;; Load the Java development environment when I edit a Java file
;;=============================================================================
(defun my-java-mode-setup ()
(c-add-style "lb-java"
'("java"
(c-offsets-alist . ((substatement-open . 0)
(arglist-intro . +)))))
;; Set the java-mode style to my own personal style
(c-set-style "lb-java")
(require 'javadoc-lookup)
(javadoc-add-roots "~/Sites/java/docs/api"
"~/Sites/java/commons-cli-docs"
"~/Sites/macports_docs/jakarta-log4j/site"
"~/Sites/macports_docs/apache-ant/manual/api"
"~/Sites/gwt/doc/javadoc")
(require 'java-import)
(local-set-key "\C-hj" 'javadoc-lookup)
(local-set-key "\C-xi" 'add-java-import)
(local-set-key "\C-xs" 'sort-java-imports)
;; Add a tags menu
(my-c-mode-tags-menu java-mode-map))
(add-hook 'java-mode-hook 'my-java-mode-setup)
;;-----------------------------------------------------------------------------
;; Setup JDE
;;-----------------------------------------------------------------------------
;;(if running-gnu-emacs-greater-than-23
;; (progn
;; (setq jde-check-version-flag nil)
;; (define-obsolete-function-alias 'make-local-hook 'ignore "21.1")
;; (unless (fboundp 'semantic-format-prototype-tag-java-mode)
;; (defalias
;; 'semantic-format-prototype-tag-java-mode
;; 'semantic-format-tag-prototype-java-mode))
;; (require 'hippie-exp)))
;;
(when (file-exists-p "/usr/local/share/emacs/site-lisp/jdee-2.4.1")
(add-to-list 'load-path
"/usr/local/share/emacs/site-lisp/jdee-2.4.1/lisp")
(require 'jde)
(require 'jde-ant))
;;=============================================================================
;; Set up C# mode
;;=============================================================================
(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(setq auto-mode-alist
(append '(("\\.cs$" . csharp-mode)) auto-mode-alist))
(defun my-csharp-mode-fn ()
"function that runs when csharp-mode is initialized for a buffer."
;; (turn-on-auto-revert-mode)
(setq indent-tabs-mode nil)
;; (require 'flymake)
;; (flymake-mode 1)
;; (require 'yasnippet)
;; (yas/minor-mode-on)
;; (require 'rfringe)
;; ...insert more code here...
;; ...including any custom key bindings you might want ...
)
(add-hook 'csharp-mode-hook 'my-csharp-mode-fn t)
;;=============================================================================
;; Setup csv mode
;;=============================================================================
(autoload 'csv-mode "csv-mode"
"Major mode for editing comma-separated value files." t)
(add-to-list 'auto-mode-alist '("\\.[Cc][Ss][Vv]\\'" . csv-mode))
(setq csv-separators '("," ";" "|" " "))
;;=============================================================================
;; Setup nxml mode
;;=============================================================================
(setq auto-mode-alist
(append '(("\\.xml\\'" . nxml-mode)
("\\.xsd\\'" . nxml-mode)
("\\.sch\\'" . nxml-mode)
("\\.rng\\'" . nxml-mode)
("\\.xslt\\'" . nxml-mode)
("\\.svg\\'" . nxml-mode)
("\\.rss\\'" . nxml-mode)
("\\.gpx\\'" . nxml-mode)
("\\.tcx\\'" . nxml-mode)
("\\.plist\\'" . nxml-mode)
("\\.pom\\'" . nxml-mode))
auto-mode-alist))
(setq magic-mode-alist (cons '("<\\?xml " . nxml-mode) magic-mode-alist))
(fset 'xml-mode 'nxml-mode)
(add-hook 'nxml-mode-hook
(lambda ()
(set (make-local-variable 'ido-use-filename-at-point) nil)))
(setq nxml-child-indent 2)
(setq nxml-attribute-indent 2)
(setq nxml-auto-insert-xml-declaration-flag nil)
(setq nxml-bind-meta-tab-to-complete-flag t)
(setq nxml-slash-auto-complete-flag t)
;; See: http://sinewalker.wordpress.com/2008/06/26/pretty-printing-xml-with-emacs-nxml-mode/
(defun sanityinc/pp-xml-region (begin end)
"Pretty format XML markup in region. The function inserts
linebreaks to separate tags that have nothing but whitespace
between them. It then indents the markup by using nxml's
indentation rules."
(interactive "r")
(save-excursion
(nxml-mode)
(goto-char begin)
(while (search-forward-regexp "\>[ \\t]*\<" nil t)
(backward-char) (insert "\n"))
(indent-region begin end)))
;;----------------------------------------------------------------------------
;; Integration with tidy for html + xml
;;----------------------------------------------------------------------------
(autoload 'tidy-buffer "tidy" "Run Tidy HTML parser on current buffer" t)
(autoload 'tidy-parse-config-file "tidy" "Parse the `tidy-config-file'" t)
(autoload 'tidy-save-settings "tidy" "Save settings to `tidy-config-file'" t)
(autoload 'tidy-build-menu "tidy" "Install an options menu for HTML Tidy." t)
(add-hook 'nxml-mode-hook (lambda () (tidy-build-menu nxml-mode-map)))
(add-hook 'html-mode-hook (lambda () (tidy-build-menu html-mode-map)))
(add-hook 'web-mode-hook (lambda () (tidy-build-menu web-mode-map)))
;;=============================================================================
;; Setup markdown mode
;;=============================================================================
;; C-c C-a l insert link [text](url)
;; C-c C-a L insert reference link [text][label]
;; C-c C-a u insert bare URL
;; C-c C-a f insert a footnote
;; C-c C-a w insert a wiki link [[WikiLink]]
;;
;; C-c C-i i insert inline image
;; C-c C-i I insert reference image
;;
;; C-c C-s e emphasis region
;; C-c C-s s strong region
;; C-c C-s c code region
;;
;; C-c C-s b blockquote region
;; C-c C-s p pre-formated text
;;
;; C-c C-t h insert heading
;; C-c C-t 1-6 insert heading of specific level
;;
;; C-c - insert horizontal rule
;;
;; C-c C-c m run markdown on current buffer; markdown -> <*markdown-output*> buffer
;; C-c C-c p preview; markdown -> tmp file -> browser
;; C-c C-c e export; markdown -> basename.html
;; C-c C-c v view; markdown -> basename.html -> browser
;; C-c C-c o open; open source file using markdown-open-command
(autoload 'markdown-mode "markdown-mode"
"Major mode for editing Markdowm files" t)
(add-to-list 'auto-mode-alist '("\\.markdown\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode))
(defun markdown-custom ()
"markdown-mode-hook"
(setq markdown-command "multimarkdown")
(setq markdown-command-needs-filename t))
(add-hook 'markdown-mode-hook '(lambda() (markdown-custom)))
;;=============================================================================
;; Setup css mode
;;=============================================================================
(add-to-list 'auto-mode-alist '("\\.css\\'" . css-mode))
(eval-after-load 'css-mode
'(progn
(setq css-indent-offset 2)
(defun my-css-mode-defaults ()
;; (smartparens-mode +1)
(rainbow-mode +1))
(setq my-css-mode-hook 'my-css-mode-defaults)
(add-hook 'css-mode-hook (lambda ()
(run-hooks 'my-css-mode-hook)))))
;;=============================================================================
;; Setup JavaScript mode
;;=============================================================================
;; Note: look into tern
(require 'js2-mode)
(add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
(add-to-list 'auto-mode-alist '("\\.pac\\'" . js2-mode))
(add-to-list 'interpreter-mode-alist '("node" . js2-mode))
(eval-after-load 'js2-mode
'(progn
(defun my-js-mode-defaults ()
;; electric-layout-mode doesn't play nice with smartparens
(setq-local electric-layout-rules '((?\; . after)))
(setq mode-name "JS2")
(js2-imenu-extras-mode +1))
(setq my-js-mode-hook 'my-js-mode-defaults)
(add-hook 'js2-mode-hook (lambda () (run-hooks 'my-js-mode-hook)))))