forked from jwiegley/dot-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
4294 lines (3563 loc) · 134 KB
/
init.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
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
;;;_. Initialization
(setq message-log-max 16384)
(defconst emacs-start-time (current-time))
(unless noninteractive
(message "Loading %s..." load-file-name))
(load (expand-file-name "load-path" (file-name-directory load-file-name)))
(require 'use-package)
;; (eval-when-compile
;; (setq use-package-verbose (null byte-compile-current-file)))
;;;_ , Utility macros and functions
(defmacro hook-into-modes (func modes)
`(dolist (mode-hook ,modes)
(add-hook mode-hook ,func)))
(defun system-idle-time ()
(with-temp-buffer
(call-process "ioreg" nil (current-buffer) nil
"-c" "IOHIDSystem" "-d" "4" "-S")
(goto-char (point-min))
(and (re-search-forward "\"HIDIdleTime\" = \\([0-9]+\\)" nil t)
(/ (float (string-to-number (match-string 1)))
1000000000.0))))
(defun quickping (host)
(= 0 (call-process "/sbin/ping" nil nil nil "-c1" "-W50" "-q" host)))
(defun cleanup-term-log ()
"Do not show ^M in files containing mixed UNIX and DOS line endings."
(interactive)
(require 'ansi-color)
(ansi-color-apply-on-region (point-min) (point-max))
(goto-char (point-min))
(while (re-search-forward "\\(.\\|$\\|P.+\\\\\n\\)" nil t)
(overlay-put (make-overlay (match-beginning 0) (match-end 0))
'invisible t))
(set-buffer-modified-p nil))
(add-hook 'find-file-hooks
(function
(lambda ()
(if (string-match "/\\.iTerm/.*\\.log\\'"
(buffer-file-name))
(cleanup-term-log)))))
;;;_ , Read system environment
(defun read-system-environment ()
(let ((plist (expand-file-name "~/.MacOSX/environment.plist")))
(when (file-readable-p plist)
(let ((dict (cdr (assq 'dict (cdar (xml-parse-file plist))))))
(while dict
(if (and (listp (car dict))
(eq 'key (caar dict)))
(setenv (car (cddr (car dict)))
(car (cddr (car (cddr dict))))))
(setq dict (cdr dict))))
;; Configure exec-path based on the new PATH
(setq exec-path nil)
(mapc (apply-partially #'add-to-list 'exec-path)
(nreverse (split-string (getenv "PATH") ":"))))))
(unless (string-match "/nix/store" (getenv "PATH"))
(read-system-environment)
(add-hook 'after-init-hook 'read-system-environment))
;;;_ , Load customization settings
(defvar running-alternate-emacs nil)
(if (string-match (concat "/Applications/\\(Misc/\\)?"
"Emacs\\([A-Za-z]+\\).app/Contents/MacOS/")
invocation-directory)
(let ((settings (with-temp-buffer
(insert-file-contents
(expand-file-name "settings.el" user-emacs-directory))
(goto-char (point-min))
(read (current-buffer))))
(suffix (downcase (match-string 2 invocation-directory))))
(setq running-alternate-emacs t
user-data-directory
(replace-regexp-in-string "/data/" (format "/data-%s/" suffix)
user-data-directory))
(let* ((regexp "/\\.emacs\\.d/data/")
(replace (format "/.emacs.d/data-%s/" suffix)))
(dolist (setting settings)
(let ((value (and (listp setting)
(nth 1 (nth 1 setting)))))
(if (and (stringp value)
(string-match regexp value))
(setcar (nthcdr 1 (nth 1 setting))
(replace-regexp-in-string regexp replace value)))))
(eval settings)))
(load (expand-file-name "settings" user-emacs-directory)))
;; (setenv "TZ" "UTC+5")
;;;_ , Enable disabled commands
(put 'downcase-region 'disabled nil) ; Let downcasing work
(put 'erase-buffer 'disabled nil)
(put 'eval-expression 'disabled nil) ; Let ESC-ESC work
(put 'narrow-to-page 'disabled nil) ; Let narrowing work
(put 'narrow-to-region 'disabled nil) ; Let narrowing work
(put 'set-goal-column 'disabled nil)
(put 'upcase-region 'disabled nil) ; Let upcasing work
;;;_. Keybindings
;; Main keymaps for personal bindings are:
;;
;; C-x <letter> primary map (has many defaults too)
;; C-c <letter> secondary map (not just for mode-specific)
;; C-. <letter> tertiary map
;;
;; M-g <letter> goto map
;; M-s <letter> search map
;; M-o <letter> markup map (even if only temporarily)
;;
;; C-<capital letter>
;; M-<capital letter>
;;
;; A-<anything>
;; M-A-<anything>
;;
;; Single-letter bindings still available:
;; C- ,'";:?<>|!#$%^&*`~ <tab>
;; M- ?#
;;;_ , global-map
;;;_ . C-?
(defvar ctl-period-map)
(define-prefix-command 'ctl-period-map)
(bind-key "C-." 'ctl-period-map)
(bind-key* "<C-return>" 'other-window)
(defun collapse-or-expand ()
(interactive)
(if (> (length (window-list)) 1)
(delete-other-windows)
(bury-buffer)))
(bind-key "C-z" 'collapse-or-expand)
(defun reformat-json ()
(interactive)
(save-excursion
(shell-command-on-region
(mark) (point) "python -m json.tool" (buffer-name) t)))
;;;_ . M-?
(defadvice async-shell-command (before uniqify-running-shell-command activate)
(let ((buf (get-buffer "*Async Shell Command*")))
(if buf
(let ((proc (get-buffer-process buf)))
(if (and proc (eq 'run (process-status proc)))
(with-current-buffer buf
(rename-uniquely)))))))
(bind-key "M-!" 'async-shell-command)
(bind-key "M-/" 'dabbrev-expand)
(bind-key "M-'" 'insert-pair)
(bind-key "M-\"" 'insert-pair)
(defun align-code (beg end &optional arg)
(interactive "rP")
(if (null arg)
(align beg end)
(let ((end-mark (copy-marker end)))
(indent-region beg end-mark nil)
(align beg end-mark))))
(bind-key "M-[" 'align-code)
(bind-key "M-`" 'other-frame)
(bind-key "M-j" 'delete-indentation-forward)
(bind-key "M-J" 'delete-indentation)
(bind-key "M-W" 'mark-word)
(defun mark-line (&optional arg)
(interactive "p")
(beginning-of-line)
(let ((here (point)))
(dotimes (i arg)
(end-of-line))
(set-mark (point))
(goto-char here)))
(bind-key "M-L" 'mark-line)
(defun mark-sentence (&optional arg)
(interactive "P")
(backward-sentence)
(mark-end-of-sentence arg))
(bind-key "M-S" 'mark-sentence)
(bind-key "M-X" 'mark-sexp)
(bind-key "M-H" 'mark-paragraph)
(bind-key "M-D" 'mark-defun)
(bind-key "M-T" 'tags-search)
(bind-key "M-g c" 'goto-char)
(bind-key "M-g l" 'goto-line)
(defun delete-indentation-forward ()
(interactive)
(delete-indentation t))
(bind-key "M-s n" 'find-name-dired)
;;(bind-key "M-s o" 'occur)
;;;_ . M-C-?
(bind-key "<C-M-backspace>" 'backward-kill-sexp)
(defun isearch-backward-other-window ()
(interactive)
(split-window-vertically)
(call-interactively 'isearch-backward))
(bind-key "C-M-r" 'isearch-backward-other-window)
(defun isearch-forward-other-window ()
(interactive)
(split-window-vertically)
(call-interactively 'isearch-forward))
(bind-key "C-M-s" 'isearch-forward-other-window)
;; Some further isearch bindings
(bind-key "C-c" 'isearch-toggle-case-fold isearch-mode-map)
(bind-key "C-t" 'isearch-toggle-regexp isearch-mode-map)
(bind-key "C-^" 'isearch-edit-string isearch-mode-map)
(bind-key "C-i" 'isearch-complete isearch-mode-map)
;;;_ . A-?
(define-key key-translation-map (kbd "A-TAB") (kbd "C-TAB"))
;;;_ , ctl-x-map
;;;_ . C-x ?
(bind-key "C-x B" 'ido-switch-buffer-other-window)
(bind-key "C-x d" 'delete-whitespace-rectangle)
(bind-key "C-x F" 'set-fill-column)
(bind-key "C-x t" 'toggle-truncate-lines)
(defun toggle-transparency ()
(interactive)
(if (/= (cadr (frame-parameter nil 'alpha)) 100)
(set-frame-parameter nil 'alpha '(100 100))
(set-frame-parameter nil 'alpha '(85 50))))
(bind-key "C-x T" 'toggle-transparency)
;;;_ . C-x C-?
(defun duplicate-line ()
"Duplicate the line containing point."
(interactive)
(save-excursion
(let (line-text)
(goto-char (line-beginning-position))
(let ((beg (point)))
(goto-char (line-end-position))
(setq line-text (buffer-substring beg (point))))
(if (eobp)
(insert ?\n)
(forward-line))
(open-line 1)
(insert line-text))))
(bind-key "C-x C-d" 'duplicate-line)
(bind-key "C-x C-e" 'pp-eval-last-sexp)
(bind-key "C-x C-n" 'next-line)
(defun find-alternate-file-with-sudo ()
(interactive)
(find-alternate-file (concat "/sudo::" (buffer-file-name))))
(bind-key "C-x C-v" 'find-alternate-file-with-sudo)
;;;_ . C-x M-?
(bind-key "C-x M-n" 'set-goal-column)
(defun refill-paragraph (arg)
(interactive "*P")
(let ((fun (if (memq major-mode '(c-mode c++-mode))
'c-fill-paragraph
(or fill-paragraph-function
'fill-paragraph)))
(width (if (numberp arg) arg))
prefix beg end)
(forward-paragraph 1)
(setq end (copy-marker (- (point) 2)))
(forward-line -1)
(let ((b (point)))
(skip-chars-forward "^A-Za-z0-9`'\"(")
(setq prefix (buffer-substring-no-properties b (point))))
(backward-paragraph 1)
(if (eolp)
(forward-char))
(setq beg (point-marker))
(delete-horizontal-space)
(while (< (point) end)
(delete-indentation 1)
(end-of-line))
(let ((fill-column (or width fill-column))
(fill-prefix prefix))
(if prefix
(setq fill-column
(- fill-column (* 2 (length prefix)))))
(funcall fun nil)
(goto-char beg)
(insert prefix)
(funcall fun nil))
(goto-char (+ end 2))))
(bind-key "C-x M-q" 'refill-paragraph)
;;;_ , mode-specific-map
;;;_ . C-c ?
(bind-key "C-c <tab>" 'ff-find-other-file)
(bind-key "C-c SPC" 'just-one-space)
;; inspired by Erik Naggum's `recursive-edit-with-single-window'
(defmacro recursive-edit-preserving-window-config (body)
"*Return a command that enters a recursive edit after executing BODY.
Upon exiting the recursive edit (with\\[exit-recursive-edit] (exit)
or \\[abort-recursive-edit] (abort)), restore window configuration
in current frame."
`(lambda ()
"See the documentation for `recursive-edit-preserving-window-config'."
(interactive)
(save-window-excursion
,body
(recursive-edit))))
(bind-key "C-c 0"
(recursive-edit-preserving-window-config (delete-window)))
(bind-key "C-c 1"
(recursive-edit-preserving-window-config
(if (one-window-p 'ignore-minibuffer)
(error "Current window is the only window in its frame")
(delete-other-windows))))
(defun delete-current-line (&optional arg)
(interactive "p")
(let ((here (point)))
(beginning-of-line)
(kill-line arg)
(goto-char here)))
(bind-key "C-c c" 'compile)
(bind-key "C-c d" 'delete-current-line)
(defun reset-dns ()
(interactive)
(message "Resetting DNS...")
(shell-command "cleardns")
(shell-command "launchctl unload ~/Library/LaunchAgents/mac.pdnsd.plist")
(shell-command "launchctl load ~/Library/LaunchAgents/mac.pdnsd.plist")
(message "Resetting DNS...done"))
(bind-key "C-c D" 'reset-dns)
(bind-key "C-c e E" 'elint-current-buffer)
(defun do-eval-buffer ()
(interactive)
(call-interactively 'eval-buffer)
(message "Buffer has been evaluated"))
(bind-key "C-c e b" 'do-eval-buffer)
(bind-key "C-c e c" 'cancel-debug-on-entry)
(bind-key "C-c e d" 'debug-on-entry)
(bind-key "C-c e e" 'toggle-debug-on-error)
(bind-key "C-c e f" 'emacs-lisp-byte-compile-and-load)
(bind-key "C-c e j" 'emacs-lisp-mode)
(bind-key "C-c e l" 'find-library)
(bind-key "C-c e r" 'eval-region)
(bind-key "C-c e s" 'scratch)
(bind-key "C-c e v" 'edit-variable)
(defun find-which (name)
(interactive "sCommand name: ")
(find-file-other-window
(substring (shell-command-to-string (format "which %s" name)) 0 -1)))
(bind-key "C-c e w" 'find-which)
(bind-key "C-c e z" 'byte-recompile-directory)
(bind-key "C-c f" 'flush-lines)
(bind-key "C-c g" 'goto-line)
(bind-key "C-c k" 'keep-lines)
(eval-when-compile
(defvar emacs-min-height)
(defvar emacs-min-width))
(unless noninteractive
(if running-alternate-emacs
(progn
(defun emacs-min-top ()
(let ((height (display-pixel-height)))
(cond ((= 1050 height) 22)
((= 900 height) 22)
(t 22))))
(defun emacs-min-left () 5)
(defvar emacs-min-height (if (= 1050 (display-pixel-height)) 47 64))
(defvar emacs-min-width 80))
(defun emacs-min-top () 22)
(defun emacs-min-left ()
(let ((width (display-pixel-width)))
(cond
((= width 3360) 1000)
(t (- width 918)))))
(defvar emacs-min-height (if (= 1050 (display-pixel-height)) 55 65))
(defvar emacs-min-width 100)))
(defun emacs-min ()
(interactive)
(set-frame-parameter (selected-frame) 'fullscreen nil)
(set-frame-parameter (selected-frame) 'vertical-scroll-bars nil)
(set-frame-parameter (selected-frame) 'horizontal-scroll-bars nil)
(set-frame-parameter (selected-frame) 'top (emacs-min-top))
(set-frame-parameter (selected-frame) 'left (emacs-min-left))
(set-frame-parameter (selected-frame) 'height emacs-min-height)
(set-frame-parameter (selected-frame) 'width emacs-min-width)
(when running-alternate-emacs
(set-background-color "grey85")
(set-face-background 'fringe "gray80")))
(if window-system
(add-hook 'after-init-hook 'emacs-min))
(defun emacs-max ()
(interactive)
(if t
(progn
(set-frame-parameter (selected-frame) 'fullscreen 'fullboth)
(set-frame-parameter (selected-frame) 'vertical-scroll-bars nil)
(set-frame-parameter (selected-frame) 'horizontal-scroll-bars nil))
(set-frame-parameter (selected-frame) 'top 26)
(set-frame-parameter (selected-frame) 'left 2)
(set-frame-parameter (selected-frame) 'width
(floor (/ (float (x-display-pixel-width)) 9.15)))
(if (= 1050 (x-display-pixel-height))
(set-frame-parameter (selected-frame) 'height
(if (>= emacs-major-version 24)
66
55))
(set-frame-parameter (selected-frame) 'height
(if (>= emacs-major-version 24)
75
64)))))
(defun emacs-toggle-size ()
(interactive)
(if (> (cdr (assq 'width (frame-parameters))) 100)
(emacs-min)
(emacs-max)))
(bind-key "C-c m" 'emacs-toggle-size)
(defun insert-date ()
(interactive)
(insert (format-time-string "%Y-%m-%d")))
(defcustom user-initials nil
"*Initials of this user."
:set
#'(lambda (symbol value)
(if (fboundp 'font-lock-add-keywords)
(mapc
#'(lambda (mode)
(font-lock-add-keywords
mode (list (list (concat "\\<\\(" value " [^:\n]+\\):")
1 font-lock-warning-face t))))
'(c-mode c++-mode emacs-lisp-mode lisp-mode
python-mode perl-mode java-mode groovy-mode
haskell-mode literate-haskell-mode)))
(set symbol value))
:type 'string
:group 'mail)
(defun insert-user-timestamp ()
"Insert a quick timestamp using the value of `user-initials'."
(interactive)
(insert (format "%s (%s): " user-initials
(format-time-string "%Y-%m-%d" (current-time)))))
(bind-key "C-c n" 'insert-user-timestamp)
(bind-key "C-c o" 'customize-option)
(bind-key "C-c O" 'customize-group)
(bind-key "C-c q" 'fill-region)
(bind-key "C-c r" 'replace-regexp)
(bind-key "C-c s" 'replace-string)
(bind-key "C-c u" 'rename-uniquely)
(autoload 'auth-source-search "auth-source")
(defun tinify-url (url)
(interactive "sURL to shorten: ")
(let* ((api-login "jwiegley")
(api-key
(funcall
(plist-get
(car (auth-source-search :host "api.j.mp" :user api-login
:type 'netrc :port 80))
:secret))))
(flet ((message (&rest ignore)))
(with-current-buffer
(let ((query
(format "format=txt&longUrl=%s&login=%s&apiKey=%s"
(url-hexify-string url) api-login api-key)))
(url-retrieve-synchronously
(concat "http://api.j.mp/v3/shorten?" query)))
(goto-char (point-min))
(re-search-forward "^$")
(prog1
(kill-new (buffer-substring (1+ (point)) (1- (point-max))))
(kill-buffer (current-buffer)))))))
(bind-key "C-c U" 'tinify-url)
(bind-key "C-c v" 'ffap)
(defun view-clipboard ()
(interactive)
(delete-other-windows)
(switch-to-buffer "*Clipboard*")
(let ((inhibit-read-only t))
(erase-buffer)
(clipboard-yank)
(goto-char (point-min))
(html-mode)
(view-mode)))
(bind-key "C-c V" 'view-clipboard)
(bind-key "C-c z" 'clean-buffer-list)
(bind-key "C-c [" 'align-regexp)
(bind-key "C-c =" 'count-matches)
(bind-key "C-c ;" 'comment-or-uncomment-region)
;;;_ . C-c C-?
(defun delete-to-end-of-buffer ()
(interactive)
(kill-region (point) (point-max)))
(bind-key "C-c C-z" 'delete-to-end-of-buffer)
;;;_ . C-c M-?
(defun unfill-paragraph (arg)
(interactive "*p")
(let (beg end)
(forward-paragraph arg)
(setq end (copy-marker (- (point) 2)))
(backward-paragraph arg)
(if (eolp)
(forward-char))
(setq beg (point-marker))
(when (> (count-lines beg end) 1)
(while (< (point) end)
(goto-char (line-end-position))
(let ((sent-end (memq (char-before) '(?. ?\; ?! ??))))
(delete-indentation 1)
(if sent-end
(insert ? )))
(end-of-line))
(save-excursion
(goto-char beg)
(while (re-search-forward "[^.;!?:]\\([ \t][ \t]+\\)" end t)
(replace-match " " nil nil nil 1))))))
(bind-key "C-c M-q" 'unfill-paragraph)
(defun unfill-region (beg end)
(interactive "r")
(setq end (copy-marker end))
(save-excursion
(goto-char beg)
(while (< (point) end)
(unfill-paragraph 1)
(forward-paragraph))))
;;;_ , ctl-period-map
;;;_ . C-. ?
(bind-key "C-. m" 'kmacro-keymap)
;;;_ . C-. C-i
(bind-key "C-. C-i" 'indent-rigidly)
;;;_ , help-map
(defvar lisp-find-map)
(define-prefix-command 'lisp-find-map)
(bind-key "C-h e" 'lisp-find-map)
;;;_ . C-h e ?
(bind-key "C-h e c" 'finder-commentary)
(bind-key "C-h e e" 'view-echo-area-messages)
(bind-key "C-h e f" 'find-function)
(bind-key "C-h e F" 'find-face-definition)
(defun my-describe-symbol (symbol &optional mode)
(interactive
(info-lookup-interactive-arguments 'symbol current-prefix-arg))
(let (info-buf find-buf desc-buf cust-buf)
(save-window-excursion
(ignore-errors
(info-lookup-symbol symbol mode)
(setq info-buf (get-buffer "*info*")))
(let ((sym (intern-soft symbol)))
(when sym
(if (functionp sym)
(progn
(find-function sym)
(setq find-buf (current-buffer))
(describe-function sym)
(setq desc-buf (get-buffer "*Help*")))
(find-variable sym)
(setq find-buf (current-buffer))
(describe-variable sym)
(setq desc-buf (get-buffer "*Help*"))
;;(customize-variable sym)
;;(setq cust-buf (current-buffer))
))))
(delete-other-windows)
(flet ((switch-in-other-buffer
(buf)
(when buf
(split-window-vertically)
(switch-to-buffer-other-window buf))))
(switch-to-buffer find-buf)
(switch-in-other-buffer desc-buf)
(switch-in-other-buffer info-buf)
;;(switch-in-other-buffer cust-buf)
(balance-windows))))
(bind-key "C-h e d" 'my-describe-symbol)
(bind-key "C-h e i" 'info-apropos)
(bind-key "C-h e k" 'find-function-on-key)
(bind-key "C-h e l" 'find-library)
(defvar lisp-modes '(emacs-lisp-mode
inferior-emacs-lisp-mode
ielm-mode
lisp-mode
inferior-lisp-mode
lisp-interaction-mode
slime-repl-mode))
(defvar lisp-mode-hooks
(mapcar (function
(lambda (mode)
(intern
(concat (symbol-name mode) "-hook"))))
lisp-modes))
(defun scratch ()
(interactive)
(let ((current-mode major-mode))
(switch-to-buffer-other-window (get-buffer-create "*scratch*"))
(goto-char (point-min))
(when (looking-at ";")
(forward-line 4)
(delete-region (point-min) (point)))
(goto-char (point-max))
(if (memq current-mode lisp-modes)
(funcall current-mode))))
(bind-key "C-h e s" 'scratch)
(bind-key "C-h e v" 'find-variable)
(bind-key "C-h e V" 'apropos-value)
;;;_. Packages
;;;_ , el-get
(use-package el-get
:disabled t
:commands (el-get
el-get-install
el-get-update
el-get-list-packages)
:init
(defvar el-get-sources nil)
:config
(progn
(defun el-get-read-status-file ()
(mapcar #'(lambda (entry)
(cons (plist-get entry :symbol)
`(status "installed" recipe ,entry)))
el-get-sources))
(defalias 'el-get-init 'ignore
"Don't use el-get for making packages available for use.")))
;;;_ , cc-mode
(use-package cc-mode
:mode (("\\.h\\(h?\\|xx\\|pp\\)\\'" . c++-mode)
("\\.m\\'" . c-mode)
("\\.mm\\'" . c++-mode))
:init
(progn
(defun my-paste-as-check ()
(interactive)
(save-excursion
(insert "/*\n")
(let ((beg (point)) end)
(yank)
(setq end (point-marker))
(goto-char beg)
(while (< (point) end)
(forward-char 2)
(insert "CHECK: ")
(forward-line 1)))
(insert "*/\n")))
(defun my-c-indent-or-complete ()
(interactive)
(let ((class (syntax-class (syntax-after (1- (point))))))
(if (or (bolp) (and (/= 2 class)
(/= 3 class)))
(call-interactively 'indent-according-to-mode)
(call-interactively 'auto-complete))))
(defvar printf-index 0)
(defun insert-counting-printf (arg)
(interactive "P")
(if arg
(setq printf-index 0))
(if t
(insert (format "std::cerr << \"step %d..\" << std::endl;\n"
(setq printf-index (1+ printf-index))))
(insert (format "printf(\"step %d..\\n\");\n"
(setq printf-index (1+ printf-index)))))
(forward-line -1)
(indent-according-to-mode)
(forward-line))
(defun my-c-mode-common-hook ()
(abbrev-mode 1)
(gtags-mode 1)
(hs-minor-mode 1)
(hide-ifdef-mode 1)
(whitespace-mode 1)
(which-function-mode 1)
(auto-complete-mode 1)
(yas-minor-mode 1)
(bug-reference-prog-mode 1)
(diminish 'gtags-mode)
(diminish 'hs-minor-mode)
(diminish 'hide-ifdef-mode)
(bind-key "C-c p" 'insert-counting-printf c-mode-base-map)
(auto-complete-mode 1)
(setq ac-sources (list (if (and (fboundp 'semantic-active-p)
(funcall #'semantic-active-p))
'ac-source-semantic
'ac-source-gtags)))
(bind-key "<A-tab>" 'ac-complete c-mode-base-map)
;;(doxymacs-mode 1)
;;(doxymacs-font-lock)
(bind-key "<return>" 'newline-and-indent c-mode-base-map)
(set (make-local-variable 'yas-fallback-behavior)
'(apply my-c-indent-or-complete . nil))
(bind-key "<tab>" 'yas-expand-from-trigger-key c-mode-base-map)
(unbind-key "M-j" c-mode-base-map)
(bind-key "C-c C-i" 'c-includes-current-file c-mode-base-map)
(bind-key "C-c C-y" 'my-paste-as-check c-mode-base-map)
(set (make-local-variable 'parens-require-spaces) nil)
(setq indicate-empty-lines t)
(setq fill-column 72)
(bind-key "M-q" 'c-fill-paragraph c-mode-base-map)
(let ((bufname (buffer-file-name)))
(when bufname
(cond
((string-match "/ledger/" bufname)
(c-set-style "ledger"))
((string-match "/ansi/" bufname)
(c-set-style "ti")
(substitute-key-definition 'fill-paragraph 'ti-refill-comment
c-mode-base-map global-map)
(bind-key "M-q" 'ti-refill-comment c-mode-base-map))
((string-match "/edg/" bufname)
(c-set-style "edg"))
(t
(c-set-style "clang")))))
(font-lock-add-keywords 'c++-mode '(("\\<\\(assert\\|DEBUG\\)("
1 font-lock-warning-face t))))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook))
:config
(progn
(setq c-syntactic-indentation nil)
(bind-key "#" 'self-insert-command c-mode-base-map)
(bind-key "{" 'self-insert-command c-mode-base-map)
(bind-key "}" 'self-insert-command c-mode-base-map)
(bind-key "/" 'self-insert-command c-mode-base-map)
(bind-key "*" 'self-insert-command c-mode-base-map)
(bind-key ";" 'self-insert-command c-mode-base-map)
(bind-key "," 'self-insert-command c-mode-base-map)
(bind-key ":" 'self-insert-command c-mode-base-map)
(bind-key "(" 'self-insert-command c-mode-base-map)
(bind-key ")" 'self-insert-command c-mode-base-map)
(bind-key "<" 'self-insert-command c++-mode-map)
(bind-key ">" 'self-insert-command c++-mode-map)
(use-package cedet
:disabled t
:init
(progn
;; Add further minor-modes to be enabled by semantic-mode. See
;; doc-string of `semantic-default-submodes' for other things you can
;; use here.
(dolist (submode '(global-semantic-idle-summary-mode
global-semantic-mru-bookmark-mode
global-semantic-idle-local-symbol-highlight-mode
global-semantic-show-unmatched-syntax-mode))
(add-to-list 'semantic-default-submodes submode t))
;; Enable Semantic
(semantic-mode 1)
(when nil ; jww (2012-06-20): this kills buffers
;; if you want to enable support for gnu global
(use-package semanticdb-global)
(semanticdb-enable-gnu-global-databases 'c-mode)
(semanticdb-enable-gnu-global-databases 'c++-mode))))
(add-to-list 'c-style-alist
'("ti"
(indent-tabs-mode . nil)
(c-basic-offset . 3)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist
. ((substatement-open before after)
(arglist-cont-nonempty)))
(c-offsets-alist
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . +)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . c-lineup-arglist-intro-after-paren)
(arglist-close . c-lineup-arglist)
(inline-open . 0)
(brace-list-open . 0)
(topmost-intro-cont
. (first c-lineup-topmost-intro-cont
c-lineup-gnu-DEFUN-intro-cont))))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(add-to-list 'c-style-alist
'("edg"
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist
. ((substatement-open before after)
(arglist-cont-nonempty)))
(c-offsets-alist
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . +)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
(topmost-intro-cont
. (first c-lineup-topmost-intro-cont
c-lineup-gnu-DEFUN-intro-cont))))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(add-to-list 'c-style-alist
'("ledger"
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist
. ((substatement-open before after)
(arglist-cont-nonempty)))
(c-offsets-alist
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . 0)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
(topmost-intro-cont
. (first c-lineup-topmost-intro-cont
c-lineup-gnu-DEFUN-intro-cont))))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(add-to-list 'c-style-alist
'("clang"
(indent-tabs-mode . nil)
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist
. ((substatement-open before after)
(arglist-cont-nonempty)))
(c-offsets-alist
. ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(case-label . 0)
(statement-case-open . 0)
(statement-cont . +)
(arglist-intro . +)
(arglist-close . +)
(inline-open . 0)
(brace-list-open . 0)
(topmost-intro-cont
. (first c-lineup-topmost-intro-cont
c-lineup-gnu-DEFUN-intro-cont))))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")))
(defun opencl ()
(interactive)
(find-file "~/src/ansi/opencl.c")
(find-file-noselect "~/Contracts/TI/bugslayer/cl_0603/cl_0603.c")
(find-file-noselect "~/Contracts/TI/bugslayer")
(magit-status "~/src/ansi")
(gud-gdb "gdb --fullname ~/Contracts/TI/bin/c60/acpia6x"))