-
Notifications
You must be signed in to change notification settings - Fork 0
/
myinit.el
1188 lines (990 loc) · 33.5 KB
/
myinit.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
;; myinit.el --- Config file for my emacs
;;; Commentary:
;;; My config file, all the packages I'm using, except use-package.
;;; Code:
;;; Functions
(defun nodno/insert-date()
"insert current date time.
Insert date in this format: yyyy-mm-dd HH:MM:SS.
for example: 2020-10-08 12:10:00."
(interactive)
(when (use-region-p) (delete-region (region-beginning) (region-end)))
(insert
(format-time-string "%Y-%m-%d %H:%M:%S")))
(defun nodno/go-tag-snakecase()
(interactive)
(setq go-tag-args (list "-transform" "snakecase")))
(defun nodno/go-tag-camelcase()
(interactive)
(setq go-tag-args (list "-transform" "camelcase")))
(defun nodno/go-tag-lispcase()
(interactive)
(setq go-tag-args (list "-transform" "lispcase")))
(defun nodno/go-tag-pascalcase()
(interactive)
(setq go-tag-args (list "-transform" "pascalcase")))
(defun nodno/go-tag-keep()
(interactive)
(setq go-tag-args (list "-transform" "keep")))
(global-set-key (kbd "C-c t") 'nodno/insert-date)
(global-set-key (kbd "C-H-f") 'toggle-frame-fullscreen)
(global-unset-key "\C-x\C-z")
;;; Libraries
(use-package diminish)
(use-package deferred :defer t)
(use-package pkg-info :defer t)
(use-package popup :defer t)
(use-package popup-pos-tip :defer t)
(use-package popwin :defer t)
(use-package pos-tip :defer t)
(use-package web :defer t)
(use-package web-server :defer t)
(use-package websocket :defer t)
(use-package with-editor :defer t)
;;; Packages
(use-package abbrev
:ensure nil
:hook
((js2-mode web-mode) . abbrev-mode))
(use-package ace-jump-mode
:defer t)
(use-package ace-mc
:bind (("<C-m> h" . ace-mc-add-multiple-cursors)
("<C-m> M-h" . ace-mc-add-single-cursor)))
(use-package ace-window
:init (setq aw-swap-invert t)
:bind (("C-x o" . ace-window)
("M-O" . ace-swap-window)))
(use-package aggressive-indent
:diminish
:hook (emacs-lisp-mode . aggressive-indent-mode))
(use-package anaconda-mode
:disabled t
:commands anaconda-mode
:ensure t
:init
(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'anaconda-eldoc-mode)
:config
(define-key anaconda-mode-map (kbd "M-/") 'anaconda-mode-show-doc)
(define-key anaconda-mode-map (kbd "M-.") 'anaconda-mode-find-definitions)
(define-key anaconda-mode-map (kbd "M-,") 'pop-tag-mark)
(define-key anaconda-mode-map (kbd "M-r") nil)
(setq anaconda-mode-localhost-address "localhost"))
(use-package auto-rename-tag
:disabled t
:hook (web-mode . auto-rename-tag-mode))
(use-package avy
;; Avy - navigate by searching for a letter on the screen and jumping to it
:bind* ("C-." . avy-goto-char-timer)
:config
(avy-setup-default))
(use-package avy-zap
:bind
("M-z" . avy-zap-to-char-dwim)
("M-Z" . avy-zap-up-to-char-dwim))
(use-package beacon
:diminish
;; :commands beacon-mode
:config
(beacon-mode t))
(use-package blacken
:ensure t
:bind ("C-c b" . blacken-buffer)
:config
(setq blacken-line-length 114))
(use-package cc-mode
:mode (("\\.h\\(h?\\|xx\\|pp\\)\\'" . c++-mode)
("\\.m\\'" . c-mode)
("\\.mm\\'" . c++-mode)))
;; :bind (:map c-mode-map
;; ("<tab>" . company-complete))
;; :bind (:map c++-mode-map
;; ("<tab>" . company-complete)))
(use-package change-inner
:bind (("M-i" . change-inner)
("M-o M-o" . change-outer)))
(use-package color-theme-modern
:disabled t)
(use-package color-theme-sanityinc-tomorrow
:config
(load-theme 'sanityinc-tomorrow-bright t))
(use-package command-log-mode
:bind (("C-c e M" . command-log-mode)
("C-c e L" . clm/open-command-log-buffer))
:after posframe
:preface
(defvar dw/command-window-frame nil)
(defun dw/toggle-command-window ()
(interactive)
(if dw/command-window-frame
(progn
(posframe-delete-frame clm/command-log-buffer)
(setq dw/command-window-frame nil))
(progn
(global-command-log-mode t)
(with-current-buffer
(setq clm/command-log-buffer
(get-buffer-create " *command-log*"))
(text-scale-set -1))
(setq dw/command-window-frame
(posframe-show
clm/command-log-buffer
:position `(,(- (x-display-pixel-width) 650) . 50)
:width 35
:height 5
:min-width 35
:min-height 5
:internal-border-width 2
:internal-border-color "#c792ea"
:override-parameters '((parent-frame . nil)))))))
:config
(setq clm/log-command-exceptions* nil))
(use-package company
:diminish (company-mode)
:hook (prog-mode . company-mode)
:config
(setq company-idle-delay 0)
(setq company-minimum-prefix-length 1)
(setq company-backends (delete 'company-semantic company-backends)))
(use-package company-anaconda
:after (company anaconda-mode)
:config
(push 'company-anaconda company-backends))
(use-package company-c-headers
:config
(add-to-list 'company-backends 'company-c-headers))
(use-package company-quickhelp
:after company
:hook (company-mode . company-quickhelp-mode))
;; :bind (:map company-active-map
;; ("C-c ?" . company-quickhelp-manual-begin)))
(use-package company-irony
:after (company irony-mode)
:config
(add-to-list 'company-backends 'company-irony))
(use-package company-irony-c-headers
:after (company-irony)
:config
(add-to-list 'company-backends 'company-irony-c-headers))
(use-package counsel
:disabled t
:after ivy
:bind
("M-y" . counsel-yank-pop))
(use-package dap-mode
:config
(require 'dap-go)
(setq dap-print-io t)
(dap-go-setup)
(dap-mode 1)
(dap-ui-mode 1)
;; enables mouse hover support
(dap-tooltip-mode 1)
;; use tooltips for mouse hover
;; if it is not enabled `dap-mode' will use the minibuffer.
(tooltip-mode 1)
;; displays floating panel with debug buttons
;; requies emacs 26+
(dap-ui-controls-mode 1)
(require 'dap-hydra)
(add-hook 'dap-stopped-hook
(lambda (arg) (call-interactively #'dap-hydra))))
(use-package dash-at-point
:bind ("C-c D" . dash-at-point)
:config
(add-to-list 'dash-at-point-mode-alist
'(lisp-mode . "Common Lisp")
'(python-mode . "Python3")))
(use-package deft
:bind ("C-c d" . deft)
:commands (deft)
:config
(setq deft-directory "~/Library/CloudStorage/Dropbox/notes"
deft-extensions '("org")
deft-default-extension "org"
deft-use-filename-as-title t
deft-use-filter-string-for-filename t))
(use-package diredfl
:hook (dired-mode . diredfl-mode))
(use-package dot-org
:load-path "lisp")
(use-package eldoc
:diminish)
(use-package eglot
:hook
(go-mode . eglot-ensure)
(python-mode . eglot-ensure)
:config
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "-i --simple-prompt")
(defvar-local flycheck-eglot-current-errors nil)
(add-to-list 'eglot-server-programs '(python-mode . ("pyright-langserver" "--stdio")))
(setq-default eglot-workspace-configuration
'((:pyright .
((useLibraryCodeForTypes . t)))))
(defun flycheck-eglot-report-fn (diags &rest _)
(setq flycheck-eglot-current-errors
(mapcar (lambda (diag)
(save-excursion
(goto-char (flymake--diag-beg diag))
(flycheck-error-new-at (line-number-at-pos)
(1+ (- (point) (line-beginning-position)))
(pcase (flymake--diag-type diag)
('eglot-error 'error)
('eglot-warning 'warning)
('eglot-note 'info)
(_ (error "Unknown diag type, %S" diag)))
(flymake--diag-text diag)
:checker 'eglot)))
diags))
(flycheck-buffer))
(defun flycheck-eglot--start (checker callback)
(funcall callback 'finished flycheck-eglot-current-errors))
(defun flycheck-eglot--available-p ()
(bound-and-true-p eglot--managed-mode))
(flycheck-define-generic-checker 'eglot
"Report `eglot' diagnostics using `flycheck'."
:start #'flycheck-eglot--start
:predicate #'flycheck-eglot--available-p
:modes '(prog-mode text-mode))
(push 'eglot flycheck-checkers)
(defun sanityinc/eglot-prefer-flycheck ()
(when eglot--managed-mode
(flycheck-add-mode 'eglot major-mode)
(flycheck-select-checker 'eglot)
(flycheck-mode)
(flymake-mode -1)
(setq eglot--current-flymake-report-fn 'flycheck-eglot-report-fn)))
(add-hook 'eglot--managed-mode-hook 'sanityinc/eglot-prefer-flycheck)
;; (define-key eglot-mode-map (kbd "C-c C-o") 'elpy-occur-definitions)
;; ;; as C-c C-o is so handy in elpy, I'll keep it with anaconda-mode
;; (defun elpy-occur-definitions ()
;; "Display an occur buffer of all definitions in the current buffer. Also, switch to that buffer."
;; (interactive)
;; (let ((list-matching-lines-face nil))
;; (occur "^\s*\\(\\(async\s\\|\\)def\\|class\\)\s"))
;; (let ((window (get-buffer-window "*Occur*")))
;; (if window
;; (select-window window)
;; (switch-to-buffer "*Occur*"))))
)
(use-package eyebrowse
:bind-keymap ("C-\\" . eyebrowse-mode-map)
:bind (:map eyebrowse-mode-map
("C-\\ C-\\" . eyebrowse-last-window-config)
("1" . eyebrowse-switch-to-window-config-1)
("2" . eyebrowse-switch-to-window-config-2)
("3" . eyebrowse-switch-to-window-config-3)
("4" . eyebrowse-switch-to-window-config-4))
:config
(eyebrowse-mode t))
(use-package elpy
:disabled t
:ensure t
:defer t
:init
(advice-add 'python-mode :before 'elpy-enable)
:config
(setq eldoc-idle-delay 1)
(setq python-shell-interpreter "ipython"
python-shell-interpreter-args "-i --simple-prompt")
(when (require 'flycheck nil t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules)))
;; force it to use black, as there this function in elpy.el seems
;; can't find black
(defun elpy-format-code ()
"Format code using the available formatter."
(interactive)
(elpy-black-fix-code))
(elpy-enable))
;; (use-package elpy
;; :defer t
;; :init
;; (elpy-enable)
;; :hook
;; (python-mode . elpy-mode)
;; :config
;; (setq eldoc-idle-delay 1)
;; (setq python-shell-interpreter "ipython"
;; python-shell-interpreter-args "-i --simple-prompt")
;; (when (require 'flycheck nil t)
;; (setq elpy-modules (delq 'elpy-module-flymake elpy-modules)))
;; ;; force it to use black, as there this function in elpy.el seems
;; ;; can't find black
;; (defun elpy-format-code ()
;; "Format code using the available formatter."
;; (interactive)
;; (elpy-black-fix-code)))
(use-package exec-path-from-shell
:config (dolist (var '("SSH_AUTH_SOCK" "SSH_AGENT_PID" "GPG_AGENT_INFO" "LANG" "LC_CTYPE"))
(add-to-list 'exec-path-from-shell-variables var)
(setq exec-path-from-shell-check-startup-files nil))
(exec-path-from-shell-initialize))
(use-package expand-region
:bind ("C-=" . er/expand-region))
(use-package f
:defer t)
(use-package flycheck
:hook
(prog-mode . flycheck-mode))
(use-package flycheck-color-mode-line
:hook (flycheck-mode . flycheck-color-mode-line-mode))
(use-package function-args
:config(fa-config-default))
(use-package ggtags
:disabled
:hook
(c-mode-common . (lambda ()
(when (derived-mode-p 'c-mode 'c++-mode 'java-mode 'asm-mode)
(ggtags-mode 1))))
:bind (:map ggtags-mode-map
("C-c g s" . ggtags-find-other-symbol)
("C-c g h" . ggtags-view-tag-history)
("C-c g r" . ggtags-find-reference)
("C-c g f" . ggtags-find-file)
("C-c g c" . ggtags-create-tags)
("C-c g u" . ggtags-update-tags)
("M-," . pop-tag-mark)))
(use-package git-gutter
:disabled
:defer 1
:diminish git-gutter-mode
:init
(global-git-gutter-mode +1))
(use-package gitlab-ci-mode
:defer 2)
(use-package gitlab-ci-mode-flycheck
:after flycheck gitlab-ci-mode
:init
(gitlab-ci-mode-flycheck-enable))
(use-package go
:disabled t
:load-path "lisp/el-go")
(use-package go-dlv
:ensure t)
(use-package go-mode
:mode ("\\.go\\'" . go-mode)
:config
(define-key go-mode-map (kbd "C-c C-o") 'zwp/go-occour-definitions)
(add-hook 'go-mode-hook (lambda () (setq tab-width 4)))
:preface
(defun zwp/go-occour-definitions()
"Display an occur buffer of all definitions in the current buffer. Also, switch to that buffer."
(interactive)
(let ((list-matching-lines-face nil))
(occur "^\s*\\(type\\|func\\|var\\|const\\)\s"))
(let ((window (get-buffer-window "*Occur*")))
(if window
(select-window window)
(switch-to-buffer "*Occur*"))))
)
(use-package go-playground
:bind ("C-c g" . go-playground-exec))
(use-package go-tag
:ensure t
:config
(nodno/go-tag-keep))
;; (use-package google-c-style
;; :config
;; (add-hook 'c-mode-common-hook 'google-set-c-style)
;; (add-hook 'c-mode-common-hook 'google-make-newline-indent))
;; (defun my-c-mode-hook ()
;; (setq c-basic-offset 4
;; c-indent-level 4
;; c-default-style "google"))
;; (add-hook'c-mode-common-hook 'my-c-mode-hook)
;;(add-to-list 'c-default-style '(c++-mode . "k&r"))
;;(add-to-list 'c-default-style '(c-mode . "k&r"))
;;(setq c-default-style "linux"
;; c-basic-offset 4)
;; (setq-default c-basic-offset 4
;; tab-width 4
;; indent-tabs-mode t)
(setq-default c-basic-offset 4
c-indent-level 4
c-default-style "google")
(use-package helm
;; based on http://tuhdo.github.io/helm-intro.html
;; :diminish (helm-mode)
:bind (("M-x" . helm-M-x)
("M-y" . helm-show-kill-ring)
("C-c h" . helm-command-prefix)
("C-h SPC" . helm-all-mark-rings)
("C-x r b" . helm-filtered-bookmarks)
("C-x C-f" . helm-find-files)
("C-x b" . helm-mini)
:map helm-map
;; rebind tab to run persistent action
("<tab>" . helm-execute-persistent-action)
;; make Tab work in terminal
("C-i" . helm-execute-persistent-action)
("C-z" . helm-select-action))
:config
;; (require 'helm-config)
(global-unset-key (kbd "C-x c"))
(global-set-key (kbd "C-c h o") 'helm-occur)
(global-set-key (kbd "C-c h g") 'helm-google-suggest)
(when (executable-find "curl")
(setq helm-google-suggest-use-curl-p t))
(when (string= system-type "darwin")
;; brew info findutils
(setq helm-locate-command
"glocate %s %s"
helm-locate-create-db-command
"gupdatedb --output='%s' --localpaths='%s'"))
(setq helm-split-window-inside-p t ; open helm buffer inside current window, not occupy whole other window
; helm-move-to-line-cycle-in-source t
helm-ff-search-library-in-sexp t ; search for library in `require' and `declare-function' sexp
;;helm-scroll-amount 8 ; scroll 8 lines other window using M-<next>/M-<prior>
helm-ff-file-name-history-use-recentf t
helm-echo-input-in-header-line t
helm-M-x-fuzzy-match t
helm-dwim-target 'next-window
helm-ff-auto-update-initial-value 1)
(helm-autoresize-mode 1)
(helm-mode 1))
(use-package helm-dash
;; fixed dash-doc.el temporary-file-directory to /tmp/ for Catalina
:commands helm-dash
:config
(setq helm-dash-enable-debugging t)
(setq helm-dash-browser-func (quote eww))
(setq helm-dash-docsets-path "/Users/zhaoweipu/Library/Application Support/Dash/DocSets/")
;; (add-to-list 'helm-dash-common-docsets "Go")
;; (add-to-list 'helm-dash-common-docsets "Django")
;; (add-to-list 'helm-dash-common-docsets "Python 2")
(add-to-list 'helm-dash-common-docsets "Python 3")
;; (add-to-list 'helm-dash-common-docsets "JavaScript")
;; (add-to-list 'helm-dash-common-docsets "Redis")
)
(use-package helm-descbinds
:defer 7
:config
(helm-descbinds-mode))
(use-package helm-gtags
:config (setq
helm-gtags-ignore-case t
helm-gtags-auto-update t
helm-gtags-use-input-at-cursor t
helm-gtags-pulse-at-cursor t
helm-gtags-prefix-key "\C-cg"
helm-gtags-suggested-key-mapping t)
:hook ((dired-mode . helm-gtags-mode)
(eshell-mode . helm-gtags-mode)
(c-mode . helm-gtags-mode)
;; (python-mode . helm-gtags-mode)
(c++-mode . helm-gtags-mode)
(java-mode . helm-gtags-mode)
(asm-mode . helm-gtags-mode))
:bind (:map helm-gtags-mode-map
("C-c g a" . helm-gtags-tags-in-this-function)
("C-j" . helm-gtags-select)
("M-." . helm-gtags-dwim)
("M-," . helm-gtags-pop-stack)
("C-c <" . helm-gtags-previous-history)
("C-c >" . helm-gtags-next-history)
("\C-x4." . helm-gtags-find-tag-other-window)))
(use-package helm-ls-git
:after
(helm-mode)
:config
(global-set-key (kbd "C-x C-d") 'helm-browse-project))
(use-package hideshow
:diminish hs-minor-mode
:commands hs-minor-mode
:hook (prog-mode . hs-minor-mode)
:bind (:map prog-mode-map
("M-[" . hs-toggle-hiding)))
(use-package hl-todo
:config
(setq hl-todo-keyword-faces
'(("TODO" . "#FF0000")
("FIXME" . "#FF0000")
("DEBUG" . "#A020F0")
("GOTCHA" . "#FF4500")
("STUB" . "#1E90FF")))
(global-hl-todo-mode)
)
(use-package htmlize)
(use-package hungry-delete
:disabled t
:config
(global-hungry-delete-mode))
(use-package iedit
:defer 5)
(use-package imenu-list
:commands imenu-list-minor-mode)
(use-package indium
:disabled t
)
;; == irony-mode ==
(use-package irony
:ensure t
:defer t
:init
(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)
:config
;; replace the `completion-at-point' and `complete-symbol' bindings in
;; irony-mode's buffers by irony-mode's function
(defun my-irony-mode-hook ()
(define-key irony-mode-map [remap completion-at-point]
'irony-completion-at-point-async)
(define-key irony-mode-map [remap complete-symbol]
'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)
(add-hook 'irony-mode-hook 'irony-cdb-autosetup-compile-options))
(use-package ivy
:disabled t
:diminish (ivy-mode)
:config
(setq ivy-count-format "%d/%d "))
(use-package js2-mode
:mode ("\\.js\\'" . js2-mode)
:config
(setq js-indent-level 2)
(use-package js2-refactor)
(use-package xref-js2)
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(js2r-add-keybindings-with-prefix "C-c C-r")
(define-key js2-mode-map (kbd "C-k") #'js2r-kill)
;; js-mode (which js2 is based on) binds "M-." which conflicts with xref, so
;; unbind it.
(define-key js-mode-map (kbd "M-.") nil)
(add-hook 'js2-mode-hook (lambda ()
(add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))))
(use-package json-mode)
(use-package leetcode
:bind
("C-x l" . leetcode)
:config
(setq leetcode-prefer-language "python3"))
(use-package link-hint
;; :defer 10
:bind ("C-c C-o" . link-hint-open-link)
:config
(add-hook 'eww-mode-hook
#'(lambda () (bind-key "f" #'link-hint-open-link eww-mode-map))))
(use-package linum
:hook
(prog-mode . linum-mode))
(use-package lua-mode
:mode "\\.lua\\'"
:interpreter "lua"
:config
(setq lua-indent-level 4))
(use-package lsp-mode
:disabled t
:commands (lsp lsp-deferred)
:custom
;; (lsp-auto-guess-root t)
(lsp-enable-snippet nil)
(lsp-prefer-flymake nil) ; Use flycheck instead of flymake
:hook
;; ((js-mode css-mode scss-mode typescript-mode web-mode go-mode) . lsp-deferred)
((go-mode python-mode) . lsp-deferred)
;;((go-mode) . lsp-deferred)
;; ((js-mode css-mode scss-mode typescript-mode web-mode) . lsp-deferred)
(lsp-mode . (lambda ()
(let ((lsp-keymap-prefix "H-l"))
(lsp-enable-which-key-integration))))
:config
;; (setq lsp-gopls-staticcheck t)
;; (setq lsp-eldoc-render-all t)
;; (setq lsp-gopls-complete-unimported t)
(add-to-list 'lsp-file-watch-ignored-directories "/usr/local/go/src")
;; don't scan 3rd party javascript libraries
(push "[/\\\\][^/\\\\]*\\.\\(json\\|html\\|jade\\)$" lsp-file-watch-ignored) ; json
(define-key lsp-mode-map (kbd "H-l") lsp-command-map)
(use-package helm-lsp :commands helm-lsp-workspace-symbol)
;; Optional - provides fancier overlays.
(use-package lsp-ui
:init
(setq lsp-ui-doc-position 'top)
:commands lsp-ui-mode))
;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
(add-hook 'before-save-hook #'lsp-format-buffer t t)
(add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)
(use-package markdown-mode
:ensure t
:mode ("README\\.md\\'" . gfm-mode)
:init (setq markdown-command "multimarkdown"))
(use-package macrostep
:bind ("C-c e m" . macrostep-expand))
(use-package magit
:bind
("C-x g" . magit-status)
("C-x M-g" . magit-dispatch)
:config
(setq magit-repository-directories
'((user-emacs-directory . 0)
("~/workspace/github.com" . 2)
("~/workspace/git" . 2)
("~/go/src/gitlab.p1staff.com" . 2))))
(use-package mule
:disabled t
:no-require t
:config
(prefer-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))
(use-package multiple-cursors
:after (phi-search selected)
;; :defer 5
;; - Sometimes you end up with cursors outside of your view. You can scroll
;; the screen to center on each cursor with `C-v` and `M-v`.
;;
;; - If you get out of multiple-cursors-mode and yank - it will yank only
;; from the kill-ring of main cursor. To yank from the kill-rings of every
;; cursor use yank-rectangle, normally found at C-x r y.
:bind (
;; Mark one more occurrence
("<C-m> w" . mc/mark-next-like-this-word)
("<C-m> y" . mc/mark-next-like-this-symbol)
("<C-m> x" . mc/mark-more-like-this-extended)
;; Mark many occurrences
("<C-m> c" . mc/mark-all-dwim)
("<C-m> ^" . mc/edit-beginnings-of-lines)
("<C-m> `" . mc/edit-beginnings-of-lines)
("<C-m> $" . mc/edit-ends-of-lines)
("<C-m> '" . mc/edit-ends-of-lines)
("<C-m> W" . mc/mark-all-words-like-this)
("<C-m> Y" . mc/mark-all-symbols-like-this)
("<C-m> a" . mc/mark-all-like-this-dwim)
("<C-m> r" . mc/mark-all-in-region)
("<C-m> %" . mc/mark-all-in-region-regexp)
("<C-m> t" . mc/mark-sgml-tag-pair)
("<C-m> C-SPC" . mc/mark-pop)
("<C-m> (" . mc/mark-all-symbols-like-this-in-defun)
("<C-m> C-(" . mc/mark-all-words-like-this-in-defun)
("<C-m> M-(" . mc/mark-all-like-this-in-defun)
("<C-m> [" . mc/vertical-align-with-space)
("<C-m> {" . mc/vertical-align)
("S-<down-mouse-1>")
("S-<mouse-1>" . mc/add-cursor-on-click)
;; Special
("<C-m> s" . set-rectangular-region-anchor)
("<C-m> R" . mc/reverse-regions)
("<C-m> S" . mc/sort-regions)
("<C-m> l" . mc/insert-letters)
("<C-m> n" . mc/insert-numbers)
("<C-m> C-x" . reactivate-mark))
:bind (:map selected-keymap
("c" . mc/edit-lines)
("." . mc/mark-next-like-this)
("<" . mc/unmark-next-like-this)
("C->" . mc/skip-to-next-like-this)
("," . mc/mark-previous-like-this)
(">" . mc/unmark-previous-like-this)
("C-<" . mc/skip-to-previous-like-this)
("y" . mc/mark-next-symbol-like-this)
("Y" . mc/mark-previous-symbol-like-this)
("w" . mc/mark-next-word-like-this)
("W" . mc/mark-previous-word-like-this))
:preface
(defun reactivate-mark ()
(interactive)
(activate-mark)))
(use-package multi-term
:disabled t
:bind (("C-c t" . multi-term-next)
("C-c T" . multi-term))
:init
(defun screen ()
(interactive)
(let (term-buffer)
;; Set buffer.
(setq term-buffer
(let ((multi-term-program (executable-find "screen"))
(multi-term-program-switches "-DR"))
(multi-term-get-buffer)))
(set-buffer term-buffer)
(multi-term-internal)
(switch-to-buffer term-buffer)))
:config
(require 'term)
(defalias 'my-term-send-raw-at-prompt 'term-send-raw)
(defun my-term-end-of-buffer ()
(interactive)
(call-interactively #'end-of-buffer)
(if (and (eobp) (bolp))
(delete-char -1)))
(defadvice term-process-pager (after term-process-rebind-keys activate)
(define-key term-pager-break-map "\177" 'term-pager-back-page)))
(use-package tern :ensure t :defer 30
:if (locate-file "tern" exec-path)
:hook (js2-mode . tern-mode))
(use-package thrift
:ensure t
:defer t
:config
(setq thrift-indent-level 4)
)
(use-package pdf-tools
;; (setenv "PKG_CONFIG_PATH" "/usr/local/lib/pkgconfig:/usr/local/Cellar/libffi/3.2.1/lib/pkgconfig")
:defer 6
:magic ("%PDF" . pdf-view-mode)
:config
(pdf-tools-install :no-query))
;; (use-package personal
;; :load-path "lisp"
;; :bind (("M-M" . my-open-Messages)
;; ("M-T" . my-open-Things3)
;; ("M-W" . my-open-WeChat)
;; ("M-S" . my-open-Safari)
;; ("M-F" . my-open-Finder)))
(use-package phi-search
:defer 5)
(use-package phi-search-mc
:after (phi-search multiple-cursors)
:config
(phi-search-mc/setup-keys)
(add-hook 'isearch-mode-mode #'phi-search-from-isearch-mc/setup-keys))
(use-package php-mode
:mode ("\\.php\\'" . php-mode)
:interpreter ("php" . python-mode))
(use-package popup
:ensure t)
(use-package pos-tip
:ensure t)
(use-package posframe)
(use-package prettier-js
:hook
(web-mode . prettier-js-mode))
(use-package protobuf-mode
:ensure t
:mode ("\\.proto\\'" . protobuf-mode)
:config
(defconst my-protobuf-style
'((c-basic-offset . 4)
(indent-tabs-mode . nil)))
(add-hook 'protobuf-mode-hook
(lambda () (c-add-style "my-style" my-protobuf-style t))))
(use-package projectile
:bind-keymap
("C-c p" . projectile-command-map)
("s-p" . projectile-command-map)
:config
(use-package helm-projectile
:ensure t
:config
(use-package helm-ag
:config
(setq helm-ag-insert-at-point 'symbol))
(helm-projectile-on))
(setq projectile-completion-system 'helm)
(setq projectile-switch-project-action 'helm-projectile)
;; (setq projectile-enable-caching t)
(projectile-mode +1))
(use-package python
;; The package is "python" but the mode is "python-mode":
:mode ("\\.py\\'" . python-mode)
:interpreter ("python" . python-mode)
:config
(setq-default indent-tabs-mode nil)
;; (setq python-indent-level 4))
(setq python-indent-guess-indent-offset t)
(setq python-indent-guess-indent-offset-verbose nil)
(define-key python-mode-map (kbd "C-c C-o") 'elpy-occur-definitions)
:preface
(defun elpy-occur-definitions ()
"Display an occur buffer of all definitions in the current buffer.
Also, switch to that buffer"
(interactive)
(let ((list-matching-lines-face nil))
(occur "^\s*\\(\\(async\s\\|\\)def\\|class\\)\s"))
(let ((window (get-buffer-window "*Occur*")))
(if window
(select-window window)
(switch-to-buffer "*Occur*"))))
)
(use-package pyvenv
:hook (python-mode . pyvenv-mode)
:config
(setenv "WORKON_HOME" "/Users/zhaoweipu/miniconda3/envs")
(pyvenv-workon "pydata-book"))
(use-package regex-tool
:commands regex-tool
:preface
(defun regex-tool-perl ()
"Set perl as backend and run regex-tool."
(interactive)
(setq regex-tool-backend 'perl)
(regex-tool))
(defun regex-tool-emacs ()
"Set perl as backend and run regex-tool."
(interactive)
(setq regex-tool-backend 'emacs)
(regex-tool)))
(use-package sdcv
:load-path "lisp"
:demand t
:config
(global-set-key (kbd "C-x t") 'sdcv-search-pointer))
(use-package selected
:demand t
:diminish selected-minor-mode
:bind (:map selected-keymap