-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.el
5724 lines (5250 loc) · 208 KB
/
functions.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
;; -*- mode: Emacs-Lisp -*-
(when (and (fboundp 'native-comp-available-p)
(native-comp-available-p))
(progn
(setq native-comp-async-report-warnings-errors nil)
(setq comp-deferred-compilation t)
(add-to-list 'native-comp-eln-load-path (expand-file-name "eln-cache/" user-emacs-directory))
(setq package-native-compile t)
;; These don't seem to work or prevent compilation but leaving here for now
;; (setq native-comp-deferred-compilation-deny-list '("^user\.el$" "^functions\.el$" "^settings\.el$" "^bindings\.el$"))
;; (setq native-comp-bootstrap-deny-list '("^user\.el$" "^functions\.el$" "^settings\.el$" "^bindings\.el$"))
))
;; ensures packages are installed or installs them but doesn't keep them updated
(require 'use-package-ensure)
(setq use-package-always-ensure t)
(require 'savehist)
(use-package multiple-cursors)
(use-package todotxt)
(use-package expand-region)
(require 'avy)
(use-package openwith)
(use-package ivy-dired-history)
(use-package ace-jump-zap)
(use-package visible-mark)
(use-package dash-functional)
(require 'dash)
(use-package visual-regexp)
(use-package visual-regexp-steroids)
(use-package transpose-frame)
(require 'desktop)
(use-package tiny)
(require 'dired-x)
(require 'dired-aux)
(require 'find-dired)
(use-package peep-dired)
(use-package dired-ranger)
(use-package dired-narrow)
(use-package dired-filter)
;; TODO: get dired+ working properly (one issue is doesn't flag dot files as before)
;; emailed Drew Adams "drew.adams@oracle.com"
;; Bindings for killing and deleting lines
(use-package simple
:ensure nil
:bind
("<M-s-backspace>" . kill-whole-line)
("M-s-˚" . jj/delete-whole-line)
)
(use-package whole-line-or-region
:bind
("C-w" . whole-line-or-region-kill-region)
("C-M-s-k" . whole-line-or-region-kill-region)
("<C-M-s-268632075>" . whole-line-or-region-kill-region)
("M-s-k" . whole-line-or-region-delete-region)
)
(use-package backup-each-save)
(use-package wttrin)
(require 'frame-cmds)
(require 'zoom-frm)
(require 'f)
(use-package evil
:config
(defun jj/evil-scroll-down-15-lines ()
(interactive)
(evil-scroll-line-down 15))
(defun jj/evil-scroll-up-15-lines ()
(interactive)
(evil-scroll-line-up 15))
)
(require 'pdf-tools)
(require 'man)
(use-package smartparens)
(use-package dtrt-indent)
(use-package clean-aindent-mode)
(require 'ws-butler)
(use-package whitespace-cleanup-mode)
(use-package cyphejor)
(use-package org-download)
(use-package dumb-jump)
(use-package counsel-projectile
:bind
("C-c p SPC" . counsel-projectile)
("C-c P" . counsel-projectile)
("C-c p r" . counsel-projectile-rg)
("C-c p a" . counsel-projectile-ag)
("C-c p g" . counsel-projectile-git-grep)
("C-c p e" . counsel-projectile-find-file-dwim)
)
(counsel-projectile-mode)
(use-package helm
:bind
("s-SPC r" . helm-recentf)
("s-p I" . helm-resume)
("s-SPC I" . helm-resume)
)
(use-package helm-rg
:after helm)
(use-package helm-ag
:after helm)
(use-package helm-projectile
:after helm
:bind
("<escape> p" . helm-projectile)
("<escape> P" . helm-projectile-rg)
("C-c h p" . helm-projectile)
("C-c h P" . helm-list-emacs-process)
("C-c h F" . helm-projectile-find-file)
(
:map spacebar-map
:prefix-map spc-projectile-map
:prefix "p"
("f" . helm-projectile-find-file)
("a" . helm-projectile-ag)
("r" . helm-projectile-rg)
("g" . helm-projectile-grep)
)
)
(use-package helm-gtags
:config
(setq
helm-gtags-ignore-case nil
helm-gtags-auto-update t
helm-gtags-use-input-at-cursor t
helm-gtags-pulse-at-cursor t
helm-gtags-suggested-key-mapping t))
(use-package find-file-in-project)
(require 'back-button)
(back-button-mode 1)
;; NOTE: Emacs slow to exit during pcache due to function below added by back-button
(remove-hook 'kill-emacs-hook 'pcache-kill-emacs-hook)
;; (require 'nice-jumper)
;; (global-nice-jumper-mode t)
(use-package easy-kill)
(use-package easy-kill-extras)
(use-package osx-trash)
(use-package beacon)
(use-package color-theme-sanityinc-tomorrow)
;; core package removed elpy and added jupyter so doing the same here (should already by installed from core but leaving
;; the jupyter here in case not)
(use-package elpy
:config
(elpy-enable))
;; (use-package ob-ipython)
(use-package jupyter)
(use-package evil-nerd-commenter)
(use-package git-commit-insert-issue)
(use-package forge
:after magit)
(use-package github-review
:after magit
:config
(setq github-review-view-comments-in-code-lines t)
(setq github-review-reply-inline-comments t)
)
(use-package visual-fill-column)
(use-package auctex-latexmk)
(use-package highlight-numbers)
(use-package yasnippet-snippets)
;; Undo tree
(use-package undo-tree
:custom
(undo-tree-visualizer-diff t)
(undo-tree-history-directory-alist '(("." . "~/.emacs.d/undo")))
(undo-tree-visualizer-timestamps t))
;; PYTHON stuff
(use-package py-isort
:bind (
:map python-mode-map
("C-c i" . py-isort-buffer)
("C-c I" . py-isort-region)
("C-c r" . jj/python-remove-unused-imports)
))
(use-package python
:bind (
:map python-mode-map
("C-c r" . jj/python-remove-unused-imports)
("C-c M-." . xref-find-definitions-other-window)
))
(use-package xref
:init (setq xref-prompt-for-identifier '(not xref-find-definitions xref-find-definitions-other-window
xref-find-definitions-other-frame xref-find-references)))
(use-package elpy
:init
(setq elpy-rpc-virtualenv-path 'current)
:bind (
:map elpy-mode-map
("C-c ," . elpy-goto-assignment)
("C-c <" . elpy-goto-assignment-other-window)
("C-c ." . elpy-goto-definition)
("C-c >" . elpy-goto-definition-other-window)
("s-SPC f" . elpy-folding-toggle-at-point)
))
(use-package counsel-pydoc)
(use-package pyvenv
:init
(if (file-directory-p (expand-file-name "~/anaconda3/envs"))
(setenv "WORKON_HOME" (expand-file-name "~/anaconda3/envs")))
(if (file-directory-p (expand-file-name "~/.pyenv/versions"))
(setenv "WORKON_HOME" (expand-file-name "~/.pyenv/versions")))
(if (file-directory-p (expand-file-name "~/miniconda/envs"))
(setenv "WORKON_HOME" (expand-file-name "~/miniconda/envs")))
:bind
("s-p e" . jj/pyvenv-activate-current-project)
("s-p s" . pyvenv-workon)
("s-p S" . pyvenv-deactivate)
:config
(pyvenv-mode)
(defvar pyvenv-current-version nil nil)
(defun jj/pyvenv-activate-current-project ()
"Automatically activates pyvenv version if .python-version file exists."
(interactive)
(let ((python-version-directory (locate-dominating-file (buffer-file-name) ".python-version")))
(if python-version-directory
(let* ((pyvenv-version-path (f-expand ".python-version" python-version-directory))
(pyvenv-current-version (s-trim (f-read-text pyvenv-version-path 'utf-8))))
(pyvenv-workon pyvenv-current-version)
(message (concat "Setting virtualenv to " pyvenv-current-version))))))
(defun jj/pyvenv-activate-jjj ()
"Initialize pyvenv's current version to the global one."
(interactive)
(pyvenv-workon "jjj")
(setq pyvenv-current-version "jjj"))
(add-hook 'emacs-startup-hook 'jj/pyvenv-activate-jjj)
;; Can use this if what it to activate the global environment, but use jjj as the global typically
;; (add-hook 'after-init-hook 'pyenv-init)
(defun jj/pyvenv-global-init ()
"Initialize pyvenv's current version to the global one."
(let ((global-pyvenv (replace-regexp-in-string "\n" "" (shell-command-to-string "pyenv global"))))
(message (concat "Setting pyvenv version to " global-pyvenv))
(pyvenv-workon global-pyvenv)
(setq pyvenv-current-version global-pyvenv))))
;; NOTE: This is another option, but the author of elpy wrote pyvenv so most the config copied to above
;; (use-package pyenv-mode
;; :init
;; (if (file-directory-p (expand-file-name "~/anaconda3/envs"))
;; (setenv "WORKON_HOME" (expand-file-name "~/anaconda3/envs")))
;; (if (file-directory-p (expand-file-name "~/.pyenv/versions"))
;; (setenv "WORKON_HOME" (expand-file-name "~/.pyenv/versions")))
;; :bind
;; ("s-p e" . jj/pyenv-activate-current-project)
;; ;; Remove these because activated globally and takes over org-mode bindings
;; :config
;; (define-key pyenv-mode-map (kbd "C-c C-u") nil)
;; (define-key pyenv-mode-map (kbd "C-c C-s") nil)
;; (define-key pyenv-mode-map (kbd "s-P s") 'pyenv-mode-set)
;; (define-key pyenv-mode-map (kbd "s-P S") 'pyenv-mode-unset)
;; (pyenv-mode)
;; (defun jj/pyenv-activate-current-project ()
;; "Automatically activates pyenv version if .python-version file exists."
;; (interactive)
;; (let ((python-version-directory (locate-dominating-file (buffer-file-name) ".python-version")))
;; (if python-version-directory
;; (let* ((pyenv-version-path (f-expand ".python-version" python-version-directory))
;; (pyenv-current-version (s-trim (f-read-text pyenv-version-path 'utf-8))))
;; (pyenv-mode-set pyenv-current-version)
;; (message (concat "Setting virtualenv to " pyenv-current-version)))))))
;; Programming shell stuff
(use-package isend-mode)
(use-package org-sidebar)
;; TERRAFORM MODE SETTINGS
;; FIXME: Switch to lsp mode for emacs 27 (if use lsp also install dap-mode and dap-python)
(use-package company-terraform
:config
(add-to-list 'company-backends 'company-terraform)
)
(use-package terraform-mode
:init (company-terraform-init)
:bind (
:map terraform-mode-map
("C-c C-j" . counsel-imenu)
("C-c j" . counsel-semantic-or-imenu)
("C-c C-d" . terraform-doc)
("C-c C-f" . terraform-format-buffer)
)
:config
(defun jj/local-hcl-mode-setup ()
"Custom variables and behaviors for `hcl-mode'."
(setq-local fill-column 87)
(display-line-numbers-mode)
(smartparens-strict-mode)
(setq-local tab-width 2)
(setq-local tab-stop-list (list 2 4 6 8 10 12 14 16 18 20)))
(defun jj/local-terraform-mode-setup ()
"Custom variables and behaviors for `terraform-mode'."
(company-mode)
(company-quickhelp-local-mode)
(terraform-format-on-save-mode))
(add-hook 'hcl-mode-hook 'jj/local-hcl-mode-setup)
(add-hook 'terraform-mode-hook 'jj/local-terraform-mode-setup)
)
(use-package terraform-doc
:bind (
:map terraform-doc-mode-map
("C-c C-c" . helm-occur)
("C-r" . helm-occur)
("C-c C-d" . terraform-doc)
))
(use-package company-quickhelp)
;; DOCKER MODE SETTINGS
(use-package dockerfile-mode)
(use-package docker
:ensure t
:bind ("s-d" . docker))
;; (use-package kubernetes
;; :ensure t
;; :commands (kubernetes-overview)
;; :bind ("s-SPC k" . kubernetes-overview))
;; Good package like the one above but can use when don't have full permissions to the cluster
;; (use-package kubel)
;; (use-package k8s-mode)
(use-package yaml-mode
:config
(defun jj/yaml-mode-setup ()
"Custom variables and behaviors for `yaml-mode'."
(setq visual-fill-column-mode nil)
(setq visual-fill-column-center-text nil)
(setq visual-fill-column-width 108)
(display-line-numbers-mode)
(smartparens-strict-mode)
(highlight-indentation-mode)
(highlight-indentation-current-column-mode)
;; TODO: Possibly need to change the face as really light gray
;; (set-face-background 'highlight-indentation-face "#e3e3d3")
;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
(setq-local tab-width 2)
(setq-local tab-stop-list (list 2 4 6 8 10 12 14 16 18 20))
)
(add-hook 'yaml-mode-hook 'jj/yaml-mode-setup)
)
;; Settings for yamllint contained in ~/.yamllint on Mac
(use-package flycheck-yamllint
:after yaml-mode
:defer t
:init
(progn
(eval-after-load 'flycheck
'(add-hook 'flycheck-mode-hook 'flycheck-yamllint-setup))))
(use-package indent-tools
:bind (
:map python-mode-map
("C-c ]" . indent-tools-hydra/body)
:map yaml-mode-map
("C-c ]" . indent-tools-hydra/body)
))
;; DOT .ENV Mode Settings
(use-package dotenv-mode)
;; DEBUGGING MODE SETTINGS
(use-package realgud
:config
(setq realgud-safe-mode nil))
(use-package realgud-ipdb)
;; PYTHON MODE SETTINGS
(use-package python
:config
(defun jj/python-remove-unused-imports()
"Removes unused imports and unused variables with autoflake."
(interactive)
(if (executable-find "autoflake")
(progn
(shell-command (format "autoflake --remove-all-unused-imports -i %s"
(shell-quote-argument (buffer-file-name))))
(revert-buffer t t t))
(warn "python-mode: Cannot find autoflake executable."))))
(use-package powershell
:config
(defun jj/powershell-mode-setup ()
"Custom variables and behaviors for `powershell-mode'."
(display-line-numbers-mode)
(smartparens-strict-mode)
;; (setq-local tab-width 2)
;; (setq-local tab-stop-list (list 2 4 6 8 10 12 14 16 18 20))
)
(add-hook 'powershell-mode-hook 'jj/powershell-mode-setup))
(use-package which-key)
(use-package ibuffer
:bind (("C-x C-B" . ibuffer)
("C-x C-b" . ibuffer-other-window)
:map ibuffer-mode-map
:prefix-map ibuffer-h-prefix-map
:prefix "h"
("h" . describe-mode)
("g" . ibuffer-clear-filter-groups)
("r" . ibuffer-clear-filter-groups)
("l" . jj/ibuffer-jump-to-last-buffer))
:config
(defun jj/ibuffer-jump-to-last-buffer ()
(interactive)
(ibuffer-jump-to-buffer (buffer-name (cadr (buffer-list)))))
;; Ibuffer settings
;; Add in some ibuffer settings for human readable sizes
(defun jj/human-readable-file-sizes-to-bytes (string)
"Convert a human-readable file size into bytes."
(interactive)
(cond
((string-suffix-p "G" string t)
(* 1000000000 (string-to-number (substring string 0 (- (length string) 1)))))
((string-suffix-p "M" string t)
(* 1000000 (string-to-number (substring string 0 (- (length string) 1)))))
((string-suffix-p "K" string t)
(* 1000 (string-to-number (substring string 0 (- (length string) 1)))))
(t
(string-to-number (substring string 0 (- (length string) 1))))
)
)
(defun jj/bytes-to-human-readable-file-sizes (bytes)
"Convert number of bytes to human-readable file size."
(interactive)
(cond
((> bytes 1000000000) (format "%6.1fG" (/ bytes 1000000000.0)))
((> bytes 100000000) (format "%6.0fM" (/ bytes 1000000.0)))
((> bytes 1000000) (format "%6.1fM" (/ bytes 1000000.0)))
((> bytes 100000) (format "%6.0fk" (/ bytes 1000.0)))
((> bytes 1000) (format "%6.1fk" (/ bytes 1000.0)))
(t (format "%6d" bytes)))
)
;; Use human readable Size column instead of original one
(define-ibuffer-column size-h
(:name "Size"
:inline t
:summarizer
(lambda (column-strings)
(let ((total 0))
(dolist (string column-strings)
(setq total
;; like, ewww ...
(+ (float (jj/human-readable-file-sizes-to-bytes string))
total)))
(jj/bytes-to-human-readable-file-sizes total))) ;; :summarizer nil
)
(jj/bytes-to-human-readable-file-sizes (buffer-size)))
)
(use-package ibuffer-vc
:after ibuffer
:bind (:map ibuffer-h-prefix-map
("v" . jj/ibuffer-vc-set-filter-groups-by-vc-root)
("V" . jj/ibuffer-vc-refresh-state))
:config
;; Modify the default ibuffer-formats (require ibuffer-vc)
(setq ibuffer-formats
'((mark modified read-only locked " "
(name 21 21 :left :elide)
" "
(size-h 7 -1 :right)
" "
(mode 12 12 :left :elide)
" "
(vc-status 12 12 :left :elide)
" "
vc-relative-file)
;; " "
;; filename-and-process)
(mark " "
(name 18 -1)
" " filename)))
(defun jj/vc-refresh-state-all-buffers ()
"Refresh all vc buffer statuses by calling `vc-refresh-state` on each one if it has an associated vc backend. Uses functions from `ibuffer-vc`, so decouple these functions if you need to use this without loading ibuffer-vc."
(interactive)
(dolist (buf (buffer-list))
(let ((file-name (with-current-buffer buf
(file-truename (or buffer-file-name
default-directory)))))
(when (ibuffer-vc--include-file-p file-name)
(let ((backend (ibuffer-vc--deduce-backend file-name)))
(when backend
(with-current-buffer buf (vc-refresh-state))
))))))
(defun jj/ibuffer-vc-refresh-state ()
"Refresh all vc buffer statuses and redisplay to update the current status in ibuffer."
(interactive)
(jj/vc-refresh-state-all-buffers)
(ibuffer-redisplay))
(defun jj/ibuffer-vc-set-filter-groups-by-vc-root ()
"First run `ibuffer-vc-set-filter-groups-by-vc-root` and then `jj/ibuffer-jump-to-last-buffer`."
(interactive)
(ibuffer-vc-set-filter-groups-by-vc-root)
(jj/ibuffer-jump-to-last-buffer))
(add-hook 'ibuffer-mode-hook 'jj/ibuffer-vc-refresh-state)
)
(use-package vlf
:config
(require 'vlf-setup))
(require 'doom-todo-ivy)
(use-package magit-todos
:after magit
:after hl-todo
:init
;; nil Forces manual update of magit-todos
;; or int is number of seconds (so updates every 24 hours)
(setq magit-todos-update 86400)
;; Needs entire regex set to optional if you want to recognize words not ending with suffixes
;; (setq magit-todos-keyword-suffix nil)
)
(use-package hideshow
:bind (("<escape> f" . hs-toggle-hiding)
("<escape> F" . hs-show-block)
("C-c f s" . hs-show-block)
("C-c f S" . hs-show-all)
("C-c f h" . hs-hide-block)
("C-c f H" . hs-hide-all)
("C-c f t" . hs-toggle-hiding)
("C-c f a" . hs-show-all))
:init (add-hook 'json-mode-hook #'hs-minor-mode)
:diminish hs-minor-mode
:config
(setq hs-special-modes-alist
(mapcar 'purecopy
'((c-mode "{" "}" "/[*/]" nil nil)
(c++-mode "{" "}" "/[*/]" nil nil)
(java-mode "{" "}" "/[*/]" nil nil)
(js-mode "{" "}" "/[*/]" nil)
(js2-mode "{" "}" "/[*/]" nil)
(json-mode "{" "}" "/[*/]" nil)
(javascript-mode "{" "}" "/[*/]" nil)))))
(use-package json-mode
:config
(defun jj/json-format-beautify ()
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
(shell-command-on-region b e
"python -mjson.tool" (current-buffer) t))))
(use-package sentence-navigation :defer t)
;; NOTE: Commented out for now because removed from melpa (look for it later to add locally but don't really use it anymore)
;; (use-package xah-lookup
;; :defer 6
;; :config
;; (defun xah-lookup-word-thesaurus-eww (&optional @word)
;; "Lookup definition of current word or text selection in URL `http://www.freethesaurus.com/curlicue'.
;; Version 2017-02-09"
;; (interactive)
;; (xah-lookup-word-on-internet
;; @word
;; (get 'xah-lookup-word-thesaurus-eww 'xah-lookup-url)
;; (get 'xah-lookup-word-thesaurus-eww 'xah-lookup-browser-function))
;; ;;
;; )
;; (put 'xah-lookup-word-thesaurus-eww 'xah-lookup-url "http://www.freethesaurus.com/word02051")
;; (put 'xah-lookup-word-thesaurus-eww 'xah-lookup-browser-function 'eww)
;; (defun xah-lookup-word-thesaurus (&optional @word)
;; "Lookup definition of current word or text selection in URL `http://www.freethesaurus.com/curlicue'.
;; Version 2017-02-09"
;; (interactive)
;; (xah-lookup-word-on-internet
;; @word
;; (get 'xah-lookup-word-thesaurus 'xah-lookup-url )
;; (get 'xah-lookup-word-thesaurus 'xah-lookup-browser-function ))
;; ;;
;; )
;; (put 'xah-lookup-word-thesaurus 'xah-lookup-url "http://www.freethesaurus.com/word02051")
;; (put 'xah-lookup-word-thesaurus 'xah-lookup-browser-function xah-lookup-browser-function)
;; (defun xah-lookup-word-definition-eww (&optional @word)
;; "Lookup definition of current word or text selection in URL `http://www.thefreedictionary.com/curlicue'.
;; Version 2017-02-09"
;; (interactive)
;; (xah-lookup-word-on-internet
;; @word
;; (get 'xah-lookup-word-definition-eww 'xah-lookup-url )
;; (get 'xah-lookup-word-definition-eww 'xah-lookup-browser-function ))
;; ;;
;; )
;; (put 'xah-lookup-word-definition-eww 'xah-lookup-url "http://www.thefreedictionary.com/word02051")
;; (put 'xah-lookup-word-definition-eww 'xah-lookup-browser-function 'eww)
;; (defun xah-lookup-power-thesaurus-eww (&optional @word)
;; "Lookup definition of current word or text selection in URL `http://www.thefreedictionary.com/curlicue'.
;; Version 2017-02-09"
;; (interactive)
;; (xah-lookup-word-on-internet
;; @word
;; (get 'xah-lookup-power-thesaurus-eww 'xah-lookup-url)
;; (get 'xah-lookup-power-thesaurus-eww 'xah-lookup-browser-function))
;; ;;
;; )
;; (put 'xah-lookup-power-thesaurus-eww 'xah-lookup-url "http://www.powerthesaurus.org/word02051/synonyms")
;; (put 'xah-lookup-power-thesaurus-eww 'xah-lookup-browser-function 'eww)
;; (defun xah-lookup-power-thesaurus (&optional @word)
;; "Lookup definition of current word or text selection in URL `http://www.thefreedictionary.com/curlicue'.
;; Version 2017-02-09"
;; (interactive)
;; (xah-lookup-word-on-internet
;; @word
;; (get 'xah-lookup-power-thesaurus 'xah-lookup-url)
;; (get 'xah-lookup-power-thesaurus 'xah-lookup-browser-function))
;; ;;
;; )
;; (put 'xah-lookup-power-thesaurus 'xah-lookup-url "http://www.powerthesaurus.org/word02051/synonyms")
;; (put 'xah-lookup-power-thesaurus 'xah-lookup-browser-function xah-lookup-browser-function)
;; )
(use-package poporg :defer t
;; bind: doesn't work here I think because prefix defined outside package
;; :bind (("s-/ o" . poporg-dwim))
;; :bind (("s-/ j" . poporg-dwim))
)
;; (use-package total-lines
;; :config (global-total-lines-mode))
(use-package darkroom :defer 6
:init
(setq darkroom-text-scale-increase 1))
(use-package pdf-tools
:pin manual ;; manually update
:config
;; initialise
(pdf-tools-install)
;; open pdfs scaled to fit page
(setq-default pdf-view-display-size 'fit-page)
;; automatically annotate highlights
(setq pdf-annot-activate-created-annotations t)
;; use normal isearch
(define-key pdf-view-mode-map (kbd "C-s") 'isearch-forward)
;; turn off cua so copy works
;; turn on pdf-view-auto-slice-minor-mode so runs s b automatically
(add-hook 'pdf-view-mode-hook
(lambda () (cua-mode 0)
(pdf-view-auto-slice-minor-mode)))
;; more fine-grained zooming
(setq pdf-view-resize-factor 1.1)
(defvar jj/pdftools-selected-pages '())
(defun jj/pdftools-select-page ()
"Add current page to list of selected pages."
(interactive)
(add-to-list 'jj/pdftools-selected-pages (pdf-view-current-page) t))
(defun jj/pdftools-unselect-page ()
"Add current page to list of selected pages."
(interactive)
(setq jj/pdftools-selected-pages (delete (pdf-view-current-page) jj/pdftools-selected-pages)))
(defun jj/pdftools-extract-selected-pages (file)
"Save selected pages to FILE."
(interactive "FSave as: ")
(setq jj/pdftools-selected-pages (sort jj/pdftools-selected-pages #'<))
(start-process "pdfjam" "*pdfjam*"
"pdfjam"
(buffer-file-name)
(mapconcat #'number-to-string
jj/pdftools-selected-pages
",")
"-o"
(expand-file-name file)))
;; keyboard shdefine-key pdf-view-mode-map (kbd "h") 'pdf-annot-add-highlight-markup-annotation)
(define-key pdf-view-mode-map (kbd "t") 'pdf-annot-add-text-annotation)
(define-key pdf-view-mode-map "S" #'jj/pdftools-select-page)
(define-key pdf-view-mode-map "U" #'jj/pdftools-unselect-page)
(define-key pdf-view-mode-map "u" #'jj/pdftools-unselect-page)
(define-key pdf-view-mode-map "l" #'jj/pdftools-select-page)
(define-key pdf-view-mode-map "s s" #'jj/pdftools-select-page)
(define-key pdf-view-mode-map "e" #'jj/pdftools-extract-selected-pages)
(define-key pdf-view-mode-map (kbd "D") 'pdf-annot-delete))
(use-package eyebrowse
:diminish eyebrowse-mode
:init
(setq eyebrowse-keymap-prefix (kbd "C-c w"))
(setq eyebrowse-new-workspace nil)
(setq eyebrowse-switch-back-and-forth t)
:bind
(("s-{" . eyebrowse-prev-window-config)
("s-}" . eyebrowse-next-window-config)
("M-`" . eyebrowse-switch-to-window-config-0)
("M-2" . eyebrowse-switch-to-window-config-2)
("M-3" . eyebrowse-switch-to-window-config-3)
("M-4" . eyebrowse-switch-to-window-config-4)
("M-5" . eyebrowse-switch-to-window-config-5)
("M-5" . eyebrowse-switch-to-window-config-5)
("M-6" . eyebrowse-switch-to-window-config-6)
("M-7" . eyebrowse-switch-to-window-config-7)
("M-8" . eyebrowse-switch-to-window-config-8)
("M-9" . eyebrowse-switch-to-window-config-9)
("M-<f11>" . eyebrowse-switch-to-window-config-21)
("M-<f12>" . eyebrowse-switch-to-window-config-22)
;; :prefix-map jj-eyebrowse-wg-map
;; :prefix "M-1"
:map jj-eyebrowse-wg-map
("C-c" . eyebrowse-create-window-config)
("\"" . eyebrowse-close-window-config)
("k" . jj/eyebrowse-close-window-config-switch-to-9)
("'" . eyebrowse-last-window-config)
("," . eyebrowse-rename-window-config)
("." . eyebrowse-switch-to-window-config)
("b" . eyebrowse-switch-to-window-config)
("<return>" . eyebrowse-switch-to-window-config)
("0" . eyebrowse-switch-to-window-config-0)
("`" . eyebrowse-switch-to-window-config-0)
("1" . eyebrowse-switch-to-window-config-1)
("M-1" . eyebrowse-last-window-config)
("2" . eyebrowse-switch-to-window-config-2)
("3" . eyebrowse-switch-to-window-config-3)
("4" . eyebrowse-switch-to-window-config-4)
("5" . eyebrowse-switch-to-window-config-5)
("6" . eyebrowse-switch-to-window-config-6)
("7" . eyebrowse-switch-to-window-config-7)
("8" . eyebrowse-switch-to-window-config-8)
("9" . eyebrowse-switch-to-window-config-9)
("<f1>" . eyebrowse-switch-to-window-config-11)
("<f2>" . eyebrowse-switch-to-window-config-12)
("<f3>" . eyebrowse-switch-to-window-config-13)
("<f4>" . eyebrowse-switch-to-window-config-14)
("<f5>" . eyebrowse-switch-to-window-config-15)
("<f6>" . eyebrowse-switch-to-window-config-16)
("<f7>" . eyebrowse-switch-to-window-config-17)
("<f8>" . eyebrowse-switch-to-window-config-18)
("<f9>" . eyebrowse-switch-to-window-config-19)
("<f10>" . eyebrowse-switch-to-window-config-20)
("<f11>" . eyebrowse-switch-to-window-config-21)
("<f12>" . eyebrowse-switch-to-window-config-22)
("," . eyebrowse-prev-window-config)
("." . eyebrowse-next-window-config)
("'" . eyebrowse-next-window-config)
("c" . eyebrowse-create-window-config))
:config (eyebrowse-mode t))
(use-package chronos
:config
;; (use-package chronos)
;; https://github.com/dxknight/chronos
;; now is 17:00
;; 5 gives an expiry time of 17:05
;; 1:30 gives 18:30
;; 0:0:30 gives 30 seconds after 17:00
;; empty or 0 gives a count up timer starting now, at 17:00.
;; =17:00/Drink coffee + -5/Brew coffee + -5/Boil kettle + 25/Finish break
;; Which will give a timer at 5 o'clock to drink coffee, a timer five minutes before that (16:55) to
;; start brewing the coffee, a reminder five minutes before that (16:50) to put the kettle on and a
;; reminder 25 minutes after that (17:15) to finish drinking coffee and get back to work.
;; Key Action
;; a add a timer by specifying expiry time and a message
;; A add multiple consecutive timer(s) in one go
;; n/p move selection down/up (also C-n/C-p <down>/<up>)
;; SPC pause/unpause (pausing affects time to go and the expiry time, but not elapsed time)
;; d delete selected timer
;; D delete all expired timers
;; e edit selected timer
;; l lap selected timer
;; F freeze/unfreeze the display
;; q quit window
(defun jj/chronos-shell-notify (c)
"Notify expiration of timer C by running a shell command."
;; NOTE: for alarm.wav to work has to be copied to /System/Library/sounds
(if (eq system-type 'darwin)
(chronos--shell-command "Chronos shell notification for Mac OS X"
(executable-find "terminal-notifier")
(list "-ignoreDnD" "-sound" "alarm.wav" "-title" "Chronos Timer" "-message" (chronos--message c) "-execute" "open -a Emacs")
)
(chronos--shell-command "Chronos shell notification for Linux & Windows"
"notify-send"
(list "-t" "3600000" "Chronos Timer" (chronos--message c))))
;; 24*60*60*1000 = 86400000 60*60*1000 = 3600000
)
(setq
;; chronos-shell-notify-program "mpg123"
;; chronos-shell-notify-parameters '("-q ~/.emacs.d/manual-addons/sounds/end.mp3")
;; chronos-shell-notify-program "notify-send"
;; chronos-shell-notify-parameters '("-t" "0" "Сработал таймер")
chronos-notification-wav (expand-file-name "~/Programs/scimax/user/sounds/techno.wav")
chronos-expiry-functions '(chronos-buffer-notify
jj/chronos-shell-notify
chronos-message-notify
;; chronos-sound-notify
))
(use-package helm-chronos)
;; hack for manual addons. helm updates?
(setq helm-chronos--fallback-source
(helm-build-dummy-source "test"
:action '(("Add timer" . helm-chronos--parse-string-and-add-timer))))
(setq helm-chronos-standard-timers
'(
"45/P: Work + 6/P: Break"
"45/P: Work"
" 6/Break"
"15/Long Break"
))
;; (global-set-key (kbd "s-p t") 'helm-chronos-add-timer)
(global-set-key (kbd "s-t") 'helm-chronos-add-timer)
(defun jj/helm-chronos-add-timer-switch-to-chronos ()
(interactive)(helm-chronos-add-timer)(switch-to-buffer "*chronos*"))
(defun jj/switch-to-chronos ()
(interactive)(switch-to-buffer "*chronos*"))
(global-set-key (kbd "s-p s-T") 'jj/helm-chronos-add-timer-switch-to-chronos)
;; Don't use helm if I don't want the timer stored
(global-set-key (kbd "s-p t") 'chronos-add-timer)
(global-set-key (kbd "s-p M-t") 'chronos-add-timer)
;; (global-set-key (kbd "s-p T") 'chronos-add-timers-from-string)
(global-set-key (kbd "s-p s-t") 'jj/switch-to-chronos)
(global-set-key (kbd "s-p T") 'chronos-delete-all-expired))
(use-package goto-chg :defer t
:bind (("M-[" . goto-last-change)
("M-]" . jj/goto-last-change-reverse)
("C-M-s-0" . jj/goto-last-change-back-to-first))
)
;; MARKDOWN mode settings and packages
(use-package markdown-mode
:bind (
:map markdown-mode-command-map
("a" . markdown-table-align)
)
:config
;; Markdown mode built-in preview (need to brew install markdown)
)
;; Used to edit github style code-blocks in native code buffer
(use-package edit-indirect
:after markdown-mode)
;; Markdown: used for realtime markdown preview
;; Need to brew install grip on mac
(use-package grip-mode
:ensure t
:after markdown-mode
:bind (:map markdown-mode-command-map
("g" . grip-mode)
("G" . jj/grip-mode-disable))
:config
;; When nil, update the preview after file saves only.
;; (setq grip-update-after-change nil)
(let ((credential (auth-source-user-and-password "api.github.com")))
(setq grip-github-user (car credential)
grip-github-password (cadr credential)))
)
;; Markdown: used for realtime markdown preview (similar to grip-mode)
;; Default port is 8080 so go to http://localhost:8080/imp/
(use-package impatient-mode
:ensure t
:after markdown-mode
:bind (:map markdown-mode-command-map
("i" . jj/markdown-preview-impatient-mode-httpd-start)
("I" . jj/markdown-preview-impatient-mode-httpd-stop)
("M-i" . impatient-mode))
)
(use-package wgrep
:custom
;; (wgrep-auto-save-buffer t)
(wgrep-change-readonly-file t))
(use-package ag
:custom
(ag-highligh-search t)
(ag-reuse-buffers t)
(ag-reuse-window t)
;; :bind
;; ("M-s a" . ag-project)
:config
(use-package wgrep-ag))
(use-package deadgrep
:bind (("C-x f d" . deadgrep))
:config
(define-key deadgrep-mode-map (kbd "C-c j") 'counsel-imenu)
(define-key deadgrep-mode-map (kbd "C-c C-j") 'counsel-semantic-or-imenu)
(define-key deadgrep-mode-map (kbd "i") 'counsel-imenu)
(define-key deadgrep-mode-map (kbd "j") 'counsel-imenu))
(use-package ox-jekyll-lite
:load-path nil
:after org
:config
(setq org-jekyll-project-root "~/Dropbox/Documents/Blog/"))
(use-package org-gcal
:after org
:config
(if (boundp 'my-google-client-id)
(setq org-gcal-client-id my-google-client-id
org-gcal-client-secret my-google-client-secret))
(setq
org-gcal-file-main "~/Dropbox/Documents/Notes/Orgzly/gcal.org"
org-gcal-email-main "jeffspencerd@gmail.com"
org-gcal-file-alist '(("jeffspencerd@gmail.com" . "~/Dropbox/Documents/Notes/Orgzly/gcal.org"))
org-gcal-auto-archive t
org-gcal-up-days 15
org-gcal-down-days 60
org-gcal-notify-p nil)
(defun jj/org-gcal-fetch-quick ()
(interactive)
(when (jj/internet-up-p)
(let ((org-gcal-auto-archive nil)
(org-gcal-up-days 1)
(org-gcal-down-days 21))
(org-gcal-fetch))))
(defun jj/org-gcal-archive-erase-then-fetch ()
(interactive)
(when (jj/internet-up-p)
(dolist (i org-gcal-fetch-file-alist)
(with-current-buffer
(find-file-noselect (cdr i))
(when org-gcal-auto-archive
(org-gcal--archive-old-event))
;; Ensures whole calender is retrieved (otherwise erases bufffer but doesn't pull calender)
(org-gcal-sync-tokens-clear)
(erase-buffer)
(org-gcal-fetch)
(save-buffer)
))))
(defun jj/org-gcal-fetch-when-idle-quick ()
;; cancel this idle timer if it exists and hasn't run
(cancel-function-timers 'jj/org-gcal-fetch-quick)
(run-with-idle-timer 21 nil 'jj/org-gcal-fetch-quick))
(defun jj/org-gcal-fetch-when-idle-full ()
;; cancel this idle timer if it exists and hasn't run
(cancel-function-timers 'jj/org-gcal-fetch-quick)
(cancel-function-timers 'jj/org-gcal-archive-erase-then-fetch)
(run-with-idle-timer 15 nil 'jj/org-gcal-archive-erase-then-fetch)
(cancel-function-timers 'jj/org-gcal-fetch-quick))
;; FIXME: This locked up due to requests.el so just call once on emacs boot
;; Can check timiers with variables timer-list or timer-idle-list
;; run org-gcal-fetch every 15 minutes when inactive
;; Do a full refresh so archive-delete-fetch every 2 hours
;; (cond
;; ;; NOTE: Doesn't set up timers when desktop-lock exists
;; ((and (string-equal system-type "darwin") (not (file-exists-p (concat (file-name-as-directory (car desktop-path)) desktop-base-lock-name))))
;; (run-with-timer (* 480 60) (* 480 60) 'jj/org-gcal-fetch-when-idle-quick)
;; ;; Run once in emacs-startup-hook
;; (run-at-time "04:05:00" (* 1440 60) 'jj/org-gcal-fetch-when-idle-full)
;; ))
)
(use-package all-the-icons)
;; TODO: some issue with the following code when moving macs that needs fixed
;; (use-package all-the-icons
;; :config
;; (defvar all-the-icons--size-data
;; (make-hash-table :test #'equal)
;; "Icon size data (WIDTH . HEIGHT). Keys formatted as (FAMILY . ICON-NAME)")
;; (defun segment-pixel-width (start end)
;; "Calculate and return the width (in pixels) of the segment between START and END."
;; (save-current-buffer
;; (save-excursion
;; (when (markerp start)
;; (switch-to-buffer (marker-buffer start))
;; (set-buffer (marker-buffer start)))
;; (-let* ((start-x (window-x-pixel-position start))
;; (end-x (window-x-pixel-position end)))
;; (when (and start-x end-x)
;; (- end-x start-x))))))
;; (defun segment-pixel-height (start end)
;; "Calculate and return the height (in pixels) of the segment between START and END."
;; (save-current-buffer
;; (save-excursion
;; (when (markerp start)
;; (switch-to-buffer (marker-buffer start))
;; (set-buffer (marker-buffer start)))
;; (-let* ((start-y (window-y-pixel-position start))
;; (end-y (window-y-pixel-position end)))