-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.el
882 lines (723 loc) · 27 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
;;----------------------------------------------------
;;; selected packages
;;;;;----------------------------------------------------
;;; LSP optimization start
;; https://emacs-lsp.github.io/lsp-mode/page/performance/#use-plists-for-deserialization
(setenv "LSP_USE_PLISTS" "true")
;; Set it to big number(100mb) like most of the popular kits like Spacemacs/Doom/Prelude do:
(setq gc-cons-threshold 100000000)
;; Again the emacs default is too low 4k considering that the some of the
;; language server responses are in 800k - 3M range.
(setq read-process-output-max (* 1024 1024)) ;; 1mb
;;; LSP optimization end
;;; doom-modeline recommendation
;; Don’t compact font caches during GC.
(setq inhibit-compacting-font-caches t)
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
;; remap left ALT below X key to CTRL
;;(setq x-meta-keysym 'ctrl)
;;(setq x-ctrl-keysym 'meta)
;; better in https://github.com/rvaiya/keyd
(setq
package-selected-packages
'(
ace-window ;; for ace-swap-window
desktop-registry
tramp
undo-tree
expand-region
paredit
smartparens
highlight-symbol
;;evil
;;evil-cleverparens
;; helm
;; helm-ls-git
async ;; required by Helm, separately installed for dev setup
;; vertico
;; consult
;; orderless
;; embark-consult
;; embark
;; corfu
;; marginalia
;; counsel
;; hydra
;; ivy-hydra
;; ivy-prescient
;; ivy-rich
company
which-key
js2-mode
tern ;; js code analysis
json-mode
web-beautify
imenu
multiple-cursors
cmake-mode
ssass-mode
flycheck
projectile
yasnippet
realgud
lsp-ui
;; Dart
dart-mode
lsp-dart
flutter
electric-case
string-inflection
jedi
go-mode
;;company-go
ccls
flycheck-irony
lua-mode
web-mode
web-mode-edit-element
yaml-mode
php-mode
magit
macrostep
ini-mode
ggtags
dired-toggle-sudo
bash-completion
slime
;;sly
;;rust-mode
;; or
;; rustic
;; cargo
geiser
geiser-guile
macrostep-geiser
doom-modeline
git-timemachine
;;dirvish
;;treemacs
;; themes
doom-themes
;; avk-emacs-themes
;; moe-theme
dakrone-light-theme
pastelmac-theme
color-theme-sanityinc-tomorrow
))
(package-initialize)
(when (display-graphic-p)
(toggle-frame-maximized) ; maximize Emacs
(setq-default frame-title-format "%b (%f)")
(set-face-attribute 'default nil :font "Consolas" :height 113)
;;(set-face-attribute 'default nil :font "UbuntuMono Nerd Font Mono" :height 120)
;;(set-face-attribute 'default nil :font "Liberation Mono" :height 105)
;; test vary width font
;;(set-face-attribute 'default nil :font "DejaVu Sans" :height 110)
(tool-bar-mode -1) ; disable toolbar
(line-number-mode) ; show line numbers in modeline
(menu-bar-mode -1) ; disable menu
(scroll-bar-mode -1) ; disable scrollbars
(setq-default indent-tabs-mode nil) ; use spaces
(setq make-backup-files nil)
(setq inhibit-startup-screen t) ; no startup screen
;; Path to Emacs C source, for functions help system
;;(setq find-function-C-source-directory "~/path/to/emacs/src")
;; check package archives cache
(unless package-archive-contents
(package-refresh-contents))
(require 'compile) ; for 'recompile'
(mapcar ;; install selected packages
(lambda (pkg)
(when (not (package-installed-p pkg))
(package-install pkg)))
package-selected-packages))
(setq create-lockfiles nil)
(global-set-key (kbd "C-c c") 'comment-region)
(setq tab-always-indent 'complete)
(add-to-list 'completion-styles 'initials t)
(show-paren-mode)
(column-number-mode)
(recentf-mode)
(global-set-key (kbd "C-c C-h") 'hl-line-mode)
(global-set-key (kbd "<f6>") 'revert-buffer)
(global-set-key (kbd "C-x b") 'bs-show)
(global-set-key (kbd "C-,") 'other-window)
(global-set-key (kbd "M-o") 'ace-swap-window)
(global-set-key (kbd "C-`")
(lambda ()
(interactive)
(kill-buffer (current-buffer))))
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(paredit-mode)
))
(defmacro conf (name &rest init-code)
(declare (indent defun))
(when (member name package-selected-packages)
`(if (package-installed-p ',name)
(progn ,@init-code)
(message "EMACS PACKAGES, %s not installed" ',name))))
;;;;; Configure packages
(conf which-key
(which-key-mode))
(conf evil
(evil-mode 1)
(evil-set-leader '(normal insert visual replace operator)
(kbd "<space>"))
;;(evil-define-key 'normal 'global (kbd "<leader>fs") 'save-buffer)
(setq evil-undo-system 'undo-tree
evil-want-c-w-delete nil)
(define-key evil-insert-state-map (kbd "C-h") 'evil-backward-char)
(define-key evil-insert-state-map (kbd "C-l") 'evil-forward-char)
(define-key evil-insert-state-map (kbd "C-k") 'evil-previous-line)
(define-key evil-insert-state-map (kbd "C-j") 'evil-next-line)
(define-key evil-insert-state-map (kbd "C-f") 'indent-for-tab-command)
(define-key evil-command-line-map (kbd "C-h") 'evil-backward-char)
(define-key evil-command-line-map (kbd "C-l") 'evil-forward-char)
(define-key evil-command-line-map (kbd ";") 'evil-ex)
(setq evil-undo-function 'undo-tree-undo
evil-redo-function 'undo-tree-redo))
(conf undo-tree
(global-undo-tree-mode)
(setq undo-tree-auto-save-history nil)
(global-set-key (kbd "C-M-/") 'undo-tree-redo)
)
(conf desktop-registry
(global-set-key (kbd "C-c d s") 'desktop-save-in-desktop-dir)
(global-set-key (kbd "C-c d r") 'desktop-registry-change-desktop))
(conf yasnippet
(yas-global-mode))
(conf electric-case)
(conf string-inflection)
(conf go-mode
(add-to-list 'auto-mode-alist '("\\.mod$" . go-mode)) ; go.mod files
(defun abbrev-iferr ()
(indent-for-tab-command)
(forward-line -1)
(delete-trailing-whitespace))
(add-hook 'go-mode-hook
(lambda ()
(setq tab-width 4)
(setq go-packages-function 'go-packages-go-list)
;; for CGO
;; (ggtags-mode 1)
;; (define-key go-mode-map (kbd "C-.") #'ggtags-find-tag-dwim)
;; (define-key go-mode-map (kbd "C-,") #'ggtags-prev-mark)
(subword-mode)
(abbrev-mode 1)
(eglot-ensure)
;;(define-key go-mode-map (kbd "C-c C-u") #'string-inflection-java-style-cycle)
;; (lsp-deferred)
;; ;; requires GO111MODULE=on go get golang.org/x/tools/gopls@latest
;; (setq lsp-ui-doc-show-with-mouse nil)
;; Bindings in go-goto-map
;; (define-key m "a" #'go-goto-arguments)
;; (define-key m "d" #'go-goto-docstring)
;; (define-key m "f" #'go-goto-function)
;; (define-key m "i" #'go-goto-imports)
;; (define-key go-goto-map "i" #'ak-go-goto-imports)
;; (define-key m "m" #'go-goto-method-receiver)
;; (define-key m "n" #'go-goto-function-name)
;; (define-key m "r" #'go-goto-return-values)
))
(defun ak-go-goto-imports ()
"Uses xref mark ring to return back from imports section, when quick (un)comment of import is done."
(interactive)
(xref-push-marker-stack)
(go-goto-imports))
;;; go assembly
(defun ak-go-asm-comment-char ()
(interactive)
(setq-local comment-start "// ")))
(conf tramp
(add-hook 'tramp--startup-hook
(lambda ()
(progn
;;(setq auth-source-debug t)
(setq-default password-cache-expiry 604800) ; seconds
(setq tramp-default-method "ssh")
(setenv "SHELL" "/bin/bash")
(tramp-set-completion-function
"ssh"
'((tramp-parse-sconfig "/etc/ssh/ssh_config")
(tramp-parse-sconfig "~/.ssh/config")))))))
(conf js2-mode
(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))
(conf tern)
;; npm install tern
(setq tern-command (list (expand-file-name "~/node_modules/tern/bin/tern")))
(defun abbrev-console-log ()
(backward-char 2) t)
(put 'abbrev-console-log 'no-self-insert t)
(add-hook 'js2-mode-hook
(lambda ()
(setq tab-width 4)
(abbrev-mode 1)
(rainbow-mode 1)
(tern-mode 1)
;;(company-mode 1)
;;(add-to-list 'company-backends 'company-tern)
(js2-imenu-extras-mode)
(define-key js-mode-map (kbd "C-c b") 'web-beautify-js)
(define-abbrev js-mode-abbrev-table "cnl" "console.log();"
'abbrev-console-log)
(setq js-indent-level 2)
))
;;; JSON
(add-to-list 'auto-mode-alist '("\\.tern-project$" . json-mode)))
(conf web-beautify
;; requires "beautifier" through npm
(eval-after-load 'css-mode '(define-key css-mode-map (kbd "C-c b") 'web-beautify-css))
(eval-after-load 'json-mode '(define-key json-mode-map (kbd "C-c b") 'web-beautify-js))
(eval-after-load 'sgml-mode '(define-key html-mode-map (kbd "C-c b") 'web-beautify-html))
(eval-after-load 'web-mode '(define-key web-mode-map (kbd "C-c b") 'web-beautify-html))
;; npm config set prefix ~/.npm
(eval-after-load "web-beautify"
#'(lambda ()
(setq web-beautify-html-program "~/.npm/bin/html-beautify")
(setq web-beautify-css-program "~/.npm/bin/css-beautify")
(setq web-beautify-js-program "~/.npm/bin/js-beautify")))
)
(conf json-mode)
(conf imenu)
(conf multiple-cursors
(global-set-key (kbd "C-;") 'mc/mark-all-dwim))
(conf cmake-mode)
(conf lsp-ui
(setq
lsp-headerline-breadcrumb-icons-enable nil
lsp-headerline-breadcrumb-enable-diagnostics nil
))
;;; sass|scss
(conf ssass-mode
(add-to-list 'auto-mode-alist '("\\.scss$" . scss-mode))
(add-to-list 'auto-mode-alist '("\\.sass$" . ssass-mode))
(eval-after-load 'scss-mode '(define-key scss-mode-map (kbd "C-c b") 'web-beautify-css))
(add-hook 'ssass-mode-hook
(lambda ()
(rainbow-mode t)
)))
(conf smartparens)
(conf projectile)
(conf highlight-symbol
(global-set-key (kbd "C-<f3>") 'highlight-symbol)
(global-set-key (kbd "<f3>") 'highlight-symbol-next)
(global-set-key (kbd "S-<f3>") 'highlight-symbol-prev)
(global-set-key (kbd "M-<f3>") 'highlight-symbol-query-replace)
)
(conf flycheck-irony)
(conf lua-mode)
(conf web-mode
(add-to-list 'auto-mode-alist '("\\.qtpl$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html$" . web-mode))
(add-to-list 'auto-mode-alist '("\\.vue$" . web-mode))
(eval-after-load 'web-mode
'(progn
(define-key web-mode-map (kbd "C-c-n") 'web-mode-element-next)
(define-key web-mode-map (kbd "C-c-p") 'web-mode-element-previous)
))
(setq web-mode-engines-alist
'(("django" . "\\.html\\'")))
(add-hook 'web-mode-hook
(lambda ()
(setq tab-width 4)
;;(hs-minor-mode)
(setq web-mode-script-padding 2) ; indent in script tag
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 4)
(setq web-mode-enable-current-element-highlight t)
;;(setq web-mode-enable-current-column-highlight t)
(face-spec-set 'web-mode-current-element-highlight-face
'((t :foreground "DimGray" :background "Aquamarine"))
'face-defface-spec)
(face-spec-set 'web-mode-current-column-highlight-face
'((t :background "Gainsboro"))
'face-defface-spec)
;;(setq web-mode-enable-part-face t)
(abbrev-mode 1)
(define-mode-abbrev "vdd" "var_dump( );die();")
(define-mode-abbrev "cnl" "console.log();")
(define-mode-abbrev "vdb" "var_dump( debug_backtrace() );die();")
(ggtags-mode 1)
;;(set-face-attribute 'web-mode-html-tag-face nil :foreground "#0000CD")
;;(set-face-attribute 'web-mode-html-attr-name-face nil :foreground "#007700")
;;(setq web-mode-enable-block-face t)
;;(set-face-attribute 'web-mode-block-face nil :background "#EBFAE8")
;;(set-face-attribute 'web-mode-block-face nil :background "#8fbc8f")
))
(setq web-mode-extra-snippets
'((nil . (("div" . ("<div class=\"\">" . "</div>"))
;;("name" . ("beg" . "end"))
))
))
(global-set-key (kbd "<f12>") 'web-mode))
(conf web-mode-edit-element)
(conf yaml-mode
(add-to-list 'auto-mode-alist '("\\.kv$" . yaml-mode))
(add-hook 'yaml-mode-hook
(lambda ()
(setq yaml-indent-offset 2))))
(conf php-mode
(eval-after-load "php-mode"
'(progn
(define-abbrev php-mode-abbrev-table "vdd" "var_dump( );die();")
(define-abbrev php-mode-abbrev-table "vdb" "var_dump( debug_backtrace() );die();")
))
(add-hook 'php-mode-hook
(lambda ()
(semantic-mode 1)
(hs-minor-mode 1)
(local-unset-key "C-M-\\")
(local-unset-key "C")
(c-set-style "symfony2")
(setq indent-tabs-mode t
tab-width 4
c-basic-offset 4)
(define-key php-mode-map (kbd "C-c i") 'imenu)
(define-key php-mode-map (kbd "C-c C-r") 'revert-buffer)
))
(add-to-list 'auto-mode-alist '("\\.php$" . php-mode))
;;(add-to-list 'auto-mode-alist '("\\.php$" . web-mode))
(global-set-key (kbd "<f11>") 'php-mode)
(global-set-key (kbd "<f12>") 'web-mode))
(conf magit
(global-set-key (kbd "C-c m") 'magit-status))
(conf ghub
)
(conf macrostep
(define-key emacs-lisp-mode-map (kbd "C-c e") 'macrostep-expand))
(conf ini-mode
(add-to-list 'auto-mode-alist '("\\.ini$" . ini-mode))
(add-to-list 'auto-mode-alist '("\\.service\\|\\.target$" . ini-mode)) ; Systemd
(add-to-list 'auto-mode-alist '("PKGBUILD$" . ini-mode)) ; Arch package file
)
(conf symbol-overlay
(global-set-key [(control f9)] 'symbol-overlay-put)
(global-set-key [f9] 'symbol-overlay-jump-next)
(global-set-key [(shift f9)] 'symbol-overlay-jump-next)
(global-set-key [(meta f9)] 'symbol-overlay-query-replace)
)
(conf ggtags)
(conf glsl-mode
(add-to-list 'auto-mode-alist '("\\.comp$" . glsl-mode)))
;; (conf company
;; (company-mode))
(conf git-timemachine)
(conf doom-modeline
;; leftmost part:
;;(setq doom-modeline-bar-width 0)
(doom-modeline-mode 1))
;;----------------------------------------------------
;; helm
;; dev
(add-to-list 'load-path (expand-file-name "~/helm"))
(require 'helm)
(require 'helm-autoloads)
(require 'helm-buffers)
(progn ;;conf helm
(helm-mode)
(global-set-key (kbd "M-x") 'helm-M-x)
(global-set-key (kbd "C-c j") 'helm-mini)
(global-set-key (kbd "C-c C-j") #'helm-command-prefix)
(global-set-key (kbd "C-x C-f") #'helm-find-files)
(global-set-key (kbd "C-c C-s") #'helm-toggle-full-frame)
(global-set-key (kbd "C-c l") #'helm-occur)
(global-set-key (kbd "C-c i") #'helm-imenu)
(define-key helm-command-map (kbd "g") #'helm-browse-project) ; uses 'helm-ls-git
(setq
helm-echo-input-in-header-line t
helm-M-x-fuzzy-match nil
helm-move-to-line-cycle-in-source t
helm-always-two-windows nil
helm-split-window-default-side 'other
;; for toggling on/off Helm full frame
helm-split-window-other-side-when-one-window 'right
helm-update-edebug t ; dev
))
(conf expand-region
(global-set-key (kbd "C-=") 'er/expand-region)
)
;;----------------------------------------------------
;; vertico consult orderless embark marginalia corfu
(conf vertico
(vertico-mode)
(vertico-buffer-mode)
(define-key vertico-map (kbd "C-o") #'vertico-next-group)
(setq vertico-cycle t
))
(conf consult
(global-set-key (kbd "C-c j") 'consult-buffer)
(global-set-key (kbd "C-c C-j") 'consult-buffer)
(global-set-key (kbd "C-c i") 'consult-imenu)
(global-set-key (kbd "C-c l") 'consult-line) ; similar to swiper
(require 'consult)
(setq consult-buffer-sources
'(consult--source-hidden-buffer
consult--source-modified-buffer
consult--source-buffer
consult--source-recent-file ; expands common column width on long paths
consult--source-file-register
consult--source-bookmark
consult--source-project-buffer-hidden
consult--source-project-recent-file-hidden
))
;; remove Dired buffers from common completions, they are grouped separately
(consult-customize
consult--source-buffer
:items (lambda ()
(consult--buffer-query
:sort 'visibility :as #'buffer-name
;; Buffers excluding Dired
:predicate
(lambda (buf) (not (eq (buffer-local-value 'major-mode buf)
'dired-mode))))))
;; Dired buffers group
(add-to-list
'consult-buffer-sources
(list :name "Dired"
:category 'buffer
:narrow ?d
:face 'consult-buffer
:items (lambda () (consult--buffer-query
:sort 'visibility :as #'buffer-name
:predicate
(lambda (buf) (eq (buffer-local-value 'major-mode buf)
'dired-mode))))
:state #'consult--buffer-preview
:action #'consult--buffer-action
)
'append)
)
(conf orderless
(setq completion-styles '(orderless basic)
completion-category-overrides '((file (styles basic partial-completion)))))
(conf embark
(global-set-key (kbd "C-.") 'embark-act)
(global-set-key (kbd "C-'") 'embark-dwim)
(global-set-key (kbd "C-h b") 'embark-bindings)
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
;; Show the Embark target at point via Eldoc. You may adjust the Eldoc
;; strategy, if you want to see the documentation from multiple providers.
(add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
(conf marginalia
(marginalia-mode))
(conf corfu
(global-corfu-mode))
;;----------------------------------------------------
;; counsel, ivy, swiper, prescient
(conf counsel
(ivy-mode)
(ivy-prescient-mode)
(counsel-mode)
;;(ivy-rich-mode)
(setq
;; ivy-use-virtual-buffers t
enable-recursive-minibuffers t
ivy-use-selectable-prompt t
ivy-wrap t
ivy-re-builders-alist '((t . ivy--regex-ignore-order))
ivy-fixed-height-minibuffer t
ivy-height 21
;;ibuffer-always-show-last-buffer
counsel-find-file-at-point t)
(global-set-key (kbd "C-c l") 'swiper)
(global-set-key (kbd "C-c C-r") 'ivy-resume)
(global-set-key (kbd "C-,") 'counsel-M-x)
(global-set-key (kbd "C-x C-f") 'counsel-find-file)
(global-set-key (kbd "<f1> f") 'counsel-describe-function)
(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
(global-set-key (kbd "<f1> o") 'counsel-describe-symbol)
(global-set-key (kbd "<f1> l") 'counsel-find-library)
(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
(global-set-key (kbd "C-c i") 'counsel-imenu)
(global-set-key (kbd "C-c f") 'counsel-recentf)
(global-set-key (kbd "C-c g") 'counsel-git)
(global-set-key (kbd "C-x j") 'counsel-git-grep)
(global-set-key (kbd "C-c k") 'counsel-ag)
(global-set-key (kbd "C-x l") 'counsel-locate)
(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
(global-set-key (kbd "C-c j") 'counsel-switch-buffer)
(global-set-key (kbd "C-c C-j") 'counsel-switch-buffer)
;;(global-set-key (kbd "C-c C-j") 'ivy-ibuffer)
)
;;----------------------------------------------------
;;; dart
(conf dart-mode
(add-hook 'dart-mode-hook
(lambda ()
(require 'electric-case)
(electric-case-mode)
(smartparens-strict-mode)
(subword-mode)
(projectile-mode +1)
(add-to-list 'projectile-project-root-files-bottom-up "pubspec.yaml")
(add-to-list 'projectile-project-root-files-bottom-up "BUILD")
(lsp-deferred)
;;(setq lsp-ui-doc-show-with-mouse nil)
(define-key dart-mode-map (kbd "s-l d d") #'lsp-ui-doc-show)
(define-key dart-mode-map (kbd "s-l d f") #'lsp-ui-doc-focus-frame)
(define-key dart-mode-map (kbd "C-c C-u") #'string-inflection-java-style-cycle)
)))
;;----------------------------------------------------
;;; shell mode
(add-hook 'shell-mode-hook #'bash-completion-setup)
;;----------------------------------------------------
;;; makefile-mode
(add-hook 'makefile-mode-hook
(lambda ()
(setq tab-width 4)))
;;----------------------------------------------------
;;; markdown-mode
(add-to-list 'auto-mode-alist '("\\.mm$" . markdown-mode))
;;----------------------------------------------------
(autoload 'python-mode "python" "Python Mode." t) ; built-in
;;(autoload 'python-mode "python-mode" "Python Mode." t)
(defun python-mode-abbrev-debug-handler ()
(forward-line -1)
(funcall indent-line-function)
(move-end-of-line 1)
(save-buffer 0))
(conf cython-mode)
(defun python-mode-func ()
(setq tab-width 4)
(hs-minor-mode)
(abbrev-mode 1)
(semantic-mode 1)
(define-abbrev python-mode-abbrev-table "pd" "import os; 'ak'; import pdb;pdb.set_trace()"
#'python-mode-abbrev-debug-handler)
(define-abbrev python-mode-abbrev-table "tr" "import os; from trepan.api import debug;debug()"
#'python-mode-abbrev-debug-handler)
(define-abbrev python-mode-abbrev-table "ipd" "import os; import ipdb;ipdb.set_trace()"
#'python-mode-abbrev-debug-handler)
(define-abbrev python-mode-abbrev-table "pp" "import pprint; pp=pprint.PrettyPrinter(); pp.pprint()")
(define-key python-mode-map (kbd "C-c C-r") 'revert-buffer) ; orig is send region to python shell
(conf jedi)
(jedi:setup)
(define-key python-mode-map (kbd "C-c x") 'jedi-direx:pop-to-buffer)
;;(setq python-shell-interpreter "ipython" python-shell-interpreter-args "-i")
(local-unset-key (kbd "C-c !")) ; unhide flycheck
(define-key jedi-mode-map (kbd "C-c p") #'jedi:goto-definition-pop-marker)
(define-key jedi-mode-map (kbd "C-c ,") nil) ; unhide `semantic-force-refresh'
;;(define-key jedi-mode-map (kbd "C-.") #'ggtags-find-tag-dwim)
(define-key python-mode-map (kbd "C-c i") 'imenu)
(auto-complete-mode -1))
(add-hook 'python-mode-hook 'python-mode-func)
;;----------------------------------------------------
;;; xml
;;(add-to-list 'auto-mode-alist '("\\.xml$" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.xml$" . web-mode))
;;----------------------------------------------------
;;; css
(add-hook 'css-mode-hook
(lambda ()
(rainbow-mode t)))
;;----------------------------------------------------
;;; Scheme mode
(add-hook
'scheme-mode-hook
(lambda ()
(paredit-mode)
(abbrev-mode 1)
(define-abbrev scheme-mode-abbrev-table "nl" "(newline)")
(define-abbrev scheme-mode-abbrev-table "dl" "(display )")
;; added `define*' to scheme mode
;; added `define-syntax-rule' for macros
(setq scheme-imenu-generic-expression
'((nil
"^(define\\(\\|\\*\\|-\\(generic\\(\\|-procedure\\)\\|method\\)\\)*\\s-+(?\\(\\sw+\\)" 4)
("Types"
"^(define-class\\s-+(?\\(\\sw+\\)" 1)
("Macros"
"^(\\(defmacro\\|define-macro\\|define-syntax\\|define-syntax-rule\\)\\s-+(?\\(\\sw+\\)" 2)))
(macrostep-geiser-setup)))
;;----------------------------------------------------
;;; c mode
(add-hook 'c-mode-hook
(lambda ()
;; gnu, k&r, bsd, stroustrup, whitesmith, ellemtel, linux, python, java, awk
(c-set-style "gnu")
(ggtags-mode)
(setq c-macro-preprocessor "cpp -CC")
;;(conf preproc-font-lock-mode)
;;(preproc-font-lock-mode 1)
(hs-minor-mode 1) ; hide/show blocks
(define-key c-mode-map "\C-c\C-f" 'ff-find-other-file)
(define-key c++-mode-map "\C-c\C-f" 'ff-find-other-file)
(semantic-mode 1)
;;(lsp-deferred)
;; (flycheck-mode 1)
;; (flycheck-clang-analyzer-setup)
(semantic-idle-breadcrumbs-mode 1)
(c-add-style "python-new"
'("python"
(c-basic-offset . 4))
t)
;; disable auto-align of endline backslashes in multiline macros
(setq c-auto-align-backslashes nil)
(abbrev-mode 1)
(define-abbrev c-mode-abbrev-table "err" "#error \"stop here\"")
))
;;----------------------------------------------------
;;; c++ mode
;; C++ language server
(conf ccls)
(add-hook 'c++-mode-hook
(lambda ()
(ggtags-mode)
;; mask a key binding of ggtags minor mode
(let ((oldmap (cdr (assoc 'ggtags-mode minor-mode-map-alist)))
(newmap (make-sparse-keymap)))
(set-keymap-parent newmap oldmap)
(make-local-variable 'minor-mode-overriding-map-alist)
(push `(ggtags-mode . ,newmap) minor-mode-overriding-map-alist))
))
;;----------------------------------------------------
;; rustic-mode
;; rustup component add rls rust-analysis rust-src
;; or
;; rustup component add --toolchain "1.42.0-x86_64-unknown-linux-gnu" rls rust-analysis rust-src
;; (add-to-list 'auto-mode-alist '("\\.rs$" . rustic-mode))
;; ;;(setq rust-format-on-save t)
;; (add-hook 'rustic-mode-hook
;; (lambda ()
;; (abbrev-mode 1)
;; (define-mode-abbrev "pnl" "println!(\"{:?}\", );")
;; ))
;;----------------------------------------------------
;; slime
;; building SBCL's ./doc/manual requires 'texinfo-plaingeneric' OS package
(conf slime
;;; quicklisp, misc config is in ~/.sbclrc
(slime-setup)
(add-hook
'lisp-mode-hook
(lambda ()
(paredit-mode)
(setq inferior-lisp-program (expand-file-name "~/sbcl/bin/sbcl --noinform")
browse-url-browser-function 'eww-browse-url
common-lisp-hyperspec-root
"file:///usr/share/doc/common-lisp-hyperspec/HyperSpec/"
)
(setq slime-lisp-implementations
'((sbcl ("sbcl") :coding-system utf-8-unix)))
)))
;;----------------------------------------------------
;; sly
;; (conf sly
;; (paredit-mode)
;; (setq inferior-lisp-program (expand-file-name "~/sbcl/bin/sbcl --noinform")
;; browse-url-browser-function 'eww-browse-url
;; common-lisp-hyperspec-root
;; "file:///usr/share/doc/common-lisp-hyperspec/HyperSpec/"
;; )
;; )