forked from jwiegley/dot-emacs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
5304 lines (4661 loc) · 181 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
;; Added by Package.el. This must come before configurations of
;; installed packages. Don't delete this line. If you don't want it,
;; just comment it out by adding a semicolon to the start of the line.
;; You may delete these explanatory comments.
(package-initialize)
(defconst emacs-start-time (current-time))
(unless noninteractive
(message "Loading %s..." load-file-name))
(defvar file-name-handler-alist-old file-name-handler-alist)
(setq package-enable-at-startup nil
file-name-handler-alist nil
message-log-max 16384
gc-cons-threshold 402653184
gc-cons-percentage 0.6
auto-window-vscroll nil)
(add-hook 'after-init-hook
`(lambda ()
(setq file-name-handler-alist file-name-handler-alist-old
gc-cons-threshold 800000
gc-cons-percentage 0.1)
(garbage-collect)) t)
(defconst user-site-lisp-directory
(expand-file-name "site-lisp/" user-emacs-directory))
(defun add-to-load-path (path &optional dir)
(setq load-path
(cons (expand-file-name path (or dir user-emacs-directory)) load-path)))
;; Add top-level lisp directories, in case they were not setup by the
;; environment.
(dolist (dir (nreverse
(list
user-site-lisp-directory)))
(dolist (entry (nreverse (directory-files-and-attributes dir)))
(if (cadr entry)
(add-to-load-path (car entry) dir))))
(eval-and-compile
(mapc
#'(lambda (path)
(push (expand-file-name path user-emacs-directory) load-path))
'("site-lisp" "override" "lisp" "lisp/use-package" ""))
(defun agda-site-lisp ()
(let ((agda
(nth 1 (split-string
(shell-command-to-string "load-env-agda which agda")
"\n")))))))
(eval-and-compile
(defvar use-package-verbose t)
;; (defvar use-package-expand-minimally t)
(eval-after-load 'advice
`(setq ad-redefinition-action 'accept))
(require 'cl)
(require 'use-package))
(require 'bind-key)
(require 'diminish nil t)
;;; Utility macros and functions
;; support textexpander (dkh (2015-03-25): check if it's running)
;; (bind-key "M-v" #'scroll-up)
(bind-key "H-v" #'yank)
(defsubst hook-into-modes (func &rest modes)
(dolist (mode-hook modes) (add-hook mode-hook func)))
;;; Load customization settings
(defvar running-alternate-emacs nil)
(defvar user-data-directory (expand-file-name "data" user-emacs-directory))
(if (not (string-match (concat "Emacs\\([A-Za-z]+\\).app/Contents/MacOS/")
invocation-directory))
(load (expand-file-name "settings" user-emacs-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 1 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))))
;;; 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
;;; Configure libraries
(eval-and-compile
(push (expand-file-name "lib" user-emacs-directory) load-path))
(use-package anaphora :defer t :load-path "lib/anaphora")
(use-package async :defer t :load-path "lisp/async")
(use-package button-lock :defer t :load-path "lib/button-lock")
(use-package ctable :defer t :load-path "lib/emacs-ctable")
(use-package dash :defer t :load-path "lib/dash-el")
(use-package deferred :defer t :load-path "lib/emacs-deferred")
(use-package epc :defer t :load-path "lib/emacs-epc")
(use-package epl :defer t :load-path "lib/epl")
(use-package f :defer t :load-path "lib/f-el")
(use-package fame :defer t)
(use-package fuzzy :defer t)
(use-package gh :defer t :load-path "lib/gh-el")
(use-package ht :defer t :load-path "lib/ht-el")
(use-package let-alist :defer t)
(use-package logito :defer t :load-path "lib/logito")
(use-package makey :defer t :load-path "lib/makey")
(use-package marshal :defer t :load-path "lib/marshal")
(use-package pcache :defer t :load-path "lib/pcache")
(use-package pkg-info :defer t :load-path "lib/pkg-info")
(use-package popup :defer t :load-path "lib/popup-el")
(use-package popwin :defer t :load-path "lib/popwin-el")
(use-package pos-tip :defer t )
(use-package s :defer t :load-path "lib/s-el")
(use-package tablist :defer t :load-path "lib/tablist")
(use-package seq :defer t)
(use-package web :defer t :load-path "lib/emacs-web")
(use-package working :defer t)
(use-package xml-rpc :defer t)
;;; Keybindings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; dkh (2015-03-25): Move all of these into declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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>
;;
;; H-<anything>
;; M-H-<anything>
;;
;; Single-letter bindings still available:
;; C- ,'";:?<>|!#$%^&*`~ <tab>
;; M- ?#
;;; global-map
(autoload 'org-cycle "org" nil t)
(autoload 'hippie-expand "hippie-exp" nil t)
(autoload 'indent-according-to-mode "indent" nil t)
(defun smart-tab (&optional arg)
(interactive "P")
(cond
((looking-back "^[-+* \t]*" nil)
(if (eq major-mode 'org-mode)
(org-cycle arg)
(indent-according-to-mode)))
(t
;; Hippie also expands yasnippets, due to `yas-hippie-try-expand' in
;; `hippie-expand-try-functions-list'.
(hippie-expand arg))))
(define-key key-translation-map (kbd "H-TAB") (kbd "C-TAB"))
(bind-key "<H-down>" #'shrink-window)
(bind-key "<H-left>" #'shrink-window-horizontally)
(bind-key "<H-right>" #'enlarge-window-horizontally)
(bind-key "<H-up>" #'enlarge-window)
(bind-key "H-`" #'make-frame)
;;; 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" #'delete-other-windows)
;;; 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-'" #'insert-pair)
(bind-key "M-\"" #'insert-pair)
(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-D" #'mark-defun)
(bind-key "M-g c" #'goto-char)
(bind-key "M-g l" #'goto-line)
(defun delete-indentation-forward ()
(interactive)
(delete-indentation t))
;;; M-C-
(bind-key "<C-M-backspace>" #'backward-kill-sexp)
;;; ctl-x-map
;;; C-x
(defvar edit-rectangle-origin)
(defvar edit-rectangle-saved-window-config)
(defun edit-rectangle (&optional start end)
(interactive "r")
(let ((strs (delete-extract-rectangle start end))
(mode major-mode)
(here (copy-marker (min (mark) (point)) t))
(config (current-window-configuration)))
(with-current-buffer (generate-new-buffer "*Rectangle*")
(funcall mode)
(set (make-local-variable 'edit-rectangle-origin) here)
(set (make-local-variable 'edit-rectangle-saved-window-config) config)
(local-set-key (kbd "C-c C-c") #'restore-rectangle)
(mapc #'(lambda (x) (insert x ?\n)) strs)
(goto-char (point-min))
(pop-to-buffer (current-buffer)))))
(defun restore-rectangle ()
(interactive)
(let ((content (split-string (buffer-string) "\n"))
(origin edit-rectangle-origin)
(config edit-rectangle-saved-window-config))
(with-current-buffer (marker-buffer origin)
(goto-char origin)
(insert-rectangle content))
(kill-buffer (current-buffer))
(set-window-configuration config)))
(bind-key "C-x D" #'edit-rectangle)
(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 delete-current-buffer-file ()
"Delete the current buffer and the file connected with it"
(interactive)
(let ((filename (buffer-file-name))
(buffer (current-buffer))
(name (buffer-name)))
(if (not (and filename (file-exists-p filename)))
(kill-buffer buffer)
(when (yes-or-no-p "Are you sure, want to remove this file? ")
(delete-file filename)
(kill-buffer buffer)
(message "File '%s' successfully removed" filename)))))
(bind-key "C-x K" #'delete-current-buffer-file)
;;; 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)
(defmacro when-feature-loaded (feature &rest body)
"When FEATURE is loaded, evaluate and execute BODY."
`(when (featurep ,feature) ,@body))
(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.
Inspired by Erik Naggum's `recursive-edit-with-single-window'."
`(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 d" #'delete-current-line)
(bind-key "C-c g" #'goto-line)
(defun do-eval-buffer ()
(interactive)
(call-interactively 'eval-buffer)
(message "Buffer has been evaluated"))
(defun do-eval-region ()
(interactive)
(call-interactively 'eval-region)
(message "Region has been evaluated"))
(bind-keys :prefix-map my-lisp-devel-map
:prefix "C-c e"
("E" . elint-current-buffer)
("b" . do-eval-buffer)
("c" . cancel-debug-on-entry)
("d" . debug-on-entry)
("e" . toggle-debug-on-error)
("f" . emacs-lisp-byte-compile-and-load)
("j" . emacs-lisp-mode)
("l" . find-library)
("r" . do-eval-region)
("s" . scratch)
("z" . byte-recompile-directory))
(use-package bytecomp-simplify :defer 15)
(bind-key "C-c f" #'flush-lines)
(bind-key "C-c k" #'keep-lines)
(eval-when-compile
(defvar emacs-min-height)
(defvar emacs-min-width))
(defvar display-name
(let ((width (display-pixel-width)))
(cond ((>= width 2560) 'retina-imac)
((= width 1440) 'retina-macbook-pro))))
(defvar emacs-min-top 23)
(defvar emacs-min-left
(cond ((eq display-name 'retina-imac) 975)
(t 521)))
(defvar emacs-min-height
(cond ((eq display-name 'retina-imac) 57)
(t 44)))
(defvar emacs-min-width 100)
(if running-alternate-emacs
(setq emacs-min-top 22
emacs-min-left 5
emacs-min-height 57
emacs-min-width 90))
(defvar emacs-min-font
(cond
((eq display-name 'retina-imac)
(if running-alternate-emacs
"-*-Myriad Pro-normal-normal-normal-*-20-*-*-*-p-0-iso10646-1"
;; "-*-Source Code Pro-normal-normal-normal-*-20-*-*-*-m-0-iso10646-1"
"-*-Hack-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1"
))
((string= (system-name) "ubuntu")
;; "-*-Source Code Pro-normal-normal-normal-*-20-*-*-*-m-0-iso10646-1"
"-*-Hack-normal-normal-normal-*-14-*-*-*-m-0-iso10646-1"
)
(t
(if running-alternate-emacs
"-*-Myriad Pro-normal-normal-normal-*-17-*-*-*-p-0-iso10646-1"
;; "-*-Source Code Pro-normal-normal-normal-*-15-*-*-*-m-0-iso10646-1"
"-*-Hack-normal-normal-normal-*-14-*-*-*-m-0-iso10646-1"
))))
(let ((frame-alist
(list (cons 'top emacs-min-top)
(cons 'left emacs-min-left)
(cons 'height emacs-min-height)
(cons 'width emacs-min-width)
(cons 'font emacs-min-font))))
(setq initial-frame-alist frame-alist))
(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)
(set-frame-font emacs-min-font))
(if window-system
(add-hook 'after-init-hook 'emacs-min))
(defun emacs-max ()
(interactive)
(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))
(defun emacs-toggle-size ()
(interactive)
(if (> (cdr (assq 'width (frame-parameters))) 100)
(emacs-min)
(emacs-max)))
(bind-key "C-c m" #'emacs-toggle-size)
(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 F" #'customize-face)
(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)
(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))))
(bind-key "C-c V" #'view-clipboard)
(bind-key "C-c z" #'clean-buffer-list)
(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)
(defun copy-current-buffer-name ()
(interactive)
(let ((name (buffer-file-name)))
(kill-new name)
(message name)))
(bind-key "C-c C-0" #'copy-current-buffer-name)
;;; 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)
(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-switch-in-other-buffer (buf)
(when buf
(split-window-vertically)
(switch-to-buffer-other-window buf)))
(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)
(switch-to-buffer find-buf)
(my-switch-in-other-buffer desc-buf)
(my-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)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; dkh (2015-03-25): Move all of the above into use-package declarations ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Delayed configuration
(use-package flycheck
:load-path "site-lisp/flycheck"
:defer 5
:config
(add-to-list 'display-buffer-alist
`(,(rx bos "*Flycheck errors*" eos)
(display-buffer-reuse-window
display-buffer-in-side-window)
(reusable-frames . visible)
(side . bottom)
(window-height . 0.4)))
(defun lunaryorn-quit-bottom-side-windows ()
"Quit side windows of the current frame."
(interactive)
(dolist (window (window-at-side-list))
(quit-window nil window)))
(bind-key "C-H-M-:" 'lunaryorn-quit-bottom-side-windows)
(use-package helm-flycheck
:load-path "site-lisp/helm-flycheck"
:init
(define-key flycheck-mode-map (kbd "C-c ! h") 'helm-flycheck))
(use-package drupal-mode
:load-path "site-lisp/drupal-mode"
:commands drupal-mode-bootstrap
:config
(add-hook 'drupal-mode-hook
'(lambda ()
(add-to-list 'Info-directory-list '"~/.emacs.d/site-lisp/drupal-mode")
(yas-activate-extra-mode 'drupal-mode)
(when (apply 'derived-mode-p drupal-php-modes)
(flycheck-mode t))))
(use-package drupal-spell
:load-path "site-lisp/drupal-spell")))
(use-package dot-org
:load-path ("override/org-mode/contrib/lisp"
"override/org-mode/lisp"
"override/org-mode/contrib/lisp")
:commands my-org-startup
:bind (("M-C" . jump-to-org-agenda)
("M-m" . org-smart-capture)
("M-M" . org-inline-note)
("C-c a" . org-agenda)
("C-c S" . org-store-link)
("C-c l" . org-insert-link)
("C-. n" . org-velocity-read))
:defer 30
:config
(when (not running-alternate-emacs)
(run-with-idle-timer 300 t 'jump-to-org-agenda)
(my-org-startup)))
(use-package dot-gnus
:bind (("M-G" . switch-to-gnus)
("C-x m" . compose-mail))
:init
(progn
(setq gnus-init-file (expand-file-name "dot-gnus" user-emacs-directory)
gnus-home-directory "~/Messages/Gnus/")))
(defun define-keys (mode-map keybindings)
"Takes a mode map, and a list of (key function-designator)
lists. The functions are bound to the keys in the given mode-map.
Keys are in kbd format."
(mapc (lambda (keybinding)
(destructuring-bind (key function) keybinding
(define-key mode-map (read-kbd-macro key) function)))
keybindings))
;;; Packages
(use-package ggtags
:load-path "site-lisp/ggtags"
:commands ggtags-mode
:diminish ggtags-mode)
(use-package abbrev
:disabled t
:commands abbrev-mode
:diminish abbrev-mode
:init
(hook-into-modes #'abbrev-mode 'text-mode-hook)
:config
(if (file-exists-p abbrev-file-name)
(quietly-read-abbrev-file))
(add-hook 'expand-load-hook
(lambda ()
(add-hook 'expand-expand-hook 'indent-according-to-mode)
(add-hook 'expand-jump-hook 'indent-according-to-mode))))
(use-package ace-jump-mode
:load-path "site-lisp/ace-jump-mode"
:bind ("M-h" . ace-jump-mode)
:config
(setq ace-jump-mode-submode-list
'(ace-jump-char-mode
ace-jump-word-mode
ace-jump-line-mode)))
(use-package ace-isearch
:disabled t
:load-path "site-lisp/ace-isearch"
:config
(global-ace-isearch-mode 1))
(use-package ace-window
:load-path "site-lisp/ace-window"
:init
(defun dkh-scroll-other-window()
(interactive)
(scroll-other-window 1))
(defun dkh-scroll-other-window-down ()
(interactive)
(scroll-other-window-down 1))
:config
(setq aw-keys (quote (97 111 101 117 105 100 104 116 110))
aw-dispatch-always t
aw-dispatch-alist
'((?x aw-delete-window "Ace - Delete Window")
(?c aw-swap-window "Ace - Swap Window")
(?n aw-flip-window)
(?v aw-split-window-vert "Ace - Split Vert Window")
(?h aw-split-window-horz "Ace - Split Horz Window")
(?m delete-other-windows "Ace - Maximize Window")
(?g delete-other-windows)
(?b balance-windows)
(?u winner-undo)
(?r winner-redo)
(?j dired-jump)
(32 mode-line-other-buffer)))
(when (when-feature-loaded 'hydra)
(defhydra hydra-window-size (:color red)
"Windows size"
("a" shrink-window-horizontally "shrink horizontal")
("." shrink-window "shrink vertical")
("j" enlarge-window "enlarge vertical")
("i" enlarge-window-horizontally "enlarge horizontal"))
(defhydra hydra-window-frame (:color red)
"Frame"
("f" make-frame "new frame")
("x" delete-frame "delete frame"))
(defhydra hydra-window-scroll (:color red)
"Scroll other window"
("<SPC>" dkh-scroll-other-window "scroll")
("<backspace>" dkh-scroll-other-window-down "scroll down"))
(add-to-list 'aw-dispatch-alist '(?w hydra-window-size/body) t)
(add-to-list 'aw-dispatch-alist '(32 hydra-window-scroll/body) t)
(add-to-list 'aw-dispatch-alist '(?\; hydra-window-frame/body) t))
(set-face-attribute 'aw-leading-char-face nil :foreground "deep sky blue" :weight 'bold :height 3.0)
(set-face-attribute 'aw-mode-line-face nil :inherit 'mode-line-buffer-id :foreground "lawn green"))
(use-package avy
:load-path "site-lisp/avy"
:bind* (("H-l" . avy-goto-line))
:init
(defun toggle-window-split ()
(interactive)
(if (= (count-windows) 2)
(let* ((this-win-buffer (window-buffer))
(next-win-buffer (window-buffer (next-window)))
(this-win-edges (window-edges (selected-window)))
(next-win-edges (window-edges (next-window)))
(this-win-2nd (not (and (<= (car this-win-edges)
(car next-win-edges))
(<= (cadr this-win-edges)
(cadr next-win-edges)))))
(splitter
(if (= (car this-win-edges)
(car (window-edges (next-window))))
'split-window-horizontally
'split-window-vertically)))
(delete-other-windows)
(let ((first-win (selected-window)))
(funcall splitter)
(if this-win-2nd (other-window 1))
(set-window-buffer (selected-window) this-win-buffer)
(set-window-buffer (next-window) next-win-buffer)
(select-window first-win)
(if this-win-2nd (other-window 1))))))
(define-key ctl-x-4-map "t" 'toggle-window-split)
:config
(setq avy-keys '(?a ?s ?d ?e ?f ?g ?r ?v ?h ?j ?k ?l ?n ?m ?u)
avy-background t
avy-all-windows t
avy-style 'at-full
avy-case-fold-search nil))
(use-package hydra
:disabled t
:load-path "site-lisp/hydra"
:defer 0.1
:preface
(require 'hydra-examples)
:init
(bind-key* "\\" 'hydra-master/body)
;; (bind-key* "C-x o" 'hydra-window/body)
(bind-key "C-z" 'delete-other-windows)
(global-set-key (kbd "M-o f") 'flash-active-buffer)
(make-face 'flash-active-buffer-face)
(set-face-attribute 'flash-active-buffer-face nil
:background "red"
:foreground "black")
(defun flash-active-buffer ()
(interactive)
(run-at-time "100 millisec" nil
(lambda (remap-cookie)
(face-remap-remove-relative remap-cookie))
(face-remap-add-relative 'default 'flash-active-buffer-face)))
(defun dkh-toggle-show-trailing-whitespace ()
"Toggle show-trailing-whitespace between t and nil"
(interactive)
(setq show-trailing-whitespace (not show-trailing-whitespace)))
;; Make window splitting more useful
;; Copied from http://www.reddit.com/r/emacs/comments/25v0eo/you_emacs_tips_and_tricks/chldury
(defun my/vsplit-last-buffer (prefix)
"Split the window vertically and display the previous buffer."
(interactive "p")
(split-window-vertically)
(other-window 1 nil)
(if (= prefix 1)
(switch-to-next-buffer)))
(defun my/hsplit-last-buffer (prefix)
"Split the window horizontally and display the previous buffer."
(interactive "p")
(split-window-horizontally)
(other-window 1 nil)
(if (= prefix 1) (switch-to-next-buffer)))
(bind-key "C-x 2" 'my/vsplit-last-buffer)
(bind-key "C-x 3" 'my/hsplit-last-buffer)
:config
(hydra-add-font-lock)
(eval-and-compile
(defhydra hydra-common (:color blue)
("<ESC>" nil "quit")))
(global-set-key