/
emacs.el
1808 lines (1591 loc) · 58.3 KB
/
emacs.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
;; -*- emacs-lisp -*-
;;; Note: this file should be loaded by bootstrap-init.el.
(defmacro when-fboundp-call (f &rest args)
"If F is bound, calls it with ARGS."
`(when (fboundp (function ,f)) (funcall (function ,f) ,@args)))
(defmacro unless-boundp-setq (var val)
"If VAR is not bound, sets it to VAL."
`(unless (boundp (quote ,var)) (setq ,var ,val)))
(defun blank-p (val)
"VAL is blank if it is `nil', the empty list, or an empty or
whitespace-only string."
(or (not val) ; nil or empty list
(and (stringp val) (not (nil-blank-string val)))
nil))
(defun val-or-default (val default)
"If VAL is not `blank-p' return it, else return DEFAULT."
(if (not (blank-p val)) val default))
(when (< emacs-major-version 24)
;; 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.
(let ((f (expand-file-name "~/.emacs.d/elpa/package.el")))
(when (and (file-exists-p f)
(load f)))))
(when-fboundp-call package-initialize)
(when (boundp 'package-archives)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/")
t))
(unless (fboundp #'caddr)
(defun caddr (list)
"Take the caddr of LIST."
(car (cdr (cdr list)))))
(defun ensure-ends-with-slash (dir)
"If DIR does not end with \"/\", return a new copy of DIR that
does."
(if (equal "/" (substring dir -1)) dir
(concat dir "/")))
(defvar my-shell #'eshell
"The shell to use inside Emacs; examples include 'shell or 'eshell.")
(defvar my-alternate-shell #'shell
"Bound to alternate key.")
(if (equal default-directory "/") (setq default-directory "~/"))
;; Add *my-emacs-lib-dir* subdirs to the end of load-path, so if it's
;; pre-installed that version is used first.
;;
;; Note that *my-emacs-lib-dir* should already be on the load path. It gets
;; added by bootstrap-init.el.
(mapc (lambda (dir)
(add-to-list 'load-path (concat *my-emacs-lib-dir* dir "/") t))
'("progmodes" "ses"))
(setq abbrev-file-name (concat *my-emacs-lib-dir* "abbrev_defs.el"))
(read-abbrev-file abbrev-file-name t)
(load "my-skeletons")
;;
;; IDO mode
;;
(when (fboundp #'ido-mode)
(ido-mode t)
(setq ido-enable-flex-matching t))
(require 'generic-x); DOS batch, ini files and much more
(add-to-list 'auto-mode-alist
'("\\.properties$" . java-properties-generic-mode))
;;
;; Global variable settings and options
;;
(when-fboundp-call appt-activate 1) ; appointment notification
(when-fboundp-call line-number-mode -1) ; don't display 'em
;; Ubuntu stuff
;(menu-bar-enable-clipboard)
(setq x-select-enable-clipboard t)
(setq mouse-drag-copy-region t)
(when-fboundp-call set-scroll-bar-mode 'right)
(setq skeleton-pair nil)
(mouse-wheel-mode 1)
(when (>= emacs-major-version 23)
(transient-mark-mode -1)
(setq confirm-nonexistent-file-or-buffer nil))
(setq save-flag 1) ; see bootstrap-ini for loc of file
(setq sentence-end-double-space nil)
(turn-on-auto-fill)
(auto-fill-mode 1)
(show-paren-mode 1)
(setq column-number-mode nil)
(setq-default fill-column 76)
(setq make-backup-files nil) ; don't make backup files
(setq delete-auto-save-files t) ; no "#" files after a save
(setq auto-save-list-file-prefix nil) ; don't record sessions
(setq inhibit-startup-screen t) ; kill the startup message
(setq initial-scratch-message nil) ; used by Emacs 23 and above
(setq inhibit-startup-echo-area-message "jimm")
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(setq compile-command "makeup ") ; script finds make/rake/pom/build
(setq Man-notify 'aggressive) ; when man found, jump there *immed*
(setq dabbrev-case-replace nil) ; preserve case when expanding
(setq grep-command "grep -n ")
(setq mode-require-final-newline nil) ; do not force newlines
(setq ns-pop-up-frames nil) ; do not create new frames on Mac
(setq auto-revert-verbose nil) ; no message on each auto-revert update
(setq isearch-lax-whitespace nil)
; (setq recenter-positions '(top middle bottom)) ; change default cycle order
(fset #'yes-or-no-p #'y-or-n-p) ; accept simple 'y'/space, 'n'/delete
(unless (fboundp #'string-match-p) (defalias #'string-match-p #'string-match))
;; For rgrep, grep-find, and friends
(load "grep")
(setq grep-find-ignored-directories
(append (list "tmp" "target" "ebin" "_build" "_site")
grep-find-ignored-directories))
(setq grep-find-ignored-files
(list
"TAGS" "*.[wj]ar" "*.beam"
"*.png" "*.gif" "*.jpg" "*.jpeg"
".#*" "*.o" "*~" "*.so" "*.a" "*.elc"
"*.class" "*.lib" "*.lo" "*.la" "*.toc" "*.aux"
"*.pyc" "*.pyo"))
(setq visible-bell t)
(setq version-control 'never) ; When to make backup files
(setq vc-handled-backends '()) ; disable VC minor mode
(setq frame-title-format
'((:eval (if (buffer-file-name)
(abbreviate-file-name (buffer-file-name))
"%b"))))
(when (functionp #'tool-bar-mode) (tool-bar-mode -1))
(unless window-system (menu-bar-mode nil))
(global-font-lock-mode t) ; always turn on, where available
(defun unix-file ()
"Change the current buffer to UTF-8 with Unix line-ends."
(interactive)
(set-buffer-file-coding-system 'utf-8-unix t))
(defun dos-file ()
"Change the current buffer to UTF-8 with DOS line-ends."
(interactive)
(set-buffer-file-coding-system 'utf-8-dos t))
(defun underscores-to-camel-case (str)
"Converts STR, which is a word using underscores, to camel case."
(interactive "S")
(apply #'concat (mapcar #'capitalize (split-string str "_"))))
;; I prefer zap-upto-char most of the time
(defun zap-upto-char (arg char)
"Kill up to but not including ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found."
(interactive (list (prefix-numeric-value current-prefix-arg)
(read-char "Zap up to char: " t)))
(zap-to-char arg char)
(insert-char char)
(backward-char))
(defun generate-random-password (arg)
"Generate a random password ARG characters long (16 by default).
Characters are selected from upper- and lower-case letters,
numbers, and punctuation."
(interactive "NPassword length: ")
(let* ((chars "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!?@#$%^&*-_=+/.,")
(chars-len (length chars)))
(mapconcat (lambda (dummy)
(let ((idx (random chars-len)))
(substring chars idx (+ idx 1))))
(number-sequence 0 (- arg 1))
"")))
(defun insert-random-password (arg)
"Generate a random password ARG characters long (16 by default) and
insert it at point. See `generate-random-password`."
(interactive "P")
(insert (generate-random-password arg)))
;;;
;;; YAML-mode
;;;
(autoload #'yaml-mode "yaml-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.ya?ml$" . yaml-mode))
;;
;; For flipping back and forth between files and headers, or Java/Ruby files
;; and Java/Ruby test files. See also rails-find-other-file.
;;
(defun my-ff-find-other-file (&optional in-other-window ignore-include)
"Find other Java or Ruby file or, if not a Java or Ruby file,
call `ff-find-other-file`."
(interactive "P")
(let* ((fname (buffer-file-name))
(ext (file-name-extension fname)))
(cond ((or (equal "java" ext) (equal "scala" ext))
(find-other-java-file fname ext))
((equal "rb" ext)
(find-other-ruby-file fname))
(t
(ff-find-other-file in-other-window ignore-include)))))
(defun find-other-java-file (&optional file-name ext)
"Visits `Foo.java' when given `FooTest.java' and vice versa.
Default file-name is current buffer's name."
(interactive)
(let* ((fname (file-name-nondirectory (or file-name (buffer-file-name))))
(non-test-from-end (- -5 (length ext)))
(test-from-end (- -1 (length ext)))
(target (if (equal (concat "Test." ext) (substring fname non-test-from-end))
(concat (substring fname 0 non-test-from-end) (concat "." ext))
(concat (substring fname 0 test-from-end) (concat "Test." ext)))))
(ef target default-directory)))
(defun find-other-ruby-file (&optional file-name)
"Visits `foo.rb' when given `foo_(test|spec).rb'. Visits `foo_test.rb' when
given `foo.rb'. Default file-name is current buffer's name."
(interactive)
(let* ((fname (file-name-nondirectory (or file-name (buffer-file-name))))
(target (if (and (> (length fname) 8)
(or (equal "_test.rb" (substring fname -8))
(equal "_spec.rb" (substring fname -8))))
(concat (substring fname 0 -8) ".rb")
(concat (substring fname 0 -3) "_test.rb"))))
(ef target default-directory)))
(setq ff-other-file-alist
'(("\\.cpp$" . ((".hpp" ".hh" ".h")))
("\\.cp$" . ((".hp" ".hh" ".h")))
("\\.hpp$" . ((".cpp" ".cp")))
("\\.icc$" . ((".hpp")))
("\\.m$" . ((".h")))
("\\.cc$" . ((".hh" ".h")))
("\\.hh$" . ((".cc" ".C" ".CC" ".cxx" ".cpp" ".cp" ".m")))
("\\.c$" . ((".h")))
("\\.h$" . ((".c" ".cc" ".C" ".CC" ".cxx" ".cpp" ".cp" ".m")))
("\\.C$" . ((".H" ".hh" ".h")))
("\\.H$" . ((".C" ".CC")))
("\\.CC$" . ((".HH" ".H" ".hh" ".h")))
("\\.HH$" . ((".CC" ".C")))
("\\.cxx$" . ((".hh" ".h" ".hxx")))
))
;; When saving files, set execute permission if #! is in first line.
(add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
(defun capitalize-next-char ()
"Capitalize next character and move point right 1 character."
(interactive "*")
(save-excursion
(forward-char)
(insert " ")
(backward-char 2)
(capitalize-word 1)
(delete-char 1)))
(defun capitalize-first-char-of-string (str)
"Capitalize first character of STR."
(interactive "s")
(concat (capitalize (substring str 0 1)) (substring str 1)))
(defun downcase-first-char-of-string (str)
"Make first character of STR lower-case."
(interactive "s")
(concat (downcase (substring str 0 1)) (substring str 1)))
(defun pluralize (str)
"Pluralize STR, which is assumed to be a single word. This is a
simple algorithm that may grow over time if needed."
(interactive "s")
(let ((len (length str)))
(cond ((equal "y" (substring str (- len 1))) (concat (substring str 0 (- len 1)) "ies"))
((equal "us" (substring str (- len 2))) (concat (substring str 0 (- len 2)) "i"))
(t (concat str "s")))))
(defun singularize (str)
"Singularize STR, which is assumed to be a single word. This is
a simple algorithm that may grow over time if needed."
(interactive "s")
(let ((len (length str)))
(cond ((equal "ies" (substring str (- len 3))) (concat (substring str 0 (- len 3)) "y"))
((equal "i" (substring str (- len 1))) (concat (substring str 0 (- len 1)) "us"))
((equal "s" (substring str (- len 1))) (substring str 0 (- len 1)))
(t str))))
(defun debug-comment ()
"Add a DEBUG comment to the current line"
(interactive "*")
(save-excursion
(comment-dwim nil)
(insert " DEBUG")))
;;
;; PIM
;;
(setq diary-file (concat *my-pim-dir* "diary")) ; must be before remember mode hook def
(defun address (str)
"Find STR in my address book file. Looks first for STR as the
beginning of a name. If not found, looks for the first occurrence
of STR anywhere."
(interactive "sSearch string: ")
(let ((search-str (replace-regexp-in-string "+" " " str))
(current-buf (current-buffer)))
(find-file (concat *my-pim-dir* "orgs/address_book.org"))
(goto-char (point-min))
(or
(search-forward (concat "\n\n" search-str) nil t)
(search-forward (concat "\n" search-str) nil t)
(search-forward search-str nil t)
(error (concat "\"" search-str "\" not found")))))
;;
;; Remember mode
;;
(autoload #'remember "remember" nil t)
(setq *my-remember-data-file* (concat *my-pim-dir* "orgs/notes.org"))
(add-hook 'remember-mode-hook
(lambda ()
(setq remember-data-file *my-remember-data-file*)
(setq remember-diary-file diary-file)))
;;
;; Browse away!
;;
(defun my-goto-calendar-date (str)
(interactive "sDate: ")
(let ((date-list (cdddr (parse-time-string str))))
(calendar)
(calendar-goto-date (list (cadr date-list)
(car date-list)
(caddr date-list)))))
;(setq browse-url-generic-program "mozilla-firefox")
(setq browse-url-generic-program "open")
; Java class Javadoc lookup
(defvar *my-javadoc-url*
"http://download.oracle.com/javase/1.5.0/docs/api/"
"The start of the URL to use to open Java API docs. Override this when
you have a local copy, for example.")
(defun my-javadoc-open (&optional klass)
(interactive)
(let* ((klass-str (if (null klass) (read-string "Full class name: ") klass))
(klass-path (replace-regexp-in-string "\\." "/" klass-str))
(url (concat *my-javadoc-url* klass-path ".html")))
(browse-url-generic url)))
;;; ================================================================
;;; Finding files
;;; ================================================================
;;
;; ef (find)
;; must come before loading my eshell customize
;;
(load "find-lisp")
(defun ef (find-name-arg root-directory &optional ignore)
"Searches recursively in ROOT-DIRECTORY or current directory
for FIND-NAME-ARG. If one file is found, that file is opened. If
more than one id found, opens a dired buffer on the list of
files. If no files are found, continue searching up the directory
tree.
Ignores certain directories such as .git, .svn, and target. This
list is hard-coded, though it would be easy to make it an
optional argument."
(interactive "sFilename regex: \nDSearch root directory: ")
(let* ((dir (file-name-as-directory root-directory))
(dirname (directory-file-name dir))
(files
(cl-remove-if
(lambda (f) (string-match
"^\\(\\.git\\|\\.svn\\|classes\\|build\\|target\\|CVS\\)$\\|^~"
f))
(split-string (shell-command-to-string
(concat "find " dirname " -name " find-name-arg)))))
(len (length files)))
(cond ((zerop len)
(cond ((equal "/" dirname) (message "%s not found" find-name-arg))
(t (ef find-name-arg (file-name-directory dirname)))))
((= 1 len) (find-file (car files)))
(t (find-dired dir (concat "-name " find-name-arg))))))
;; Returns file(s) starting at default directory. See also
;; get-closest-pathname defined below (which does the same thing but assumes
;; root-directory is default-directory).
(defun find-up (fname-regexp root-directory)
"Searches starting at ROOT-DIRECTORY for FNAME-REGEXP. If not
found, goes up until it hits the system root directory, looking
for FNAME-REGEXP."
(interactive "sFilename regex: \nDSearch root directory: ")
(let* ((dir (file-name-as-directory (expand-file-name root-directory)))
(dirname (directory-file-name dir))
(filter-regexp "\\.git\\|\\.svn\\|classes\\|build\\|target\\|TAGS\\|CVS\\|~")
(files
(remove-if
(lambda (f) (string-match filter-regexp f))
(directory-files dirname t fname-regexp)))
(len (length files)))
(cond ((zerop len)
; (message "%s not found in %s" fname-regexp dir))
(cond ((equal "/" dirname) (message "%s not found" fname-regexp))
(t (find-up fname-regexp (file-name-directory dirname)))))
((= 1 len) (car files))
(t files))))
;; See also find-up and the built-in function locate-dominating-file.
(defun get-closest-pathname (file)
"Find the first instance of FILE at or above the current directory.
If it does not find FILE, then it returns the name of FILE in the
current directory, suitable for creation.
This may not do the correct thing in presence of links."
(let* ((path (expand-file-name file))
(f (file-name-nondirectory path))
(d (locate-dominating-file path f)))
(if d (concat d f)
(expand-file-name f default-directory))))
;;; ================================================================
;;
;; Shell script
;;
(add-hook 'sh-mode-hook
(lambda ()
(define-key sh-mode-map "\C-cr" #'executable-interpret)))
;;
;; Tramp
;;
; (setq tramp-default-method "scp")
(defun debug-tramp ()
(interactive)
(setq tramp-debug-buffer t)
(setq tramp-verbose 10))
;;
;; ssh-ing
;;
(defun ssh (host)
"Open a shell on a buffer named *HOST* and run ssh HOST. Note that HOST can
be of the form USER@HOST."
(interactive "sHost: ")
(shell (concat "*" host "*"))
(insert (concat "ssh " host))
(comint-send-input))
;;
;; Text-mode
;;
(add-hook 'text-mode-hook
(lambda ()
(auto-fill-mode 1)
(four-tab-stops)))
;;
;; For both C and C++ mode
;;
(add-hook 'c-mode-common-hook
(lambda ()
(setq c-basic-offset 2)
(setq c-tab-always-indent nil)
;; BAD! BAD! Screws up ^D
;; (setq c-delete-function #'backward-delete-char)
(setq c-recognize-knr-p nil)
;; (define-key c-mode-map "{" #'skeleton-pair-insert-maybe)
;; (define-key c-mode-map "(" #'skeleton-pair-insert-maybe)
;; (local-set-key "\M-o" #'fh-open-header-file-other-window)
;; (local-set-key "\M-O" #'fh-open-header-file-other-frame)
(local-set-key "\r" #'newline-and-indent)
(autoload #'fh-open-header-file-other-window "find-header"
"Locate header file and load it into other window" t)
(autoload #'fh-open-header-file-other-frame "find-header"
"Locate header file and load it into other frame" t)))
;;
;; C++-mode
;;
(add-to-list 'auto-mode-alist '("\\.[ch]pp?$" . c++-mode))
(add-to-list 'auto-mode-alist '("\\.h?$" . c++-mode)) ; mostly C++, now a days
(add-to-list 'auto-mode-alist '("\\.pde$" . c++-mode)) ; Arduino
(add-hook 'c++-mode-hook
(lambda ()
(c-set-style "stroustrup")
(setq c-basic-offset 2)))
;;
;; Java-mode
;;
(eval-after-load "java"
(load "my-java-mode"))
(add-to-list 'auto-mode-alist '("\\.aj$" . java-mode)) ; Roo aspect files
(add-to-list 'auto-mode-alist '("\\.jsp$" . html-mode))
(add-to-list 'auto-mode-alist '("\\.w[as]r$" . archive-mode))
(add-hook 'java-mode-hook
(lambda ()
(c-set-style "java")
;; (c-set-offset 'inclass 0)
;; (define-key java-mode-map "{" #'skeleton-pair-insert-maybe)
;; (define-key java-mode-map "(" #'skeleton-pair-insert-maybe)
(if window-system (font-lock-mode 1))))
;;;
;; Compilation mode
;;
(require 'compile)
;; Maven 2 error messages are of the form file:[line,column]
(setq compilation-error-regexp-alist
(cons
'("^\\(/[^:]+\\):\\[\\([0-9]+\\),\\([0-9]+\\)\\]" 1 2 3)
compilation-error-regexp-alist))
;; Scala error messages
(setq compilation-error-regexp-alist
(cons
'("\\(\\([a-zA-Z0-9]*/\\)*\\([a-zA-Z0-9]*\\.scala\\)\\):\\([0-9]*\\).*" 1 2)
compilation-error-regexp-alist))
;;
;; YASnippet
;;
(when-fboundp-call yas-global-mode 1)
;; Don't do the following; link ~/.emacs.d/snippets to snippets instead
;; (add-to-list 'yas-snippet-dirs (concat *my-emacs-lib-dir* "snippets"))
;; (yas-reload-all)
;;
;; JavaScript
;;;
(autoload #'javascript-mode "javascript" nil t)
(add-to-list 'auto-mode-alist '("\\.[agj]s$" . javascript-mode))
(add-to-list 'auto-mode-alist '("\\.jsx$" . javascript-mode))
(add-hook 'js-mode-hook
(lambda ()
(setq js-indent-level 2) ; need both?????
(setq javascript-indent-level 2)))
;; (autoload #'js2-mode "js2-mode" nil t)
;; (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(setq js2-basic-offset 2)
;;(setq js2-use-font-lock-faces t)
;;
;; CoffeeScript
;;
(add-to-list 'auto-mode-alist '("\\.cjsx$" . coffee-mode))
(defun compile-coffee-buffer ()
(interactive)
(shell-command (concat "coffee"
" -o " (shell-quote-argument (file-name-directory (buffer-file-name)))
" -c " (shell-quote-argument (buffer-file-name)))))
(autoload #'coffee-mode "coffee-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode))
(add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode))
(add-hook 'coffee-mode-hook
(lambda ()
(setq coffee-js-mode #'javascript-mode)
(define-key coffee-mode-map "\C-cr" #'executable-interpret)
(define-key coffee-mode-map "\C-ck" #'compile-coffee-buffer)
(set (make-local-variable 'tab-width) 2)))
;;
;; Objective-C mode
;;
(add-hook 'objc-mode-hook
(lambda ()
(if window-system (font-lock-mode 1))
(setq c-basic-offset 4)))
;;
;; Groovy mode
;;
(autoload #'groovy-mode "groovy-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.groovy$" . groovy-mode))
(add-hook 'groovy-mode-hook
(lambda ()
(setq groovy-basic-offset 4)
(define-key groovy-mode-map "\r" #'newline-and-indent)
(define-key groovy-mode-map "\C-cr" #'executable-interpret)
(font-lock-mode 1)))
;; Groovy shell mode
(autoload #'run-groovy "inf-groovy" "Run an inferior Groovy shell process")
(autoload #'inf-groovy-keys "inf-groovy"
"Set local key defs for inf-groovy in groovy-mode")
(add-hook 'groovy-mode-hook
(lambda ()
(inf-groovy-keys)))
;;
;; Scheme mode
;;
(add-hook 'scheme-mode-hook
(lambda ()
(define-key scheme-mode-map "\r" #'newline-and-indent)
(define-key scheme-mode-map "\C-cd" #'debug-comment)))
;;
;; Perl-mode
;;
(autoload #'perl-mode "perl-mode" "Perl mode" t nil)
(add-hook 'perl-mode-hook
(lambda ()
(define-key perl-mode-map "\r" #'newline-and-indent)
(define-key perl-mode-map "\M-\C-h" #'backward-kill-word)
(define-key perl-mode-map "\C-cd" #'debug-comment)
(setq c-basic-offset 2)
(setq c-tab-always-indent nil)))
;;
;; Environment variables and path. Use "launchctl setenv var value" to set
;; environment vars on OS X so that they get passed to GUI apps like
;; Emacs.app when they are launched. Since Mac OS X is pretty much all I use
;; these days, I've put this code here. Shouldn't do any harm if run on
;; another flavor of Unix.
;;
;; For each PATH element, prepend it to exec-path if it's not already there.
(mapc (lambda (path)
(add-to-list 'exec-path path))
(split-string (getenv "PATH") ":"))
;;
;; sh-mode
;;
(add-hook 'sh-mode-hook
(lambda ()
(define-key sh-mode-map "\C-c\C-k" #'compile)))
;;
;; Eshell-mode
;; must come after defining ef
;;
(when (eq my-shell #'eshell)
(load "eshell")
(load "eshell-customize"))
;;
;; Shell-mode
;;
;; Don't echo passwords
(add-hook 'comint-output-filter-functions
#'comint-watch-for-password-prompt)
(setq shell-completion-execonly nil) ; Any file is completion candidate
(add-hook 'shell-mode-hook
(lambda ()
(auto-fill-mode -1)
(setq comint-scroll-show-maximum-output nil)))
;;
;; LaTeX-mode
;;
(eval-after-load "latex-mode"
(progn
(setq tex-dvi-view-command "latex-view '*'") ; in my ~/bin dir
;; (setq tex-dvi-view-command "xdvi -expert -hush")
(setq tex-dvi-print-command "dvips -f * | lpr")
(defun my-tex-to-text ()
(interactive)
(save-buffer)
(shell-command (concat
"/usr/bin/dvi2tty "
(file-name-sans-extension (buffer-file-name))
" >"
(file-name-sans-extension (buffer-file-name))
".txt"))
)
(add-hook 'tex-mode-hook
(lambda () (define-key tex-mode-map "\C-c\C-k" #'compile)))
(add-hook 'latex-mode-hook
(lambda ()
(define-key latex-mode-map "\C-c\C-p" #'tex-print)
;; (define-key latex-mode-map "\C-c\C-t" #'my-tex-to-text)
(define-key latex-mode-map "\C-c\C-k" #'compile)
(define-key latex-mode-map "\C-c\C-i" #'find-mine)
(define-key latex-mode-map "\C-c\C-s" #'my-tex-slide-dvi-view)))))
;;
;; Sql-mode
;;
(add-to-list 'auto-mode-alist '("\\.mysql$" . sql-mode))
(eval-after-load "sql-mode"
(load "my-sql-mode"))
;;
;; Clojure-mode (lisp)
;;
;; ClojureScript
(add-to-list 'auto-mode-alist '("\\.\\(cljs\\|boot\\)$" . clojure-mode))
(eval-after-load "clojure-mode"
(load "my-clojure-mode"))
(setq inferior-lisp-program "lein repl")
(defun lein-repl ()
(interactive)
(setq inferior-lisp-program "lein repl")
(inferior-lisp "lein repl"))
(defun boot-repl ()
(interactive)
(setq inferior-lisp "boot repl")
(inferior-lisp "boot repl"))
(add-hook 'lisp-mode-hook
(lambda ()
(define-key lisp-mode-map "\r" #'newline-and-indent)
(define-key lisp-mode-map "\C-cd" #'debug-comment)))
;;
;; Clisp and SBCL
;;
;; (require 'slime)
;; (slime-setup)
;; Clisp
(defun clisp ()
(interactive)
(setq inferior-lisp-program "clisp")
(inferior-lisp "clisp"))
;; SBCL
(defun sbcl ()
(interactive)
(setq inferior-lisp-program "sbcl")
(inferior-lisp "sbcl"))
;;
;; Emacs-Lisp-mode
;;
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(define-key emacs-lisp-mode-map "\C-cd" #'debug-comment)
(define-key emacs-lisp-mode-map "\r" #'newline-and-indent)))
;;
;; PHP-mode
;;
(autoload #'php-mode "php-mode" "PHP mode" t nil)
(add-to-list 'auto-mode-alist '("\\.\\(php\\|inc\\)$" . php-mode))
(eval-after-load "php-mode"
(progn
(add-hook 'php-mode-hook
(lambda ()
(auto-fill-mode 1)
(setq c-basic-offset 4)
(define-key php-mode-map "\C-d" #'delete-char)
(define-key php-mode-map "\C-ct" #'html-mode)
(define-key php-mode-map "\C-ch" #'insert-ruby-hash-arrow)
(define-key php-mode-map "\C-cr" #'executable-interpret)))))
;;
;; HTML-mode and SGML-mode
;;
(eval-after-load "html-mode"
(progn
(defun my-html-insert-comment ()
(interactive "*")
(insert "<!-- -->")
(backward-char 4))
(defun unescape-html ()
(interactive "*")
(let ((repl-alist '(("<" . "<") (">" . ">") (""" . "\"")
("'" . "'") ("&" . "&"))))
(save-excursion
(mapcar (lambda (alist)
(goto-char (point-min))
(while (re-search-forward (car alist) nil t)
(replace-match (cdr alist) nil nil)))
repl-alist))))))
(mapcar (lambda (ext)
(add-to-list 'auto-mode-alist
(cons (concat "\\." ext "$") #'sgml-mode)))
; jwcs, application, page: Tapestry
; ftl: FreeMarker
'("xsd" "wsd[ld]" "jwcs" "application" "page" "ftl"))
(eval-after-load "sgml-mode"
(progn
(add-hook 'sgml-mode-hook
(lambda ()
(require 'tex-mode)
(auto-fill-mode 1)
(define-key sgml-mode-map "\C-c\C-k" #'compile)))
(add-hook 'html-mode-hook
(lambda ()
(auto-fill-mode 1)
(define-key html-mode-map "\C-c;" #'my-html-insert-comment)
(define-key html-mode-map "\C-cp" #'php-mode)
;; The remaining functions are defined in my-ruby-mode.el
(define-key html-mode-map "\C-ce" #'erb-eval-skeleton)
(define-key html-mode-map "\C-cp" #'erb-print-skeleton)
(define-key html-mode-map "\C-ch" #'insert-ruby-hash-arrow)
(define-key html-mode-map "\C-cl" #'rails-link-to-skeleton)
(define-key html-mode-map "\C-cr" #'rails-render-partial-skeleton)))))
;;
;; CSS-mode
;;
(autoload #'css-mode "css-mode" "CSS mode" t nil)
(add-to-list 'auto-mode-alist '("\\.css$" . css-mode))
(add-to-list 'auto-mode-alist '("\\.less$" . css-mode))
;;
;; Ruby-mode
;;
;; Use "M-x run-ruby" to start inf-ruby.
(autoload #'ruby-mode "ruby-mode" "Ruby mode" t nil)
(add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.r\\(b\\(w\\|x\\)?\\|html?\\|js\\)$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\([Rr]ake\\|[Cc]ap\\|[Gg]em\\)file$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.rake$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.gem\\(spec\\)?$" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.duby$" . ruby-mode))
(eval-after-load "ruby-mode"
(load "my-ruby-mode"))
(eval-after-load "inf-ruby"
(load "my-ruby-mode"))
;;
;; Erlang-mode
;;
(when (and (boundp '*my-erlang-emacs-tools-dir*)
(file-exists-p *my-erlang-emacs-tools-dir*))
(add-to-list 'load-path *my-erlang-emacs-tools-dir* t))
(autoload #'erlang-mode "erlang" "Erlang mode" t nil)
(add-to-list 'auto-mode-alist '("\\.[he]rl$" . erlang-mode))
(add-to-list 'auto-mode-alist '("\\.yaws$" . erlang-mode))
(add-hook 'erlang-mode-hook
(lambda ()
(setq indent-tabs-mode nil)
(comment-set-column 32)))
;;
;; Elixir-mode
;;
;; use MELPA version now
(eval-after-load "elixir-mode"
(load "my-elixir-mode"))
(add-hook 'elixir-mode-hook
(lambda ()
(define-key elixir-mode-map "\C-cd" #'debug-comment)
(define-key elixir-mode-map "\r" #'newline-and-indent)
(define-key elixir-mode-map "\C-cr" #'executable-interpret)
(define-key elixir-mode-map "\C-c\C-z" #'iex-switch-to-inf)))
;;
;; Lua-mode
;;
(autoload #'lua-mode "lua-mode" "Lua mode" t nil)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode))
;;
;; ChucK-mode
;;
(autoload #'chuck-mode "chuck-mode" "ChucK mode" t nil)
(add-to-list 'auto-mode-alist '("\\.ck$" . chuck-mode))
;;
;; Scala-mode
;;
;; You might need to "sbaz install scala-tool-support" which puts emacs support
;; into /usr/local/scala/misc/scala-tool-support/emacs"
(condition-case ex
(progn
(autoload #'scala-mode "scala-mode2" "Scala mode" t nil)
(add-to-list 'auto-mode-alist '("\\.scala$" . scala-mode))
(load "inf-sbt")
(add-hook 'scala-mode-hook
(lambda ()
(define-key scala-mode-map [f1] my-shell) ; I don't use Speedbar
(define-key scala-mode-map "\r" #'newline-and-indent)
(define-key scala-mode-map "\C-cr" #'executable-interpret)))
;; That bright red face for vars is too annoying
(set-face-attribute 'scala-font-lock:var-face nil :bold nil :foreground "red3"))
(error nil))
;;; Derived from path-to-java-package in progmodes/my-java-mode.el
(defun path-to-scala-package (path)
"Returns a Scala package name for PATH, which is a file path.
Looks for 'src' or 'src/scala/{main,test}' in PATH and uses everything after
that, turning slashes into dots. For example, the path
/home/foo/project/src/main/scala/com/yoyodyne/project/Foo.scala becomes
'com.yoyodyne.project'. If PATH is a directory, the last part of
the path is ignored. That is a bug, but it's one I can live with
for now."
(interactive)
(let ((reverse-path-list (cdr (reverse (split-string path "/")))))
(mapconcat
#'identity
(reverse (upto reverse-path-list
(if (or (member "main" reverse-path-list)
(member "test" reverse-path-list))
"scala" "src")))
".")))
;;
;; Dired-mode
;;
(put 'dired-find-alternate-file 'disabled nil)
(defun my-dired-only-show (only-string)
"Only show files that match a regular expression."
(interactive "sOnly show files that match regexp: ")
(dired-mark-files-regexp only-string)
(dired-toggle-marks)
(dired-do-kill-lines))
(defun my-dired-cruft-remove ()
(interactive)
(dired-mark-files-regexp
"\\.\\(aux\\|class\\|o\\|elc\\|dvi\\|lj\\|log\\|toc\\)$")
(dired-do-kill-lines))
(defun my-dired-dot-remove ()
(interactive)
(dired-mark-files-regexp "^\\.")
(dired-do-kill-lines))
(add-hook 'dired-mode-hook
(lambda ()
(define-key dired-mode-map "\C-c\C-c" #'my-dired-cruft-remove)
(define-key dired-mode-map "\C-c." #'my-dired-dot-remove)
(defvar dired-compress-file-suffixes
'(("\\.gz\\'" "" "gunzip")
("\\.tgz\\'" ".tar" "gunzip")
("\\.Z\\'" "" "uncompress")
;; For .z, try gunzip. It might be an old gzip file,
;; or it might be from compact? pack? (which?) but gunzip
;; handles both.
("\\.z\\'" "" "gunzip")
;; This item controls naming for compression.
("\\.tar\\'" ".tar.gz" nil))
"Control changes in file name suffixes for compression and uncompression.
Each element specifies one transformation rule, and has the form:
(REGEXP NEW-SUFFIX PROGRAM)
The rule applies when the old file name matches REGEXP.
The new file name is computed by deleting the part that matches REGEXP
(as well as anything after that), then adding NEW-SUFFIX in its place.
If PROGRAM is non-nil, the rule is an uncompression rule,
and uncompression is done by running PROGRAM.
Otherwise, the rule is a compression rule, and compression is done with
gzip.")))
;;
;; Python-mode
;;
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(add-hook 'python-mode-hook
(lambda ()
(turn-on-font-lock)
(define-key python-mode-map "\C-cr" #'executable-interpret)
;; these two are in addition to the \C-< and \C-> bindings
;; that already exist in Python mode
(define-key python-mode-map "\M-[" #'python-indent-shift-left)
(define-key python-mode-map "\M-]" #'python-indent-shift-right)))
;;
;; EMMS (Emacs Multi-Media System)
;;
(when (fboundp #'emms-all)
(defun emms-init ()
(interactive)
(emms-all)