forked from jeapostrophe/exp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.emacs.el
1424 lines (1198 loc) · 44.8 KB
/
.emacs.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;; Based a lot on https://github.com/avar/dotemacs/blob/726f0b6cd5badce641be6euf690ca82e9dbdcc605/.emacs
;;(add-to-list 'load-path "~/.emacs.d/")
(byte-recompile-directory "~/.emacs.d/")
(setq exec-path (append '("/usr/local/bin") exec-path))
(require 'package)
(setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
("melpa" . "http://melpa.milkbox.net/packages/")))
(package-initialize)
;; font & color
(set-face-attribute 'default nil
:font "Triplicate_T4c"
:height 120)
;; Theme
;; Don't change the font for some headings and titles
(setq solarized-use-variable-pitch nil)
;; Don't change size of org-mode headlines (but keep other size-changes)
(setq solarized-scale-org-headlines nil)
;; Avoid all font-size changes
(setq solarized-height-minus-1 1)
(setq solarized-height-plus-1 1)
(setq solarized-height-plus-2 1)
(setq solarized-height-plus-3 1)
(setq solarized-height-plus-4 1)
(load-theme 'solarized-light t)
;; ag
(setq ag-executable "/usr/local/bin/ag")
(setq ag-highlight-search nil)
(defalias 'agp 'ag-project)
(defalias 'mg 'magit-status)
(defalias 'isb 'ispell-buffer)
(defalias 'isw 'ispell-word)
;;;; Do we have X? This is false under Debian's emacs-nox package
;;;; where many features are compiled out
(defvar emacs-has-x
(fboundp 'tool-bar-mode))
;;;; Emacs' interface
(setq ns-pop-up-frames t)
(setq confirm-kill-emacs 'yes-or-no-p)
(setq initial-buffer-choice "~/.emacs.el")
;; Don't get weird properties when pasting
(setq yank-excluded-properties t)
;; Kill menu, tool and scrollbars with fire!
(when t
(tool-bar-mode -1)
(menu-bar-mode -1)
(when (fboundp 'scroll-bar-mode)
(scroll-bar-mode -1)))
;; Bell
(setq ring-bell-function 'ignore)
(setq visible-bell t)
;; Don't ever use graphic dialog boxes
(setq use-dialog-box nil)
;; Don't open new annoying windows under X, use the echo area
(when (fboundp 'tooltip-mode)
(tooltip-mode -1))
;; Don't display the 'Welcome to GNU Emacs' buffer on startup
(setq inhibit-startup-message t)
;; Display this instead of "For information about GNU Emacs and the
;; GNU system, type C-h C-a.". This has been made intentionally hard
;; to customize in GNU Emacs so I have to resort to hackery.
(defun display-startup-echo-area-message ()
(message ""))
;; Don't insert instructions in the *scratch* buffer
(setq initial-scratch-message nil)
;; Display the line and column number in the modeline
(setq line-number-mode t)
(setq column-number-mode t)
(line-number-mode t)
(column-number-mode t)
;; syntax highlight everywhere
(global-font-lock-mode t)
;; Show matching parens
(show-paren-mode t)
(setq show-paren-style 'expression)
(setq show-paren-delay 0.0)
;; Show matching paren, even if off-screen
(defadvice show-paren-function
(after show-matching-paren-offscreen activate)
"If the matching paren is offscreen, show the matching line in the
echo area. Has no effect if the character before point is not of
the syntax class ')'."
(interactive)
(if (not (minibuffer-prompt))
(let ((matching-text nil))
;; Only call `blink-matching-open' if the character before point
;; is a close parentheses type character. Otherwise, there's not
;; really any point, and `blink-matching-open' would just echo
;; "Mismatched parentheses", which gets really annoying.
(if (and (point)
(char-before (point))
(char-syntax (char-before (point)))
(char-equal (char-syntax (char-before (point))) ?\)))
(setq matching-text (blink-matching-open)))
(if (not (null matching-text))
(message matching-text)))))
(set-face-background 'show-paren-match-face "lavender")
;; Highlight selection
(transient-mark-mode t)
;; make all "yes or no" prompts show "y or n" instead
(fset 'yes-or-no-p 'y-or-n-p)
;; Switching
(iswitchb-mode 1)
(icomplete-mode 1)
;; Smash the training wheels
(put 'narrow-to-region 'disabled nil)
(put 'not-modified 'disabled t)
(put 'upcase-region 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'erase-buffer 'disabled nil)
(put 'dired-find-alternate-file 'disabled nil)
;; I use version control, don't annoy me with backup files everywhere
(setq make-backup-files nil)
(setq auto-save-default nil)
;; Make C-h a act as C-u C-h a
(setq apropos-do-all t)
;; For C-u C-x v d. Probably a good idea for everything else too
(setq completion-ignore-case t)
;; Ask me whether to add a final newline to files which don't have one
(setq require-final-newline t)
;;;; User info
(setq user-full-name "Jay McCarthy")
(setq user-mail-address "jay.mccarthy@gmail.com")
;;; Used in ChangeLog entries
(setq add-log-mailing-address user-mail-address)
;;;; Encoding
;; I use UTF-8 for everything on my systems, some of the below might
;; be redundant.
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(setq file-name-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
;;;; Indenting
;; Use spaces, not tabs
(setq indent-tabs-mode nil)
(setq-default indent-tabs-mode nil)
;; Use 4 spaces
(setq default-tab-width 4)
(setq tab-width 4)
(setq backward-delete-char-untabify nil)
;;;; Mode settings
;;;;; compiling
(setq compilation-scroll-output 'first-error)
(setq comint-prompt-read-only t)
;; ANSI colors in command interaction and compile:
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region compilation-filter-start (point))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
;; Found these in one place
;; (setq ansi-color-names-vector
;; ["black" "#dc322f" "#859900" "#b58900"
;; "#268bd2" "#d33682" "#2aa198" "white"])
;; (ansi-color-map-update 'ansi-color-names-vector ansi-color-names-vector)
;; http://emacsworld.blogspot.com/2009/02/setting-term-mode-colours.html
;; (setq ansi-term-color-vector
;; [unspecified "#000000" "#963F3C" "#859900" "#b58900"
;; "#0082FF" "#FF2180" "#57DCDB" "#FFFFFF"])
;;;;; conf-mode
(add-to-list 'auto-mode-alist '("\\.gitconfig$" . conf-mode))
;;;;; simple.el
(defadvice kill-ring-save (before slickcopy activate compile)
"When called interactively with no active region, copy
a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
(defadvice kill-region (before slickcut activate compile)
"When called interactively with no active region, kill
a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
;;;;; Comint
(setq comint-buffer-maximum-size (expt 2 16))
;;;;; Dired
(setq ls-lisp-format-time-list '("%Y.%m.$d %H:%M:%S" "%Y.%m.$d %H:%M:%S")
ls-lisp-use-localized-time-format t)
(add-hook 'dired-mode-hook
'(lambda ()
;; Only open one dired buffer at most
(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file)
;; Edit files in dired with "e", which previously did what "RET" did
(define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)))
(setq dired-listing-switches "-alho")
(setq dired-use-ls-dired nil)
;; xxx change dired-find-alternate-file
;;;;; emacs-lisp-mode
(add-hook 'emacs-lisp-mode-hook 'eldoc-mode t)
;;;;; eshell-mode
;; Don't display the "Welcome to the Emacs shell" banner
(defun eshell-banner-message "")
;;;;; gdb
;; Turn off the new emacs 22 UI
(setq gdb-many-windows nil)
;;;;; Info-mode
;; scroll to subnodes by default
(setq Info-scroll-prefer-subnodes t)
;;;;; progmodes
;; Settings for progmodes (cperl, c-mode etc.)
(dolist (mode '(c-mode
java-mode
html-mode-hook
css-mode-hook
emacs-lisp-mode))
(font-lock-add-keywords mode
'(("\\(XXX\\|FIXME\\|TODO\\)"
1 font-lock-warning-face prepend))))
;;;;; shell-mode
(add-hook
'shell-mode-hook
'ansi-color-for-comint-mode-on)
;;;;; Tramp
(require 'tramp)
(setq tramp-default-method "ssh")
;;;;; vc
;; This could be made portable but I'm not interested in that at the
;; moment so it's git-only.
(defun vc-push-or-pull ()
"`vc-push' if given an argument, otherwise `vc-pull'"
(interactive)
(if current-prefix-arg
(vc-push)
(vc-pull)))
(defun vc-push ()
"Run git-push on the current repository, does a dry-run unless
given a prefix arg."
(interactive)
(shell-command "git push"))
(defun vc-pull ()
"Run git-pull on the current repository."
(interactive)
(shell-command "git up"))
;;;;; woman
;; Use woman instead of man
(defalias 'man 'woman)
;;;; Packages
;;;;; start server for emacsclient
(setq server-use-tcp t)
(setq server-host "localhost")
(setq server-name "lightning")
;;(defadvice make-network-process (before force-tcp-server-ipv4 activate)
;; "Monkey patch the server to force the port"
;; (if (string= "lightning" (plist-get (ad-get-args 0) :name))
;; (ad-set-args 0 (plist-put (ad-get-args 0) :service 50000))))
(server-start)
;;(require 'edit-server)
;;(edit-server-start)
;;;;; line numbering
;;(global-linum-mode 1)
;;(setq linum-disabled-modes-list '(eshell-mode term-mode compilation-mode org-mode))
;;(defun linum-on ()
;; (unless (or (minibufferp) (member major-mode linum-disabled-modes-list))
;; (linum-mode 1)))
;;;;; auto-fill
(add-hook 'text-mode-hook 'turn-on-auto-fill)
;;;; multi-term ()
;; (require 'multi-term)
;; (setq multi-term-program "/usr/bin/zsh")
;;;;; racket-mode
;;(require 'racket-mode)
(add-to-list 'auto-mode-alist '("\\.dc$" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.rkt$" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.rktl$" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.scrbl$" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.rktd$" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.ss$" . racket-mode))
(add-to-list 'auto-mode-alist '("\\.scm$" . racket-mode))
;;;; Platform specific settings
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "open")
;;;; global-set-key
(global-set-key (kbd "s-S-t") 'eval-region)
(global-set-key (kbd "s-a") 'mark-whole-buffer)
;;(global-set-key (kbd "s-q") 'kill-emacs)
(global-set-key (kbd "s-c") 'clipboard-kill-ring-save)
(global-set-key (kbd "s-x") 'clipboard-kill-region)
(global-set-key (kbd "s-v") 'clipboard-yank)
(global-set-key (kbd "s-n") 'new-frame)
(global-set-key (kbd "s-s") 'save-buffer)
(global-set-key (kbd "s-f") 'isearch-forward)
(global-set-key (kbd "s-g") 'isearch-repeat-forward)
(global-set-key (kbd "s-'") 'next-buffer)
(global-set-key (kbd "s-;") 'previous-buffer)
(defun je/delete-window ()
"Remove window or frame"
(interactive)
(save-current-buffer
(if (one-window-p 1)
(delete-frame)
(delete-window))))
(global-set-key (kbd "s-w") 'je/delete-window)
(global-set-key (kbd "M-w") 'delete-other-windows)
;; Replace the standard way of looking through buffers
(progn
(global-set-key (kbd "C-x C-b") 'ibuffer))
(define-key global-map (kbd "C-`") 'ibuffer)
(define-key global-map (kbd "C-b") 'ibuffer)
(define-key global-map (kbd "M-`") 'iswitchb-buffer)
(define-key global-map (kbd "M-<tab>") 'other-window)
;; ibuffer
(require 'ibuffer)
(setq ibuffer-use-header-line nil)
(setq directory-abbrev-alist
'())
(defun je/abbreviate-file-name (name)
(let ((directory-abbrev-alist
'(("^/home/jay" . "~")
("^/Users/jay" . "~")
("^~/Dev/scm" . "~scm")
("^~/Dev/dist" . "~dist")
("^~dist/sf" . "~sf")
("^~sf/full" . "~sff")
("^~scm/plt" . "~plt")
("^~plt/collects" . "~collects")
("^~collects/web-server" . "~ws")
("^~scm/github.jeapostrophe" . "~github")
("^~github/exp" . "~exp")
("^~github/work" . "~work")
("^~work/papers" . "~papers")
("^~work/courses" . "~courses")
("^~github/home" . "~home")
("^~home/etc" . "~etc")
("^~home/finance" . "~fin")
("^~home/journal" . "~j")
("^~github/get-bonus" . "~gb")
("^~scm/blogs" . "~blogs")
("^~blogs/jeapostrophe.github.com/source/downloads/code" . "~je-blog"))))
(abbreviate-file-name name)))
(setq frame-title-format
'(:eval (if (buffer-file-name)
(je/abbreviate-file-name (buffer-file-name))
"%b")))
(define-ibuffer-column je/name ()
(cond
((buffer-file-name buffer)
(je/abbreviate-file-name (buffer-file-name buffer)))
(t
(buffer-name buffer))))
(setq ibuffer-formats
'((mark modified " "
(je/name 65 65 :left :elide)
" "
(mode 16 16 :left :elide))))
(defun ibuffer-previous-line ()
(interactive) (previous-line)
(if (<= (line-number-at-pos) 3)
(goto-line (count-lines (point-min) (point-max)))))
(defun ibuffer-next-line ()
(interactive) (next-line)
(if (> (line-number-at-pos) (count-lines (point-min) (point-max)))
(goto-line 4)))
(define-key ibuffer-mode-map (kbd "<up>") 'ibuffer-previous-line)
(define-key ibuffer-mode-map (kbd "<down>") 'ibuffer-next-line)
;; Switching to ibuffer puts the cursor on the most recent buffer
(defadvice ibuffer (around ibuffer-point-to-most-recent) ()
"Open ibuffer with cursor pointed to most recent buffer name"
(let ((recent-buffer-name (buffer-name)))
ad-do-it
(ibuffer-jump-to-buffer recent-buffer-name)))
(ad-activate 'ibuffer)
;; Setup some font size changers
(define-key global-map (kbd "C-=") 'text-scale-increase)
(define-key global-map (kbd "C--") 'text-scale-decrease)
;; DrRacket-like compiler
(defcustom je/racket-test-p t
"Whether rkt or rk is run"
:type 'boolean)
(defun run-current-file (writep)
"Execute or compile the current file."
(interactive)
(let (suffixMap fname suffix progName cmdStr)
;; a keyed list of file suffix to comand-line program path/name
(setq suffixMap
`(("java" . "javai")
("ll" . "llvmi")
("c" . "cci")
("sh" . "zsh")
("py" . "python")
("cc" . "ccci")
("glsl" . "glslangValidator")
("rkt" . ,(if je/racket-test-p "rkt" "rk"))
("dc" . ,(if je/racket-test-p "rkt" "rk"))
("scrbl" . ,(if je/racket-test-p "rkt" "rk"))
("txt" . "ctxt")
("dot" . "dot -Tpdf -O")
("tex" . "pdflatex")))
(save-buffer)
(setq fname (buffer-file-name))
(setq suffix (file-name-extension fname))
(setq progName (cdr (assoc suffix suffixMap)))
(setq cmdStr (concat "-i -c \'" progName " \"" fname "\"\'"))
(if (string-equal suffix "el") ; special case for emacs lisp
(load-file fname)
(if (and t (file-exists-p (concat default-directory "/Makefile")))
(compile (concat "zsh -i -c 'cd \"" default-directory "\" && make'"))
(if progName
(progn
(if (not writep)
(compile (concat "zsh " cmdStr))
(let ((multi-term-program-switches
(list "-i" "-c" (concat progName " \"" fname "\""))))
(multi-term-dedicated-open))))
(progn
(message "No recognized program file suffix for this file.")))))))
(defun run-current-file-ro ()
"Execute or compile the current file."
(interactive)
(run-current-file nil))
(defun run-current-file-wr ()
"Execute or compile the current file."
(interactive)
(run-current-file t))
(global-set-key (kbd "C-t") 'run-current-file-ro)
(global-set-key (kbd "C-M-t") 'run-current-file-wr)
;; A few editing things
(progn
(global-set-key (kbd "C-c C-i") 'indent-region)
(global-set-key (kbd "C-c C-c") 'comment-region)
(global-set-key (kbd "C-c C-v") 'uncomment-region)
(global-set-key (kbd "C-c q") 'query-replace)
(global-set-key (kbd "C-c Q") 'query-replace-regexp)
(global-set-key (kbd "C-c o") 'occur)
(global-set-key (kbd "C-c d") 'cd)
(global-set-key (kbd "C-c f") 'find-dired)
(global-set-key (kbd "C-c g") 'grep))
(defun my-indent-buffer ()
"Indent the buffer"
(interactive)
(save-excursion
(delete-trailing-whitespace)
(indent-region (point-min) (point-max) nil)
(untabify (point-min) (point-max))))
(global-set-key (kbd "s-i") 'my-indent-buffer)
(progn
(global-set-key (kbd "C-h F") 'find-function-at-point))
;; vc.el - add commands to push and pull with git
(progn
(define-key vc-prefix-map "p" 'vc-push-or-pull))
;; turn off the ability to kill
(defun custom-cxcc ()
"Kill the buffer and the frame"
(interactive)
(progn
(kill-buffer)
(delete-frame)))
(global-set-key (kbd "C-x C-c") 'custom-cxcc)
(global-set-key (kbd "s-r") 'revert-buffer)
(global-set-key (kbd "M-r") 'replace-string)
(global-set-key (kbd "<C-up>") 'beginning-of-buffer)
(global-set-key (kbd "<C-down>") 'end-of-buffer)
(global-set-key (kbd "<C-left>") 'move-beginning-of-line)
(global-set-key (kbd "<C-right>") 'move-end-of-line)
(global-set-key (kbd "<M-left>") 'backward-sexp)
(global-set-key (kbd "<M-right>") 'forward-sexp)
;; For grading
(defun custom-sl ()
"Submit grade"
(interactive)
(progn
(save-buffer)
(server-edit)))
(global-set-key (kbd "s-l") 'custom-sl)
(normal-erase-is-backspace-mode 1)
;; Auto saving
(defun je/save-all ()
"Save all buffers"
(interactive)
(desktop-save-in-desktop-dir)
(save-some-buffers t))
(defvar je/save-timer (run-with-idle-timer 30 t 'je/save-all))
(global-set-key (kbd "s-S") 'je/save-all)
;; Org Mode
(setq load-path (cons "~/Dev/local/org-mode/lisp" load-path))
(setq load-path (cons "~/Dev/local/org-mode/contrib/lisp" load-path))
(add-to-list 'Info-default-directory-list
(expand-file-name "~/Dev/local/org-mode/doc"))
(require 'org)
(require 'org-faces)
(require 'org-protocol)
(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
(setq org-directory "~/Dev/scm/github.jeapostrophe/home/etc/")
(setq org-bookmarks-file "~/Dev/scm/github.jeapostrophe/home/etc/bookmarks.org")
(setq org-default-notes-file "~/Dev/scm/github.jeapostrophe/home/etc/brain.org")
(setq org-agenda-files (list org-directory))
(defun je/org-open-bookmarks ()
"Open bookmark file"
(interactive)
(find-file org-bookmarks-file))
(defun je/org-archive-all ()
"Archive everything that is done"
(interactive)
(org-map-entries 'org-archive-subtree "/DONE" 'file))
(defun je/clear-state-changes ()
"Clear state changes"
(interactive)
(let ((regexp "- State \"DONE\""))
(let ((buffer-file-name nil)) ;; HACK for `clone-buffer'
(with-current-buffer (clone-buffer nil nil)
(let ((inhibit-read-only t))
(keep-lines regexp)
(kill-region (line-beginning-position)
(point-max)))
(kill-buffer)))
(unless (and buffer-read-only kill-read-only-ok)
;; Delete lines or make the "Buffer is read-only" error.
(flush-lines regexp))))
(global-set-key (kbd "s-t")
(lambda ()
(interactive)
(if (eq major-mode 'org-mode)
(org-todo)
(progn
(org-agenda-todo)
;; XXX I added this because sometimes it would
;; check the same one twice, but this feels slow
;; and hacky
(je/todo-list)))))
(org-defkey org-mode-map [(meta tab)] nil)
(org-defkey org-mode-map (kbd "s-[") 'org-metaleft)
(org-defkey org-mode-map (kbd "s-]") 'org-metaright)
(org-defkey org-mode-map (kbd "s-{") 'org-shiftleft)
(org-defkey org-mode-map (kbd "s-}") 'org-shiftright)
(defun je/org-meta-return ()
(interactive)
(newline)
(org-meta-return))
(org-defkey org-mode-map [(meta return)] 'je/org-meta-return)
(setq org-M-RET-may-split-line '((default . t)))
(org-defkey org-mode-map [(meta left)] nil)
(org-defkey org-mode-map [(meta right)] nil)
(org-defkey org-mode-map [(shift meta left)] nil)
(org-defkey org-mode-map [(shift meta right)] nil)
(org-defkey org-mode-map [(shift up)] nil)
(org-defkey org-mode-map [(shift down)] nil)
(org-defkey org-mode-map [(shift left)] nil)
(org-defkey org-mode-map [(shift right)] nil)
(org-defkey org-mode-map [(control shift up)] nil)
(org-defkey org-mode-map [(control shift down)] nil)
(org-defkey org-mode-map [(control shift left)] nil)
(org-defkey org-mode-map [(control shift right)] nil)
(setq org-hide-leading-stars t)
(setq org-return-follows-link t)
(setq org-completion-use-ido t)
(setq org-log-done t)
(setq org-clock-modeline-total 'current)
(setq org-support-shift-select t)
(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-start-on-weekday nil)
(setq org-agenda-include-diary nil)
(setq org-agenda-remove-tags t)
(setq org-agenda-restore-windows-after-quit t)
(setq org-enforce-todo-dependencies t)
(setq org-agenda-dim-blocked-tasks t)
(setq org-agenda-repeating-timestamp-show-all t)
(setq org-agenda-show-all-dates t)
(setq org-timeline-show-empty-dates nil)
(setq org-ctrl-k-protect-subtree t)
(setq org-use-property-inheritance nil)
(setq org-agenda-todo-keyword-format "")
(setq org-agenda-prefix-format
'((agenda . " %i %-12:c%?-12t% s")
(timeline . " % s")
(todo . "%-12:c")
(tags . " %i %-12:c")
(search . " %i %-12:c")))
(setq org-prefix-format-compiled nil)
(setq org-agenda-use-tag-inheritance nil)
(setq org-agenda-dim-blocked-tasks nil)
(setq org-agenda-ignore-drawer-properties '(effort appt category))
(setq org-todo-keywords
'((sequence "TODO" "DONE")))
(setq org-time-clocksum-format
'(:hours "%d" :require-hours t :minutes ":%02d" :require-minutes t))
(setq org-refile-use-outline-path t)
(setq org-outline-path-complete-in-steps t)
(setq org-refile-targets `((nil . (:maxlevel . 20))))
;; This ensures that headings are not refile targets if they do not
;; already have children.
(defun je/has-children ()
(save-excursion
(let ((this-level (funcall outline-level)))
(outline-next-heading)
(let ((child-level (funcall outline-level)))
(> child-level this-level)))))
(setq org-refile-target-verify-function 'je/has-children)
(setq org-agenda-todo-ignore-scheduled 'future)
;; Doesn't have an effect in todo mode
;;(setq org-agenda-ndays 365)
;; XXX Make some more for getting %x, %a, and %i
(setq org-capture-templates
'(("t" "Todo" entry (file+headline org-default-notes-file "Tasks")
"* TODO %?\n SCHEDULED: %T\tDEADLINE: %T\n%a")
("u" "URL" entry (file+headline org-default-notes-file "Tasks")
"* TODO %?\n SCHEDULED: %T\tDEADLINE: %T\n %a\n %i")
("b" "Bookmark" entry (file+headline org-bookmarks-file "To Parse")
"* %a\n %i"
:immediate-finish t)))
(global-set-key
(kbd "<s-f1>")
(lambda () (interactive) (org-capture nil "t")))
(global-set-key
(kbd "<s-XF86MonBrightnessDown>")
(lambda () (interactive) (org-capture nil "t")))
(global-set-key
(kbd "<f1>")
(lambda () (interactive) (org-capture nil "t")))
(setq org-agenda-before-sorting-filter-function nil)
(setq org-agenda-before-sorting-filter-function 'je/todo-color)
(setq org-agenda-cmp-user-defined 'je/agenda-sort)
(setq org-agenda-sorting-strategy '(user-defined-up))
(setq org-agenda-overriding-columns-format "%56ITEM %DEADLINE")
(setq org-agenda-overriding-header "")
(setq org-agenda-custom-commands
'(("t" "Todo list" todo "TODO"
())))
(defun je/org-finalize-agenda-hook ()
(goto-char (point-min))
(mapcar (lambda (n) (insert n " ")) je/org-agenda/filter-ctxt)
;; xxx strike through
(mapcar (lambda (n) (insert "!" n " ")) je/org-agenda/filter-ctxt-not)
(center-line)
(remove-text-properties
(point-min) (point-max) '(mouse-face t)))
(add-hook 'org-finalize-agenda-hook
'je/org-finalize-agenda-hook)
;;; These are the default colours from OmniFocus
(defface je/due
(org-compatible-face 'default
'((t (:foreground "#000000"))))
"Face for due items"
:group 'org-faces)
(set-face-foreground 'je/due "#dc322f")
(defface je/today
(org-compatible-face 'default
'((t (:foreground "#000000"))))
"Face for today items"
:group 'org-faces)
(set-face-foreground 'je/today "#cb4b16")
(defface je/soon
(org-compatible-face 'default
'((t (:foreground "#000000"))))
"Face for soon items"
:group 'org-faces)
(set-face-foreground 'je/soon "#859900")
(defface je/near
(org-compatible-face 'default
'((t (:foreground "#000000"))))
"Face for near items"
:group 'org-faces)
(set-face-foreground 'je/near "#6c71c4")
(defface je/normal
(org-compatible-face 'default
'((t (:foreground "#000000"))))
"Face for normal items"
:group 'org-faces)
(set-face-foreground 'je/normal "#657b83")
(defface je/distant
(org-compatible-face 'default
'((t (:foreground "#000000"))))
"Face for distant items"
:group 'org-faces)
(set-face-foreground 'je/distant "#93a1a1")
(defvar je/left-col 0)
(setq je/left-col 60)
(defun je/columate (a d)
(if (> (length a) je/left-col)
(setq a (concat (substring a 0 je/left-col) "...")))
(setq d (replace-regexp-in-string "^<" "" d))
(setq d (replace-regexp-in-string ">$" "" d))
(setq d (concat d (make-string (- 26 (length d)) ? )))
(let ((pad (make-string (- 90 (length a) (length d)) ? )))
(concat a pad d)))
(defvar je-schedule-flag? t)
(setq je-schedule-flag? t)
(defun je/todo-color (a)
"Color things in the column view differently based on deadline"
(let* ((ma (or (get-text-property 1 'org-marker a)
(get-text-property 1 'org-hd-marker a)))
(tn (org-float-time (org-current-time)))
(sa (org-entry-get ma "SCHEDULED"))
(da (org-entry-get ma "DEADLINE"))
(ta (if da (org-time-string-to-seconds da) 1.0e+INF))
(a-day (if da (time-to-days (seconds-to-time ta)) 0))
(sta (if sa (org-time-string-to-seconds sa) 0)))
;; Remove the leading *s
(setq a (replace-regexp-in-string "^[^ ]*: *" "" a))
(if da
(setq a (je/columate a da)))
;; Remove the old face
(remove-text-properties
0 (length a) '((face nil) (fontified nil)) a)
;; Put on the new face
(put-text-property
0 (length a)
'face
(cond
((< ta tn)
;; The deadline has passed
'je/due)
((= a-day (org-today))
;; The deadline is today
'je/today)
((< ta (+ tn (* 60 60 24)))
;; The deadline is in the next day
'je/soon)
((< ta (+ tn (* 60 60 24 7)))
;; The deadline is in the next week
'je/near)
((< ta (+ tn (* 60 60 24 7 4 )))
;; The deadline is in the next four weeks
'je/normal)
(t
'je/distant))
a)
;; Lame to implement filtering here
(if (or
;; If we care about the schedule, and this is after now, then
;; drop it.
(and je-schedule-flag? (< tn sta))
(let* ((tag-str (or (org-entry-get ma "TAGS") ""))
(tags (org-split-string tag-str ":")))
;; If there are tags, implement filtering
(and tags
(or
;; If all its tags are not what we care about
(and je/org-agenda/filter-ctxt
(je/andmap
(lambda (f)
(not (member/eq f tags)))
je/org-agenda/filter-ctxt))
;; OR
;; If any of its tags are what we want to ignore
(je/ormap
(lambda (f)
(member/eq f tags))
je/org-agenda/filter-ctxt-not)))))
nil
a)))
(defun je/andmap (f l)
(cond
(l
(and (funcall f (car l))
(je/andmap f (cdr l))))
(t t)))
(defun je/ormap (f l)
(cond
(l
(or (funcall f (car l))
(je/ormap f (cdr l))))
(t nil)))
(defun member/eq (o l)
(or (equal o l)
(member o l)))
(defun je/todo-list ()
"Open up the org-mode todo list"
(interactive)
(org-agenda "" "t"))
(setq org-agenda-columns-show-summaries nil)
(setq org-agenda-columns-compute-summary-properties nil)
(defun je/column-display (ctitle value)
(cond
((equal ctitle "ITEM")
(replace-regexp-in-string "^\** " "" value))
(t
value)))
(setq org-columns-modify-value-for-display-function 'je/column-display)
(defvar je/org-agenda/filter-ctxt nil)
(defvar je/org-agenda/filter-ctxt-not nil)
(defun je/todo-list/all ()
"Open up the org-mode todo list (all)"
(interactive)
(progn
(setq je/org-agenda/filter-ctxt nil
je/org-agenda/filter-ctxt-not nil)
(je/todo-list)))
(global-set-key (kbd "s-o") 'je/todo-list/all)
(defun je/org-agenda/filter-ctxt-toggle (n)
(cond
((member n je/org-agenda/filter-ctxt)
(setq je/org-agenda/filter-ctxt
(je/filter-out je/org-agenda/filter-ctxt n))
(add-to-list 'je/org-agenda/filter-ctxt-not n))
((member n je/org-agenda/filter-ctxt-not)
(setq je/org-agenda/filter-ctxt-not
(je/filter-out je/org-agenda/filter-ctxt-not n)))
(t
(add-to-list 'je/org-agenda/filter-ctxt n))))
(defun je/org-filter (n)
"Change filter"
(interactive "sFilter: ")
(progn (je/org-agenda/filter-ctxt-toggle n)
(je/todo-list)))
(defun je/filter-out (l o)
(cond
(l
(cond
((equal (car l) o)
(je/filter-out (cdr l) o))
(t
(cons (car l) (je/filter-out (cdr l) o)))))
(t l)))
(defun je/todo-list/work ()
"Open up the org-mode todo list (work)"
(interactive)
(progn
(je/org-agenda/filter-ctxt-toggle "Work")
(je/todo-list)))
(global-set-key (kbd "s-O") 'je/todo-list/work)
(defun je/todo-list/home ()
"Open up the org-mode todo list (home)"
(interactive)
(progn
(je/org-agenda/filter-ctxt-toggle "Home")
(je/todo-list)))
(global-set-key (kbd "s-h") 'je/todo-list/home)
(defun je/org/toggle-internet ()
"toggle internet status in org"