-
Notifications
You must be signed in to change notification settings - Fork 0
/
dot_emacs
1346 lines (1171 loc) · 41.9 KB
/
dot_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
;;; package -- Summary
;;;
;;; Commentary:
;;;
;;; Written by Marc Henry de Frahan
;;;
;;; Required externals:
;;; - aspell or hunspell
;;; - emms-print-metadata
;;; - global
;;; - clang/llvm
;;; - ccls
;;; - mp3info
;;; - mpv
;;; - pianobar
;;; - shellcheck
;;; - vlc
;;; - vorbis-tools
;;;
;;; Code:
;;================================================================================
;;
;; Set up
;;
;;================================================================================
(setq custom-file (concat user-emacs-directory "custom.el"))
(when (file-exists-p custom-file)
(load custom-file 'noerror))
(setq inhibit-startup-screen t)
(setq kill-ring-max 200)
(setq user-full-name "Marc Henry de Frahan")
(set-face-attribute 'default nil :height 110)
;; never tabs
(setq-default indent-tabs-mode nil)
;; syntax color
(global-font-lock-mode t)
;; For accents. To toggle: C-\
(setq default-input-method "latin-1-prefix")
;;Turn alarm completely off
(setq ring-bell-function 'ignore )
;; Never follow symlinks (don't prompt to ask). This allows me to keep
;; the syntax coloring when editing a symlinked file (useful for the
;; dotfiles thing)
(setq vc-follow-symlinks nil)
;; Backup. A lot.
(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))
(setq delete-old-versions -1)
(setq version-control t)
(setq vc-make-backup-files t)
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/auto-save-list/" t)))
;; Change "yes or no" to "y or n"
(fset 'yes-or-no-p 'y-or-n-p)
;; warn when opening files bigger than 200MB
(setq large-file-warning-threshold 200000000)
;; silence warnings from native-comp
(setq native-comp-async-report-warnings-errors 'silent)
;;================================================================================
;;
;; Package management
;;
;;================================================================================
;; Enable the MELPA package repo (http://melpa.org/#/getting-started)
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package))
;;================================================================================
;;
;; recentf
;;
;;================================================================================
(use-package recentf
:config
(recentf-mode 1))
;;================================================================================
;;
;; Code completion
;;
;;================================================================================
(use-package yasnippet
:ensure t
:hook ((prog-mode . yas-minor-mode)))
(use-package company
:ensure t
:bind
;;("M-[" . company-complete-common)
:config
(use-package company-shell
:ensure t)
(setq company-show-numbers t
company-backends '((company-shell company-shell-env company-capf)))
(global-company-mode))
;;================================================================================
;;
;; LSP
;;
;;================================================================================
(use-package lsp-mode
:ensure t
:commands lsp
:hook ((c-mode c++-mode objc-mode python-mode bash-mode sh-mode) . lsp)
:bind
("C-c i" . lsp-format-region)
("C-c u" . lsp-format-buffer)
("C-c f d" . lsp-find-definition)
("C-c f r" . lsp-find-references)
("C-c f p" . xref-pop-marker-stack)
:config
(setq lsp-pyls-plugins-autopep8-enabled nil)
(setq lsp-pyls-plugins-yapf-enabled nil)
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]plt.+\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]chk.+\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]Submodules\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]Docs\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]submods\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]build\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]Build\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]AMR-WindGoldFiles\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]test_files\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]PeleCGoldFiles\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]tmp_build_dir\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]spack-build-.+\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\].spack-env\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/.cache\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/.tmp\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/configs\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/docs\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/env-templates\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/golds\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/repos\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/scripts\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/spack\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/spack-manager\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/spack-scripting\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/stage\\'")
(add-to-list 'lsp-file-watch-ignored-directories "[/\\\\]exawind-manager/tests\\'")
;; Increase garbage collection threshold
;; https://emacs-lsp.github.io/lsp-mode/page/performance/
;; https://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/
(setq gc-cons-threshold 100000000)
(defun my-minibuffer-setup-hook ()
(setq gc-cons-threshold most-positive-fixnum))
(defun my-minibuffer-exit-hook ()
(setq gc-cons-threshold 100000000))
(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)
;; Increase the amount of data which Emacs reads from the process
(setq read-process-output-max (* 1024 1024)) ;; 1mb
(use-package lsp-ui
:ensure t
:after (lsp-mode)
:hook (lsp-mode . lsp-ui-mode)
:bind
("C-c f u" . lsp-ui-imenu)
("C-c f D" . lsp-ui-peek-find-definitions)
("C-c f R" . lsp-ui-peek-find-references)
([remap xref-find-definitions] . lsp-ui-peek-find-definitions)
([remap xref-find-references] . lsp-ui-peek-find-references)
:config
(setq lsp-ui-flycheck-enable t))
;; Servers
;; ccls is in homebrew, to compile from source do:
;; $ git clone --depth=1 --recursive https://github.com/MaskRay/ccls
;; $ cd ccls
;; $ cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/opt/llvm -DCMAKE_CXX_COMPILER=/usr/local/opt/llvm/bin/clang++
;; $ VERBOSE=1 cmake --build Release
(use-package ccls
:ensure t
:after (lsp-mode)
:bind
("C-c f m" . ccls-member-hierarchy)
("C-c f i" . ccls-inheritance-hierarchy)
:hook ((c-mode c++-mode objc-mode) .
(lambda () (require 'ccls) (lsp))))
(setq lsp-prefer-flymake nil)
(setq lsp-file-watch-threshold 2000))
(use-package dap-mode
:ensure t
:after lsp-mode
:functions dap-hydra/nil
:config
(dap-register-debug-template
"LLDB::PeleG"
(list :type "lldb"
:cwd "/Users/mhenryde/combustion/Pele/PeleG/MyBuild"
:request "launch"
:program "pelec"
:args ["input-3d"]
:name "LLDB::PeleG"))
:hook ((after-init . dap-mode)
(dap-mode . dap-ui-mode)
(dap-mode . dap-tooltip-mode)
(dap-session-created . (lambda (_args) (dap-hydra)))
(dap-stopped . (lambda (_args) (dap-hydra)))
(dap-terminated . (lambda (&_rest) (dap-hydra/nil)))
((c-mode c++-mode objc-mode) . (lambda () (require 'dap-lldb)))))
;;================================================================================
;;
;; Syntax checking
;;
;;================================================================================
(use-package flycheck
:ensure t
:init
(global-flycheck-mode)
:config
(setq flycheck-python-flake8-executable "flake8"))
;; ;;================================================================================
;; ;;
;; ;; treesit
;; ;;
;; ;;================================================================================
;; (use-package treesit
;; :if (treesit-available-p)
;; :defer t
;; :init
;; (setq treesit-language-source-alist
;; '((bash . ("https://github.com/tree-sitter/tree-sitter-bash"))
;; (c . ("https://github.com/tree-sitter/tree-sitter-c"))
;; (cmake . ("https://github.com/uyha/tree-sitter-cmake"))
;; (cpp . ("https://github.com/tree-sitter/tree-sitter-cpp"))
;; (json . ("https://github.com/tree-sitter/tree-sitter-json"))
;; (julia . ("https://github.com/tree-sitter/tree-sitter-julia"))
;; (markdown . ("https://github.com/ikatyang/tree-sitter-markdown"))
;; (python . ("https://github.com/tree-sitter/tree-sitter-python"))
;; (toml . ("https://github.com/tree-sitter/tree-sitter-toml"))
;; (yaml . ("https://github.com/ikatyang/tree-sitter-yaml"))))
;; :config
;; (setq major-mode-remap-alist
;; '((bash-mode . bash-ts-mode)
;; (sh-mode . bash-ts-mode)
;; (c++-mode . c++-ts-mode)
;; (cmake-mode . cmake-ts-mode)
;; (python-mode . python-ts-mode)
;; (conf-toml-mode . toml-ts-mode)
;; (yaml-mode . yaml-ts-mode)))
;; (defun treesit-install-all-language-grammars ()
;; "Install all languages specified by `treesit-language-source-alist'."
;; (interactive)
;; (let ((languages (mapcar 'car treesit-language-source-alist)))
;; (dolist (lang languages)
;; (treesit-install-language-grammar lang)
;; (message "`%s' parser was installed." lang)
;; (sit-for 0.75)))))
;;================================================================================
;;
;; Projectile
;;
;;================================================================================
(use-package projectile
:ensure t
:bind
("C-c p a" . projectile-find-other-file)
("C-c p p" . projectile-switch-project)
("C-c p f" . projectile-find-file)
("C-c p d" . projectile-find-dir)
("C-c p b" . projectile-switch-to-buffer)
("C-c p e" . projectile-recentf)
:config
(setq projectile-globally-ignored-files
(append projectile-globally-ignored-files
'(".DS_Store" ".dir-locals.el" ".pyc"))
projectile-globally-ignored-directories
(append projectile-globally-ignored-directories
'("build" "__pycache__" "Build"))
projectile-enable-caching t
projectile-completion-system 'default)
(projectile-mode))
;;================================================================================
;;
;; Vertico
;;
;;================================================================================
(use-package vertico
:ensure t
:init
(vertico-mode)
:custom
(vertico-cycle t))
(use-package vertico-directory
:after vertico
:ensure nil
;; More convenient directory navigation commands
:bind (:map vertico-map
("RET" . vertico-directory-enter)
("DEL" . vertico-directory-delete-char)
("<right>" . vertico-directory-enter)
("<left>" . vertico-directory-delete-char)
("M-DEL" . vertico-directory-delete-word))
;; Tidy shadowed file names
:hook (rfn-eshadow-update-overlay . vertico-directory-tidy))
(use-package vertico-quick
:after vertico
:ensure nil
:bind (:map vertico-map
("C-i" . vertico-quick-insert)
("C-o" . vertico-quick-exit)))
;;================================================================================
;;
;; Orderless
;;
;;================================================================================
(use-package orderless
:ensure t
:init
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles partial-completion)))))
;;================================================================================
;;
;; savehist
;;
;;================================================================================
;; Persist history over Emacs restarts.
(use-package savehist
:init
(savehist-mode))
;;================================================================================
;;
;; Consult
;;
;;================================================================================
(use-package consult
:bind
(("C-c h" . consult-history)
("C-x b" . consult-buffer)
("M-g g" . consult-goto-line)
("M-g M-g" . consult-goto-line)
("C-c g" . consult-git-grep)
("C-c s" . consult-git-grep-symbol-at-point)
("C-s" . consult-line-symbol-at-point)
("C-r" . consult-line-symbol-at-point))
:config
(defun consult-line-symbol-at-point ()
"Use symbol at point for consult-line."
(interactive)
(consult-line (thing-at-point 'symbol)))
(defun consult-git-grep-symbol-at-point ()
"Use symbol at point for consult-git-grep."
(interactive)
(require 'project)
(consult-git-grep (project-root (project-current)) (thing-at-point 'symbol))))
(use-package consult-company
:ensure t
:after (consult company)
:config
(define-key company-mode-map [remap completion-at-point] #'consult-company))
(use-package consult-lsp
:ensure t
:after (consult lsp))
(use-package consult-projectile
:ensure t
:after (consult projectile)
:bind
("C-c p h" . consult-projectile)
([remap projectile-switch-project] . consult-projectile-switch-project)
([remap projectile-find-file] . consult-projectile-find-file)
([remap projectile-find-dir] . consult-projectile-find-dir)
([remap projectile-switch-to-buffer] . consult-projectile-switch-to-buffer)
([remap projectile-recentf] . consult-projectile-recentf))
;;================================================================================
;;
;; Embark
;;
;;================================================================================
(use-package embark
:ensure t
:after consult
:bind
(("M-." . embark-act)
("M-," . embark-dwim)
:map embark-general-map
("C-s" . consult-line)
("C-c g" . embark-consult-git-grep))
:custom
(embark-help-key "?")
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
:config
(defun embark-consult-git-grep (target)
"Use consult-git-grep on target."
(consult-git-grep nil target))
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
(use-package embark-consult
:ensure t
:after (embark consult)
:demand t
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;;================================================================================
;;
;; Enable richer annotations using the Marginalia package
;;
;;================================================================================
(use-package marginalia
:ensure t
:init
(marginalia-mode))
;;================================================================================
;;
;; Moving around with avy
;;
;;================================================================================
(use-package avy
:ensure t
:bind
("M-;" . avy-goto-char-timer)
("M-j" . hydra-avy/body)
:config
(defhydra hydra-avy (:exit t :hint nil)
"
Line^^ Region^^ Goto
----------------------------------------------------------
[_y_] yank [_Y_] yank [_c_] timed char
[_m_] move [_M_] move [_w_] word
[_k_] kill [_K_] kill [_l_] line [_L_] end of line"
("c" avy-goto-char-timer)
("w" avy-goto-word-1)
("l" avy-goto-line)
("L" avy-goto-end-of-line)
("m" avy-move-line)
("M" avy-move-region)
("k" avy-kill-whole-line)
("K" avy-kill-region)
("y" avy-copy-line)
("Y" avy-copy-region)))
;;================================================================================
;;
;; Navigating windows with ace-window
;;
;;================================================================================
(use-package ace-window
:ensure t
:bind ("M-o" . ace-window)
:config
(setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))
;;================================================================================
;;
;; Wgrep
;;
;;================================================================================
(use-package wgrep
:ensure t)
;;================================================================================
;;
;; Kill current buffer, but ask to save, but only if it has been modified
;;
;;================================================================================
;; Based on
;; http://ergoemacs.org/emacs/elisp_close_buffer_open_last_closed.html
;; and
;; http://stackoverflow.com/questions/2357881/emacs-cant-get-buffer-offer-save-working
(defun kill-this-buffer-volatile ()
"Kill current buffer, even if it has been modified. But ask to save first."
(interactive)
(if (buffer-modified-p)
(if (y-or-n-p (format "Buffer %s modified; Do you want to save? " (buffer-name)))
(save-buffer)))
(kill-this-buffer))
;; set the hotkey
(global-set-key (kbd "C-x C-k") 'kill-this-buffer-volatile)
;;================================================================================
;;
;; C/C++
;;
;;================================================================================
(use-package cc-mode
:mode
("\\.geo" . c++-mode) ;; Gmsh files
("\\.cu$" . c++-mode) ;; CUDA files
("\\.C$" . c++-mode)
("\\.H$" . c++-mode)
:bind
("C-M-l" . forloop)
("C-M-p" . printf-binding)
:after (projectile)
:config
(use-package modern-cpp-font-lock
:ensure t
:hook (c++-mode . modern-c++-font-lock-mode))
(c-add-style "my-cpp-style"
'("stroustrup"
(c-offsets-alist
(innamespace . 0)
(inline-open . 0)
(arglist-close . 0))))
(defun my-cpp-mode-hook ()
(add-to-list 'projectile-other-file-alist
'("C" "H" "hpp" "hxx"))
(add-to-list 'projectile-other-file-alist
'("H" "cpp"))
(c-set-style "my-cpp-style")
(setq c-basic-offset 2))
(add-hook 'c++-mode-hook 'my-cpp-mode-hook)
(defun printf-binding (out vars)
"Binding for printf to make things easier. OUT is the output string and VARS is the variables to printf."
(interactive "MOutput:\nMVariables:")
(let ((beg (point)))
(insert "printf(\"" out "\\n\"," vars ");")
(indent-region beg (point))))
(defun forloop (i imax)
"Build a C/C++ for loop given I and IMAX."
(interactive "Miterator:\nMmax:")
(let ((beg (point)))
(insert "for(int " i "=0; " i "<" imax "; " i "++){\n\n}")
(indent-region beg (point))
(forward-line -1)
(c-indent-command))))
;;================================================================================
;;
;; Clang formatting
;;
;;================================================================================
(use-package clang-format
:ensure t)
;;================================================================================
;;
;; Fortran
;;
;;================================================================================
(use-package fortran
:init
;; Make Fortran indent at the level of the code. Not a fixed width.
(add-hook 'f90-mode-hook
(lambda ()
(setq fortran-comment-indent-style 'relative))))
;;================================================================================
;;
;; Matlab
;;
;;================================================================================
(use-package matlab
:ensure matlab-mode)
;;================================================================================
;;
;; Latex
;;
;;================================================================================
(use-package latex
:ensure auctex
:mode
("\\.tex\\'" . latex-mode)
:commands (latex-mode LaTeX-mode plain-tex-mode)
:bind
("C-c %" . replace-newlines-with-percent-in-region)
("M-F" . insert-figure-reference)
("M-E" . insert-equation-reference)
("M-T" . insert-table-reference)
("M-H" . insert-chapter-reference)
("M-G" . insert-appendix-reference)
("M-L (" . insert-left-right-paren)
("M-L {" . insert-left-right-brace)
("M-L [" . insert-left-right-bracket)
:config
(add-to-list 'TeX-command-list
'("Make" "make" TeX-run-compile nil t
:help "Compile with Makefile"))
;; function to replace all \n with %\n in a region. Useful for latex
;; when you are in the minipage environment.
(defun replace-newlines-with-percent-in-region ()
"Replace newlines with %\n in region."
(interactive)
(save-restriction
(narrow-to-region (point) (mark))
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match "%\n" nil t))))
(defun insert-figure-reference ()
"Insert a figure reference for LaTex."
(interactive)
(insert "Figure\\,\\ref{fig:}") (backward-char 1))
(defun insert-equation-reference ()
"Insert an equation reference for LaTex."
(interactive)
(insert "Equation\\,(\\ref{eq:})") (backward-char 2))
(defun insert-table-reference ()
"Insert a table reference for LaTex."
(interactive)
(insert "Table\\,\\ref{tab:}") (backward-char 1))
(defun insert-chapter-reference ()
"Insert a chapter reference for LaTex."
(interactive)
(insert "Chapter\\,\\ref{chap:}") (backward-char 1))
(defun insert-appendix-reference ()
"Insert an appendix reference for LaTex."
(interactive)
(insert "Appendix\\,\\ref{app:}") (backward-char 1))
(defun insert-left-right-paren ()
"Insert a left right paren for LaTex math mode."
(interactive)
(insert "\\left( \\right)") (backward-char 8))
(defun insert-left-right-brace ()
"Insert a left right brace for LaTex math mode."
(interactive)
(insert "\\left\\{ \\right\\}") (backward-char 9))
(defun insert-left-right-bracket ()
"Insert a left right bracket for LaTex math mode."
(interactive)
(insert "\\left[ \\right]") (backward-char 8))
(setq TeX-auto-save t
TeX-newline-function 'reindent-then-newline-and-indent
TeX-parse-self t))
(use-package bibtex
:ensure t
:mode ("\\.bib" . bibtex-mode))
;;================================================================================
;;
;; Dictionary stuff
;;
;;================================================================================
(use-package ispell
:ensure t
:config
(cond
((executable-find "hunspell")
(setq ispell-program-name "hunspell")
(setq ispell-extra-args '("-d en_US")))
(executable-find "aspell")
(setq ispell-program-name "aspell")
(setq ispell-extra-args '("--sug-mode=ultra"
"--lang=en_US")))
;; Switch dictionaries
(defun fd-switch-dictionary()
"Binding to switch between dictionaries."
(interactive)
(let* ((dic ispell-current-dictionary)
(change (if (string= dic "francais") "en_US" "francais")))
(ispell-change-dictionary change)
(message "Dictionary switched from %s to %s" dic change)
))
(use-package flyspell
:ensure t
:config
(use-package flyspell-correct
:ensure t
:bind
;;("C-c s" . 'flyspell-correct-previous-word-generic)
)
;; No spell check for embedded snippets in org-mode
;; From http://emacs.stackexchange.com/questions/9333/how-does-one-use-flyspell-in-org-buffers-without-flyspell-triggering-on-tangled/9347#9347
(defadvice org-mode-flyspell-verify (after org-mode-flyspell-verify-hack activate)
(let ((rlt ad-return-value)
(begin-regexp "^[ \t]*#\\+begin_\\(src\\|html\\|latex\\)")
(end-regexp "^[ \t]*#\\+end_\\(src\\|html\\|latex\\)")
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)))
;; No spell check for code snippets in Markdown
(defun flyspell-generic-textmode-verify ()
"Used for `flyspell-generic-check-word-predicate' in text modes."
;; (point) is next char after the word. Must check one char before.
(let ((f (get-text-property (- (point) 1) 'face)))
(not (memq f '(markdown-pre-face)))))
(setq flyspell-generic-check-word-predicate 'flyspell-generic-textmode-verify)
(add-hook 'text-mode-hook #'flyspell-mode)
(add-hook 'org-mode-hook #'flyspell-mode)
(add-hook 'latex-mode-hook #'flyspell-mode)
(add-hook 'tex-mode-hook #'flyspell-mode)
(add-hook 'prog-mode-hook #'flyspell-prog-mode)))
;;================================================================================
;;
;; Color theme
;;
;;================================================================================
(use-package reverse-theme
:ensure t)
(use-package zenburn-theme
:ensure t
:init
(load-theme 'zenburn t))
;;================================================================================
;;
;; Mode line
;;
;;================================================================================
(use-package minions
:ensure t
:config
(minions-mode 1))
(use-package doom-modeline
:ensure t
:config
(doom-modeline-mode 1)
(setq doom-modeline-minor-modes t))
;;================================================================================
;;
;; Anzu
;;
;;================================================================================
(use-package anzu
:ensure t
:bind
("M-%" . anzu-query-replace)
:config
(global-anzu-mode 1))
;;================================================================================
;;
;; Icons
;;
;;================================================================================
(use-package all-the-icons
:ensure t
:if (display-graphic-p))
(use-package all-the-icons-completion
:ensure t
:after all-the-icons
:if (display-graphic-p)
:config
(all-the-icons-completion-mode))
;;================================================================================
;;
;; OSX specific
;;
;;================================================================================
(if (eq system-type 'darwin)
(when (display-graphic-p)
(setq mac-command-modifier 'control)))
;;================================================================================
;;
;; Shell editing
;;
;;================================================================================
(use-package sh-script
:mode
("\\.zsh" . sh-mode)
("\\.pbs" . sh-mode))
;;================================================================================
;;
;; Word counting
;;
;;================================================================================
(use-package wc-mode
:ensure t
:bind
("\C-cw" . wc-mode))
;;================================================================================
;;
;; Org-mode
;;
;;================================================================================
(use-package org
:ensure t
:bind
("C-c a" . org-agenda)
:init
(setq org-startup-truncated nil)
(setq org-log-done 'note)
(setq org-lowest-priority ?E)
(setq org-agenda-files '("~/org/work.org" "~/org/di.org")))
;;================================================================================
;;
;; ESS
;;
;;================================================================================
(use-package ess-site
:ensure ess
:mode
("\\.R\\'" . R-mode)
("\\.Rprofile" . R-mode)
:commands R
:config
;; inspiration for the following:
;; http://stats.blogoverflow.com/2011/08/using-emacs-to-work-with-r/
;; save more commands
(setq comint-input-ring-size 1000)
;; "This recalls the R statement from your R statement history, but it
;; tries to match it with the one which is already on your line."
(add-hook 'inferior-ess-mode-hook
(lambda nil
(define-key inferior-ess-mode-map [\C-up]
'comint-previous-matching-input-from-input)
(define-key inferior-ess-mode-map [\C-down]
'comint-next-matching-input-from-input)
(define-key inferior-ess-mode-map [\C-x \t]
'comint-dynamic-complete-filename)))
;; To assign ":" to "<-" and to stop the assignment of underscore
;; (underbar) "_" to "<-"
(setq ess-smart-S-assign-key ":")
(ess-toggle-S-assign nil)
(ess-toggle-S-assign nil)
(ess-toggle-underscore nil))
;;================================================================================
;;
;; Markdown and polymode
;;
;;================================================================================
(use-package markdown-mode
:ensure t
:mode
("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
(use-package polymode
:ensure t
:mode
("\\.Snw" . poly-noweb+r-mode)
("\\.Rnw" . poly-noweb+r-mode)
("\\.Rmd" . poly-markdown+r-mode))
;;================================================================================
;;
;; reStructuredText
;;
;;================================================================================
(use-package rst
:ensure t
:mode
("\\.rst$" . rst-mode)
("\\.rest$" . rst-mode))
;;================================================================================
;;
;; Python
;;
;;================================================================================
(use-package python)
;; add this to autoformat before saving:
;; :hook ((python-mode . (lambda () (add-hook 'before-save-hook 'lsp-format-buffer nil 'local)))))
(use-package pyvenv
:ensure t
:config
(pyvenv-workon "dotfiles"))
(use-package jedi
:ensure t)
;;================================================================================
;;
;; Git
;;
;;================================================================================
(use-package magit
:ensure t
:bind
("M-m" . magit-status))
;;================================================================================
;;
;; Haskell
;;
;;================================================================================
(use-package haskell-mode
:ensure t
:mode
("\\.hs\\'" . haskell-mode)
("\\.lhs\\'" . haskell-mode))
;;================================================================================
;;
;; YAML
;;
;;================================================================================