-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
971 lines (848 loc) · 32.2 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
;;; init --- my personal emacs config
;;; Commentary:
;;; Code:
(setq inhibit-startup-screen t ; do not display turtorial
package-enable-at-startup nil ; prevent accidentally loading packages twice
initial-major-mode 'fundamental-mode) ; disable lisp-mode for *scatch*
;; load custome package archives or china mirror
(unless (load (concat user-emacs-directory "my-package-archives.el") t t t)
(setq package-archives '(("gnu" . "http://elpa.emacs-china.org/gnu/")
("melpa" . "http://elpa.emacs-china.org/melpa/"))))
(add-to-list 'load-path (concat user-emacs-directory "my/"))
(add-to-list 'load-path (concat user-emacs-directory "contrib/"))
(package-initialize)
;; Avoid errors of emacs-nox
(when (display-graphic-p)
(menu-bar-mode 0)
(tool-bar-mode 0)
(scroll-bar-mode 0)
(horizontal-scroll-bar-mode 0))
(setq auto-window-vscroll nil
message-log-max 16384
mode-require-final-newline t
column-number-mode t
gc-cons-threshold 1073741824 ; 1G
gc-cons-percentage 0.6)
(when (eq system-type 'windows-nt)
;; use local encoding avoid chinese encoding problem on Windows
(set-locale-environment)
;; create new file as utf-8 encoding
(defun my/set-new-file-to-utf-8 ()
(with-current-buffer (current-buffer)
(setq buffer-file-coding-system 'utf-8))
t)
(add-to-list 'find-file-not-found-functions #'my/set-new-file-to-utf-8))
(setq-default indent-tabs-mode nil
tab-width 4)
(defalias 'yes-or-no-p 'y-or-n-p)
(global-set-key (kbd "M-/") #'hippie-expand)
(global-set-key (kbd "C-x C-b") #'ibuffer)
(global-set-key (kbd "C-c w") #'whitespace-mode)
(global-set-key (kbd "C-s") #'isearch-forward-regexp)
(global-set-key (kbd "C-r") #'isearch-backward-regexp)
(global-set-key (kbd "C-M-s") #'isearch-forward)
(global-set-key (kbd "C-M-r") #'isearch-backward)
(global-set-key (kbd "C-c C-f") #'find-file-at-point)
(setq save-interprogram-paste-before-kill t
apropos-do-all t
mouse-yank-at-point t
require-final-newline t
visible-bell t
load-prefer-newer t
ediff-window-setup-function 'ediff-setup-windows-plain
save-place-file (concat user-emacs-directory "places")
backup-directory-alist `(("." . ,(concat user-emacs-directory
"backups"))))
;; make file executable if it contains a shebang comment
(add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
(defun my/edit-init-file ()
"Open init.el file for editing."
(interactive)
(find-file user-init-file))
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
;; install use-package automatically (use :ensure t for other package)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(eval-when-compile
(require 'use-package)
(require 'my-use-package-ensure-contrib))
(use-package bind-key)
(use-package diminish
:ensure t)
(diminish 'abbrev-mode)
(use-package misc
:bind ("M-z" . zap-up-to-char))
(use-package uniquify
:init (setq uniquify-buffer-name-style 'forward))
(use-package saveplace
:init (setq-default save-place t))
(use-package linum
:defer 1
:config (global-linum-mode t))
(use-package autorevert
:defer 1
:config (global-auto-revert-mode))
(use-package paren
:defer 1
:config (show-paren-mode 1))
(use-package hl-line
:defer 2
:config (global-hl-line-mode))
(use-package f
:ensure t
:defer t)
(use-package s
:ensure t
:defer t)
(use-package dash
:ensure t
:defer t)
(use-package hl-todo
:ensure t
:defer 2
:config (global-hl-todo-mode))
(use-package volatile-highlights
:ensure t
:defer 2
:diminish volatile-highlights-mode
:config (volatile-highlights-mode t))
(use-package danneskjold-theme
:ensure t
:init
(load-theme 'danneskjold t))
;; loading spaceline
(use-package spaceline
:ensure t
:defer t)
(use-package spaceline-config
:commands (spaceline-emacs-theme spaceline-spacemacs-theme)
:init
(defun my/load-spaceline ()
"Load spaceline (two slow to load automatically)."
(interactive)
(spaceline-emacs-theme))
:config (setq spaceline-window-numbers-unicode t))
;; TODO custom spaceline!
(use-package spaceline-all-the-icons
:ensure t
:after (spaceline)
:config (spaceline-all-the-icons-theme))
(use-package all-the-icons-dired
:ensure t
:hook (dired-mode . all-the-icons-dired-mode))
(use-package company
:ensure t
:diminish company-mode
:commands (company-complete company-complete-common)
:config
(if (eq system-type 'windows-nt)
(setq-default company-idle-delay 0.05 ; 0 will cause company-clany error on windows
company-async-timeout 5) ; company-clang very slow on windows
(setq-default company-idle-delay 0))
(setq-default company-minimum-prefix-length 2)
;; remove unused backend
(setq company-backends (delq #'company-bbdb company-backends))
(setq company-backends (delq #'company-nxml company-backends))
(setq company-backends (delq #'company-css company-backends))
(setq company-backends (delq #'company-eclim company-backends))
(setq company-backends (delq #'company-xcode company-backends))
(setq company-backends (delq #'company-oddmuse company-backends))
(setq company-dabbrev-downcase nil)
:hook ((prog-mode . global-company-mode)
(yaml-mode . global-company-mode)))
(use-package helpful
:ensure t
:bind (("C-h f" . helpful-callable)
("C-h v" . helpful-variable)
("C-h k" . helpful-key)
("C-h F" . helpful-function)
("C-h C" . helpful-command)
("C-h p" . helpful-at-point)))
(use-package which-key
:ensure t
:defer 2
:diminish which-key-mode
:config (which-key-mode))
; ivy-immediate-done C-M-j
(use-package ivy
:ensure t
:defer 2
:diminish ivy-mode
:bind ("C-x C-r" . ivy-resume)
:config
(setq ivy-use-virtual-buffers t
enable-recursive-minibuffers t)
(ivy-mode 1))
(use-package hydra
:ensure t
:defer t)
(use-package avy
:ensure t
:defer t)
(use-package ivy-hydra
:ensure t
:after (ivy))
(use-package swiper
:ensure t
:bind ("C-s" . swiper))
(use-package tramp
:defer 2)
(use-package counsel
:ensure t
:bind (("M-x" . counsel-M-x)
("M-y" . counsel-yank-pop)
("C-x C-f" . counsel-find-file)
("C-x l" . counsel-locate)
("C-c i" . counsel-semantic-or-imenu)
("C-h l" . counsel-find-library)
("<C-tab>" . counsel-company)
("C-x r RET" . counsel-recentf)))
(use-package wgrep
:ensure t
:defer 2)
(use-package bm
:ensure t
:bind (("<f2>" . bm-toggle)
("C-<f2>" . bm-next)
("S-<f2>" . bm-previous)))
(use-package ace-jump-mode
:ensure t
:bind ("C-c SPC" . ace-jump-mode))
(use-package ace-window
:ensure t
:bind ("M-o" . ace-window)
:config (setq aw-keys '(?a ?s ?d ?f ?g ?h ?j ?k ?l)))
(use-package ace-link
:ensure t
:after (:any xref info compile helpful woman eww)
:config (ace-link-setup-default))
(use-package projectile
:ensure t
:defer t
:config
(setq-default projectile-globally-ignored-files '("TAGS" "cscope.*"))
(projectile-register-project-type 'cmake '("CMakeLists.txt"))
(projectile-register-project-type 'kernel '("Kbuild" "Kconfig" "kernel" "mm" "init"))
(projectile-register-project-type 'u-boot '("Kbuild" "Kconfig" "include/u-boot"))
(projectile-register-project-type 'kernel-module '(".kernel-module"))
(projectile-register-project-type 'openapi-yaml '("index.yaml")
:compile "openapi-bundle > openapi.yaml && openapi-spec-validator openapi.yaml")
(projectile-register-project-type 'openapi-json '("index.json")
:compile "openapi-bundle -y > openapi.yaml && openapi-spec-validator openapi.yaml")
(require 'f)
(require 's)
(require 'dash)
(require 'compile)
(defun my/projectile--kbuild-build-dir-p (dir)
"Whether `DIR' is a build-dir directory."
(f-exists-p (f-join dir ".config")))
(defun my/projectile--kbuild-build-dirs (root)
"All build-dir directories found at top directories of `ROOT'."
(let ((build-dirs (f-directories root #'my/projectile--kbuild-build-dir-p)))
(if (my/projectile--kbuild-build-dir-p root)
(cons root build-dirs)
build-dirs)))
(defun my/projectile--kbuild-default-build-dir (root)
"Default build-dir directory on switching project.
If no build-dir directory found, `ROOT' is returned."
(let ((build-dirs (my/projectile--kbuild-build-dirs root)))
(if (null build-dirs)
root
(car build-dirs))))
(defun my/projectile--kbuild-finish-selecting-build-dir (source-dir build-dir &optional source-incs build-incs)
(setq cscope-option-do-not-update-database t)
(cscope-set-initial-directory build-dir)
(let ((incs (-concat (--map (f-join source-dir it) source-incs)
(--map (f-join build-dir it) build-incs))))
;; includes for semantic
(when (my/semantic-enabled?)
(my/semantic-clear-cc-includes)
(-map #'my/semantic-add-cc-include incs))
;; includes for company-c-headers
(setq-default company-c-headers-path-system incs)))
(defun my/projectile--kbuild-select-default-build-dir (source-dir &optional source-incs build-incs)
(let ((build-dir (my/projectile--kbuild-default-build-dir source-dir)))
(my/projectile--kbuild-finish-selecting-build-dir source-dir build-dir source-incs build-incs)))
(defun my/projectile--kbuild-select-build-dir (source-dir &optional source-incs build-incs)
(ivy-read "Select build directory: "
(my/projectile--kbuild-build-dirs source-dir)
:require-match t
:action (lambda (build-dir)
(my/projectile--kbuild-finish-selecting-build-dir source-dir build-dir source-incs build-incs))
:caller 'my/projectile--kbuild-select-build-dir))
(defvar my/projectile--kernel-includes '(("include" "include/uapi" "arch/arm/include" "arch/arm/include/uapi")
. ("include" "include/uapi" "include/generated" "include/generated/uapi" "arch/arm/include/generated" "arch/arm/include/generated/uapi"))
"Linux kernel includes")
(defvar my/projectile--u-boot-includes '(("include" "arch/arm/include")
. ("include" "include/generated" "arch/arm/include/generated"))
"U-boot includes")
(defun my/projectile-kbuild-select-build-dir ()
"Select build directory for kbuild project."
(interactive)
(let ((ptype (projectile-project-type))
(source-dir (projectile-project-root)))
(cond
((equal ptype 'kernel)
(my/projectile--kbuild-select-build-dir source-dir (car my/projectile--kernel-includes)
(cdr my/projectile--kernel-includes)))
((equal ptype 'u-boot)
(my/projectile--kbuild-select-build-dir source-dir (car my/projectile--u-boot-includes)
(cdr my/projectile--u-boot-includes)))
(t (message "Not a Kbuild project")))))
(defun my/projectile--kbuild-teardown ()
(cscope-unset-initial-directory)
(setq cscope-option-do-not-update-database nil)
(if (my/semantic-enabled?)
(my/semantic-reset-cc-includes))
(setq company-c-headers-path-system '("/usr/include" "/usr/local/include")))
(defun my/projectile--kernel-module-current-kernel-dirs ()
(let* ((kver (s-trim (shell-command-to-string "uname -r")))
(kmod (concat "/lib/modules/" kver "/")))
(cons (concat kmod "source") (concat kmod "build"))))
(defun my/projectile--kernel-module-auto-kernel-dirs (proj-root)
(let ((maybe-build (f-join proj-root "build"))
(maybe-source (f-join proj-root "source")))
(if (and (f-symlink-p maybe-build) (f-directory-p maybe-build))
(cons maybe-source maybe-build)
(my/projectile--kernel-module-current-kernel-dirs))))
(defun my/projectile--kernel-module-setup (proj-root)
"Read kernel source and build directories from .kernel-module.
If .kernel-module is empty, current kernel is used, otherwise the format
is ('source dir' . 'build-dir')."
(let* ((dot-kernel-module-path (f-join proj-root ".kernel-module"))
(dot-kernel-module-text (s-trim (f-read-text dot-kernel-module-path)))
(kernel-dirs (if (s-blank-p dot-kernel-module-text)
(my/projectile--kernel-module-auto-kernel-dirs proj-root)
(car (read-from-string dot-kernel-module-text))))
(kernel-source-dir (car kernel-dirs))
(kernel-build-dir (cdr kernel-dirs)))
(my/projectile--kbuild-finish-selecting-build-dir kernel-source-dir kernel-build-dir
(car my/projectile--kernel-includes)
(cdr my/projectile--kernel-includes))
(setq compile-command (concat "make " "KDIR=" kernel-build-dir))
(message "Linux kernel source %s, build %s" kernel-source-dir kernel-build-dir)))
(defun my/cmake--configs-path (proj-root)
(f-join proj-root ".cmake-configs"))
(defun my/cmake--configs (proj-root)
(let ((dot-configs-path (my/cmake--configs-path proj-root)))
(if (file-readable-p dot-configs-path)
(let* ((dot-configs-text (s-trim (f-read-text dot-configs-path)))
(configs (if (s-blank-p dot-configs-text)
nil
(car (read-from-string dot-configs-text)))))
configs)
nil)))
(defun my/cmake--set-configs (proj-root configs)
(f-write-text (prin1-to-string configs) 'utf-8 (my/cmake--configs-path proj-root)))
(defun my/cmake--clear-configs (proj-root)
(my/cmake--set-configs proj-root '()))
(defun my/cmake--config-name (cfg)
(car cfg))
(defun my/cmake--config-flags (cfg)
(concat (cdr cfg) " -DCMAKE_EXPORT_COMPILE_COMMANDS=1"))
(defun my/cmake--config-build-dir (proj-root cfg)
(f-join proj-root (format "cmake-build-%s" (my/cmake--config-name cfg))))
(defun my/cmake--config-command (proj-root cfg)
(let ((build-dir (my/cmake--config-build-dir proj-root cfg))
(flags (my/cmake--config-flags cfg)))
(concat "mkdir -p " build-dir
" && cd " build-dir
" && cmake " flags " ..")))
(defun my/cmake--config-build-command (proj-root cfg)
(let ((build-dir (my/cmake--config-build-dir proj-root cfg)))
(concat "cmake --build " build-dir)))
(defun my/cmake--select-config (proj-root cfg)
(shell-command (my/cmake--config-command proj-root cfg))
(setq compile-command (my/cmake--config-build-command proj-root cfg)))
(defun my/cmake--add-or-subs-config (proj-root cfg)
(let* ((configs (my/cmake--configs proj-root))
(new-configs (cons cfg (--select (not (equal name (car it))) configs))))
(my/cmake--set-configs proj-root new-configs)))
(defun my/cmake--rm-config-by-name (proj-root name)
(let* ((configs (my/cmake--configs proj-root))
(new-configs (--select (not (equal name (car it))) configs)))
(my/cmake--set-configs proj-root new-configs)))
(defun my/cmake-make-config (name flags)
"Make a new or substitute a config."
(interactive (list
(read-string "Name: ")
(read-string "Flags: " "-DCMAKE_BUILD_TYPE=Debug")))
(when (equal (projectile-project-type) 'cmake)
(let ((proot (projectile-project-root))
(cfg (cons name flags)))
(my/cmake--add-or-subs-config proot cfg)
;; delete build directory because the flags may be changed
(let ((build-dir (my/cmake--config-build-dir proot cfg)))
(when (file-directory-p build-dir)
(delete-directory build-dir t)))
(my/cmake--select-config proot cfg))))
(defun my/cmake-remove-config ()
"Remove a config"
(interactive)
(when (equal (projectile-project-type) 'cmake)
(let* ((proot (projectile-project-root)))
(ivy-read "Remove config: "
(--map (car it) (my/cmake--configs proot))
:require-match t
:action (lambda (name)
(my/cmake--rm-config-by-name proot name))
:caller 'my/cmake-remove-config))))
(defun my/cmake-clear-config ()
"Clear all configs"
(interactive)
(when (equal (projectile-project-type) 'cmake)
(my/cmake--clear-configs (projectile-project-root))))
(defun my/cmake-select-config ()
"Select a config."
(interactive)
(when (equal (projectile-project-type) 'cmake)
(let* ((proot (projectile-project-root))
(configs (my/cmake--configs proot))
(config-names (--map (car it) configs)))
(ivy-read "Select config: "
config-names
:require-match t
:action (lambda (name)
(my/cmake--select-config proot (assoc name configs)))
:caller 'my/cmake-remove-config))))
(defun my/cmake-open-config-file ()
"Open config file for edit."
(interactive)
(when (equal (projectile-project-type) 'cmake)
(find-file (my/cmake--configs-path (projectile-project-root)))))
(defun my/cmake--project-setup (proj-root)
(let ((configs (my/cmake--configs proj-root)))
(unless (null configs)
(my/cmake--select-config proj-root (car configs)))))
(defun my/projectile-project-setup ()
(let ((ptype (projectile-project-type))
(proot (projectile-project-root)))
(message "Entered a %s project" (symbol-name ptype))
(cond
((equal ptype 'kernel)
(message "Linux kernel found at %s" proot)
(my/projectile--kbuild-select-default-build-dir proot (car my/projectile--kernel-includes) (cdr my/projectile--kernel-includes))
)
((equal ptype 'u-boot)
(message "U-boot found at %s" proot)
(my/projectile--kbuild-select-default-build-dir proot (car my/projectile--u-boot-includes) (cdr my/projectile--u-boot-includes))
)
((equal ptype 'kernel-module)
(message "Kernel module found at %s" proot)
(my/projectile--kernel-module-setup proot)
)
((equal ptype 'cmake)
(message "CMake project found at %s" proot)
(my/cmake--project-setup proot)
))))
(add-hook 'projectile-after-switch-project-hook #'my/projectile-project-setup)
(defun my/projectile-project-teardown ()
(let ((ptype (projectile-project-type)))
(message "Leaving a %s project" (symbol-name ptype))
(cond
((equal ptype 'kernel) (my/projectile--kbuild-teardown))
((equal ptype 'u-boot) (my/projectile--kbuild-teardown))
((equal ptype 'kernel-module) (my/projectile--kbuild-teardown))
((equal ptype 'cmake) nil))))
(add-hook 'projectile-before-switch-project-hook #'my/projectile-project-teardown))
(use-package counsel-projectile
:ensure t
:bind-keymap ("C-c p" . counsel-projectile-command-map)
:config (counsel-projectile-mode))
(use-package magit
:ensure t
:bind ("C-x g" . magit-status)
:config (setq magit-completing-read-function 'ivy-completing-read))
(use-package gitignore-mode
:ensure t
:mode "\\.gitignore\\'")
(use-package git-timemachine
:ensure t
:defer t)
(use-package multi-term
:ensure t
:defer t)
(use-package vlf
:ensure t
:defer 2
:config (require 'vlf-setup))
;; programming
(use-package rainbow-delimiters
:ensure t
:hook (prog-mode . rainbow-delimiters-mode))
(use-package smartparens
:ensure t
:diminish smartparens-mode
:hook ((prog-mode . smartparens-mode)
(yaml-mode . smartparens-mode))
:bind (("M-p" . 'sp-forward-parallel-sexp)
("C-M-p" . 'sp-backward-parallel-sexp)))
(use-package smartparens-config
:after (smartparens))
(use-package yasnippet
:ensure t
:diminish yas-minor-mode
:after (company)
:config (yas-global-mode))
(use-package yasnippet-snippets
:ensure t
:after (yasnippet))
(use-package company-yasnippet
:after (yasnippet)
:bind ("C-M-y" . company-yasnippet))
(use-package expand-region
:ensure t
:bind ("C-=" . er/expand-region))
(use-package iedit
:ensure t
:bind ("C-;" . iedit-mode))
(put 'narrow-to-region 'disabled nil)
(use-package sr-speedbar
:ensure t
:bind ("<f6>" . sr-speedbar-toggle)
:config (setq speedbar-show-unknown-files t))
(use-package aggressive-indent
:ensure t
:hook (emacs-lisp-mode . aggressive-indent-mode))
(use-package highlight-indentation
:ensure t
:commands (highlight-indentation-mode)
:hook (yaml-mode . highlight-indentation-mode)
:config
(set-face-background 'highlight-indentation-face "#e3e3d3")
(set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
(defun aj-toggle-fold ()
"Toggle fold all lines larger than indentation on current line"
(interactive)
(let ((col 1))
(save-excursion
(back-to-indentation)
(setq col (+ 1 (current-column)))
(set-selective-display
(if selective-display nil (or col 1))))))
(global-set-key (kbd "C-`") #'aj-toggle-fold))
(use-package smart-shift
:ensure t
:commands (smart-shift-mode)
:hook (yaml-mode . smart-shift-mode))
(use-package hungry-delete
:ensure t
:diminish hungry-delete-mode
:hook (prog-mode . hungry-delete-mode))
(use-package tdd
:ensure-contrib "https://raw.githubusercontent.com/jorgenschaefer/emacs-tdd/master/tdd.el"
:commands (tdd-mode))
;; backtrace buffer: realgud:window-bt
;; enable short key debugging: use short-key mode (C-x C-a C-q)
;; clear mark: loc-change-clear-buffer
(use-package realgud
:ensure t
:commands (realgud:gdb realgud:pdb)
:config
(setq-default realgud:pdb-command-name "python -m pdb")
(setq-default gdb-many-windows t
gdb-show-main t))
(use-package my-indent-whole-buffer
:commands (my/indent-whole-buffer)
:init (defalias 'iwb 'my/indent-whole-buffer))
(use-package my-prog-mode-config
:hook (prog-mode . my/prog-mode-config))
(use-package my-semantic
:commands (my/semantic-enabled? my/semantic-enable my/semantic-disable my/semantic-reset-cc-includes my/semantic-add-cc-include))
(use-package srefactor
:ensure t
:after (my-enable-semantic)
:bind (:map c-mode-base-map
("M-RET" . srefactor-refactor-at-point)))
(use-package flycheck
:ensure t
:diminish flycheck-mode
:hook (prog-mode . flycheck-mode)
:config
(add-to-list 'display-buffer-alist
`(,(rx bos "*Flycheck errors" eos)
(display-buffer-reuse-window display-buffer-in-side-window)
(side . bottom)
(reuseable-frames . visible)
(window-height . 0.23)))
(setq flycheck-display-errors-function #'flycheck-display-error-messages-unless-error-list))
;; lua
(use-package lua-mode
:ensure t
:mode "\\.lua\\'")
;; python
(use-package elpy
:ensure t
:diminish elpy-mode
:after (python)
:config
(elpy-enable)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(elpy-set-test-runner 'elpy-test-pytest-runner)
(setq-default python-shell-interpreter "jupyter"
python-shell-interpreter-args "console --simple-prompt"
python-shell-prompt-detect-failure-warning nil)
(add-to-list 'python-shell-completion-native-disabled-interpreters "jupyter"))
(use-package pipenv
:ensure t
:init (setenv "WORKON_HOME" "~/.virtualenvs")
:diminish pipenv-mode
:hook (python-mode . pipenv-mode)
:mode ("/Pipfile\\'" . conf-mode)
:config
(defun pipenv-install-elpy ()
(interactive)
(pipenv-install "--dev jedi rope autopep8 yapf flake8 jupyter")))
(use-package json-mode
:ensure t
:mode (("\\.json\\'" . json-mode)
("/Pipfile.lock\\'" . json-mode)))
(use-package py-autopep8
:ensure t
:hook (elpy-mode . py-autopep8-enable-on-save))
(use-package sphinx-doc
:ensure t
:diminish sphinx-doc-mode
:hook (python-mode . sphinx-doc-mode))
(use-package live-py-mode
:ensure t
:defer t)
(use-package hy-mode
:ensure t
:mode "\\.hy\\'")
(use-package yaml-mode
:ensure t
:mode "\\.yml\\'"
:config
(defun swagger-ui--do-start (app-dir)
(let ((default-directory app-dir))
(async-shell-command "docker run --rm --name swagger-ui -p 8000:8080 -e SWAGGER_JSON=/app/openapi.yaml -v $PWD:/app swaggerapi/swagger-ui")
(browse-url-firefox "http://localhost:8000")))
(defun swagger-ui-start ()
(interactive)
(let ((ptype (projectile-project-type)))
(when (or (equal ptype 'openapi-yaml) (equal ptype 'openapi-json))
(swagger-ui--do-start (projectile-project-root)))))
(defun swagger-ui-stop ()
(interactive)
(shell-command "docker stop swagger-ui"))
(defun swagger-ui-restart ()
(interactive)
(swagger-ui-stop)
(swagger-ui-start))
(add-hook 'yaml-mode-hook #'(lambda ()
(local-set-key (kbd "C-c C-p SPC") #'swagger-ui-start)
(local-set-key (kbd "C-c C-p s") #'swagger-ui-start)
(local-set-key (kbd "C-c C-p t") #'swagger-ui-stop)
(local-set-key (kbd "C-c C-p r") #'swagger-ui-restart))))
(use-package ob-hy
:ensure t
:defer t)
(use-package org
:ensure t
:mode ("\\.org\\'" . org-mode)
:config
(setq org-src-fontify-natively t)
(org-babel-do-load-languages
'org-babel-load-languages
'((sh . t)
(python . t)
(dot . t)
(octave . t)
(sqlite . t)
(C . t)))
(setq org-latex-pdf-process '("xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"
"xelatex -interaction nonstopmode -output-directory %o %f"))
(defun my/org-pandoc-to-rst ()
"Convert org to rst using pandoc."
(interactive)
(set (make-local-variable 'compile-command)
(format "pandoc -o %s.rst %s"
(file-name-sans-extension (file-name-nondirectory (buffer-file-name)))
(file-name-nondirectory (buffer-file-name))))
(call-interactively 'compile)))
(use-package my-rest
:after (rst)
:bind (:map rst-mode-map
("<f5> p" . my/rest-pandoc-to-pdf)
("<f5> d" . my/rest-pandoc-to-docx)
("<f5> f" . my/rest-rst2pdf-to-pdf)
("C-c C-p" . my/rest-restview-preview)))
;; device tree
(use-package dts-mode
:ensure t
:mode "\\.dtsi?\\'")
;; Kconfig
;; NOTE: full path is used for compare, '/' restrict to last component
(use-package kconfig-mode
:ensure-contrib "https://raw.githubusercontent.com/delaanthonio/kconfig-mode/master/kconfig-mode.el"
:mode "/Kconfig\\'")
;; Makefile.host Makefile.include Kbuild Kbuild.include
(add-to-list 'auto-mode-alist '("/Kbuild\\'\\|/Kbuild\\.\\|/[Mm]akefile\\." . makefile-gmake-mode))
;; CMakefileLists.txt
(use-package cmake-mode
:ensure t
:mode "/CMakeFileLists\\.txt\\'\\|\\.cmake\\'"
:bind (:map cmake-mode-map
("<f1> d" . cmake-help)
("C-c C-d" . cmake-help)))
(use-package counsel-gtags
:ensure t
:init
(setq tags-revert-without-query t
large-file-warning-threshold nil)
:bind (("C-c g d" . counsel-gtags-find-definition)
("C-c g r" . counsel-gtags-find-reference)
("C-c g s" . counsel-gtags-find-symbol)
("C-c g f" . counsel-gtags-find-file)
("C-c g ." . counsel-gtags-go-forward)
("C-c g ," . counsel-gtags-go-backward)
("C-c g m" . counsel-gtags-dwim)))
(use-package xcscope
:ensure t
:commands (cscope-unset-initial-directory cscope-set-initial-directory)
:hook ((c-mode-common . cscope-minor-mode)
(dired-mode . cscope-minor-mode))
:config
(defadvice cscope-set-initial-directory (around cscope-set-initial-directory-from-old activate)
"set cscope initial directory starting from old one"
(interactive (list
(read-directory-name "cscope initial directory: "
(or cscope-initial-directory default-directory))))
ad-do-it))
(use-package clang-format
:ensure t
:after (cc-mode)
:config (setq-default clang-format-style "Google")
:bind (:map c-mode-base-map
("C-c c f" . clang-format)))
;;; rtags system packages(rdm & rc) install commands
;;; - git clone --recursive https://github.com/Andersbakken/rtags.git
;;; - cd rtags
;;; - cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 .
;;; make
;;; make install
(use-package rtags
:ensure t
:hook ((c-mode-common . rtags-start-process-unless-running)
(c-mode-common . rtags-enable-standard-keybindings))
:bind (:map c-mode-base-map
("M-." . rtags-find-symbol-at-point)
("M-?" . rtags-find-references-at-point)
("M-," . rtags-location-stack-back)))
(use-package company-rtags
:ensure t
:after (rtags company)
:init
(setq rtags-autostart-diagnostics t
rtags-completions-enabled t)
:config
(add-to-list 'company-backends 'company-rtags))
(use-package flycheck-rtags
:ensure t
:after (flycheck rtags)
:config
(defun my/flycheck-rtags-setup ()
(flycheck-select-checker 'rtags)
(setq-local flycheck-highlighting-mode nil) ;; RTags creates more accurate overlays.
(setq-local flycheck-check-syntax-automatically nil))
(add-hook 'c-mode-common-hook #'my/flycheck-rtags-setup t))
(use-package ivy-rtags
:ensure t
:after (ivy rtags)
:config (setq rtags-display-result-backend 'ivy))
(use-package modern-cpp-font-lock
:ensure t
:hook (c++-mode . modern-c++-font-lock-mode))
(use-package company-c-headers
:ensure t
:after (company)
:config
(add-to-list 'company-backends 'company-c-headers)
(defun company-c-headers-path-system ()
(if (boundp 'semantic-c-dependency-system-include-path)
semantic-c-dependency-system-include-path
(symbol-value 'company-c-headers-path-system))))
(use-package hideshow
:diminish hs-minor-mode
:init
(defun my/set-hideshow-binding ()
(local-set-key (kbd "M-s h t") #'hs-toggle-hiding))
:hook ((c-mode-common . hs-minor-mode)
(c-mode-common . my/set-hideshow-binding)))
(use-package google-c-style
:ensure t
:commands (google-set-c-style google-make-newline-indent)
:init
(defun my/set-google-cc-style ()
"Set google cc style"
(interactive)
(google-set-c-style)
(google-make-newline-indent)))
(defun my/set-cc-style ()
"Set my custom cc style."
(interactive)
(c-set-style "linux")
(setq-local tab-width 8)
(setq-local indent-tabs-mode nil)
(setq-local c-basic-offset 8))
(defun my/set-cc-key ()
"Set my custom cc key binding."
(local-set-key (kbd "<f1> d") 'man)
(local-set-key (kbd "C-c C-d") 'man))
(add-hook 'c-mode-common-hook #'my/set-cc-style)
(add-hook 'c-mode-common-hook #'my/set-cc-key)
(use-package dockerfile-mode
:ensure t
:mode "/Dockerfile\\'")
(use-package docker-tramp
:ensure t
:after tramp)
(use-package nginx-mode
:ensure t)
(use-package go-mode
:ensure t
:init (load "go-mode-autoloads")
:hook (before-save . gofmt-before-save))
(use-package go-eldoc
:ensure t
:hook (go-mode . go-eldoc-setup))
(use-package company-go
:ensure t
:after (company go-mode)
:config (add-to-list 'company-backends 'company-go))
(use-package protobuf-mode
:ensure t
:mode "\\.proto\\'")
(use-package rust-mode
:ensure t
:mode "\\.rs\\'"
:config (setq rust-format-on-save t)
:hook (flycheck-mode . flycheck-rust-setup))
(use-package flycheck-rust
:ensure t)
(use-package cargo
:ensure t
:hook (rust-mode . cargo-minor-mode))
(use-package antlr-mode
:ensure t
:mode "\\.g4\\'")
(message "Emacs init time %s" (emacs-init-time))
(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.
'(package-selected-packages
(quote
(company-yasnippet diminish clang-format company-c-headers modern-cpp-font-lock ivy-rtags counsel-rtags flycheck-rtags company-rtags rtags hl-todo volatile-highlights dts-mode iedit ace-link spaceline-all-the-icons use-package spaceline danneskjold-theme))))
(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.
)
(provide 'init)
;;; init ends here