-
Notifications
You must be signed in to change notification settings - Fork 0
/
.emacs
1660 lines (1496 loc) · 58.3 KB
/
.emacs
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
(require 'cl) ;; (loop for ...)
;;(setq debug-on-error t)
;; _____________________________________________________________________
;; custom path
(setq my-home (expand-file-name (concat "~" (or (getenv "SUDO_USER") (getenv "USER")))))
(setq my-name "Sébastien Delafond")
(setq my-emacsd (concat my-home "/.emacs.d/"))
(loop for file in (directory-files my-emacsd t ".*.el$")
do (load-file file))
(setq auto-save-list-file-prefix my-emacsd)
(setq user-emacs-directory my-emacsd)
(setq load-path (cons (concat my-emacsd "/lisp") load-path))
(setq load-path (cons "/usr/share/org-mode/lisp" load-path))
;; _____________________________________________________________________
;; macros
(defmacro make-interactive-fun (fn args)
`(lambda () (interactive) (funcall ,fn ,args)))
(defmacro make-fun (fn args)
`(lambda () (funcall ,fn ,args)))
(defmacro bol-with-prefix (function)
"Define a new function which calls FUNCTION.
Except it moves to beginning of line before calling FUNCTION when
called with a prefix argument. The FUNCTION still receives the
prefix argument."
(let ((name (intern (format "endless/%s-BOL" function))))
`(progn
(defun ,name (p)
,(format
"Call `%s', but move to BOL when called with a prefix argument."
function)
(interactive "P")
(when p
(forward-line 0))
(call-interactively ',function))
',name)))
;; _____________________________________________________________________
;; functions
(defun volatile-kill-buffer ()
"Kill current buffer unconditionally."
(interactive)
(let ((buffer-modified-p nil))
(kill-buffer (current-buffer))))
(global-set-key (kbd "C-x k") 'volatile-kill-buffer)
(defun save-current-kbd-macro-to-dot-emacs (name)
"Save the current macro as named function definition inside your
initialization file so you can reuse it anytime in the future."
(interactive "SSave Macro as: ")
(name-last-kbd-macro name)
(save-excursion
(find-file-literally user-init-file)
(goto-char (point-max))
(insert "\n\n;; Saved macro\n")
(insert-kbd-macro name)
(insert "\n")))
(defun file-change-too-close-for-comfort ()
(let* ((file-time-raw (nth 5 (file-attributes (buffer-file-name))))
(file-time (+ (lsh (nth 0 file-time-raw) 16) (nth 1 file-time-raw)))
(current-time (+ (lsh (nth 0 (current-time)) 16) (nth 1 (current-time)))))
(and (eq current-time file-time)
(message "%s: postpone revert" (buffer-name))
t)))
(defun my-auto-revert-handler ()
"Revert current buffer, if appropriate.
This is an internal function used by Auto-Revert Mode. We rewrite it so it
postpones an auto-revert if the last mod time of the file is the same as
the current system time. It’ll pick it up the next auto-revert iteration,
which appears to be to be every 2 seconds by default.
From http://printfdebugger.tumblr.com/post/25085225264/unfortunate-emacs-auto-revert-mode-and-git-pull"
(when (or auto-revert-tail-mode (not (buffer-modified-p)))
(let* ((buffer (current-buffer)) size
(revert
(or (and buffer-file-name
(file-readable-p buffer-file-name)
(if auto-revert-tail-mode
;; Tramp caches the file attributes. Setting
;; `tramp-cache-inhibit' forces Tramp to
;; reread the values.
(let ((tramp-cache-inhibit-cache t))
(/= auto-revert-tail-pos
(setq size
(nth 7 (file-attributes
buffer-file-name)))))
(and (not (file-remote-p buffer-file-name))
(not (verify-visited-file-modtime buffer))
(not (file-change-too-close-for-comfort)))))
(and (or auto-revert-mode
global-auto-revert-non-file-buffers)
revert-buffer-function
(boundp 'buffer-stale-function)
(functionp buffer-stale-function)
(funcall buffer-stale-function t))))
eob eoblist)
(when revert
(when (and auto-revert-verbose
(not (eq revert 'fast)))
(message "Reverting buffer `%s'." (buffer-name)))
;; If point (or a window point) is at the end of the buffer,
;; we want to keep it at the end after reverting. This allows
;; to tail a file.
(when buffer-file-name
(setq eob (eobp))
(walk-windows
#'(lambda (window)
(and (eq (window-buffer window) buffer)
(= (window-point window) (point-max))
(push window eoblist)))
'no-mini t))
(if auto-revert-tail-mode
(auto-revert-tail-handler size)
;; Bind buffer-read-only in case user has done C-x C-q,
;; so as not to forget that. This gives undesirable results
;; when the file's mode changes, but that is less common.
(let ((buffer-read-only buffer-read-only))
(revert-buffer 'ignore-auto 'dont-ask 'preserve-modes)))
(when buffer-file-name
(when eob (goto-char (point-max)))
(dolist (window eoblist)
(set-window-point window (point-max)))))
;; `preserve-modes' avoids changing the (minor) modes. But we
;; do want to reset the mode for VC, so we do it manually.
(when (or revert auto-revert-check-vc-info)
(vc-find-file-hook)))))
(defun format-email-body ()
"Format email body, respecting (or at least trying to) quote levels."
(interactive)
(save-excursion
(let ((re1 "^\\(> \\)+\\w")
(re2 "^\\(> *\\)*$"))
(goto-char (point-min))
(while (<= (point) (point-max))
(progn
(search-forward-regexp re1 nil t)
(move-beginning-of-line nil)
(set-mark-command nil)
(search-forward-regexp re2 nil t)
(search-forward-regexp re1)
(previous-line)
(move-beginning-of-line nil)
(fill-paragraph nil t))))))
(defun id ()
(interactive)
(insert (concat my-name " <" my-email ">")))
(defun insert-sig-fr ()
(interactive)
(insert (concat "Bien cordialement," "\n\n" "-- \nSD\n")))
(global-set-key (kbd "C-c s") 'insert-sig-fr)
(defun insert-sig-en ()
(interactive)
(insert (concat "Cheers," "\n\n" "-- \nSeb\n")))
(global-set-key (kbd "C-c S") 'insert-sig-en)
(defun system-short-name ()
(car (split-string system-name "\\.")))
(defun ts ()
(interactive)
(shell-command "date -R" t))
(defun my-browse-url-tab (url &optional new-window)
"Open URL"
(interactive (browse-url-interactive-arg "URL: "))
(let ((cmd "firefox"))
(start-process (concat cmd " " url) "*Messages*" cmd url)))
(defun paste-and-shift (arg)
(interactive)
(let ((begin (point)))
(insert arg)
(indent-rigidly begin (point) 2)))
(defun kill-to-eof ()
(interactive)
(kill-region (point) (point-max)))
(global-set-key (kbd "C-c k") 'kill-to-eof)
(defun show-file-name ()
"Show the full path file name in the minibuffer"
(interactive)
(message (buffer-file-name))
(kill-new (file-truename buffer-file-name)))
(global-set-key (kbd "C-c z") 'show-file-name)
(defun update-ssh-agent-info ()
"Update SSH_AUTH_SOCK"
(interactive)
(let* ((cmd ". ~/.zsh.function ; refresh-ssh-agent-info ; echo -n $SSH_AUTH_SOCK")
(new (shell-command-to-string cmd)))
(setenv "SSH_AUTH_SOCK" new)
(message (concat "SSH_AUTH_SOCK=" new))))
(defun my-backup-enable-predicate (filename)
"Do not create backups for certain files."
(when (normal-backup-enable-predicate filename)
(not (or (string-match "svn-commit" filename)
(string-match "dwssap" filename)
(string-match "MSG" filename)
(string-match "passwd" filename)
(string-match "/tmp/dpep" filename)))))
(setq backup-enable-predicate 'my-backup-enable-predicate)
(defun my-autoload (&rest modes)
"Autoload each mode listed in MODES."
(loop for mode in modes do (autoload (intern mode) mode nil t)))
(my-autoload "id" "ace-jump-mode" "align"
"multi-mode" "org" "time-stamp" "pf-mode"
"gtags" "outdent" "vcl-mode")
(defun add-function-to-hooks (fun modes-hooks)
"Add a call to FUN to each mode-hook listed in MODES-HOOKS."
(loop for mode-hook in modes-hooks do
(add-hook mode-hook fun)))
(add-function-to-hooks (make-fun 'set-fill-column 78) '(c-mode-hook lisp-mode-hook
emacs-lisp-mode-hook
html-mode-hook))
(add-function-to-hooks (make-fun 'set-fill-column 72) '(text-mode-hook))
;; ELPA/MELPA
(if (>= emacs-major-version 24)
(require 'package)
(load-file (concat my-emacsd "/23/package.el")))
(setq tls-checktrust t)
(setq gnutls-verify-error t)
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(let ((trustfile "/etc/ssl/certs/ca-certificates.crt"))
(setq gnutls-trustfiles (list trustfile))
(setq tls-program
(list
(format "gnutls-cli --x509cafile %s -p %%p %%h" trustfile))))
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
;; ("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")
("melpa-stable" . "https://stable.melpa.org/packages/")))
(setq package-archive-priorities '(("melpa-stable" . 10)
("gnu" . 5)
("melpa" . 1)))
(package-initialize)
;; fetch the list of packages available
(unless package-archive-contents
(package-refresh-contents))
;; install the missing packages
(unless (package-installed-p 'use-package)
(package-install 'use-package))
;; use-package
(require 'use-package)
(setq use-package-always-ensure t)
(setq use-package-always-pin "melpa-stable")
;; use-package extensions
(use-package use-package-chords
:config (key-chord-mode 1))
;; _____________________________________________________________________
;; Hooks
(defun seb/mutt-hook ()
(progn
(mail-mode)
(turn-on-orgtbl)
(local-set-key (kbd "C-c n i") 'org-footnote-new)
(local-set-key (kbd "C-c n p") 'org-mark-ring-goto)
(local-set-key (kbd "C-c i") 'format-email-body)))
(defun my-org-mode-hook ()
;; (require 'org-expiry)
;; (org-expiry-insinuate)
;; (setq org-expiry-handler-function 'org-expiry-archive-subtree)
;; (require 'org-crypt)
;; (org-crypt-use-before-save-magic)
;; (setq org-crypt-key "[email protected]")
;; (add-hook 'before-save-hook 'org-encrypt-entries)
(require 'ob-ruby)
(require 'ob-python)
(setq org-babel-python-command "python3")
(require 'ob-js)
(require 'ob-ditaa)
;; (defun my-org-confirm-babel-evaluate (lang body)
;; (not (string= lang "ditaa"))) ; don't ask for ditaa
;; (setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)
(setq org-confirm-babel-evaluate nil
org-babel-min-lines-for-block-output 1
org-babel-default-header-args
(cons '(:noweb . "yes")
(assq-delete-all :noweb org-babel-default-header-args))
org-babel-default-header-args
(cons '(:exports . "both")
(assq-delete-all :exports org-babel-default-header-args))
org-babel-default-header-args
(cons '(:results . "output verbatim replace")
(assq-delete-all :results org-babel-default-header-args)))
(require 'ob-shell)
(require 'ob-sql)
(require 'ob-emacs-lisp)
(setq org-src-fontify-natively t)
(require 'org-inlinetask)
(setq org-inlinetask-default-state "TODO")
(setq org-inlinetask-min-level 8)
(define-key org-mode-map "\C-c\C-xt" 'org-inlinetask-insert-task)
(require 'org-protocol)
(require 'org-tempo)
(use-package org-ql
:config
(require 'org-ql-view)
(add-to-list 'org-ql-views
'("TODO"
:buffers-files
org-agenda-files
:query
(and (not (done)) (ts-active :from today :to 4))
:sort
(date priority)
:narrow nil :super-groups org-super-agenda-groups :title "TODO"))
(add-to-list 'org-ql-views
'("NO DEADLINE"
:buffers-files
(lambda () (cons "~/org/links.org" org-agenda-files))
:query
(and (todo) (not (deadline)))
:sort
(date priority)
:narrow nil :super-groups org-super-agenda-groups :title "NO DEADLINE")))
(use-package org-roam
:init
(setq org-roam-v2-ack t)
:config
(setq org-roam-directory "~/vcs/roam"))
;; adapted from
;; https://github.com/ag91/ag91.github.io/blob/source/blog/LeadYourFutureWithOrg.org
(defun seb/org/get-tasks (todo-tag from &optional tag to files category)
"Get stats for tasks of last week with TODO-TAG TAG FROM optionally define TO date and source FILES to use."
(org-ql-query
:from (or files (org-agenda-files))
:where
`(and (todo ,todo-tag)
(if ,tag (tags ,tag) t)
(if ,category (category ,category) t)
(ts :from ,from :to ,(or to 'today)))))
(defun seb/org/get-stats-tasks (todo-tag from &optional tag to files category)
"Get stats for tasks of last week with TODO-TAG TAG FROM optionally define TO date and source FILES to use."
(let ((tasks (seb/org/get-stats-tasks todo-tag from tag to files category))
`((tasks . ,(length tasks))
(tasks-per-day . ,(/ (length tasks) (abs from)))))))
;; (require 'ox-confluence)
(require 'ox-beamer)
(require 'ox-md)
(use-package ox-pandoc)
(setq org-ellipsis " ▼")
(setq org-footnote-auto-adjust t)
(toggle-word-wrap)
;; LaTeX
(require 'ox-latex)
(setq org-export-latex-listings t)
;; (add-to-list 'org-export-latex-packages-alist '("" "listings"))
;; (add-to-list 'org-export-latex-packages-alist '("" "color"))
(setq org-export-latex-emphasis-alist
'(("*" "\\textbf{%s}" nil)
("/" "\\emph{%s}" nil)
("_" "\\underline{%s}" nil)
("+" "\\st{%s}" nil)
("=" "\\url{%s}" nil)
;; `url' breaks lines in long strings (was `verb')
("~" "\\verb~%s~" t)
("@" "\\alert{%s}" nil)))
;; clock
(setq org-clock-into-drawer t)
;; (setq org-clock-clocktable-default-properties '(:maxlevel 5 :formula "$7='(org-clock-time% @2$2 $2..$6);%1.f" :narrow 80!))
(setq org-clock-clocktable-default-properties '(:maxlevel 5 :formula % :narrow 80!))
;; speed commands
(setq org-use-speed-commands t)
(setq org-speed-commands-user (quote (("S" . widen))))
;; agenda
(use-package org-super-agenda
:config
(org-super-agenda-mode t))
(setq org-agenda-include-diary nil)
(setq org-agenda-span 'year)
(setq org-agenda-start-day "-4m")
(setq org-agenda-show-all-dates nil)
(setq org-agenda-show-log nil)
(setq org-agenda-show-future-repeats 'next)
(setq org-agenda-skip-deadline-if-done t)
(setq org-agenda-skip-scheduled-delay-if-deadline t)
(setq org-agenda-skip-scheduled-if-deadline-is-shown t)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-skip-timeline-if-done t)
(setq org-agenda-skip-timestamp-if-deadline-is-shown t)
(setq org-agenda-start-on-weekday nil)
(setq org-agenda-start-with-log-mode nil)
(setq org-blank-before-new-entry '((heading . nil) (plain-list-item . nil)))
;; (setq org-combined-agenda-icalendar-file "~/org/org.ics")
(setq org-icalendar-categories '(all-tags))
(setq org-icalendar-store-UID t)
(setq org-icalendar-use-deadline '(event-if-todo))
;; (setq org-icalendar-include-todo t)
(setq org-deadline-warning-days 0)
(setq org-default-priority 67)
(setq org-duration-format (quote h:mm))
;; (setq org-fast-tag-selection-single-key 'expert)
(setq org-adapt-indentation t)
(setq org-fast-tag-selection-single-key t)
(setq org-return-follows-link t)
(setq org-hide-leading-stars t)
(setq org-id-locations-file (concat my-emacsd "org-id-locations"))
(setq org-log-done 'time)
(setq org-log-into-drawer t)
(setq org-lowest-priority 69)
(setq org-popup-calendar-for-date-prompt nil)
(setq org-reverse-note-order nil)
(setq org-use-fast-todo-selection t)
(setq org-use-sub-superscripts nil)
;; (setq org-agenda-custom-commands
;; (quote (("c" todo "DONE|LATER|CANCELED" nil)
;; ("w" todo "TODO|WAITING" nil)
;; ("Z" "blah" todo "WAITING")
;; ("Y" "Weekly Review......." todo "TODO"
;; ((agenda (org-agenda-ndays 7))))
;; ("W" agenda "Month" ((org-agenda-ndays 30)))
;; ("A" agenda "Custom"
;; ((org-agenda-skip-function
;; (lambda nil
;; (org-agenda-skip-entry-if (quote notregexp) "\\=.*\\[#A\\]")))
;; (org-agenda-ndays 1)
;; (org-agenda-overriding-header "Today's Priority #A tasks: ")))
;; ("B" agenda "No (CANCELED|DONE|LATER)"
;; ((org-agenda-skip-function '(org-agenda-skip-subtree-if
;; 'regexp "\\* \\(CANCELED\\|LATER\\|DONE\\)")))
;; (org-agenda-ndays 7)
;; (org-show-hierarchy-above t)
;; (org-agenda-overriding-header "No (CANCELED|DONE|LATER): ")))
;; ("u" alltodo ""
;; ((org-agenda-skip-function
;; (lambda nil
;; (org-agenda-skip-entry-if (quote scheduled) (quote deadline)
;; (quote regexp) "<[^>\n]+>")))
;; (org-agenda-overriding-header "Unscheduled TODO entries: ")))))
;; (define-key org-agenda-mode-map
;; "v" 'hydra-org-agenda-view/body)
(defun org-agenda-cts ()
(let ((args (get-text-property
(min (1- (point-max)) (point))
'org-last-args)))
(nth 2 args)))
;; (defhydra hydra-org-agenda-view (:hint nil)
;; "
;; _d_: ?d? day _g_: time grid=?g? _a_: arch-trees
;; _w_: ?w? week _[_: inactive _A_: arch-files
;; _t_: ?t? fortnight _f_: follow=?f? _r_: report=?r?
;; _m_: ?m? month _e_: entry =?e? _D_: diary=?D?
;; _y_: ?y? year _q_: quit _L__l__c_: ?l?"
;; ("SPC" org-agenda-reset-view)
;; ("d" org-agenda-day-view
;; (if (eq 'day (org-agenda-cts))
;; "[x]" "[ ]"))
;; ("w" org-agenda-week-view
;; (if (eq 'week (org-agenda-cts))
;; "[x]" "[ ]"))
;; ("t" org-agenda-fortnight-view
;; (if (eq 'fortnight (org-agenda-cts))
;; "[x]" "[ ]"))
;; ("m" org-agenda-month-view
;; (if (eq 'month (org-agenda-cts)) "[x]" "[ ]"))
;; ("y" org-agenda-year-view
;; (if (eq 'year (org-agenda-cts)) "[x]" "[ ]"))
;; ("l" org-agenda-log-mode
;; (format "% -3S" org-agenda-show-log))
;; ("L" (org-agenda-log-mode '(4)))
;; ("c" (org-agenda-log-mode 'clockcheck))
;; ("f" org-agenda-follow-mode
;; (format "% -3S" org-agenda-follow-mode))
;; ("a" org-agenda-archives-mode)
;; ("A" (org-agenda-archives-mode 'files))
;; ("r" org-agenda-clockreport-mode
;; (format "% -3S" org-agenda-clockreport-mode))
;; ("e" org-agenda-entry-text-mode
;; (format "% -3S" org-agenda-entry-text-mode))
;; ("g" org-agenda-toggle-time-grid
;; (format "% -3S" org-agenda-use-time-grid))
;; ("D" org-agenda-toggle-diary
;; (format "% -3S" org-agenda-include-diary))
;; ("!" org-agenda-toggle-deadlines)
;; ("["
;; (let ((org-agenda-include-inactive-timestamps t))
;; (org-agenda-check-type t 'timeline 'agenda) (org-agenda-redo)))
;; ("q" (message "Abort") :exit t))
;; todo
(setq org-todo-keywords
'((sequence "TODO(t)" "WAITING(w@/!)" "LATER(l@)" "|" "DONE(d!/@)" "CANCELED(c@)")))
(setq org-todo-keyword-faces
(quote (("TODO" :foreground "light grey" :weight bold :background "red")
("LATER" :foreground "dark violet" :weight bold)
("DONE" :foreground "dark green" :weight bold)
("WAITING" :foreground "dark orange" :weight bold)
("LATER" :foreground "light orange" :weight bold))))
(setq org-priority-faces
(quote ((?A . (:background "blue" :foreground "yellow" :weight bold)))))
;; links
(setq org-link-abbrev-alist '(("debian-bug" . "https://bugs.debian.org/%s")
("debian-dp" . "https://packages.debian.org/%s")
("debian-dsp" . "https://tracker.debian.org/%s")
("debian-dst" . "https://security-tracker.debian.org/tracker/%s")
("salsa-dt-mr" . "https://salsa.debian.org/qa/distro-tracker/merge_requests/%")))
;; *** [[url][desc]] :tag1:tag2: -> url #tag1,tag2#
(defun org-convert-entry-to-irc ()
(interactive)
(let* ((org-link (nth 4 (org-heading-components)))
(link (progn
(if (string-match org-link-bracket-re org-link)
(org-link-decode (match-string 1 org-link))
org-link)))
(tags (delete "todo_gcu" (org-get-tags nil t)))
(irctags (mapconcat 'identity tags ","))
(delim "#"))
(org-set-tags tags)
(org-todo "")
(message (concat link " " delim irctags delim))))
;; spelling
(defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
"from http://emacs.stackexchange.com/questions/9333/how-does-one-use-flyspell-in-org-buffers-without-flyspell-triggering-on-tangled/9347"
(let ((rlt ad-return-value)
(begin-regexp "^\\*")
(end-regexp "\n")
old-flag
b e)
(when ad-return-value
(save-excursion
(setq old-flag case-fold-search)
(setq case-fold-search t)
(setq b (re-search-backward begin-regexp nil t))
(if b (setq e (re-search-forward end-regexp nil t)))
(setq case-fold-search old-flag))
(if (and b e (< (point) e)) (setq rlt nil)))
(setq ad-return-value rlt)))
;; archiving
(setq org-auto-archive-required-days 21)
(setq org-auto-archive-handler-function 'org-archive-subtree)
(defun org-archive-region-default ()
"Archive all entries in the selected region"
(interactive)
(save-excursion
(let ((beg (if (org-region-active-p)
(region-beginning)
(point-min)))
(end (if (org-region-active-p)
(region-end)
(point-max))))
(goto-char end)
(outline-previous-heading)
(while (>= (point) beg)
(org-archive-subtree-default)
(outline-previous-heading)))))
(defun org-auto-archivable-p ()
"Determines if the current heading is auto-archivable,
meaning that it has been in a DONE state for more than
org-auto-archive-required-days."
(interactive)
(save-excursion
(goto-char (line-beginning-position))
(let ((end-heading (save-excursion
(outline-next-heading)
(point)))
(state-regexp
(concat "CLOSED: \\[\\([^]\n]+\\)\\]")))
(if (and (org-entry-is-done-p)
(re-search-forward state-regexp end-heading t))
(let* ((time-string (match-string 1))
(when-closed (apply #'encode-time
(org-parse-time-string time-string)))
(days-since-closed (time-to-number-of-days
(time-subtract (current-time)
when-closed))))
(>= days-since-closed org-auto-archive-required-days))))))
(defun org-my-archive-done ()
"Archive the current heading and its subtree if it is
auto-archivable."
(if (org-auto-archivable-p)
(funcall org-auto-archive-handler-function)))
(defun org-my-archive-done-tasks ()
"Archive all auto-archivable headings in the current region,
or in the entire buffer if no region is active."
(interactive)
(save-excursion
(let ((beg (if (org-region-active-p)
(region-beginning)
(point-min)))
(end (if (org-region-active-p)
(region-end)
(point-max))))
(goto-char end)
(outline-previous-heading)
(while (and (>= (point) beg))
(org-my-archive-done)
(outline-previous-heading)))))
;; (add-hook 'after-save-hook 'org-my-archive-done-tasks)
;; note/capture/refile
(setq org-refile-use-outline-path t)
(setq org-outline-path-complete-in-steps nil)
(setq org-default-notes-file org-agenda-files)
(setq seb/org-refile-files '())
(setq org-refile-targets '((seb/org-refile-files . (:maxlevel . 2))))
(setq org-capture-templates
(quote (("h" "Home" entry (file+olp "~/org/home.todo" "Home" "Inbox")
"* TODO %?\n DEADLINE: %t")
("l" "Link" entry (file+olp "~/org/links.org" "URLs" "Inbox")
"* %?\n %U")
("L" "Link from FF" entry (file+olp "~/org/links.org" "URLs" "Inbox")
"* %a %?\n %U")
("e" "Mail" entry (file+headline "~/org/home.todo" "Inbox")
"* TODO %? %U\n Source: %u, %c\n %i"))))
;; bindings
(define-key org-mode-map (kbd "C-c a") 'org-agenda)
(define-key org-mode-map (kbd "C-c l") 'org-store-link)
(define-key org-mode-map (kbd "C-c /") 'org-sparse-tree)
(define-key org-mode-map (kbd "C-c C-x C-r") 'org-clock-report)
(define-key org-mode-map (kbd "C-c SPC") 'nil)
(define-key global-map (kbd "C-c c") 'org-capture)
(define-key global-map (kbd "C-c /") 'org-sparse-tree)
(key-chord-define org-mode-map "uu" '(lambda ()
(interactive)
(let ((prefix-arg last-prefix-arg))
(org-ctrl-c-ctrl-c))))
;; (defun hot-expand (str)
;; "Expand org template."
;; (insert str)
;; (org-try-structure-completion))
;; (defhydra hydra-org-template (:color blue :hint nil)
;; "
;; _c_enter _q_uote _L_aTeX:
;; _l_atex _e_xample _i_ndex:
;; _a_scii _v_erse _I_NCLUDE:
;; _s_rc ^ ^ _H_TML:
;; _h_tml ^ ^ _A_SCII:
;; "
;; ("s" (hot-expand "<s"))
;; ("e" (hot-expand "<e"))
;; ("q" (hot-expand "<q"))
;; ("v" (hot-expand "<v"))
;; ("c" (hot-expand "<c"))
;; ("l" (hot-expand "<l"))
;; ("h" (hot-expand "<h"))
;; ("a" (hot-expand "<a"))
;; ("L" (hot-expand "<L"))
;; ("i" (hot-expand "<i"))
;; ("I" (hot-expand "<I"))
;; ("H" (hot-expand "<H"))
;; ("A" (hot-expand "<A"))
;; ("<" self-insert-command "ins")
;; ("o" nil "quit"))
;; (define-key org-mode-map "<"
;; (lambda () (interactive)
;; (if (looking-back "^")
;; (hydra-org-template/body)
;; (self-insert-command 1))))
(local-set-key (kbd "<M-RET>") 'org-meta-return)
(setq org-priority-faces '((65 :foreground "color-81" :weight bold)))
(defun seb/org-previous-timestamp ()
(save-excursion
(org-previous-visible-heading 2)
(forward-line 1)
(back-to-indentation)
(org-kill-line)
(yank)
(current-kill 0 t)))
(defhydra hydra-org-timestamp (:color amaranth :hint nil)
("a" (let ((current-prefix-arg '(16)))
(call-interactively 'org-time-stamp))
"active")
("A" (insert (format-time-string "<%F %a>"))
"active (date-only)")
("i" (let ((current-prefix-arg '(16)))
(call-interactively 'org-time-stamp-inactive))
"inactive")
("I" (insert (format-time-string "[%F %a]"))
"inactive (date-only)")
("l" (insert (seb/org-previous-timestamp)) "insert last timestamp")
("L" (progn
(back-to-indentation)
(org-kill-line)
(insert (seb/org-previous-timestamp)) "set last timestamp"))
("b" (org-timestamp-change -1 'hour) "-1h")
("f" (org-timestamp-change 1 'hour) "+1h")
("p" (org-timestamp-change -1 'day) "-1d")
("n" (org-timestamp-change 1 'day) "+1d")
("q" nil "quit" :color blue))
(key-chord-define org-mode-map "hh" 'hydra-org-timestamp/body))
(add-hook 'org-load-hook 'my-org-mode-hook)
(add-hook 'org-mode-hook 'my-org-mode-hook)
(defun my-recentf-mode-hook ()
(setq recentf-save-file (concat my-emacsd "recentf"))
(setq recentf-max-saved-items 500)
(setq recentf-max-menu-items 60)
(setq recentf-exclude '("/tmp/.*")))
(add-hook 'recentf-load-hook 'my-recentf-mode-hook)
(defun my-time-stamp-hook ()
(time-stamp-format "%3a, %02d %3b %Y %02H:%02M:%02S %z"))
(add-hook 'time-stamp-hook 'my-time-stamp-hook)
(defun my-change-log-hook ()
(setq left-margin 2))
(add-hook 'change-log-mode-hook 'my-change-log-hook)
(defun my-no-electric-indent-hook ()
(local-set-key (kbd "C-j") 'newline)
(local-set-key (kbd "C-m") 'newline))
(add-hook 'puppet-mode-hook (lambda () (electric-indent-local-mode -1)))
(add-hook 'puppet-mode-hook 'my-no-electric-indent-hook)
(add-hook 'ruby-mode-hook (lambda () (electric-indent-local-mode -1)))
(add-hook 'ruby-mode-hook 'my-no-electric-indent-hook)
;; _____________________________________________________________________
;; General preferences
;; No more "C-x C-s C-x #' (server-mode)
(define-key global-map (kbd "C-x j") '(lambda ()
(interactive)
(progn
(save-buffer)
(if (and (fboundp 'server-running-p)
(server-running-p))
(server-edit)
(kill-emacs)))))
;; ace-window/avy
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l))
(setq aw-background nil)
;;(csetq aw-flip-keys '("n" "ν"))
;;(add-to-list 'aw-dispatch-alist '(?ν aw-flip-window))
(avy-setup-default)
(setq avy-all-windows nil)
(setq avy-styles-alist '((avy-goto-char-2 . post)))
(define-key global-map (kbd "C-c SPC") 'avy-goto-line)
(define-key global-map (kbd "M-n") 'avy-goto-char-2)
;; saving history locally: available on every system, and still private as
;; it's not in the public git emacs configuration
;; (from https://github.com/baron42bba/.emacs.d/blob/master/bba.org#save-history)
(setq savehist-additional-variables '(kill-ring
search-ring
regexp-search-ring
last-kbd-macro
kmacro-ring
shell-command-history))
(setq kmacro-ring-max 42)
(if (file-directory-p "~/org")
(progn
(setq history-delete-duplicates t)
(setq savehist-file "~/org/emacs_history")
(if (file-exists-p savehist-file)
(load-file savehist-file))
(savehist-mode 1)))
;; save files starting with #! as executable
;; (from https://github.com/baron42bba/.emacs.d/blob/master/bba.org#safe-hash-bang-files-executable)
(defun make-buffer-executable-if-hashbang ()
(if (and (save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(save-match-data
(looking-at "^#!"))))
(not (file-executable-p buffer-file-name)))
(progn
(shell-command (concat "chmod ugo+x " buffer-file-name))
(message (concat "Saved " buffer-file-name " with +x")))))
(add-hook 'after-save-hook 'make-buffer-executable-if-hashbang)
(use-package key-chord
:config
(key-chord-mode 1)
(setq key-chord-one-key-delay 0.2)
(setq key-chord-two-keys-delay 0.1))
(use-package edit-server
:defer 2
:config
(setq edit-server-new-frame nil)
(if (and (fboundp 'server-running-p)
(server-running-p)
(string= server-name "main"))
(edit-server-start)))
(use-package ledger-mode
:defer t
:mode "\\.ledger$"
:config
(setq ledger-use-iso-dates t))
(use-package flycheck
:defer 2
:init
(global-flycheck-mode t)
:config
(setq flycheck-keymap-prefix (kbd "C-c ~"))
(defhydra hydra-flycheck
(:pre (progn (setq hydra-lv t) (flycheck-list-errors))
:post (progn (setq hydra-lv nil) (quit-windows-on "*Flycheck errors*")))
"Errors"
("f" flycheck-error-list-set-filter "Filter")
("n" flycheck-next-error "Next")
("p" flycheck-previous-error "Previous")
("<" flycheck-first-error "First")
(">" (progn (goto-char (point-max)) (flycheck-previous-error)) "Last")
("q" nil "quit"))
:bind
("M-g f" . hydra-flycheck/body))
(use-package flycheck-color-mode-line
:after flycheck
:config
(flycheck-color-mode-line-mode t))
(use-package magit
:mode ("\\(svn-commit\\|COMMIT_EDITMSG\\|MERGE_MSG\\)" . git-commit-mode)
:config
(setq magit-commit-ask-to-stage "stage")
(setq magit-diff-refine-hunk "all")
:bind
("C-x g" . magit-status)
("C-x M-g" . magit-dispatch-popup)
:chords (("kk" . magit-status)
("KK" . magit-file-dispatch)))
(use-package forge
:after magit)
(use-package gitconfig-mode)
(use-package gitignore-mode)
(use-package notmuch
:config
(setq notmuch-saved-searches '((:name "inbox" :query "tag:inbox" :key "i")
(:name "unread" :query "tag:unread" :key "u")
(:name "flagged" :query "tag:flagged" :key "F")
(:name "sent" :query "tag:sent" :key "s")
(:name "drafts" :query "tag:draft" :key "d")
(:name "all mail" :query "*" :key "a")))
(setq notmuch-show-tag-macro-alist
(list
'("u" "-unread" "+test")
;; '("n" "+notmuch::patch" "+notmuch::needs-review" "-notmuch::pushed")
;; '("o" "+notmuch::patch" "+notmuch::obsolete"
;; "-notmuch::needs-review" "-notmuch::moreinfo")
;; '("p" "-notmuch::pushed" "-notmuch::needs-review"
;; "-notmuch::moreinfo" "+pending")
;; '("P" "-pending" "-notmuch::needs-review" "-notmuch::moreinfo" "+notmuch::pushed")
;; '("r" "-notmuch::patch" "+notmuch::review")
;; '("s" "+notmuch::patch" "-notmuch::obsolete" "-notmuch::needs-review" "-notmuch::moreinfo" "+notmuch::stale")
;; '("t" "+notmuch::patch" "-notmuch::needs-review" "+notmuch::trivial")
'("w" "+notmuch::patch" "+notmuch::wip" "-notmuch::needs-review")))
(defun notmuch-show-apply-tag-macro (key)
(interactive "k")
(let ((macro (assoc key notmuch-show-tag-macro-alist)))
(apply 'notmuch-show-tag-message (cdr macro))
(notmuch-refresh-this-buffer)))
(defun notmuch-search-apply-tag-macro (key)
(interactive "k")
(let ((macro (assoc key notmuch-show-tag-macro-alist)))
(apply 'notmuch-search-tag (list (cdr macro)))
(notmuch-refresh-this-buffer)))
(eval-after-load 'notmuch-show
'(define-key notmuch-show-mode-map "`" 'notmuch-show-apply-tag-macro))
(eval-after-load 'notmuch-search
'(define-key notmuch-search-mode-map "`" 'notmuch-search-apply-tag-macro))
)
(use-package gnus
:defer t
:config
(setq user-mail-address my-email)
(setq user-full-name my-name)
(setq gnus-select-method '(nntp "news.gmane.io"))
(setq gnus-secondary-select-methods '((nntp "localhost" 8119)))
(setq smtpmail-smtp-server "localhost")
(setq gnus-thread-ignore-subject t)
(setq gnus-thread-hide-subtree t)
(setq gnus-startup-file (concat my-emacsd "/gnus/.newsrc"))
(setq gnus-dribble-directory (concat my-emacsd "/gnus"))
(setq gnus-always-read-dribble-file t)
(setq gnus-summary-line-format "%U%R %z {%5L} [%-35,35n] %&user-date; %t %B%-80,80S\n"
gnus-user-date-format-alist '((t . "%Y-%m-%d %H:%M"))
gnus-summary-thread-gathering-function 'gnus-gather-threads-by-references
gnus-sum-thread-tree-false-root ""
gnus-sum-thread-tree-indent " "
gnus-sum-thread-tree-leaf-with-other "├► "
gnus-sum-thread-tree-root ""
gnus-sum-thread-tree-single-leaf "╰► "
gnus-sum-thread-tree-vertical "│")
(gnus-add-configuration
'(article
(horizontal 1.0
(vertical 50
(group 1.0))
(vertical 1.0
(summary 0.40 point)
(article 1.0)))))
(gnus-add-configuration
'(summary
(horizontal 1.0
(vertical 50
(group 1.0))
(vertical 1.0
(summary 1.0 point)))))
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode))
(use-package ivy
:defer 0.1
:diminish
:bind (("C-c C-r" . ivy-resume)
("C-x B" . ivy-switch-buffer-other-window))
:custom
(ivy-count-format "(%d/%d) ")
(ivy-use-virtual-buffers t)
:config
(setq ivy-height 20) ;; number result lines to display
(setq ivy-initial-inputs-alist nil) ;; no anchor by default
(setq ivy-re-builders-alist '((t . ivy--regex-ignore-order)))
(setq split-height-threshold nil)
(setq enable-recursive-minibuffers t)
(ivy-mode t))
(use-package ivy-hydra
:after ivy)
(use-package ivy-rich
:after (:all ivy counsel)
:init
(setq ivy-rich-path-style 'abbrev)
(setq ivy-virtual-abbreviate 'full)
:config
(ivy-rich-mode t))
(use-package swiper
:after ivy