summaryrefslogtreecommitdiffstats
path: root/emacs/init.el
blob: 2b9594b2286980b265382a7fedd18ce446a7dc4b (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
(eval-and-compile
  (package-initialize)

  (mapc #'(lambda (directory)
            (add-to-list 'load-path directory)
            (let ((default-directory directory))
              (normal-top-level-add-subdirs-to-load-path)))
        '("/usr/share/emacs/site-lisp" "~/.emacs.d/site-lisp"))
  (add-to-list 'load-path "~/.emacs.d/"))

(eval-when-compile
  (require 'appt)
  (require 'browse-url)
  (require 'em-dirs)
  (require 'em-prompt)
  (require 'emms-source-file)
  (require 'erc-join)
  (require 'erc-stamp)
  (require 'fill-column-indicator)
  (require 'geiser-repl)
  (require 'gtags)
  (require 'hideshow)
  (require 'jabber)
  (require 'message)
  (require 'mu4e)
  (require 'org-capture)
  (require 'org-contacts)
  (require 'org-feed)
  (require 'org-html)
  (require 'php-mode)
  (require 'rainbow-delimiters)
  (require 'sauron)
  (require 'sendmail)
  (require 'smex)
  (require 'time-stamp)
  (require 'whitespace)
  (require 'yasnippet))

(autoload 'identica-mode "identica-mode" nil t)
(autoload 'mu4e "mu4e" nil t)
(autoload 'naquadah-get-colors "naquadah-theme")
(load (expand-file-name "~/.emacs.d/site-lisp/loaddefs.el"))
(load (expand-file-name "~/.emacs.d/loaddefs.el"))

(defalias 'yes-or-no-p 'y-or-n-p)

(defconst oni:c-outline-regex
  (eval-when-compile
    (concat
     "\\(?:static\\s +\\)?\\(?:\\sw+\\(?: \\|\t\\|\n\\)*?\\*?\\)"
     "\\(?:\\s \\|\t\\|\n\\)\\(?:\\sw\\|_\\)+([^)]*)[^;\n]*$"))
  "Regex for `outline-minor-mode' for `c-mode'.")

(defmacro oni:define-mailbox (name email &optional signature longname)
  "Define a mailbox function."
  `(defun ,(make-symbol (concat "oni:" name "-mailbox")) ()
     ,(concat "Settings for " name " mailbox")
     (setq mu4e-mu-home ,(expand-file-name (concat "~/.mu/" name))
           mu4e-maildir ,(expand-file-name (concat "~/documents/mail/"
                                                   (or longname name)))
           mu4e-get-mail-command ,(concat "offlineimap -oa " (or longname
                                                                 name))
           mu4e~main-buffer-name ,(concat "*mu4e-" name "*")
           user-mail-address ,email
           message-sendmail-extra-arguments '("-a" ,name)
           message-signature-file ,signature)))

(defmacro oni:email (user at host dot com)
  "Turn arguments into an email address."
  (concat (symbol-name user) "@" (symbol-name host) "."
          (symbol-name com)))

(defmacro oni:generic-outline (regex)
  "Prepare for enabling `outline-minor-mode'."
  `(progn
     (outline-minor-mode)
     (set (make-local-variable 'outline-regexp) ,regex)
     (hide-body)
     (local-set-key [C-tab] 'outline-toggle-children)))

(defmacro oni:color (name)
  `(naquadah-get-colors (quote ,name)))

(defvar oni:mailbox-map
  '("top" ("menu"
           ("ryulash.org" . "ryuslash")
           ("ninthfloor"  . "ninthfloor")
           ("gmail"       . "gmail")
           ("aethon"      . "aethon")))
  "A mailbox map for use with `tmm-prompt'.")

(defvar oni:required-packages
  '(graphviz-dot-mode htmlize magit rainbow-delimiters
                      rainbow-mode yasnippet markdown-mode flymake
                      flymake-cursor pony-mode sauron dispass
                      expand-region fill-column-indicator
                      git-auto-commit-mode idomenu magit smex)
  "List of all the packages I have (want) installed")

(defun oni:after-save-func ()
  "Function for `after-save-hook'."
  (oni:compile-el)
  (executable-make-buffer-file-executable-if-script-p))

(defun oni:before-save-func ()
  "Function for `before-save-hook'."
  (if (eq major-mode 'html-mode)
      (oni:replace-html-special-chars))
  (if (not (eq major-mode 'markdown-mode))
      (delete-trailing-whitespace)))

(defun oni:c-mode-common-func ()
  "Function for `c-mode-common-hook'."
  (setq hs-adjust-block-beginning 'hs-c-like-adjust-block-beginning)
  (hs-minor-mode))

(defun oni:compile-el ()
  "Compile the current buffer file if it is an .el file."
  (let* ((full-file-name (buffer-file-name))
         (file-name (file-name-nondirectory full-file-name))
         (suffix (file-name-extension file-name)))
      (if (and (not (string-equal file-name ".dir-locals.el"))
               (string-equal suffix "el"))
          (byte-compile-file full-file-name))))

(defun oni:hs-minor-mode-func ()
  "Function for `hs-minor-mode-hook'."
  (local-set-key [C-tab] 'hs-toggle-hiding)
  (hs-hide-all))

(defun oni:jabber-chat-mode-func ()
  "Function for `jabber-chat-mode-hook'."
  (visual-line-mode))

(defun oni:mini-fix-timestamp-string (date-string)
  "A minimal version of Xah Lee's `fix-timestamp-string'
  function, found at http://xahlee.org/emacs/elisp_parse_time.html"
  (setq date-string (replace-regexp-in-string "Jan" "01" date-string)
        date-string (replace-regexp-in-string "Feb" "02" date-string)
        date-string (replace-regexp-in-string "Mar" "03" date-string)
        date-string (replace-regexp-in-string "Apr" "04" date-string)
        date-string (replace-regexp-in-string "May" "05" date-string)
        date-string (replace-regexp-in-string "Jun" "06" date-string)
        date-string (replace-regexp-in-string "Jul" "07" date-string)
        date-string (replace-regexp-in-string "Aug" "08" date-string)
        date-string (replace-regexp-in-string "Sep" "09" date-string)
        date-string (replace-regexp-in-string "Oct" "10" date-string)
        date-string (replace-regexp-in-string "Nov" "11" date-string)
        date-string (replace-regexp-in-string "Dec" "12" date-string))
  (string-match
   "^\\([0-9]\\{2\\}\\)-\\([0-9]\\{2\\}\\)-\\([0-9]\\{4\\}\\)$"
   date-string)
  (format "%s-%s-%s"
          (match-string 3 date-string)
          (match-string 2 date-string)
          (match-string 1 date-string)))

(defun oni:myepisodes-formatter (plist)
  "Format RSS items from MyEpisodes as org tasks."
  (let ((str (plist-get plist :title)))
    (string-match
     "^\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]\\[ \\([^\]]+\\) \\]$"
     str)
    (let* ((title (match-string 1 str))
           (episode (match-string 2 str))
           (name (match-string 3 str))
           (date (oni:mini-fix-timestamp-string (match-string 4 str))))
      (format "* ACQUIRE %s %s - %s <%s>" title episode name date))))

(defun oni:prog-mode-func ()
  "Function for `prog-mode-hook'."
  (rainbow-delimiters-mode)
  (fci-mode)
  (pretty-symbols-mode))

(defun oni:replace-html-special-chars ()
  (oni:replace-occurrences "é" "&eacute;"))

(defun oni:replace-occurrences (from to)
  "Replace all occurrences of FROM with TO in the current buffer."
  (save-excursion
    (goto-char (point-min))
    (while (search-forward from nil t)
      (replace-match to))))

(defun oni:required-packages-installed-p ()
  "Check if all the packages I need are installed."
  (let ((tmp-packages oni:required-packages)
        (result t))
    (while (and tmp-packages result)
      (if (not (package-installed-p (car tmp-packages)))
          (setq result nil))
      (setq tmp-packages (cdr tmp-packages)))
    result))

(defun oni:view-mail ()
  "Show a menu with all mailbox options from `oni:mailbox-map'
for easy selection."
  (interactive)
  (require 'tmm)
  (let* ((tmm-completion-prompt "Choose a mailbox\n")
         (inbox (tmm-prompt oni:mailbox-map)))
    (if inbox
        (progn
          (require 'mu4e)
          (funcall (intern (concat "oni:" inbox "-mailbox")))
          (mu4e)))))

(eval-after-load "info"
  '(require 'info+))

(eval-after-load "mu4e"
  '(add-to-list
    'org-capture-templates
    '("c" "Contact" entry (file "~/documents/org/misc/contacts.org")
      (concat "* %(mu4e-view-snarf-from 'name)\n"
              "  :PROPERTIES:\n"
              "  :EMAIL: %(mu4e-view-snarf-from 'email)\n"
              "  :END:"))))

(oni:define-mailbox "aethon"
                    (oni:email thomas at aethon dot nl)
 (expand-file-name "~/documents/work/aethon/signature.txt"))
(oni:define-mailbox "gmail" (oni:email ryuslash at gmail dot com))
(oni:define-mailbox "ninthfloor"
                    (oni:email ryuslash at ninthfloor dot org))
(oni:define-mailbox "ryuslash" (oni:email tom at ryuslash dot org)
                    nil "ryuslash.org")

(setq-default c-basic-offset 4)
(setq-default fci-rule-column 73)

(setq avandu-article-render-function #'avandu-view-w3m)
(setq fci-rule-color "darkred")
(setq inferior-lisp-program "sbcl")
(setq jabber-account-list '(("ryuslash@jabber.org")))
(setq jabber-chat-buffer-format "*jabber:%n*")
(setq jabber-chat-buffer-show-avatar nil)
(setq jabber-chat-fill-long-lines nil)
(setq jabber-chat-foreign-prompt-format "[%t] < ")
(setq jabber-chat-local-prompt-format "[%t] > ")
(setq jabber-chatstates-confirm nil)
(setq jabber-history-dir "~/.emacs.d/jabber")
(setq jabber-roster-show-bindings nil)
(setq mail-header-separator "")
(setq mu4e-headers-date-format "%d-%m %H:%M")
(setq mu4e-headers-fields '((:date . 11)
                            (:flags . 6)
                            (:to . 22)
                            (:from . 22)
                            (:subject)))
(setq mu4e-headers-show-threads nil)
(setq mu4e-headers-sort-revert nil)
(setq mu4e-my-email-addresses (list
                               (oni:email tom at ryuslash dot org)
                               (oni:email ryuslash at gmail dot com)
                               (oni:email ryuslash at ninthfloor dot org)
                               (oni:email thomas at aethon dot nl)))
(setq package-archives
      '(("melpa" . "http://melpa.milkbox.net/packages/")
        ("ELPA" . "http://tromey.com/elpa/")
        ("gnu" . "http://elpa.gnu.org/packages/")
        ("marmalade" . "http://marmalade-repo.org/packages/")))
(setq package-load-list '((htmlize "1.39")
                          all))
(setq org-feed-alist
      '(("MyEpisodes"
         "http://www.myepisodes.com/rss.php?feed=mylist&uid=Slash&pwdmd5=04028968e1f0b7ee678b748a4320ac17"
         "~/documents/org/org" "MyEpisodes"
         :formatter oni:myepisodes-formatter)))
(setq send-mail-function 'smtpmail-send-it)
(setq sendmail-program "/usr/bin/msmtp")
(setq yas-prompt-functions '(yas-ido-prompt))

(add-hook 'after-save-hook 'oni:after-save-func)
(add-hook 'before-save-hook 'oni:before-save-func)
(add-hook 'c-mode-common-hook 'oni:c-mode-common-func)
(add-hook 'hs-minor-mode-hook 'oni:hs-minor-mode-func)
(add-hook 'jabber-chat-mode-hook 'oni:jabber-chat-mode-func)
(add-hook 'prog-mode-hook 'oni:prog-mode-func)

(global-set-key (kbd "<f6>") 'jabber-switch-to-roster-buffer)
(global-set-key (kbd "<f8>") 'oni:raise-eshell)
(global-set-key (kbd "M-n") 'idomenu)

(unless (oni:required-packages-installed-p)
  (message "%s" "Refreshing package database...")
  (package-refresh-contents)
  (message "%s" " done.")
  (mapc #'(lambda (package)
            (when (not (package-installed-p package))
              (package-install package)))
        oni:required-packages))

(defun oni:c-mode-func ()
  "Function for `c-mode-hook'."
  (local-set-key [f9] 'compile)
  (local-set-key "\C-j" 'oni:newline-and-indent))

(add-hook 'c-mode-hook 'oni:c-mode-func)

(defun oni:css-mode-func ()
  "Function for `css-mode-hook'."
  (setq hs-adjust-block-beginning 'hs-c-like-adjust-block-beginning)
  (hs-minor-mode)
  (local-set-key "\C-j" 'oni:newline-and-indent)
  (rainbow-mode))

(add-hook 'css-mode-hook 'oni:css-mode-func)

(defun oni:emacs-lisp-mode-func ()
  "Function for `emacs-lisp-mode-hook'."
  (eldoc-mode)
  (when (buffer-file-name)
    (hs-minor-mode)))

(add-hook 'emacs-lisp-mode-hook 'oni:emacs-lisp-mode-func)

(defun oni:go-mode-func ()
  "Function for `go-mode-hook'."
  (setq indent-tabs-mode nil)
  (local-set-key "\C-j" 'oni:newline-and-indent))

(add-hook 'go-mode-hook 'oni:go-mode-func)

(defun oni:html-mode-func ()
  "Function for `html-mode-hook'."
  (fci-mode))

(add-hook 'html-mode-hook 'oni:html-mode-func)

(defconst oni:javascript-outline-regex "function \\(\\w\\|_\\)+("
  "Regex for `outline-minor-mode' for `js-mode'.")

(defun oni:js-mode-func ()
  "Function for `js-mode-hook'."
  (oni:generic-outline oni:javascript-outline-regex)
  (rainbow-delimiters-mode)
  (local-set-key "\C-j" 'oni:newline-and-indent))

(add-hook 'js-mode-hook 'oni:js-mode-func)

(add-to-list 'auto-mode-alist '("\\.js\\(on\\)?$" . js-mode))

(defun oni:lisp-mode-func ()
  "Function for `lisp-mode-hook'."
  (hs-minor-mode))

(add-hook 'lisp-mode-hook 'oni:lisp-mode-func)

(defconst oni:python-outline-regex
  (eval-when-compile
    (concat "^[ \t]*\\(?:@[a-zA-Z0-9_]+\\(?:([a-zA-Z0-9_=, ]*)\\)?"
            "\n\\)*[ \t]*\\(?:\\(class\\|def\\)[ \t]+\\(\\sw\\|\\s_\\)+"
            "\\(([^)]*):\\)?\\|\\#[ a-zA-Z0-9]*\\#\\)"))
  "Regex for `outline-minor-mode' for `python-mode'.")

(defun oni:python-mode-func ()
  "Function for `python-mode-hook'."
  (flymake-mode)
  (local-set-key (kbd "C->") 'python-indent-shift-right)
  (local-set-key (kbd "C-<") 'python-indent-shift-left)
  (local-set-key [C-tab] 'outline-toggle-children)
  (oni:generic-outline oni:python-outline-regex)
  (set (make-local-variable 'electric-indent-chars) nil)
  (rainbow-delimiters-mode)
  (fci-mode))

(add-hook 'python-mode-hook 'oni:python-mode-func)

(autoload 'pony-mode "pony-mode" nil t)

(defconst oni:php-outline-regex
  (eval-when-compile
    (concat
     "^ *\\(\\(?:namespace\\|interface\\) [a-zA-Z0-9_]\\|\\(\\(abstract"
     "\\|final\\) \\)?class [a-zA-Z0-9_]+\\( extends [\\a-zA-Z0-9_]+\\)?"
     "\\|\\(abstract \\)?\\(public\\|private\\|protected\\)?"
     "\\( static\\)? function [a-zA-Z0-9_]+(\\|/\\*\\*\\)"))
  "Regex for `outline-minor-mode' for `php-mode'.")

(defun oni:php-mode-func ()
  "Function for `php-mode-hook'."
  (flymake-mode)
  ;; (oni:gtags-for-php)
  (local-set-key "\C-j" 'oni:newline-and-indent)
  (c-set-offset 'arglist-intro '+)
  (c-set-offset 'arglist-close '0)
  (rainbow-delimiters-mode)
  (setq fci-rule-column 81))

(autoload 'php-mode "php-mode" nil t)

(setq-default php-mode-warn-if-mumamo-off nil)

(setq php-function-call-face 'font-lock-function-name-face
      php-mode-force-pear t)

(add-to-list 'auto-mode-alist '("\\.php[345]?$" . php-mode))

(add-hook 'php-mode-hook 'oni:php-mode-func)

(add-to-list 'auto-mode-alist '("\\.tpl$" . html-mode))

(defun oni:scheme-mode-func ()
  "Function for `scheme-mode-hook'."
  (hs-minor-mode))

(add-hook 'scheme-mode-hook 'oni:scheme-mode-func)

(require 'geiser-install)

(setq geiser-active-implementations '(guile)
      geiser-repl-history-filename "~/.emacs.d/geiser-history")

(defun oni:java-mode-func ()
  "Function for `java-mode-hook'."
  (local-set-key "\C-j" 'oni:newline-and-indent))

(add-hook 'java-mode-hook 'oni:java-mode-func)

(defun oni:close-client-window ()
  "Close a client's frames."
  (interactive)
  (server-save-buffers-kill-terminal nil))

(when (daemonp)
  (global-set-key "\C-x\C-c" 'oni:close-client-window))

(defun oni:org-mode-func ()
  "Function for `org-mode-hook'."
  (flyspell-mode)
  (auto-fill-mode))

(add-hook 'org-mode-hook 'oni:org-mode-func)

(global-set-key "\C-ca" 'org-agenda)
(global-set-key "\C-cc" 'org-capture)

(eval-after-load "org"
  '(progn
     (require 'appt)
     (require 'org-protocol)
     (require 'org-habit)
     (require 'org-contacts)

     (add-to-list 'org-modules 'habit)

     (org-indent-mode t)

     (org-agenda-to-appt)
     (ad-activate 'org-agenda-redo)))

(eval-after-load "org-crypt"
  '(org-crypt-use-before-save-magic))

(setq org-hide-emphasis-markers t)

(setq org-refile-allow-creating-parent-nodes t
      org-refile-targets '((nil . (:maxlevel . 6)))
      org-refile-use-outline-path 'file)

(defadvice org-agenda-redo (after org-agenda-redo-add-appts)
  "Pressing `r' on the agenda will also add appointments."
  (progn
    (setq appt-time-msg-list nil)
    (org-agenda-to-appt)))

(setq org-agenda-custom-commands
      '(("b" "Bookmarks to look at."
         todo "LOOKAT")
        ("w" "Work todo."
         tags-todo "CATEGORY=\"Work\"")))

(setq org-directory (expand-file-name "~/documents/org"))

(setq org-default-notes-file (concat org-directory "/org"))

(setq org-agenda-files
      `(,(concat org-directory "/org")
        ,(concat org-directory "/misc/contacts.org")
        ,(concat org-directory "/misc/bookmarks.org")))

(setq org-agenda-sorting-strategy       ; How to sort my agenda.
      '((agenda habit-down time-up priority-down category-keep)
        (todo priority-down category-up)
        (tags priority-down category-keep)
        (search category-keep)))

(setq org-capture-templates             ; What to capture when.
      '(("t" "Task" entry (file+headline "" "tasks")
         "* TODO %^{Description}\n  %u\n\n  %?")
        ("T" "Task with link" entry (file+headline "" "tasks")
         "* TODO %^{Description}\n  %u\n\n  %a\n  %?")
        ("h" "Habit" entry (file+headline "" "tasks")
         (concat "* TODO %^{Description}\n"
                 "  SCHEDULED: %^T\n"
                 "  :PROPERTIES:\n"
                 "  :STYLE:    habit\n"
                 "  :END:")
         :immediate-finish t)
        ("l" "Log" entry (file+headline "" "notes")
         (concat "* %n %<%d-%m-%Y %H:%M:%S>\n"
                 "  %a\n\n"
                 "  %?")
         :prepend t :empty-lines 1)
        ("a" "Appointment" entry (file+headline "" "appointments")
         "* %^{Description} %^T" :immediate-finish t)
        ("b" "Bookmark" entry (file "~/documents/org/misc/bookmarks.org")
         "* %c\n\n  %:initial")))

(setq org-export-htmlize-output-type 'css
      org-outline-path-complete-in-steps t
      org-return-follows-link t
      org-src-fontify-natively t
      org-tags-exclude-from-inheritance '("crypt")
      org-use-fast-todo-selection t)

(setq org-todo-keyword-faces
      '(("TODO"        :foreground "red")
        ("IN PROGRESS" :foreground "yellow")
        ("DONE"        :foreground "forest green")
        ("SUCCEEDED"   :foreground "forest green")
        ("WAITING"     :foreground "orange")
        ("CANCELLED"   :foreground "orangered")
        ("FAILED"      :foreground "orangered")))

(setq org-todo-keywords
      '((sequence "TODO(t)" "IN PROGRESS" "WAITING(@/!)" "|"
                  "DONE(!/!)" "CANCELLED(@/!)")))

(defun oni:diary-display-func ()
  "Function for `diary-display-hook'."
  (diary-fancy-display))

(add-hook 'diary-display-hook 'oni:diary-display-func)

(setq appt-display-diary nil)

(defun oni:newline-and-indent ()
  (interactive)
  (if (and (not (or (= (point) (point-max))
                    (= (point) (point-min))))
           (or (and (char-equal (char-before) ?{)
                    (char-equal (char-after) ?}))
               (and (char-equal (char-before) ?\()
                    (char-equal (char-after) ?\)))))
      (save-excursion (newline-and-indent)))
  (newline-and-indent))

(defun oni:emms-toggle-playing ()
  "Toggle between playing/paused states."
  (interactive)
  (if (eq emms-player-playing-p nil)
      (emms-start)
    (emms-pause)))

(eval-after-load "emms-source-file"
      '(progn
         (require 'emms-setup)

         (emms-standard)
         (require 'emms-player-mpd)

         (setq emms-player-mpd-server-name "localhost")
         (setq emms-player-mpd-server-port "6600")

         (add-to-list 'emms-info-functions 'emms-info-mpd)
         (add-to-list 'emms-player-list 'emms-player-mpd)
         (setq emms-player-mpd-music-directory "/mnt/music/mp3")))

(setq emms-source-file-default-directory "/mnt/music/")

(global-set-key [XF86AudioNext] 'emms-next)
(global-set-key [XF86AudioPlay] 'oni:emms-toggle-playing)
(global-set-key [XF86AudioPrev] 'emms-previous)
(global-set-key [XF86AudioStop] 'emms-stop)
(global-set-key [XF86Tools] 'emms)

(defun oni:erc-mode-func ()
  "Function for `erc-mode-hook'."
  (erc-fill-mode -1)
  (visual-line-mode)
  (setq truncate-lines nil))

(setq erc-autojoin-channels-alist
      '(("freenode.net" "#herbstluftwm" "#ninthfloor" "#emacs"
         "#dispass")))

(setq erc-nick "ryuslash")

(add-hook 'erc-mode-hook 'oni:erc-mode-func)

(setq erc-insert-timestamp-function 'erc-insert-timestamp-left
      erc-timestamp-format "[%H:%M] "
      erc-timestamp-only-if-changed-flag nil)

(setq erc-hide-list '("JOIN" "PART" "QUIT"))

(defun oni:flymake-mode-func ()
  "Function for `flymake-mode-hook'."
  (local-set-key [M-P] 'flymake-goto-prev-error)
  (local-set-key [M-N] 'flymake-goto-next-error))

(add-hook 'flymake-mode-hook 'oni:flymake-mode-func)

(defun oni:flymake-pyflakes-init ()
  "Initialize function for flymake with pyflakes."
  (let* ((temp-file (flymake-init-create-temp-buffer-copy
                     'flymake-create-temp-inplace))
         (local-file (file-relative-name temp-file (file-name-directory
                                                    buffer-file-name))))
    (list "pyflakes" (list local-file))))

(eval-after-load "flymake"
  '(progn
     (require 'flymake-cursor)

     (add-to-list                       ; Make sure pyflakes is loaded
      'flymake-allowed-file-name-masks  ; for python files.
      '("\\.py\\'" oni:flymake-pyflakes-init))

     (add-to-list                       ; Error line repexp for go
      'flymake-err-line-patterns        ; compilation.
      '("^\\([a-zA-Z0-9_]+\\.go\\):\\([0-9]+\\):\\(.*\\)$"
        1 2 nil 3))

     (add-to-list                       ; Go uses makefiles, makes
      'flymake-allowed-file-name-masks  ; flymaking 'easy'.
      '("\\.go$" flymake-simple-make-init))))

(setq flymake-log-file-name (expand-file-name "~/.emacs.d/flymake.log")
      flymake-log-level 0
      flymake-gui-warnings-enabled nil)

(autoload 'gtags-mode "gtags" nil t)

(defun oni:gtags-create-or-update ()
  "Create or update the GNU Global tag file"
  (interactive)
  (if (not (= 0 (call-process "global" nil nil nil " -p")))
      (let ((olddir default-directory)
            (topdir (read-directory-name
                     "gtags: top of source tree:" default-directory)))
        (cd topdir)
        (shell-command "~/bin/create_gtags")
        (cd olddir))
    ;; Tagfile already exists; update it
    (shell-command "~/bin/update_gtags")))

(defun oni:gtags-for-php ()
  "Setup gtags for `php-mode'."
  (let* ((file-name (buffer-file-name))
         (fext (if (not (eq nil file-name))
                   (file-name-extension (buffer-file-name))
                 nil)))
    (if (equal fext "php")
        (progn
          (gtags-mode)
          (oni:gtags-create-or-update)))))

(defun oni:gtags-mode-func ()
  "Function for `gtags-mode-hook'."
  (local-set-key "\M-," 'gtags-find-tag)
  (local-set-key "\M-." 'gtags-find-rtag))

(add-hook 'gtags-mode-hook 'oni:gtags-mode-func)

(setq gtags-auto-update t)

(require 'newcomment)

(defun oni:kill-region-or-backward-char ()
  "Kill either the active region, or delete the character left of
  the cursor"
  (interactive)
  (if (region-active-p)
      (kill-region (region-beginning) (region-end))
    (backward-delete-char-untabify 1)))

(global-set-key "\C-w" 'oni:kill-region-or-backward-char)

(defun oni:kill-region-or-forward-char ()
  "Kill either the active region, or delete the character right
  of the cursor"
  (interactive)
  (if (region-active-p)
      (kill-region (region-beginning) (region-end))
    (delete-forward-char 1)))

(global-set-key "\C-d" 'oni:kill-region-or-forward-char)

(defun oni:kill-region-or-line ()
  "Kill either the active region, or the rest of the line,
  depending on whether or not `region-active-p' is t"
  (interactive)
  (if (region-active-p)
      (kill-region (region-beginning) (region-end))
    (kill-line)))

(global-set-key "\C-k" 'oni:kill-region-or-line)

(defun oni:move-beginning-of-dwim ()
  "Move to the beginning of line, either after the indentatoin of
  before."
  (interactive)
  (let ((start (point)))
    (back-to-indentation)
    (if (= start (point))
        (beginning-of-line))))

(global-set-key "\C-a" 'oni:move-beginning-of-dwim)

(defun oni:move-end-of-dwim ()
  "Move to the end of line, either before any comments or after
  them."
  (interactive)
  (let ((start (point))
        (eolpos (line-end-position)))
    (beginning-of-line)
    (if (and comment-start
             (comment-search-forward eolpos t))
        (progn
          (search-backward-regexp (concat "[^ \t" comment-start "]"))
          (forward-char)

          (when (or (bolp)
                    (= start (point)))
            (end-of-line)))
      (end-of-line))))

(global-set-key "\C-e" 'oni:move-end-of-dwim)

(defun oni:self-insert-dwim ()
  "Execute self insert, but when the region is active call self
  insert at the end of the region and at the beginning."
  (interactive)
  (if (region-active-p)
      (let ((electric-pair-mode nil)
            (beginning (region-beginning))
            (end (region-end)))
        (goto-char end)
        (self-insert-command 1)
        (save-excursion
          (goto-char beginning)
          (self-insert-command 1)))
    (self-insert-command 1)))

(global-set-key "'" 'oni:self-insert-dwim)
(global-set-key "\"" 'oni:self-insert-dwim)

(global-set-key [f7] 'magit-status)

(defun oni:magit-log-edit-mode-func ()
  "Function for `magit-log-edit-mode-hook'."
  (auto-fill-mode)
  (font-lock-add-keywords
   nil
   '(("\\`\\(.\\{,50\\}\\)\\(.*\\)\n?\\(.*\\)$"
      (1 'git-commit-summary-face)
      (2 'git-commit-overlong-summary-face)
      (3 'git-commit-nonempty-second-line-face))
     ("`\\([^']+\\)'" 1 font-lock-constant-face))
   t))

(add-hook 'magit-log-edit-mode-hook 'oni:magit-log-edit-mode-func)

(defun oni:markdown-mode-func ()
  "Function for `markdown-mode-hook'."
  (auto-fill-mode)
  (whitespace-mode))

(add-hook 'markdown-mode-hook 'oni:markdown-mode-func)

(add-to-list 'auto-mode-alist '("\\.m\\(ark\\)?do?wn$" . markdown-mode))

(setq whitespace-style '(face trailing))

(defun oni:message-mode-func ()
  "Function for `message-mode-hook'."
  (auto-fill-mode)
  (flyspell-mode)
  (ispell-change-dictionary (read-string "New dictionary: ")))

(setq message-send-mail-function 'message-send-mail-with-sendmail)

(add-hook 'message-mode-hook 'oni:message-mode-func)

(require 'w3m-load)

(require 'uniquify)

(setq uniquify-buffer-name-style 'post-forward)

(defun oni:raise-scratch (&optional mode)
  "Show the *scratch* buffer. If called with a universal
argument, ask the user which mode to use. If MODE is not nil,
open a new buffer with the name *MODE-scratch* and load MODE as
its major mode."
  (interactive (list (if current-prefix-arg
                         (read-string "Mode: ")
                       nil)))
  (let* ((bname (if mode
                    (concat "*" mode "-scratch*")
                  "*scratch*"))
         (buffer (get-buffer bname))
         (mode-sym (intern (concat mode "-mode"))))

    (unless buffer
      (setq buffer (generate-new-buffer bname))
      (with-current-buffer buffer
        (when (fboundp mode-sym)
          (funcall mode-sym))))

    (switch-to-buffer buffer)))

(setq initial-major-mode 'emacs-lisp-mode
      initial-scratch-message nil)

(global-set-key [XF86HomePage] 'oni:raise-scratch)

(defun oni:reload-buffer ()
  "Reload current buffer."
  (interactive)
  (revert-buffer nil t nil))

(global-set-key [f5] 'oni:reload-buffer)

(defun oni:term-mode-func ()
  "Function for `term-mode-hook'."
  (setq truncate-lines nil))

(add-hook 'term-mode-hook 'oni:term-mode-func)

(defun oni:texinfo-mode-func ()
  "Function for `texinfo-mode-hook'."
  (auto-fill-mode))

(add-hook 'texinfo-mode-hook 'oni:texinfo-mode-func)

(autoload 'xmodmap-mode "xmodmap-mode" nil t)
(add-to-list 'auto-mode-alist '("^\\.Xmodmap$" . xmodmap-mode))

(defun oni:indent-shift-left (start end &optional count)
  (interactive
   (if mark-active
       (list (region-beginning) (region-end) current-prefix-arg)
     (list (line-beginning-position)
           (line-end-position)
           current-prefix-arg)))
  (if count
      (setq count (prefix-numeric-value count))
    (setq count tab-width))
  (when (> count 0)
    (let ((deactivate-mark nil))
      (save-excursion
        (goto-char start)
        (while (< (point) end)
          (if (and (< (current-indentation) count)
                   (not (looking-at "[ \t]*$")))
              (error "Can't shift all lines enough"))
          (forward-line))
        (indent-rigidly start end (- count))))))

(add-to-list 'debug-ignored-errors "^Can't shift all lines enough")

(defun oni:indent-shift-right (start end &optional count)
  (interactive
   (if mark-active
       (list (region-beginning) (region-end) current-prefix-arg)
     (list (line-beginning-position)
           (line-end-position)
           current-prefix-arg)))
  (let ((deactivate-mark nil))
    (if count
        (setq count (prefix-numeric-value count))
      (setq count tab-width))
    (indent-rigidly start end count)))

(global-set-key (kbd "C-<") 'indent-shift-left)
(global-set-key (kbd "C->") 'indent-shift-right)

(autoload 'po-mode "po-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.po\\'\\|\\.po\\." . po-mode))

(autoload 'sawfish-mode "sawfish" nil t)

(add-to-list 'auto-mode-alist '("\\.jl$" . sawfish-mode))

(electric-indent-mode)
(electric-pair-mode)
(show-paren-mode)
(savehist-mode)

(blink-cursor-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)

(defun oni:write-file-func ()
  "Function for `write-file-hooks'."
  (time-stamp))

(add-hook 'write-file-hooks 'oni:write-file-func)

(setq time-stamp-active t)
(setq time-stamp-format "%04y-%02m-%02d %02H:%02M:%02S (%u)")

(ido-mode)

(setq ido-auto-merge-delay-time 1000000)

(setq ido-save-directory-list-file nil)

(eval-after-load "ido"
  '(setq ido-ignore-buffers `(,@ido-ignore-buffers
                              "^\\*.*\\*$" "^irc\\." "^\\#")))

(setq smex-save-file "~/.emacs.d/smex-items")

(smex-initialize)

(eval-after-load "smex"
  '(progn
     (global-set-key (kbd "M-x") 'smex)
     (global-set-key (kbd "C-M-x") 'smex-major-mode-commands)))

(require 'iso-transl)

(setq-default bidi-paragraph-direction 'left-to-right)

(setq-default gac-automatically-push-p t)

(setq-default indent-tabs-mode nil
              tab-width 4)

(setq-default require-final-newline t)

(setq-default truncate-lines t)

(add-to-list 'auto-mode-alist '("^PKGBUILD$" . shell-script-mode))

(setq auto-mode-case-fold nil)

(setq auto-save-file-name-transforms
      `((".*" ,temporary-file-directory t))

      backup-directory-alist
      `((".*" . ,temporary-file-directory)))

(setq browse-url-browser-function 'browse-url-generic
      browse-url-generic-program (getenv "BROWSER"))

(setq custom-file "~/.emacs.d/custom.el")

(setq custom-theme-directory "~/.emacs.d/themes")
(add-to-list 'custom-theme-load-path
             (concat custom-theme-directory "/naquadah-theme"))
(load-theme 'naquadah t)

(setq
 default-frame-alist
 `((border-width . 0)
   (internal-border-width . 0)
   (vertical-scroll-bars . nil)
   (menu-bar-lines . nil)
   (tool-bar-lines . nil)
   (font . "DejaVu Sans Mono:pixelsize=18")
   (left-fringe . 0)))

(setq frame-title-format '(:eval (concat "emacs: " (buffer-name))))

(setq help-at-pt-display-when-idle t)
(help-at-pt-set-timer)

(setq sauron-max-line-length 189)

(eval-after-load "sauron"
  '(setq sauron-modules (append '(sauron-identica sauron-jabber)
                                sauron-modules)))

(setq sauron-column-alist               ; I don't need as much
      '((timestamp . 6)                 ; information as the default.
        (message)))

(setq sauron-hide-mode-line t)
(setq sauron-timestamp-format "%H:%M")
(setq sauron-watch-nicks '("ryuslash"))
(setq sauron-watch-patterns '("ryuslash"))
(setq special-display-buffer-names '("*Sauron*"))
(setq special-display-frame-alist
      '((minibuffer . nil)
        (right-fringe . 0)))

(setq inhibit-default-init t)

(setq inhibit-local-menu-bar-menus t)

(setq inhibit-startup-message t)

(setq jit-lock-defer-time 0.2)

(setq message-log-max 1000)

(setq org-contacts-files '("~/documents/org/misc/contacts.org"))

(setq rainbow-delimiters-max-face-count 12)

(setq redisplay-dont-pause t)

(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'narrow-to-region 'disabled nil)

(global-set-key (kbd "C-@") 'er/expand-region)

(defface oni:mode-line-modified
  '((t (:inherit font-lock-warning-face)))
  "Face for the modified state in the mode-line"
  :group 'local)

(defface oni:mode-line-mode
  '((t (:inherit font-lock-string-face)))
  "Face for the major mode in the mode-line"
  :group 'local)

(defface oni:mode-line-buffer-position
  '((t (:inherit font-lock-constant-face)))
  "Face for the buffer position in the mode-line"
  :group 'local)

(defface oni:mode-line-buffer-line
  '((t (:inherit font-lock-type-face)))
  "Face for the line number in the mode-line"
  :group 'local)

(defface oni:mode-line-buffer-column
  '((t (:inherit font-lock-type-face)))
  "Face for the column number in the mode-line"
  :group 'local)

(defface oni:mode-line-buffer-state
  '((t (:inherit font-lock-preprocessor-face)))
  "Face for the state of the buffer in the mode-line"
  :group 'local)

(setq-default
 mode-line-format
 (list
  '(:eval (if (and (buffer-modified-p) (buffer-file-name))
              (propertize "!"
                          'face 'oni:mode-line-modified
                          'help-echo "Buffer has been modified")
            " "))

  '(:eval (propertize "%m"
                      'face 'oni:mode-line-mode
                      'help-echo buffer-file-coding-system))

  ": "

  '(:eval (propertize "%b "
                      'face 'mode-line-buffer-id
                      'help-echo (buffer-file-name)))

  "("
  (propertize "%p" 'face 'oni:mode-line-buffer-position) ":"
  (propertize "%04l" 'face 'oni:mode-line-buffer-line) ","
  (propertize "%02c" 'face 'oni:mode-line-buffer-column)
  ") "

  "["
  '(:eval (propertize
           (if buffer-read-only
               "R"
             (if overwrite-mode "O" "I"))
           'face 'oni:mode-line-buffer-state
           'help-echo (concat "Buffer is "
                              (if buffer-read-only
                                  "read-only"
                                (if overwrite-mode
                                    "in overwrite mode"
                                  "in insert mode")))))

  "] "

  '(:eval (propertize (format-time-string "%H:%M")
                      'help-echo
                      (concat (format-time-string "%c; ")
                              (emacs-uptime "Uptime: %hh"))))
  " --"
  '(:eval global-mode-string)))

(setq scroll-conservatively 101)

(setq use-dialog-box nil)

(setq user-full-name "Tom Willemsen")

(define-key key-translation-map (kbd "C-j") (kbd "C-l"))
(define-key key-translation-map (kbd "C-l") (kbd "C-j"))

(global-set-key "\C-x\C-b" 'electric-buffer-list)
(global-set-key "\C-\M-d" 'kill-word)
(global-set-key "\C-\M-w" 'backward-kill-word)
(global-set-key (kbd "C-S-k") 'kill-whole-line)
(global-set-key [XF86Mail] 'oni:view-mail)
(global-set-key "\C-cip" 'identica-update-status-interactive)

(when (or window-system (daemonp))
  (global-unset-key "\C-z"))

(load custom-file)
(load "rudel-loaddefs.el")
(load (expand-file-name "~/quicklisp/slime-helper.el"))

;; Local Variables:
;; no-update-autoloads: t
;; End: