-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
2409 lines (1795 loc) · 85.3 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
;; Fix issue: Failed to download ‘melpa-stable’ archive.
;; Ref: https://melpa.org/#/getting-started
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
;; (require 'package)
;; (add-to-list 'package-archives
;; '("melpa-stable" . "https://stable.melpa.org/packages/"))
;; (add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
;;
;; (package-initialize)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; Comment/uncomment this line to enable MELPA Stable if desired. See `package-archive-priorities`
;; and `package-pinned-packages`. Most users will not need or want to do this.
;;(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "https://orgmode.org/elpa/") t)
(package-initialize)
;; For org-mode
;; =============================================================================
(add-to-list 'load-path "~/Documents/emacs-downloads/org-9.1.9/lisp")
(add-to-list 'load-path "~/Documents/emacs-downloads/org-9.1.9/contrib/lisp" t)
;; Custom variables/faces
;; =============================================================================
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(beacon-mode t)
'(custom-enabled-themes (quote (night-owl)))
'(custom-safe-themes
(quote
("82d2cac368ccdec2fcc7573f24c3f79654b78bf133096f9b40c20d97ec1d8016" "bb08c73af94ee74453c90422485b29e5643b73b05e8de029a6909af6a3fb3f58" "3c83b3676d796422704082049fc38b6966bcad960f896669dfc21a7a37a748fa" "4aa183d57d30044180d5be743c9bd5bf1dde686859b1ba607b2eea26fe63f491" "039399f7bf49e440fee74e17e77c6ad982a6336831769e51958b02db6ed77952" "7673563371dcabdad088479a99950c9e96b59f12fd8018b90726c545fdcc4843" "addb8dddf1706c88f77205c339db3189968216b8b0f04ab5f3a3cb47a41b2c9c" "21fb497b14820147b2b214e640b3c5ee19fcadc15bc288e3c16c9c9575d95d66" "bfdcbf0d33f3376a956707e746d10f3ef2d8d9caa1c214361c9c08f00a1c8409" "40da996f3246a3e99a2dff2c6b78e65307382f23db161b8316a5440b037eb72c" default)))
'(doc-view-continuous t)
'(fci-rule-color "gray50")
'(highlight-indent-guides-auto-character-face-perc 20)
'(highlight-indent-guides-method (quote character))
'(initial-buffer-choice "~/projects")
'(line-spacing 0.15)
'(markdown-command "/usr/local/bin/pandoc")
'(org-bullets-bullet-list (quote ("❊" "▶" "▶" "✸" "✿" "◉")))
'(org-format-latex-options
(quote
(:foreground default :background default :scale 1.5 :html-foreground "white" :html-background "Transparent" :html-scale 1.0 :matchers
("begin" "$1" "$" "$$" "\\(" "\\["))))
'(org-hide-emphasis-markers t)
'(org-indirect-buffer-display (quote other-window))
'(org-replace-disputed-keys t)
'(org-use-speed-commands t)
'(outshine-use-speed-commands t)
'(package-selected-packages
(quote
(highlight-indent-guides bicycle quarto-mode color-theme-sanityinc-tomorrow zenburn-theme langtool org-superstar poly-R poly-markdown polymode adaptive-wrap ess fold-this night-owl-theme multi-term ess-R-data-view writegood-mode outshine undo-tree eink-theme tramp-theme emamux org-download fold-dwim ov ox-pandoc org company-shell company flycheck org-babel-eval-in-repl use-package benchmark-init osx-dictionary evil-search-highlight-persist synosaurus rainbow-delimiters nord-theme pdf-tools auctex htmlize highlight-parentheses git-gutter-fringe fringe-helper git-gutter visual-fill-column zotxt swiper pandoc-mode multiple-cursors markdown-mode magit json-mode exec-path-from-shell elpy csv-mode cl-lib-highlight auto-complete))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(cursor ((t (:background "forest green"))))
'(ess-constant-face ((t (:inherit font-lock-type-face :foreground "#60CD9D"))))
'(ess-function-call-face ((t (:inherit font-lock-function-name-face :foreground "HotPink3" :slant oblique))))
'(ess-paren-face ((t (:inherit font-lock-constant-face :foreground "#608FCD"))))
'(font-lock-comment-delimiter-face ((t (:foreground "SkyBlue4"))))
'(font-lock-comment-face ((t (:foreground "SkyBlue4"))))
'(font-lock-string-face ((t (:foreground "#CD9D60"))))
'(font-lock-warning-face ((t (:foreground "forest green" :slant normal :weight normal))))
'(helm-selection ((t (:background "dark magenta" :distant-foreground "yellow3"))))
'(hi-yellow ((t (:background "saddle brown" :foreground "gold1"))))
'(highlight-changes ((t (:foreground "DodgerBlue3" :underline t :slant oblique))))
'(highlight-changes-delete ((t (:foreground "IndianRed3" :underline t))))
'(isearch ((t (:background "orange3" :foreground "White"))))
'(ivy-current-match ((t (:background "#010F1D" :foreground "forest green"))))
'(markdown-header-face-1 ((t (:inherit markdown-header-face :slant italic :height 2.0 :family "Baskerville"))))
'(markdown-header-face-2 ((t (:inherit markdown-header-face :slant italic :weight normal :height 1.7 :family "Baskerville"))))
'(markdown-header-face-3 ((t (:inherit markdown-header-face :slant italic :height 1.15 :family "Baskerville"))))
'(match ((t (:background "RoyalBlue4" :foreground "gray100"))))
'(mode-line ((t (:background "#191970" :foreground "#D6DEEB" :box (:line-width 1 :color "#2F4F2F")))))
'(mode-line-buffer-id ((t (:foreground "#D6DEEB" :weight normal))))
'(mode-line-inactive ((t (:background "#383838" :foreground "#676E95" :box (:line-width 1 :color "#2F4F2F")))))
'(org-block ((t (:background "#141414" :foreground "#8BA2B6"))))
'(org-block-begin-line ((t (:background "#141414" :foreground "#8BA2B6" :slant italic))))
'(org-block-end-line ((t (:background "#141414" :foreground "#8BA2B6" :slant italic))))
'(org-code ((t (:inherit (shadow fixed-pitch)))))
'(org-document-info ((t (:foreground "dark orange"))))
'(org-document-info-keyword ((t (:inherit (shadow fixed-pitch)))))
'(org-document-title ((t (:foreground "#FFFFFF" :weight normal :height 1))))
'(org-indent ((t (:inherit (org-hide fixed-pitch)))))
'(org-level-1 ((t (:inherit outline-1 :foreground "#d47500" :weight normal :height 1.1))))
'(org-level-2 ((t (:inherit outline-2 :foreground "#009652" :weight normal :height 1.1))))
'(org-level-3 ((t (:inherit outline-3 :foreground "#0077BD" :weight normal :height 1.1))))
'(org-level-4 ((t (:inherit default :weight bold :foreground "dark gray" :font "Lucida Grande" :height 1.1))))
'(org-level-5 ((t (:inherit default :weight bold :foreground "dark gray" :font "Lucida Grande"))))
'(org-level-6 ((t (:inherit default :weight bold :foreground "dark gray" :font "Lucida Grande"))))
'(org-level-7 ((t (:inherit default :weight bold :foreground "dark gray" :font "Lucida Grande"))))
'(org-level-8 ((t (:inherit default :weight bold :foreground "dark gray" :font "Lucida Grande"))))
'(org-link ((t (:foreground "royal blue" :underline t))))
'(org-meta-line ((t (:inherit (font-lock-comment-face fixed-pitch)))))
'(org-property-value ((t (:inherit fixed-pitch))) t)
'(org-special-keyword ((t (:inherit (font-lock-comment-face fixed-pitch)))))
'(org-table ((t (:inherit fixed-pitch :foreground "#83a598"))))
'(org-tag ((t (:inherit (shadow fixed-pitch) :weight bold :height 0.8))))
'(org-verbatim ((t (:inherit (shadow fixed-pitch)))))
'(outline-3 ((t (:inherit font-lock-keyword-face :foreground "DodgerBlue3"))))
'(outshine-level-1 ((t (:foreground "#4DB6CF" :weight extra-bold :height 1.2))))
'(outshine-level-2 ((t (:foreground "goldenrod2" :weight normal :height 1.2))))
'(outshine-level-3 ((t (:foreground "tan3" :height 1.2))))
'(region ((t (:background "dark green" :foreground "#f6f3e8"))))
'(swiper-line-face ((t (:inherit highlight :background "#010F1D" :foreground "forest green"))))
'(swiper-match-face-2 ((t (:background "#4F002B" :foreground "forest green" :weight semi-bold))))
'(variable-pitch ((t (:height 1.05 :family "verdana"))))
'(writegood-duplicates-face ((t (:background "LightGoldenrod1" :foreground "deep pink" :slant italic))))
'(writegood-passive-voice-face ((t (:underline "DodgerBlue1"))))
'(writegood-weasels-face ((t (:underline "SlateGray4")))))
;; ESS
;; =============================================================================
(add-to-list 'load-path "/Users/nistara/Documents/ESS/lisp") ;;for R
(require 'ess-site)
;; (load "ess-site")
;; ref for updated ess: https://stackoverflow.com/a/52315071/5443003
;; Benchmark init
;; =============================================================================
;; ref: https://github.com/dholm/benchmark-init-el
(require 'benchmark-init)
;; To disable collection of benchmark data after init is done.
(add-hook 'after-init-hook 'benchmark-init/deactivate)
;; use package and elpy
;; =============================================================================
;; Note: If I edit bits of this section I can't load org-ref for some reason
;; Possibly some dependency/loading issue:
;; Error: load-with-code-conversion: Symbol’s value as variable is void: <!DOCTYPE
;; This is only needed once, near the top of the file
(eval-when-compile
;; Following line is not needed if use-package.el is in ~/.emacs.d
;; (add-to-list 'load-path "<path where use-package is installed>")
(require 'use-package))
(require 'package)
(add-to-list 'package-archives
'("elpy" . "http://jorgenschaefer.github.io/packages/"))
(package-initialize)
(elpy-enable)
;; Get terminal's customizations
;; =============================================================================
(when (memq window-system '(mac ns));;
(exec-path-from-shell-initialize))
;; To get emacs to use the anaconda python 3, else it was using the older python 2
;; =============================================================================
;; (setq python-shell-interpreter "/Users/nistara/anaconda3/bin/python")
;;(elpy-use-ipython)
;;add-hook 'python-mode-hook #'(lambda () (setq py-python-command "/usr/local/Cellar/python3/3.5.1/bin/python3")))
;; For correcting tab and space issue
(add-hook 'inferior-python-mode-hook
(lambda ()
(setq
indent-tabs-mode nil ;; i.e. indent with spaces
tab-width 4 ;; i.e. tabs consts of 4 spaces
)))
;; Smart underscore
;; =============================================================================
;; ref: http://jmonlong.github.io/Hippocamplus/emacs/#smart-underscores
(add-to-list 'load-path "/Users/nistara/Documents/emacs-downloads")
(require 'ess-smart-underscore)
(setq ess-S-underscore-when-last-character-is-a-space t)
;; ;; For polymode. From https://github.com/vspinu/polymode
;; ;; =============================================================================
;; (setq load-path
;; (append '("/Users/nistara/Documents/emacs-downloads/polymode" "/Users/nistara/Documents/emacs-downloads/polymode/modes")
;; load-path))
;; (require 'poly-R)
;; (require 'poly-markdown)
;; ;;; MARKDOWN
;; ;; =============================================================================
;; (add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))
;;
;; ;;; R modes
;; (add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
;; (add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
;; (add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))(add-to-list 'auto-mode-alist '("\\.Rmd\\'" . poly-markdown+r-mode))
;; keybinding for occur
;; =============================================================================
(global-set-key (kbd "C-c o") 'occur)
;; stop indenting after single '#':
;; =============================================================================
;; http://stackoverflow.com/questions/780796/emacs-ess-mode-tabbing-for-comment-region
(setq ess-fancy-comments nil)
;; (add-hook 'ess-mode-hook
;; (lambda ()
;; (local-set-key (kbd "RET") 'newline)))
;; (defun my-ess-settings ()
;; (setq ess-indent-with-fancy-comments nil))
;; (add-hook 'ess-mode-hook #'my-ess-settings)
;; ESS Keybinding for C-RET so that I can use Cmd-RET as well
;; =============================================================================
;; https://stat.ethz.ch/pipermail/ess-help/2013-November/009530.html
(define-key ess-mode-map (kbd "<s-return>") 'ess-eval-region-or-line-and-step)
(define-key ess-mode-map (kbd "<M-return>") 'ess-eval-line)
;; multiple cursors
;; =============================================================================
;; ref: http://pragmaticemacs.com/emacs/multiple-cursors/
(global-set-key (kbd "C-c m c") 'mc/edit-lines)
;; move-lines.el
;; =============================================================================
;; ref: https://github.com/targzeta/move-lines
(require 'move-lines)
(move-lines-binding)
;; ESS switch between the R command line and the file
;; =============================================================================
(global-set-key [C-tab] 'other-window)
;; ;; Backward-kill-line shortcut: http://emacsredux.com/blog/2013/04/08/kill-line-backward/
;; (global-set-key (kbd "<s-backspace>") (lambda ()
;; (interactive)
;; (kill-line 0)))
;; Kill whole line (because I wanted to delete from anywhere in line)
;; =============================================================================
(global-set-key (kbd "s-d") 'kill-whole-line)
;; Backward kill line
;; =============================================================================
;; ref:https://www.emacswiki.org/emacs/BackwardKillLine
(defun backward-kill-line (arg)
"Kill ARG lines backward."
(interactive "p")
(kill-line (- 1 arg)))
(global-set-key (kbd "<s-backspace>") 'backward-kill-line)
;; Switching between visible windows easily:
;; =============================================================================
;; http://emacs.stackexchange.com/questions/3458/how-to-switch-between-windows-quickly
(windmove-default-keybindings)
;; Create shortcut for 'M-x buffer-menu'
;; =============================================================================
;; (global-set-key (kbd "s-b") 'buffer-menu)
(global-set-key (kbd "s-b") 'ibuffer)
;; Allows use of erase-buffer (first time use sets this command):
;; =============================================================================
;; ref: http://stackoverflow.com/questions/4886745/emacs-what-is-the-shortcut-key-to-clear-buffer
(put 'erase-buffer 'disabled nil)
;; Erase buffer (something like ctrl-l)
(global-set-key (kbd "C-l") 'erase-buffer)
;; Getting emacs to use the 'Marked' app
;; =============================================================================
;; http://superuser.com/questions/569517/is-there-an-extension-that-previews-markdown-instantly
(defun markdown-preview-file ()
"run Marked on the current file and revert the buffer"
(interactive)
(shell-command
(format "open -a /Applications/Marked\\ 2.app %s"
(shell-quote-argument (buffer-file-name))))
)
(eval-after-load 'markdown-mode
'(define-key markdown-mode-map (kbd "C-x p") 'markdown-preview-file)
)
;; Fix markdown-mode's hijacking of left-word and right-word
;; =============================================================================
;; https://www.reddit.com/r/emacs/comments/51zyda/markdown_mode_hijacked_leftword_and_rightword/d7g9ix1/
;; (eval-after-load "markdown-mode"
;; '(progn
;; (define-key markdown-mode-map (kbd "M-<left>") nil)
;; (define-key markdown-mode-map (kbd "M-<right>") nil)))
;; Replace highlighted text with what I type?:
;; =============================================================================
;; https://www.gnu.org/software/emacs/manual/html_node/efaq/Replacing-highlighted-text.html
(delete-selection-mode 1)
;; Keybinding to use CMD-Left/Right to move through lines
;; =============================================================================
(global-set-key (kbd "<s-right>") 'move-end-of-line)
(global-set-key (kbd "<s-left>") 'move-beginning-of-line)
;; (global-set-key (kbd "<s-left>") 'comint-bol-or-process-mark)
;; Highlight or color characters written after 8 columns:
;; https://github.com/jordonbiondo/column-enforce-mode
(require 'column-enforce-mode)
;; Pandoc mode:
;; https://joostkremers.github.io/pandoc-mode/
;; (add-hook 'markdown-mode-hook 'pandoc-mode)
;; Fill line with dashes till the end (column 80)
;; =============================================================================
;; http://stackoverflow.com/questions/29435904/emacs-fill-a-line-with-character-x-up-to-column-y
;; NOTE: I edited it to go to end of line and new line as well!!!! :)
(defun fill-to-end ()
(interactive)
(save-excursion
(end-of-line)
(while (< (current-column) 80)
(insert-char ?-)))
(end-of-line)
;; (newline)
)
(global-set-key (kbd "s--") 'fill-to-end)
;; ;; Add hashes till end of line (based on above)
;; (defun fill-hash-to-end ()
;; (interactive)
;; (save-excursion
;; (end-of-line)
;; (while (< (current-column) 80)
;; (insert-char ?#)))
;; (end-of-line)
;; ;; (newline)
;; )
;;
;; (global-set-key (kbd "s-3") 'fill-hash-to-end)
;; Add = till end of line (based on above)
(defun fill-equal-to-end ()
(interactive)
(save-excursion
(end-of-line)
(while (< (current-column) 80)
(insert-char ?=)))
(end-of-line)
;; (newline)
)
(global-set-key (kbd "s-=") 'fill-equal-to-end)
;; Get defau;t copy-pasting behaviour
;; =============================================================================
;; https://www.emacswiki.org/emacs/Comments_on_CopyAndPaste
(setq x-select-enable-clipboard t)
(require 'simpleclip)
(simpleclip-mode 1)
;; Adding back deleted stuff
;; Multiple cursors
;; =============================================================================
;; Multiple cursors!!! Add one on mouse click :) 'Binding mouse events'
;; https://github.com/magnars/multiple-cursors.el
(global-set-key (kbd "<C-s-mouse-1>") 'mc/add-cursor-on-click)
;; Other interesting shortcuts:
(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
;; NOTE: to copy paste multiple cursor words, exit multiple-cursor (enter) and hit C-x r y
;; Above: http://emacs.stackexchange.com/questions/10879/copying-text-selected-by-multiple-cursors-to-a-new-buffer
;; Turning off echoing of the script inside the R to improve buffer speeds
;; =============================================================================
;; https://stat.ethz.ch/pipermail/ess-help/2011-March/006734.html
(setq ess-eval-visibly-p nil)
;; Toggle comment on region or line
;; =============================================================================
;; ref: http://stackoverflow.com/a/9697222/5443003
(defun comment-or-uncomment-region-or-line ()
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)
(next-line)))
(global-set-key (kbd "M-3") 'comment-or-uncomment-region-or-line)
;; Copy paste file from one directory to another
;; =============================================================================
;; http://emacs.stackexchange.com/questions/5603/how-to-quickly-copy-move-file-in-emacs-dired
(setq dired-dwim-target t)
;; Auto revert doc view mode: http://stackoverflow.com/a/4705746/5443003
;; =============================================================================
(add-hook 'doc-view-mode-hook 'auto-revert-mode)
(add-hook 'pdf-view-mode-hook 'auto-revert-mode)
;; ;; Today's date and time: http://stackoverflow.com/a/619525/5443003
;; (defun now ()
;; "Insert string for the current time formatted like '2:34 PM'."
;; (interactive) ; permit invocation in minibuffer
;; (insert (format-time-string "%D %-I:%M %p")))
;; (defun today ()
;; "Insert string for today's date nicely formatted in American style,
;; e.g. Sunday, September 17, 2000."
;; (interactive) ; permit invocation in minibuffer
;; (insert (format-time-string "%A, %B %e, %Y")))
;; journal: https://www.emacswiki.org/emacs/Journal
;; =============================================================================
(load "journal")
(if (file-directory-p "/Users/nistara/projects/journal/")
(setq-default journal-dir "/Users/nistara/projects/journal/"))
;; journal: https://www.emacswiki.org/emacs/Journal
(load "meetings")
(if (file-directory-p "/Users/nistara/projects/meetings/")
(setq-default meeting-dir "/Users/nistara/projects/meetings/"))
(setq insert-directory-program "gls" dired-use-ls-dired t)
;; So emacs opens shell in the same buffer that called it (instead of opening in a separate one
;; and messing up my arrangement
;; https://www.reddit.com/r/emacs/comments/gjqki/is_there_any_way_to_tell_emacs_to_not/#bottom-comments
;; http://www.chemie.fu-berlin.de/chemnet/use/info/emacs/emacs_20.html#SEC157
(add-to-list 'same-window-buffer-names "*shell*")
;; A better shortcut to delete frame:
;; =============================================================================
;; http://pragmaticemacs.com/emacs/a-better-shortcut-for-delete-frame/
(global-set-key (kbd "C-x w") 'delete-frame)
;; Stop emacs from locking files: https://www.emacswiki.org/emacs/LockFiles
;; =============================================================================
(setq create-lockfiles nil)
;; ESS customizations:
;; =============================================================================
;; -----------------------------------------------------------------------------
;; For my current directory to show up in the shell prompt:---------------------
;; From: http://superuser.com/questions/31533/how-do-i-fix-my-prompt-in-emacs-shell-mode
;; http://emacs.stackexchange.com/questions/28995/bash-profile-or-bashrc-for-shell-in-emacs/28999#28999
;; http://stackoverflow.com/questions/27953807/how-to-set-shell-mode-prompt-in-emacs
;; http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html
;;
;; Hence, created an .emacs_bash file with just the single line:
;; export PS1='\u@ \W\$ '
;;
;; Note: \w instead of \W will give directory path also
;;
;; When calling shell mode, the first line is bash, but the subsequent ones reflect my current directory.
;; -----------------------------------------------------------------------------
;; ;; Highlight the cursor line.
;; ;; ==========================================================================
;; (global-hl-line-mode 1)
;; Highlight matching pairs
;; =============================================================================
(show-paren-mode 1)
;; More ESS
;; =============================================================================
;; (require 'ess-site)
;; (setq-default ess-dialect "R")
;; (require 'ess-eldoc)
;; (setq-default inferior-R-args "--no-restore-history --no-save ")
;; (defadvice ess-eval-buffer (before really-eval-buffer compile activate)
;; "Prevent call ess-eval-buffer by accident, frequently by
;; hitting C-c C-b instead of C-c C-n."
;; (if (yes-or-no-p
;; (format "Are you sure you want to evaluate the %s buffer?"
;; buffer-file-name))
;; (message "ess-eval-buffer started.")
;; (error "ess-eval-buffer canceled!")
;; )
;; )
;; http://www.kieranhealy.org/blog/archives/2009/10/12/make-shift-enter-do-a-lot-in-ess/
(add-hook 'ess-mode-hook
'(lambda()
;; (setq comint-scroll-to-bottom-on-input t)
;; (setq comint-scroll-to-bottom-on-output t)
;; (setq comint-move-point-for-output t)
;; (setq ess-smart-operators t)
;; No indent styles.
(setq ess-indent-with-fancy-comments nil)
;; No ## as default to comment.
(setq-local comment-add 0)
))
(setq ess-fancy-comments nil)
(defun my-ess-settings ()
(setq ess-indent-with-fancy-comments nil))
(add-hook 'ess-mode-hook #'my-ess-settings)
;; Comment even in empty lines
;; =============================================================================
(setq comment-empty-lines t)
;; Mark a word at a point.
;; =============================================================================
(defun mark-whole-word ()
"Mark the word where the point is."
(interactive)
(skip-chars-backward "[[:alnum:]]._")
(set-mark (point))
(skip-chars-forward "[[:alnum:]]._"))
(global-set-key (kbd "s-'") 'mark-whole-word)
;; https://github.com/walmes/emacs/blob/master/functions.el
;; (require 'bm) ;https://github.com/joodland/bm
;; (defun bm-bookmark-chunk-in-buffer ()
;; "Set bookmark on chunk header lines in Rnw and Rmd files."
;; (interactive)
;; (let ((regexp "^<<.*>>=$\\|^```{.*}$")
;; (annotation nil)
;; (count 0))
;; (save-excursion
;; (if bm-annotate-on-create
;; (setq annotation
;; (read-from-minibuffer
;; "Annotation: " nil nil nil 'bm-annotation-history)))
;; (goto-char (point-min))
;; (while (and (< (point) (point-max))
;; (re-search-forward regexp (point-max) t))
;; (bm-bookmark-add annotation)
;; (setq count (1+ count))
;; (forward-line 1)))
;; (message "%d bookmark(s) created." count)))
;; Pomodoro: https://www.emacswiki.org/emacs/pomodoro.el
;; =============================================================================
;; (require 'pomodoro)
;; Shortcut to open and eval .emacs buffer. And Other shorcuts:
;; =============================================================================
;; http://stackoverflow.com/a/12558095
(global-set-key (kbd "s-9") (lambda() (interactive)(find-file "~/.emacs.d/init.el")))
(global-set-key (kbd "s-0") 'eval-buffer)
;; Shortcut to open journal, todo, agenda
(global-set-key (kbd "s-1") 'journal)
;; (global-set-key (kbd "s-2") 'todo)
(global-set-key (kbd "s-2") (lambda() (interactive)(find-file "~/projects/meetings/project_list.org")))
;; Shorcut to open notes folder
(global-set-key (kbd "C-c note") (lambda() (interactive)(find-file "~/projects/journal/notes")))
;; Shorcut to open meetings folder
(global-set-key (kbd "C-c meet") (lambda() (interactive)(find-file "~/projects/meetings")))
;; Shortcut to open bat-tracking folder
(global-set-key (kbd "C-c bat") (lambda() (interactive)(find-file "~/projects/bat-tracking")))
;; Shortcut to open scrap R file
(global-set-key (kbd "s-4") (lambda() (interactive)(switch-to-buffer "*scratch*")))
;; Shortcut to open network folders
(global-set-key (kbd "C-c net") (lambda() (interactive)(find-file "~/projects/epi-net")))
(global-set-key (kbd "C-c flu") (lambda() (interactive)(find-file "~/projects/flu-net")))
(global-set-key (kbd "C-c ebo") (lambda() (interactive)(find-file "~/projects/ebo-net")))
(global-set-key (kbd "C-c dis") (lambda() (interactive)(find-file "~/projects/disnet")))
;; Shortcut to open Projects folder in Dropbox
(global-set-key (kbd "C-c dpo") (lambda() (interactive)(find-file "~/Dropbox/UC Davis/Projects")))
;; Shortcut to open Projects folder in Drive
(global-set-key (kbd "C-c dri") (lambda() (interactive)(find-file "~/Drive/projects")))
;; Shortcut to open projects folder
(global-set-key (kbd "C-c pro") (lambda() (interactive)(find-file "~/projects")))
;; Shortcut to hugo blog folder
(global-set-key (kbd "C-c nis") (lambda() (interactive)(find-file "~/projects/website")))
;; Shortcut to open grassdata
(global-set-key (kbd "C-c gra") (lambda() (interactive)(find-file "~/grassdata")))
;; Insert ""/[]/() around highlighted word:
;; =============================================================================
;; http://stackoverflow.com/questions/2951797/wrapping-selecting-text-in-enclosing-characters-in-emacs
;; For parens you can do M-(
(global-set-key (kbd "M-\"") 'insert-pair)
(global-set-key (kbd "M-(") 'insert-pair)
(global-set-key (kbd "M-[") 'insert-pair)
;; Finding file shortcut
;; =============================================================================
(global-set-key (kbd "C-x o") 'find-file)
;; Bigger sized emacs window when launching:
;; =============================================================================
;; http://emacs.stackexchange.com/a/2272
;; http://emacs.stackexchange.com/a/3008
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
;; Disable menu bars when launching:
;; =============================================================================
;; http://kb.mit.edu/confluence/display/istcontrib/Disabling+the+Emacs+menubar,+toolbar,+or+scrollbar
;; To disable the menu bar, place the following line in your .emacs file:
(menu-bar-mode -1)
;; To disable the scrollbar, use the following line:
(toggle-scroll-bar -1)
;; To disable the toolbar, use the following line:
(tool-bar-mode -1)
;; Improving vertical window divider's color (from white to gray)
;; =============================================================================
;; https://www.reddit.com/r/emacs/comments/3u0d0u/how_do_i_make_the_vertical_window_divider_more/cxbth2e/
(set-face-background 'vertical-border "dark gray")
(set-face-foreground 'vertical-border (face-background 'vertical-border))
;; =============================================================================
;; For pdf-tools to work:
;; =============================================================================
;; (pdf-tools-install) ; only install when needed, because it slows things down
(global-set-key (kbd "M-g h") 'pdf-annot-add-highlight-markup-annotation)
;; To copy files easily from one dired to another:
;; =============================================================================
;; http://emacs.stackexchange.com/questions/5603/how-to-quickly-copy-move-file-in-emacs-dired
;; Put this in your init file: (setq dired-dwim-target t). Then, go to dired, split your window,
;; split-window-vertically & go to another dired directory. When you will press C to copy,
;; the other dir in the split pane will be default destination.
(setq dired-dwim-target t)
;; Setting up emacs backups: http://stackoverflow.com/a/20824625
;; =============================================================================
(setq version-control t ;; Use version numbers for backups.
kept-new-versions 10 ;; Number of newest versions to keep.
kept-old-versions 0 ;; Number of oldest versions to keep.
delete-old-versions t ;; Don't ask to delete excess backup versions.
backup-by-copying t) ;; Copy all files, don't rename them.
(setq vc-make-backup-files t)
;; Default and per-save backups go here:
(setq backup-directory-alist '(("" . "~/.emacs.d/backup/per-save")))
(defun force-backup-of-buffer ()
;; Make a special "per session" backup at the first save of each
;; emacs session.
(when (not buffer-backed-up)
;; Override the default parameters for per-session backups.
(let ((backup-directory-alist '(("" . "~/.emacs.d/backup/per-session")))
(kept-new-versions 3))
(backup-buffer)))
;; Make a "per save" backup on each save. The first save results in
;; both a per-session and a per-save backup, to keep the numbering
;; of per-save backups consistent.
(let ((buffer-backed-up nil))
(backup-buffer)))
(add-hook 'before-save-hook 'force-backup-of-buffer)
;; To get spell check in emacs
;; =============================================================================
;; http://emacs.stackexchange.com/questions/19175/where-is-ispell
(setq ispell-program-name "/usr/local/bin/ispell")
;; ;; So I can get function indents like Duncan's suggestions
;; ;; https://stat.ethz.ch/pipermail/ess-help/2010-May/006089.html
;; ;; Changing the default style to RRR+ within R session led to
;; ;; emacs forgetting that I didn't want fancy indents. So
;; ;; making RRR+ the default style ensured that emacs combined it
;; ;; with the indent specification
;; (setq ess-default-style 'RRR+)
;; So I can find the active window more easily, instead of squinting!!
;; =============================================================================
;; http://stackoverflow.com/a/9448316
;; To see colors: M-x list-colors-display
;; (set-face-attribute 'mode-line
;; nil
;; ;; :background "deepskyblue3"
;; ;; :background "deep sky blue"
;; ;; :background "DodgerBlue4"
;; :box '(:line-width 1 :style released-button))
;; Icomplete mode
;; https://www.emacswiki.org/emacs/IcompleteMode
;; As you type in the minibuffer, a list of matching commands is echoed
;; there so you can see how to complete a command
;; (icomplete-mode 1)
;; Visual line mode
;; =============================================================================
;; https://github.com/joostkremers/visual-fill-column
;; (global-visual-line-mode t)
(setq visual-fill-column-fringes-outside-margins t
visual-fill-column-center-text t
visual-fill-column-width 90)
;; Making it more intuitive to split windows
;; =============================================================================
;; Ref: ftp://ftp.gnu.org/old-gnu/Manuals/emacs-20.7/html_chapter/emacs_20.html
;; Ref: https://stackoverflow.com/a/6465415/5443003
;; (global-set-key (kbd "M-1") 'split-window-vertically)
;; (global-set-key (kbd "M-2") 'split-window-horizontally)
(global-set-key (kbd "M-1") (lambda () (interactive)(split-window-horizontally) (other-window 1)))
(global-set-key (kbd "M-2") (lambda () (interactive)(split-window-vertically) (other-window 1)))
(global-set-key (kbd "M-0") 'delete-other-windows)
(global-set-key (kbd "M-`") 'delete-window)
;; Get visual-fill-column-mode to be enabled on markdown files
;; (add-hook 'markdown-mode-hook 'visual-fill-column)
;; Seeing file sizes in kbytes
;; =============================================================================
;; http://stackoverflow.com/a/2859033/5443003
(setq dired-listing-switches "-alk")
;; Postgres in emacs:
;; =============================================================================
;; https://www.emacswiki.org/emacs/SqlMode
;; Workaround for postgres database names---------------------------------------
;; Note from site: "PostgreSQL databases with underscores in their names trip
;; up the prompt specified in sql.el. I work around this with the following. Warning,
;; this sets the prompt globally, which is fine by me since I only ever use Postgres.
(add-hook 'sql-interactive-mode-hook
(lambda ()
(setq sql-prompt-regexp "^[_[:alpha:]]*[=][#>] ")
(setq sql-prompt-cont-regexp "^[_[:alpha:]]*[-][#>] ")))
;; https://truongtx.me/2014/08/23/setup-emacs-as-an-sql-database-client
(add-hook 'sql-interactive-mode-hook
(lambda ()
(toggle-truncate-lines t)))
(add-hook 'sql-login-hook 'my-sql-login-hook)
(defun my-sql-login-hook ()
"Custom SQL log-in behaviours. See `sql-login-hook'."
;; n.b. If you are looking for a response and need to parse the
;; response, use `sql-redirect-value' instead of `comint-send-string'.
(when (eq sql-product 'postgres)
(let ((proc (get-buffer-process (current-buffer))))
;; Output each query before executing it. (n.b. this also avoids
;; the psql prompt breaking the alignment of query results.)
(comint-send-string proc "\\set ECHO queries\n"))))
;; For regex
;; =============================================================================
;; https://www.masteringemacs.org/article/re-builder-interactive-regexp-builder
(require 're-builder)
(setq reb-re-syntax 'string)
;; neotree
;; vimish
;; git gutter
;; Code folding
;; ref: https://github.com/mrkkrp/vimish-fold
;; (require 'vimish-fold)
;; (vimish-fold-global-mode 1)
;; ;; sending line to shell
;; ;; ref: https://www.emacswiki.org/emacs/essh.el
;; (require 'essh) ;;
;; (defun essh-sh-hook () ;;
;; (define-key sh-mode-map "\C-c\C-r" 'pipe-region-to-shell) ;;
;; (define-key sh-mode-map "\C-c\C-b" 'pipe-buffer-to-shell) ;;
;; (define-key sh-mode-map "\C-c\C-j" 'pipe-line-to-shell) ;;
;; (define-key sh-mode-map "\C-c\C-n" 'pipe-line-to-shell-and-step) ;;
;; (define-key sh-mode-map "\C-c\C-f" 'pipe-function-to-shell) ;;
;; (define-key sh-mode-map "\C-c\C-d" 'shell-cd-current-directory)) ;;
;; (add-hook 'sh-mode-hook 'essh-sh-hook) ;;
;; ;; SQL
;; (add-hook 'sql-mode-hook
;; (lambda ()
;; ;; (load-library "sql-library")
;; (local-set-key (kbd "<s-return>") 'sql-send-line-and-next)))
;; ;; From Dr. Mathieu Basille
;; ;; ref:
;; (electric-pair-mode 1)
;; (setq electric-pair-pairs '(
;; (?\" . ?\")
;; (?\` . ?\`)
;; (?\( . ?\))
;; (?\[ . ?\])
;; (?\{ . ?\})
;; ) )
;; (setq frame-title-format '(buffer-file-name "Emacs: %b (%f)" "Emacs: %b"))
(setq initial-scratch-message nil)
;; Git gutter
;; =============================================================================
;; ref: https://github.com/syohex/emacs-git-gutter
;; ref: https://github.com/syohex/emacs-git-gutter-fringe
;; Installed fringe-helper, git-gutter-fringe and git-gutter-mode through MELPA
(require 'git-gutter-fringe)
(global-git-gutter-mode +1)
;; Color of the fringe
(set-face-background 'fringe "#181a26")
;; (set-face-background 'git-gutter:modified "purple") ;; background color
(set-face-foreground 'git-gutter:added "SeaGreen4")
(set-face-foreground 'git-gutter:deleted "IndianRed")
;; ;; Speedbar
;; ;; =============================================================================
;; (require 'sr-speedbar)
;; Highlight parenthesis
;; =============================================================================
; Highlight matching parentheses (from Gabor's emacs)
;; (require 'highlight-parentheses)
;; (setq hl-paren-colors '("DeepSkyBlue1" "gold" "IndianRed" "cyan" "green" "orange"
;; "magenta"))
;;
;; (defun hpm-on ()
;; (highlight-parentheses-mode t))
;; (add-hook 'ess-mode-hook 'hpm-on)
;; (add-hook 'inferior-ess-mode-hook 'hpm-on)
;; Select/mark current line
;; =============================================================================
(defun xah-select-current-line ()
"Select current line.
URL `http://ergoemacs.org/emacs/modernization_mark-word.html'
Version 2016-07-22"