-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
1692 lines (1495 loc) · 58.6 KB
/
init.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; -*- coding: utf-8 lexical-binding: t; -*-
;; * configure packages
(when (< emacs-major-version 27)
(package-initialize))
(init:report-elapsed-time "package-initialize")
;; ** load secrets
;; to fix gpg while using ipad, force reading password from stdin
(unless (display-graphic-p)
;; running without GUI
;; accept gpg passphrase without GUI/gpg-agent
(setq epa-pinentry-mode 'loopback))
(require '.secrets "~/.secrets.el.gpg" 'noerror)
;; ** Ensure system binaries exist alongside your package declarations.
;; Enable :ensure-system-package keyword for use-package
;; https://github.com/jwiegley/use-package?tab=readme-ov-file#keyword-extensions
(use-package use-package-ensure-system-package
:ensure t)
;; ** delight: remove modes from ModeLine
;; C-h v minor-mode-alist
(use-package delight
:commands delight)
;; ** which-key: show commands for the current prefix after a delay
(use-package which-key
:delight
:config
(which-key-mode))
;; ** show typed keys
(use-package command-log-mode
:commands command-log-mode
:config
;; M-x clm/open-command-log-buffer
(global-command-log-mode))
;; ** theme-changer: use dark theme after sunset
(use-package theme-changer
:custom
(calendar-latitude 55.8) ; for solar package
(calendar-longitude 37.6)
:init
(defun init:disable-before-load (theme &optional no-confirm no-enable)
"Reset old theme settings while loading a new theme"
(mapc 'disable-theme custom-enabled-themes))
(advice-add 'load-theme :before #'init:disable-before-load)
:config
(change-theme 'tango 'tango-dark))
;; ** navigating,searching,selecting lists ivy, swiper, counsel
;; *** ivy
; https://writequit.org/denver-emacs/presentations/2017-04-11-ivy.html
(use-package ivy
:delight
:init
(ivy-mode 1) ; turn on ivy for default functions
:bind ("C-c C-r" . ivy-resume)
:config
; https://sam217pa.github.io/2016/09/13/from-helm-to-ivy/
(setq ivy-re-builders-alist
;; allow input not in order
'((t . ivy--regex-ignore-order))) ; "C-o m" toggles the current regexp builder
(setq ivy-height 20)
(setq ivy-use-virtual-buffers t
ivy-count-format "%d/%d")
; remove "^" from the default regex
(setq ivy-initial-inputs-alist nil)
)
;; **** ~C-o~ (=hydra-ivy/body=) invokes Hydra menus with key shortcuts.
;; When in Hydra, ~C-o~ or ~i~ resumes editing.
(use-package ivy-hydra
:after (ivy hydra))
(use-package swiper
)
;; *** amx -- M-x smex fork
(use-package amx
) ; used by counsel-M-x
(use-package request
) ; used by counsel-search
(use-package counsel
:ensure-system-package (rg . ripgrep)
:delight
:bind (("C-s" . counsel-grep-or-swiper)
("M-x" . counsel-M-x) ; show keybindings
("<f5>" . compile)
("<S-f5>" . counsel-compile)
("C-x C-f" . counsel-find-file)
("C-h f" . counsel-describe-function)
("C-h v" . counsel-describe-variable)
("C-h a" . counsel-apropos))
:custom
(enable-recursive-minibuffers t)
(counsel-search-engine 'google)
:init
; https://oremacs.com/2017/08/04/ripgrep/
(setq counsel-grep-base-command
"rg -i -M 120 --no-heading --line-number --color never --text -e %s %s")
:config
;; Enabling counsel-mode remaps built-in Emacs functions that have counsel replacements
(counsel-mode 1)
(minibuffer-depth-indicate-mode) ;; for enable-recursive-minibuffers
)
(with-eval-after-load-feature (counsel vterm)
(defun vterm-counsel-yank-pop-action (orig-fun &rest args)
(if (equal major-mode 'vterm-mode)
(let ((inhibit-read-only t)
(yank-undo-function (lambda (_start _end) (vterm-undo))))
(cl-letf (((symbol-function 'insert-for-yank)
(lambda (str) (vterm-send-string str t))))
(apply orig-fun args)))
(apply orig-fun args)))
(advice-add 'counsel-yank-pop-action :around #'vterm-counsel-yank-pop-action)
)
;; *** projectile C-c p p
(use-package projectile
:delight
:custom
(projectile-completion-system 'ivy))
(use-package counsel-projectile
:bind-keymap
("C-c p" . projectile-command-map)
:config
(counsel-projectile-mode +1))
;; counsel-dash
;; *** counsel-dash
(use-package counsel-dash
:ensure-system-package sqlite3
:bind ("C-c d" . counsel-dash-at-point)
:custom
(dash-docs-browser-func 'eww)
;; Note: can't use :config here -- too late for the hook to run then the
;; keys are invoked (causing the config) in the corresponding buffer
:init
(progn ;; M-x counsel-dash-install-docset (after using counsel-dash)
;; M-x counsel-dash-install-user-docset -> 404 from https://dashes-to-dashes.herokuapp.com/docsets/contrib
;;;; (setq url-debug t) ;; see *URL-DEBUG* buffer
(defun python3-doc ()
(interactive)
(setq-local counsel-dash-docsets
'("Pandas" "Python 3" "NumPy" "SciPy" "Matplotlib" "scikit-learn" "seaborn")))
(add-hook 'python-mode-hook 'python3-doc)
(add-hook 'org-mode-hook 'python3-doc)
(defun c++-doc ()
(interactive)
(setq-local counsel-dash-docsets
'("C++")))
(add-hook 'c++-mode-hook 'c++-doc)
(defun c-doc ()
(interactive) (setq-local counsel-dash-docsets '("C")))
(add-hook
'c-mode-hook 'c-doc)
(defun bash-doc ()
(interactive)
(setq-local
counsel-dash-docsets '("Bash")))
(add-hook 'sh-mode-hook 'bash-doc))
:config
;; from https://github.com/dash-docs-el/dash-docs/issues/23#issuecomment-1694059091
(defun dash-docs-unofficial-docsets ()
"Return a list of lists with docsets contributed by users.
The first element is the docset's name second the docset's archive url."
(let ((user-docs (assoc-default 'docsets
(dash-docs-read-json-from-url
"https://kapeli.com/feeds/zzz/user_contributed/build/index.json"))))
(mapcar (lambda (docset)
(list
(assoc-default 'name docset)
(car docset)
(assoc-default 'archive docset)))
user-docs)))
(defun dash-docs-install-user-docset ()
"Download an unofficial docset with specified DOCSET-NAME and move its stuff to docsets-path."
(interactive)
(let* ((docsets (dash-docs-unofficial-docsets))
(docset-name (dash-docs-read-docset
"Install docset"
(mapcar 'car docsets)))
(docset (assoc-default docset-name docsets)))
(when (dash-docs--ensure-created-docsets-path (dash-docs-docsets-path))
(let ((url
(format "https://kapeli.com/feeds/zzz/user_contributed/build/%s/%s"
(car docset)
(cadr docset))))
(dash-docs--install-docset url (car docset)))))))
;; ** ripgrep
;;; type `e' in rg-mode to edit search results, `C-x C-s' to save them
(use-package wgrep
;; save buffers automatically before finishing wgrep mode
:custom
(wgrep-auto-save-buffer t))
(use-package rg
:ensure-system-package (rg . ripgrep)
:bind ("C-x C-r" . rg))
;; ** ace-link
(use-package ace-link
:ensure nil
:config
(require 'info)
(ace-link-setup-default))
;; ** magit
(use-package magit
:ensure-system-package git
:bind ("C-c M-g" . magit-file-dispatch)
:bind ("C-c g" . magit-status)
:custom
(magit-log-section-commit-count 40)
(git-commit-major-mode 'markdown-mode)
:config
(setq magit-completing-read-function 'ivy-completing-read))
(with-eval-after-load-feature (magit org)
(define-key magit-process-mode-map (kbd "o") 'ace-link-org))
(use-package forge
:defer t
:after magit)
;; ***
(use-package git-gutter
:delight
:custom
(git-gutter:window-width 2)
(git-gutter:modified-sign "☁")
(git-gutter:added-sign "☀")
(git-gutter:deleted-sign "☂")
:config
(global-git-gutter-mode t))
;; ***
(use-package git-timemachine
:commands git-timemachine-toggle)
;; ***
(use-package diffview
:commands (diffview-region diffview-current))
;; *** handle git conflicts
;;; from https://ladicle.com/post/config/#smerge
(use-package smerge-mode
:ensure nil
:delight
:preface
(with-eval-after-load 'hydra
(defhydra smerge-hydra
(:color pink :hint nil :post (smerge-auto-leave))
"
^Move^ ^Keep^ ^Diff^ ^Other^
^^-----------^^-------------------^^---------------------^^-------
_n_ext _b_ase _<_: upper/base _C_ombine
_p_rev _u_pper _=_: upper/lower _r_esolve
^^ _l_ower _>_: base/lower _k_ill current
^^ _a_ll _R_efine
^^ _RET_: current _E_diff
"
("n" smerge-next)
("p" smerge-prev)
("b" smerge-keep-base)
("u" smerge-keep-upper)
("l" smerge-keep-lower)
("a" smerge-keep-all)
("RET" smerge-keep-current)
("\C-m" smerge-keep-current)
("<" smerge-diff-base-upper)
("=" smerge-diff-upper-lower)
(">" smerge-diff-base-lower)
("R" smerge-refine)
("E" smerge-ediff)
("C" smerge-combine-with-next)
("r" smerge-resolve)
("k" smerge-kill-current)
("ZZ" (lambda ()
(interactive)
(save-buffer)
(bury-buffer))
"Save and bury buffer" :color blue)
("q" nil "cancel" :color blue)))
:hook ((find-file . (lambda ()
(save-excursion
(goto-char (point-min))
(when (re-search-forward "^<<<<<<< " nil t)
(smerge-mode 1)))))
(magit-diff-visit-file . (lambda ()
(when smerge-mode
(smerge-hydra/body))))))
;; ** debugger
(use-package realgud
:ensure nil ; ; realgud has to be installed manually to avoid https://github.com/realgud/realgud/issues/77
:commands (realgud:pdb realgud:trepan3k) ; run it from a Python file
)
;; ** real-time syntax check
(use-package flycheck
:defer t
)
(use-package sh-mode
:ensure-system-package shellcheck
:ensure nil
:hook (sh-mode . flycheck-mode))
;; ** yasnippet
;; from https://github.com/Schnouki/dotfiles/blob/master/emacs/init-30-yasnippet.el
(use-package yasnippet
:defer t
:config
(progn
;; Snippets dir:
;; - make sure the local one (~/.emacs.d/snippets) comes first
(setq yas-snippet-dirs
(cons "~/.emacs.d/snippets"
(cl-remove-if (lambda (item) (string-equal "~/.emacs.d/snippets" item))
yas-snippet-dirs)))
(yas-global-mode 1)))
(use-package yasnippet-snippets
:defer t
:after yasnippet
)
;; ** elpy (python)
(use-package elpy
:ensure-system-package
(
(pipx . "python -m pip install pipx")
(flake8 . "pipx install flake8 --include-deps")
(pylint . "pipx install pylint --include-deps"))
:commands elpy-enable
:custom
(elpy-rpc-python-command "~/.pyenv/versions/3.11.7/bin/python3.11")
(python-check-command "flake8")
(flycheck-python-flake8-executable "flake8")
(flycheck-python-pylint-executable "pylint")
(flycheck-pylintrc "pylintrc")
:init
;; https://github.com/jorgenschaefer/elpy/blob/master/docs/introduction.rst
(advice-add 'python-mode :before 'elpy-enable)
:config
;; flycheck
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook #'flycheck-mode))
(use-package blacken
:ensure-system-package (black . "pipx install black-macchiato --include-deps")
:ensure nil
:hook (python-mode . blacken-mode)
:custom
(blacken-only-if-project-is-blackened t)
)
(use-package idle-highlight-mode
:ensure nil
:hook ((python-mode . init:enable-idle-highlight-mode)
(emacs-lisp-mode . init:enable-idle-highlight-mode))
:config
(defun init:enable-idle-highlight-mode ()
(idle-highlight-mode t)))
(use-package gist
:defer 1
)
;; ** web-mode
(use-package web-mode
:ensure nil
:mode "\\.html?\\'")
;; ** yaml-mode
(use-package yaml-mode
:ensure nil
:mode "\\.yml\\'"
:bind ("C-m" . newline-and-indent))
;; ** typescript
(use-package tide
:after (typescript-mode company flycheck)
:hook ((typescript-mode . tide-setup)
(typescript-mode . tide-hl-identifier-mode)))
;; ** php
(use-package php-mode
:defer t
)
;; ** golang
(use-package flycheck-gometalinter
:defer t
:config
(progn
(flycheck-gometalinter-setup)))
;;; from https://github.com/mswift42/.emacs.d/blob/master/init.el
(use-package company-go
:defer t
:init
(with-eval-after-load 'company
(add-to-list 'company-backends 'company-go)))
(use-package go-mode
:defer t
)
(use-package go-eldoc
:defer t
:hook (go-mode-hook . go-eldoc-setup))
;; ** Dockerfile
(use-package dockerfile-mode
:defer t
)
;; ** hydra
(use-package hydra
:ensure nil
:init
(progn
;; https://github.com/abo-abo/hydra/wiki/Basics
(defhydra hydra-zoom (global-map "C-c")
"zoom"
("+" text-scale-increase "in")
("-" text-scale-decrease "out"))
;; *** C-c n/p - next/prev logical line
(defhydra hydra-logical-line (global-map "C-c")
"logical line"
("n" next-logical-line "next")
; note: "C-c p" is reserved for projectile
("p" previous-logical-line "prev" :bind nil))
;; *** https://github.com/abo-abo/hydra/wiki/Compilation
(defhydra hydra-next-error (global-map "C-x")
"
Compilation errors:
_j_: next error _h_: first error _q_uit
_k_: previous error _l_: last error
"
("`" next-error nil)
("j" next-error nil :bind nil)
("k" previous-error nil :bind nil)
("h" first-error nil :bind nil)
("l" (condition-case err
(while t
(next-error))
(user-error nil))
nil :bind nil)
("q" nil nil :color blue))
;; *** https://github.com/abo-abo/hydra/wiki/multiple-cursors
(global-set-key (kbd "C-c m") (defhydra hydra-multiple-cursors (:hint nil)
"
^Up^ ^Down^ ^Mark^ ^Edit^ ^Other^
--------------------------------------------------------------------------------------
[_p_] Next [_n_] Next [_a_] Mark all [_l_] Edit lines [_i_] Insert numbers
[_P_] Skip [_N_] Skip [_m_] Mark all dwim [_C-a_] Edit BOL [_R_] Reverse regions
[_M-p_] Unmark [_M-n_] Unmark [_r_] Mark by regexp [_C-e_] Edit EOL [_s_] Sort regions
^ ^ ^ ^ [_d_] Mark in defun [_C-'_] Hide unmatched [_q_] Quit
"
("a" mc/mark-all-like-this :exit t)
("d" mc/mark-all-symbols-like-this-in-defun :exit t)
("C-'" mc-hide-unmatched-lines-mode)
("i" mc/insert-numbers :exit t)
("n" mc/mark-next-like-this)
("N" mc/skip-to-next-like-this)
("l" mc/edit-lines :exit t)
("m" mc/mark-all-dwim :exit t)
("M-n" mc/unmark-next-like-this)
("p" mc/mark-previous-like-this)
("P" mc/skip-to-previous-like-this)
("M-p" mc/unmark-previous-like-this)
("r" mc/mark-all-in-region-regexp :exit t)
("R" mc/reverse-regions)
("s" mc/sort-regions)
("q" nil)
("C-a" mc/edit-beginnings-of-lines :exit t)
("C-e" mc/edit-ends-of-lines :exit t)))
;; *** https://github.com/abo-abo/hydra/wiki/Dired
(with-eval-after-load-feature 'dired
(define-key dired-mode-map "."
(defhydra hydra-dired (:hint nil :color pink)
"
_+_ mkdir _v_iew _m_ark _(_ details _i_nsert-subdir wdired
_C_opy _O_ view other _U_nmark all C-x C-q : edit
_D_elete _o_pen other _u_nmark _l_ redisplay _w_ kill-subdir C-c C-c : commit
_R_ename _M_ chmod _t_oggle _g_ revert buf ^ ^ C-c ESC : abort
_Y_ rel symlink _G_ chgrp ^ ^ _s_ort ^ ^
_S_ymlink ^ ^ _._ toggle hydra \\ flyspell
^ ^ ^ ^ ^ ^ ^ ^ _?_ summary
^ ^ _A_ find regexp
_Z_ compress _Q_ repl regexp
T - tag prefix
"
("(" dired-hide-details-mode)
("+" dired-create-directory)
("?" dired-summary)
("A" dired-do-find-regexp)
("C" dired-do-copy) ;; Copy all marked files
("D" dired-do-delete)
("G" dired-do-chgrp)
("g" revert-buffer) ;; read all directories again (refresh)
("i" dired-subtree-insert) ;; insert subtree under its line
("l" dired-do-redisplay) ;; relist the marked or singel directory
("M" dired-do-chmod)
("m" dired-mark)
("O" dired-display-file)
("o" dired-find-file-other-window)
("Q" dired-do-find-regexp-and-replace)
("R" dired-do-rename)
("S" dired-do-symlink)
("s" dired-sort-toggle-or-edit)
("t" dired-toggle-marks)
("U" dired-unmark-all-marks)
("u" dired-unmark)
("v" dired-view-file) ;; q to exit, s to search, = gets line #
("w" dired-kill-subdir)
("Y" dired-do-relsymlink)
("Z" dired-do-compress)
("q" nil :color blue)
("." nil :color blue))))
;; *** https://github.com/abo-abo/hydra/wiki/Rectangle-Operations
(with-eval-after-load-feature 'rect
(global-set-key
(kbd "C-c r")
(defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1)
:color pink
:hint nil
:post (deactivate-mark))
"
^_k_^ _w_ copy _o_pen _N_umber-lines |\\ -,,,--,,_
_h_ _l_ _y_ank _t_ype _e_xchange-point /,`.-'`' .. \-;;,_
^_j_^ _d_ kill _c_lear _r_eset-region-mark |,4- ) )_ .;.( `'-'
^^^^ _u_ndo _q_ quit ^ ^ '---''(./..)-'(_\_)
"
("k" rectangle-previous-line)
("j" rectangle-next-line)
("h" rectangle-backward-char)
("l" rectangle-forward-char)
("d" kill-rectangle) ;; C-x r k
("y" yank-rectangle) ;; C-x r y
("w" copy-rectangle-as-kill) ;; C-x r M-w
("o" open-rectangle) ;; C-x r o
("t" string-rectangle) ;; C-x r t
("c" clear-rectangle) ;; C-x r c
("e" rectangle-exchange-point-and-mark) ;; C-x C-x
("N" rectangle-number-lines) ;; C-x r N
("r" (if (region-active-p)
(deactivate-mark)
(rectangle-mark-mode 1)))
("u" undo nil)
("q" nil))))
;; *** Windows management
(progn
;; return to a previous window configuration easily with C-c <left>
(require 'winner)
(winner-mode)
; Navigate windows with s-<arrows>
(windmove-default-keybindings 'super)
(customize-set-variable 'windmove-wrap-around t)
;;
(customize-set-variable 'confirm-kill-processes nil)
;; https://github.com/erreina/.emacs.d/blob/master/init.d/init-keybindings.el
(require 'hydra-move-splitter)
(with-eval-after-load-feature (ivy counsel)
(global-set-key (kbd "C-c w") (defhydra hydra-window (:hint nil)
"
Movement^^ ^Split^ ^Switch^ ^Resize^
----------------------------------------------------------------
_j_ ← _v_ertical _b_uffer _J_ X←
_k_ ↓ _h_ horizontal _f_ind files _K_ X↓
_i_ ↑ _u_ undo _a_ce 1 _I_ X↑
_l_ → _r_ reset _s_ave _L_ X→
_q_ cancel _D_lt Other _S_wap _m_aximize
^ ^ _o_nly this _d_elete
"
("j" windmove-left )
("k" windmove-down )
("i" windmove-up )
("l" windmove-right )
("J" hydra-move-splitter-left)
("K" hydra-move-splitter-down)
("I" hydra-move-splitter-up)
("L" hydra-move-splitter-right)
("b" ivy-switch-buffer :color blue)
("B" ivy-switch-buffer)
("f" counsel-find-file :color blue)
("F" counsel-find-file)
("a" (lambda ()
(interactive)
(ace-window 1)
(add-hook 'ace-window-end-once-hook
'hydra-window/body)))
("h" (lambda ()
(interactive)
(split-window-right)
(windmove-right)))
("v" (lambda ()
(interactive)
(split-window-below)
(windmove-down)))
("S" (lambda ()
(interactive)
(ace-window 4)
(add-hook 'ace-window-end-once-hook
'hydra-window/body))
:color blue)
("s" save-buffer :color blue)
("d" delete-window :color blue)
("D" (lambda ()
(interactive)
(ace-window 16)
(add-hook 'ace-window-end-once-hook
'hydra-window/body)))
("o" delete-other-windows :color blue)
("O" delete-other-windows)
("m" ace-delete-other-windows :color blue)
("M" ace-delete-other-windows)
("u" (progn
(winner-undo)
(setq this-command 'winner-undo)))
("r" winner-redo)
("q" nil)))))))
;; *** PDF Tools https://github.com/abo-abo/hydra/wiki/PDF-Tools
(use-package pdf-tools
:config
(pdf-tools-install))
(with-eval-after-load-feature 'pdf-tools
(setq-default pdf-view-display-size #'fit-page)
(defhydra hydra-pdftools (:color blue :hint nil)
"
╭───────────┐
Move History Scale/Fit Annotations Search/Link Do │ PDF Tools │
╭──────────────────────────────────────────────────────────────────┴───────────╯
^^_g_^^ _B_ ^↧^ _+_ ^ ^ [_al_] list [_s_] search [_u_] revert buffer
^^^↑^^^ ^↑^ _H_ ^↑^ ↦ _W_ ↤ [_am_] markup [_o_] outline [_i_] info
^^_p_^^ ^ ^ ^↥^ _0_ ^ ^ [_at_] text [_F_] link [_d_] dark mode
^^^↑^^^ ^↓^ ╭─^─^─┐ ^↓^ ╭─^ ^─┐ [_ad_] delete [_f_] search link
_h_ ←pag_e_→ _l_ _N_ │ _P_ │ _-_ _b_ [_aa_] dired
^^^↓^^^ ^ ^ ╰─^─^─╯ ^ ^ ╰─^ ^─╯ [_y_] yank
^^_n_^^ ^ ^ _r_eset slice box
^^^↓^^^
^^_G_^^
--------------------------------------------------------------------------------
"
("\\" nil "back")
("<ESC>" nil "quit")
("al" pdf-annot-list-annotations)
("ad" pdf-annot-delete)
("aa" pdf-annot-attachment-dired)
("am" pdf-annot-add-markup-annotation)
("at" pdf-annot-add-text-annotation)
("y" pdf-view-kill-ring-save)
("+" pdf-view-enlarge :color red)
("-" pdf-view-shrink :color red)
("0" pdf-view-scale-reset)
("H" pdf-view-fit-height-to-window)
("W" pdf-view-fit-width-to-window)
("P" pdf-view-fit-page-to-window)
("n" pdf-view-next-page-command :color red)
("p" pdf-view-previous-page-command :color red)
("d" pdf-view-dark-minor-mode)
("b" pdf-view-set-slice-from-bounding-box)
("r" pdf-view-reset-slice)
("g" pdf-view-first-page)
("G" pdf-view-last-page)
("e" pdf-view-goto-page)
("o" pdf-outline)
("s" pdf-occur)
("i" pdf-misc-display-metadata)
("u" pdf-view-revert-buffer)
("F" pdf-links-action-perfom)
("f" pdf-links-isearch-link)
("B" pdf-history-backward :color red)
("N" pdf-history-forward :color red)
("l" image-forward-hscroll :color red)
("h" image-backward-hscroll :color red))
(progn
(define-key pdf-view-mode-map (kbd "\\") #'hydra-pdftools/body)
(define-key pdf-view-mode-map (kbd "<s-spc>") #'pdf-view-scroll-down-or-next-page)
(define-key pdf-view-mode-map (kbd "g") #'pdf-view-first-page)
(define-key pdf-view-mode-map (kbd "G") #'pdf-view-last-page)
(define-key pdf-view-mode-map (kbd "l") #'image-forward-hscroll)
(define-key pdf-view-mode-map (kbd "h") #'image-backward-hscroll)
(define-key pdf-view-mode-map (kbd "j") #'pdf-view-next-page)
(define-key pdf-view-mode-map (kbd "k") #'pdf-view-previous-page)
(define-key pdf-view-mode-map (kbd "e") #'pdf-view-goto-page)
(define-key pdf-view-mode-map (kbd "u") #'pdf-view-revert-buffer)
(define-key pdf-view-mode-map (kbd "al") #'pdf-annot-list-annotations)
(define-key pdf-view-mode-map (kbd "ad") #'pdf-annot-delete)
(define-key pdf-view-mode-map (kbd "aa") #'pdf-annot-attachment-dired)
(define-key pdf-view-mode-map (kbd "am") #'pdf-annot-add-markup-annotation)
(define-key pdf-view-mode-map (kbd "at") #'pdf-annot-add-text-annotation)
(define-key pdf-view-mode-map (kbd "y") #'pdf-view-kill-ring-save)
(define-key pdf-view-mode-map (kbd "i") #'pdf-misc-display-metadata)
(define-key pdf-view-mode-map (kbd "s") #'pdf-occur)
(define-key pdf-view-mode-map (kbd "b") #'pdf-view-set-slice-from-bounding-box)
(define-key pdf-view-mode-map (kbd "r") #'pdf-view-reset-slice)))
;; ** org-fc :: spaced repetition system SRS in emacs
(use-package org-fc
:load-path "~/src/org-fc"
:custom (org-fc-directories '("~/org/"))
:bind
("C-c f" . org-fc-hydra/body)
:config
(require 'org-fc-hydra))
;; ** misc
(progn
; uniquify buffers with the same name
; instead of buf<2>, etc it shows
(setq uniquify-buffer-name-style 'reverse)
(setq uniquify-after-kill-buffer-p t)
(setq uniquify-ignore-buffers-re "^\\*")
; enable recent files menu
(recentf-mode t)
(setq recentf-max-saved-items 100)
; use 4 spaces instead of tabs for indentation
; http://stackoverflow.com/a/471916/
(setq tab-width 4)
(setq tab-stop-list '(4 8 12 16 20 24 28 32 36 40 44 48 52 56 60 64 68 72 76 80))
;; Part of the Emacs Starter Kit
;; Registers allow you to jump to a file or other location
;; quickly. Use C-x r j followed by the letter of the register (i for
;; init.el) to jump to it.
;; You should add registers here for the files you edit most often.
(dolist (r `((?i (file . ,(expand-file-name "~/.emacs")))))
(set-register (car r) (cadr r)))
;; Commands which ask for a destination directory, such as those which
;; copy and rename files or create links for them, try to guess the
;; default target directory for the operation. Normally, they suggest
;; the Dired buffer's default directory, but if the variable
;; dired-dwim-target is non-nil, and if there is another Dired buffer
;; displayed in the next window, that other buffer's directory is
;; suggested instead.
(setq dired-dwim-target t)
;; [[~/src/emacs-starter-kit/starter-kit-bindings.el]]
;; . Indentation help
(global-set-key (kbd "C-x ^") #'join-line)
; [[https://github.com/dimitri/emacs-kicker/blob/master/init.el]]
; If you do use M-x term, you will notice there's line mode that acts like
; emacs buffers, and there's the default char mode that will send your
; input char-by-char, so that curses application see each of your key
; strokes.
;
; The default way to toggle between them is C-c C-j and C-c C-k, let's
; better use just one key to do the same.
(require 'term)
(define-key term-raw-map (kbd "C-'") #'term-line-mode)
(define-key term-mode-map (kbd "C-'") #'term-char-mode)
; Have C-y act as usual in term-mode, to avoid C-' C-y C-'
; Well the real default would be C-c C-j C-y C-c C-k.
(define-key term-raw-map (kbd "C-y") #'term-paste)
(global-unset-key (kbd "C-x C-c"))
; C-x C-j opens dired with the cursor right on the file you're editing
(require 'dired-x))
;; *** Insert directory subtree at point or remove it if it was not present
(use-package dired-subtree
:bind (:map dired-mode-map ("TAB" . dired-subtree-toggle)))
;; ** Save point position between sessions
(require 'saveplace)
(setq-default save-place t) ; set global default value for buffer local variable
(setq save-place-file (expand-file-name ".places" user-emacs-directory))
;; ** save minibuffer history
(use-package savehist
:ensure nil
:config (savehist-mode))
;; ** gnus
(with-eval-after-load "gnus"
(setq mm-discouraged-alternatives '("text/html" "text/richtext"))
(setq gnus-message-archive-group
'((if (message-news-p)
"sent-news"
"sent-mail")))
(setq gnus-use-adaptive-scoring t)
(setq gnus-score-expiry-days 14)
(setq gnus-default-adaptive-score-alist
'((gnus-unread-mark)
(gnus-ticked-mark (from 4))
(gnus-dormant-mark (from 5))
(gnus-saved-mark (from 20) (subject 5))
(gnus-del-mark (from -2) (subject -5))
(gnus-read-mark (from 2) (subject 1))
(gnus-killed-mark (from 0) (subject -3))))
(setq gnus-decay-scores t)
(setq gnus-global-score-files
'("~/gnus/scores/all.SCORE"))
;; all.SCORE contains:
(setq gnus-summary-expunge-below -999)
(setq gnus-summary-line-format "%O%U%R%z%d %B%(%[%4L: %-22,22f%]%) %s\n")
(setq gnus-summary-mode-line-format "Gnus: %p [%A / Sc:%4z] %Z")
(setq gnus-summary-same-subject "")
(setq gnus-sum-thread-tree-root "")
(setq gnus-sum-thread-tree-single-indent "")
(setq gnus-sum-thread-tree-leaf-with-other "+-> ")
(setq gnus-sum-thread-tree-vertical "|")
(setq gnus-sum-thread-tree-single-leaf "`-> ")
(setq message-generate-headers-first t)
(setq message-kill-buffer-on-exit t)
(add-hook 'message-mode-hook #'turn-on-auto-fill)
(add-hook 'message-sent-hook #'gnus-score-followup-article)
(add-hook 'message-sent-hook #'gnus-score-followup-thread)
(setq gnus-directory "~/gnus")
(setq message-directory "~/gnus/mail")
(setq nnml-directory "~/gnus/nnml-mail")
(setq gnus-article-save-directory "~/gnus/saved")
(setq gnus-kill-files-directory "~/gnus/scores")
(setq gnus-cache-directory "~/gnus/cache")
(add-hook 'dired-mode-hook #'turn-on-gnus-dired-mode)
(require 'gnus-registry)
(gnus-registry-initialize)
(setq gnus-visible-headers "^From:\\|^Newsgroups:\\|^Subject:\\|^Date:\\|^Followup-To:\\|^Reply-To:\\|^Summary:\\|^Keywords:\\|^To:\\|^[BGF]?Cc:\\|^Posted-To:\\|^Mail-Copies-To:\\|^Mail-Followup-To:\\|^Apparently-To:\\|^Gnus-Warning:\\|^Resent-From:\\|^X-Sent:\\|^User-Agent:\\|^X-Mailer:\\|^X-Newsreader:")
(setq gnus-sorted-header-list '("^From:" "^Subject:" "^Summary:" "^Keywords:" "^Newsgroups:" "^Followup-To:" "^To:" "^Cc:" "^Date:" "^User-Agent:" "^X-Mailer:" "^X-Newsreader:"))
(add-hook 'gnus-group-mode-hook #'gnus-topic-mode)
(define-key gnus-summary-mode-map [(meta up)] (lambda() (interactive) (scroll-other-window -1)))
(define-key gnus-summary-mode-map [(meta down)] (lambda() (interactive) (scroll-other-window 1)))
(define-key gnus-summary-mode-map [(control down)] #'gnus-summary-next-thread)
(define-key gnus-summary-mode-map [(control up)] #'gnus-summary-prev-thread)
(setq spam-directory "~/gnus/spam/")
(setq gnus-spam-process-newsgroups
'(("^gmane\\."
((spam spam-use-gmane)))))
(require 'spam))
;; ** irc
(defun irc-start ()
(interactive)
(.secrets-irc-start))
(with-eval-after-load "erc"
; IRC client (*nix only)
; . Make C-c RET (or C-c C-RET) send messages instead of RET.
(define-key erc-mode-map (kbd "RET") nil)
(define-key erc-mode-map (kbd "C-c RET") #'erc-send-current-line)
(define-key erc-mode-map (kbd "C-c C-RET") #'erc-send-current-line)
; Kill buffers for channels after /part
(setq erc-kill-buffer-on-part t)
; Kill buffers for private queries after quitting the server
(setq erc-kill-queries-on-quit t)
; Kill buffers for server messages after quitting the server
(setq erc-kill-server-buffer-on-quit t)
(setq erc-auto-query 'buffer) ; add a whois when someone pms
; keep erc from eating ram by truncating chat logs
(setq erc-max-buffer-size 20000)
(add-hook 'erc-insert-post-hook #'erc-truncate-buffer)
; Notify when someone mentions my nick.
; http://bbs.archlinux.org/viewtopic.php?id=40190
(defun erc-global-notify (matched-type nick msg)
(interactive)
(when (eq matched-type 'current-nick)
(shell-command
(concat "notify-send -t 4000 -c \"im.received\" \""
(car (split-string nick "!"))
" mentioned your nick\" \""
msg
"\""))))
(add-hook 'erc-text-matched-hook #'erc-global-notify))
;; ** misc
; * https://stackoverflow.com/questions/15390178/emacs-and-symbolic-links
(setq vc-follow-symlinks t)
; suppress Warning (mule): Invalid coding system `ascii' is specified
(define-coding-system-alias 'ascii 'us-ascii)
(setq compilation-ask-about-save nil)
(setq compilation-read-command nil)
; use 'y'/'n' instead of 'yes'/'no'
(fset 'yes-or-no-p 'y-or-n-p)
; whenever an external process changes a file underneath emacs, and there
; was no unsaved changes in the corresponding buffer, just revert its
; content to reflect what's on-disk.
(global-auto-revert-mode 1)
(column-number-mode) ; enable columns numbers globally, it has a performance hit
;;
(defun init-trailing-whitespace-hook ()
(setq show-trailing-whitespace t)
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
;; don't edit non programming files such as images (png, jpg, etc)
;; https://stackoverflow.com/questions/6138029/how-to-add-a-hook-to-only-run-in-a-particular-mode
(add-hook 'prog-mode-hook #'init-trailing-whitespace-hook)
;;; for some reason groovy mode is not derived from the prog mode
(add-hook 'groovy-mode-hook #'init-trailing-whitespace-hook)
(add-hook 'markdown-mode-hook #'init-trailing-whitespace-hook)
(add-hook 'yaml-mode-hook #'init-trailing-whitespace-hook)
; copy/kill line on M-w, C-w
(defun init:slickcopy (beg end &optional region)
"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)))))
(advice-add 'kill-ring-save :before #'init:slickcopy)
(defun init:slickcut (beg end &optional region)
"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)))))
(advice-add 'kill-region :before #'init:slickcut)
; http://www.emacswiki.org/emacs/BackupDirectory
(setq
backup-by-copying t ; don't clobber symlinks
backup-directory-alist
'(("." . "~/.saves")) ; don't litter my fs tree
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
vc-make-backup-files t ; make backups of files, even when they're in version control
version-control t) ; use versioned backups
; Open *.m in Octave-mode instead of ObjC
(setq auto-mode-alist
(cons
'("\\.m$" . octave-mode)
auto-mode-alist))
; style I want to use in c++ mode
; from http://www.emacswiki.org/emacs/CPlusPlusMode
(c-add-style "my-style"
'("python"
(indent-tabs-mode . nil) ; use spaces rather than tabs
(c-basic-offset . 2)))
(defun init:c-mode-common-hook ()
(c-set-style "my-style") ; use my-style defined above
(auto-fill-mode)
(c-toggle-auto-hungry-state 1))
(add-hook 'c-mode-common-hook #'init:c-mode-common-hook)
;; from https://emacs.stackexchange.com/questions/508/how-to-configure-specific-java-indentation
;; by @Sigma
(c-add-style "my-java-style"