-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathpackages.el
More file actions
1578 lines (1433 loc) · 65.9 KB
/
Copy pathpackages.el
File metadata and controls
1578 lines (1433 loc) · 65.9 KB
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
;;; packages.el --- Spacemacs Core Layer packages File
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
(setq spacemacs-base-packages
'(
bind-key
(bind-map :step pre)
bookmark
diminish
(electric-indent-mode :location built-in)
ediff
eldoc
evil
evil-escape
;; evil-leader
evil-surround
evil-visualstar
(evil-evilified-state :location local :step pre :protected t)
exec-path-from-shell
fill-column-indicator
helm
helm-descbinds
helm-flx
helm-projectile
(helm-spacemacs :location local)
help-fns+
hl-todo
(hs-minor-mode :location built-in)
(holy-mode :location local :step pre)
(hybrid-mode :location local :step pre)
(ido :location built-in)
ido-vertical-mode
(package-menu :location built-in)
page-break-lines
popup
popwin
(process-menu :location built-in)
projectile
quelpa
recentf
restart-emacs
savehist
saveplace
spacemacs-theme
subword
undo-tree
(uniquify :location built-in)
(url :location built-in)
use-package
which-key
whitespace
winner
ws-butler))
;; Initialization of packages
(defun spacemacs-base/init-bind-key ())
(defun spacemacs-base/init-bind-map ()
(use-package bind-map
:init
(bind-map spacemacs-default-map
:prefix-cmd spacemacs-cmds
:keys (dotspacemacs-emacs-leader-key)
:evil-keys (dotspacemacs-leader-key)
:override-minor-modes t
:override-mode-name spacemacs-leader-override-mode)))
(defun spacemacs-base/init-bookmark ()
(use-package bookmark
:defer t
:init
(setq bookmark-default-file (concat spacemacs-cache-directory "bookmarks")
;; autosave each change
bookmark-save-flag 1)))
(defun spacemacs-base/init-diminish ()
(use-package diminish
:init
(progn
;; Minor modes abbrev --------------------------------------------------------
(when (display-graphic-p)
(with-eval-after-load 'eproject
(diminish 'eproject-mode " eⓅ"))
(with-eval-after-load 'flymake
(diminish 'flymake-mode " Ⓕ2")))
;; Minor Mode (hidden) ------------------------------------------------------
(with-eval-after-load 'elisp-slime-nav
(diminish 'elisp-slime-nav-mode))
(with-eval-after-load 'hi-lock
(diminish 'hi-lock-mode))
(with-eval-after-load 'abbrev
(diminish 'abbrev-mode))
(with-eval-after-load 'subword
(when (eval-when-compile (version< "24.3.1" emacs-version))
(diminish 'subword-mode))))))
(defun spacemacs-base/init-eldoc ()
(use-package eldoc
:defer t
:config
(progn
;; enable eldoc in `eval-expression'
(add-hook 'eval-expression-minibuffer-setup-hook #'eldoc-mode)
;; enable eldoc in IELM
(add-hook 'ielm-mode-hook #'eldoc-mode)
;; don't display eldoc on modeline
(spacemacs|hide-lighter eldoc-mode))))
(defun spacemacs-base/init-electric-indent-mode ()
(electric-indent-mode))
;; notes from mijoharas
;; We currently just set a few variables to make it look nicer.
;; Here is my first attempt at evilifying the buffer, does not work correctly, help is very much welcome.
;; ```
;; (defun ediff/setup-ediff-keymaps ()
;; "setup the evil ediff keymap"
;; (progn
;; (add-to-list 'evil-emacs-state-modes 'Ediff)
;; (evilified-state-evilify ediff-mode-map)
;; (spacemacs/activate-evil-leader-for-map 'ediff-mode-map)
;; )
;; )
;; ;; inside the use-package function
;; (add-hook 'ediff-keymap-setup-hook 'ediff/setup-ediff-keymaps)
;; ```
(defun spacemacs-base/init-ediff ()
(use-package ediff
:defer t
:init
(progn
;; first we set some sane defaults
(setq-default
ediff-window-setup-function 'ediff-setup-windows-plain
;; emacs is evil and decrees that vertical shall henceforth be horizontal
ediff-split-window-function 'split-window-horizontally
ediff-merge-split-window-function 'split-window-horizontally))))
(defun spacemacs-base/init-eldoc ()
(use-package eldoc
:defer t
:config
(progn
;; enable eldoc in `eval-expression'
(add-hook 'eval-expression-minibuffer-setup-hook #'eldoc-mode)
;; enable eldoc in IELM
(add-hook 'ielm-mode-hook #'eldoc-mode)
;; don't display eldoc on modeline
(spacemacs|hide-lighter eldoc-mode))))
(defun spacemacs-base/init-evil ()
(use-package evil
:init
(progn
(defvar spacemacs-evil-cursors '(("normal" "DarkGoldenrod2" box)
("insert" "chartreuse3" (bar . 2))
("emacs" "SkyBlue2" box)
("hybrid" "SkyBlue2" (bar . 2))
("replace" "chocolate" (hbar . 2))
("evilified" "LightGoldenrod3" box)
("visual" "gray" (hbar . 2))
("motion" "plum3" box)
("lisp" "HotPink1" box)
("iedit" "firebrick1" box)
("iedit-insert" "firebrick1" (bar . 2)))
"Colors assigned to evil states with cursor definitions.")
(loop for (state color cursor) in spacemacs-evil-cursors
do
(eval `(defface ,(intern (format "spacemacs-%s-face" state))
`((t (:background ,color
:foreground ,(face-background 'mode-line)
:box ,(face-attribute 'mode-line :box)
:inherit 'mode-line)))
(format "%s state face." state)
:group 'spacemacs))
(eval `(setq ,(intern (format "evil-%s-state-cursor" state))
(list (when dotspacemacs-colorize-cursor-according-to-state color)
cursor))))
;; put back refresh of the cursor on post-command-hook see status of:
;; https://bitbucket.org/lyro/evil/issue/502/cursor-is-not-refreshed-in-some-cases
;; (add-hook 'post-command-hook 'evil-refresh-cursor)
(defun spacemacs/state-color-face (state)
"Return the symbol of the face for the given STATE."
(intern (format "spacemacs-%s-face" (symbol-name state))))
(defun spacemacs/state-color (state)
"Return the color string associated to STATE."
(face-background (spacemacs/state-color-face state)))
(defun spacemacs/current-state-color ()
"Return the color string associated to the current state."
(face-background (spacemacs/state-color-face evil-state)))
(defun spacemacs/state-face (state)
"Return the face associated to the STATE."
(spacemacs/state-color-face state))
(defun spacemacs/current-state-face ()
"Return the face associated to the current state."
(let ((state (if (eq evil-state 'operator)
evil-previous-state
evil-state)))
(spacemacs/state-color-face state)))
(defun evil-insert-state-cursor-hide ()
(setq evil-insert-state-cursor '((hbar . 0))))
(evil-mode 1))
:config
(progn
;; bind function keys
;; evil ex-command key
(define-key evil-normal-state-map (kbd dotspacemacs-command-key) 'evil-ex)
(define-key evil-visual-state-map (kbd dotspacemacs-command-key) 'evil-ex)
(define-key evil-motion-state-map (kbd dotspacemacs-command-key) 'evil-ex)
;; Make the current definition and/or comment visible.
(define-key evil-normal-state-map "zf" 'reposition-window)
;; toggle maximize buffer
(define-key evil-window-map (kbd "o") 'spacemacs/toggle-maximize-buffer)
(define-key evil-window-map (kbd "C-o") 'spacemacs/toggle-maximize-buffer)
;; make cursor keys work
(define-key evil-window-map (kbd "<left>") 'evil-window-left)
(define-key evil-window-map (kbd "<right>") 'evil-window-right)
(define-key evil-window-map (kbd "<up>") 'evil-window-up)
(define-key evil-window-map (kbd "<down>") 'evil-window-down)
(spacemacs/set-leader-keys "re" 'evil-show-registers)
;; After major mode has changed, reset evil-shift-width
(add-hook 'after-change-major-mode-hook 'spacemacs//set-evil-shift-width 'append)
;; It's better that the default value is too small than too big
(setq-default evil-shift-width 2)
(defmacro evil-map (state key seq)
"Map for a given STATE a KEY to a sequence SEQ of keys.
Can handle recursive definition only if KEY is the first key of SEQ.
Example: (evil-map visual \"<\" \"<gv\")"
(let ((map (intern (format "evil-%S-state-map" state))))
`(define-key ,map ,key
(lambda ()
(interactive)
,(if (string-equal key (substring seq 0 1))
`(progn
(call-interactively ',(lookup-key evil-normal-state-map key))
(execute-kbd-macro ,(substring seq 1)))
(execute-kbd-macro ,seq))))))
;; Keep the region active when shifting
(evil-map visual "<" "<gv")
(evil-map visual ">" ">gv")
(defun spacemacs/evil-smart-doc-lookup ()
"Version of `evil-lookup' that attempts to use
the mode specific goto-definition binding,
i.e. `SPC m h h`, to lookup the source of the definition,
while falling back to `evil-lookup'"
(interactive)
(condition-case nil
(execute-kbd-macro (kbd (concat dotspacemacs-leader-key " mhh")))
(error (evil-lookup))))
(define-key evil-normal-state-map (kbd "K") 'spacemacs/evil-smart-doc-lookup)
(defun spacemacs/evil-smart-goto-definition ()
"Version of `evil-goto-definition' that attempts to use
the mode specific goto-definition binding,
i.e. `SPC m g g`, to lookup the source of the definition,
while falling back to `evil-goto-definition'"
(interactive)
(condition-case nil
(execute-kbd-macro (kbd (concat dotspacemacs-leader-key " mgg")))
(error (evil-goto-definition))))
(define-key evil-normal-state-map
(kbd "gd") 'spacemacs/evil-smart-goto-definition)
;; scrolling micro state
(defun spacemacs/scroll-half-page-up ()
"Scroll half a page up while keeping cursor in middle of page."
(interactive)
(evil-window-top)
(let ((recenter-redisplay nil))
(recenter nil)))
(defun spacemacs/scroll-half-page-down ()
"Scroll half a page down while keeping cursor in middle of page."
(interactive)
(evil-window-bottom)
;; required to make repeated presses idempotent
(evil-next-visual-line)
(let ((recenter-redisplay nil))
(recenter nil)))
(spacemacs|define-micro-state scroll
:doc "[,] page up [.] page down [<] half page up [>] half page down"
:execute-binding-on-enter t
:evil-leader "n." "n," "n<" "n>"
:bindings
;; page
("," evil-scroll-page-up)
("." evil-scroll-page-down)
;; half page
("<" spacemacs/scroll-half-page-up)
(">" spacemacs/scroll-half-page-down))
;; support for auto-indentation inhibition on universal argument
(spacemacs|advise-commands
"handle-indent" (evil-paste-before evil-paste-after) around
"Handle the universal prefix argument for auto-indentation."
(let ((prefix (ad-get-arg 0)))
(ad-set-arg 0 (unless (equal '(4) prefix) prefix))
ad-do-it
(ad-set-arg 0 prefix)))
;; pasting micro-state
(spacemacs|advise-commands
"paste-micro-state"
(evil-paste-before evil-paste-after evil-visual-paste) after
"Initate the paste micro-state."
(unless (or (evil-ex-p)
(eq 'evil-paste-from-register this-command))
(spacemacs/paste-micro-state)))
(defun spacemacs//paste-ms-doc ()
"The documentation for the paste micro-state."
(format (concat "[%s/%s] Type [p] or [P] to paste the previous or "
"next copied text, [.] to paste the same text")
(length kill-ring-yank-pointer) (length kill-ring)))
(spacemacs|define-micro-state paste
:doc (spacemacs//paste-ms-doc)
:use-minibuffer t
:bindings
("p" evil-paste-pop)
("P" evil-paste-pop-next))
(unless dotspacemacs-enable-paste-micro-state
(ad-disable-advice 'evil-paste-before 'after
'evil-paste-before-paste-micro-state)
(ad-activate 'evil-paste-before)
(ad-disable-advice 'evil-paste-after 'after
'evil-paste-after-paste-micro-state)
(ad-activate 'evil-paste-after)
(ad-disable-advice 'evil-visual-paste 'after
'evil-visual-paste-paste-micro-state)
(ad-activate 'evil-visual-paste))
;; define text objects
(defmacro spacemacs|define-text-object (key name start end)
(let ((inner-name (make-symbol (concat "evil-inner-" name)))
(outer-name (make-symbol (concat "evil-outer-" name)))
(start-regex (regexp-opt (list start)))
(end-regex (regexp-opt (list end))))
`(progn
(evil-define-text-object ,inner-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count nil))
(evil-define-text-object ,outer-name (count &optional beg end type)
(evil-select-paren ,start-regex ,end-regex beg end type count t))
(define-key evil-inner-text-objects-map ,key (quote ,inner-name))
(define-key evil-outer-text-objects-map ,key (quote ,outer-name))
(when (configuration-layer/package-usedp 'evil-surround)
(push (cons (string-to-char ,key)
(if ,end
(cons ,start ,end)
,start))
evil-surround-pairs-alist)))))
(defun spacemacs//standard-text-objects ()
;; between dollars sign:
(spacemacs|define-text-object "$" "dollar" "$" "$")
;; define stars
(spacemacs|define-text-object "*" "star" "*" "*")
;; define block star text object
(spacemacs|define-text-object "8" "block-star" "/*" "*/")
;; between pipe characters:
(spacemacs|define-text-object "|" "bar" "|" "|")
;; between percent signs:
(spacemacs|define-text-object "%" "percent" "%" "%"))
(spacemacs/add-to-hook 'prog-mode-hook '(spacemacs//standard-text-objects))
;; define text-object for entire buffer
(evil-define-text-object evil-inner-buffer (count &optional beg end type)
(evil-select-paren "\\`" "\\'" beg end type count nil))
(define-key evil-inner-text-objects-map "g" 'evil-inner-buffer)
;; support smart 1parens-strict-mode
(when (configuration-layer/package-usedp 'smartparens)
(defadvice evil-delete-backward-char-and-join
(around spacemacs/evil-delete-backward-char-and-join activate)
(if (bound-and-true-p smartparens-strict-mode)
(call-interactively 'sp-backward-delete-char)
ad-do-it)))
;; Define history commands for comint
(evil-define-key 'insert comint-mode-map
(kbd "C-k") 'comint-next-input
(kbd "C-j") 'comint-previous-input)
(evil-define-key 'normal comint-mode-map
(kbd "C-k") 'comint-next-input
(kbd "C-j") 'comint-previous-input))))
(defun spacemacs-base/init-evil-escape ()
(use-package evil-escape
:init
(evil-escape-mode)
:config
(spacemacs|hide-lighter evil-escape-mode)))
(defun spacemacs-base/init-evil-surround ()
(use-package evil-surround
:init
(progn
(global-evil-surround-mode 1)
;; `s' for surround instead of `substitute'
;; see motivation for this change in the documentation
(evil-define-key 'visual evil-surround-mode-map "s" 'evil-surround-region)
(evil-define-key 'visual evil-surround-mode-map "S" 'evil-substitute))))
(defun spacemacs-base/init-evil-visualstar ()
(use-package evil-visualstar
:commands (evil-visualstar/begin-search-forward
evil-visualstar/begin-search-backward)
:init
(progn
(define-key evil-visual-state-map (kbd "*")
'evil-visualstar/begin-search-forward)
(define-key evil-visual-state-map (kbd "#")
'evil-visualstar/begin-search-backward))))
(defun spacemacs-base/init-evil-evilified-state ()
(use-package evil-evilified-state)
(define-key evil-evilified-state-map (kbd dotspacemacs-leader-key)
spacemacs-default-map))
(defun spacemacs-base/init-exec-path-from-shell ()
(use-package exec-path-from-shell
:init (when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize))))
(defun spacemacs-base/init-fill-column-indicator ()
(use-package fill-column-indicator
:defer t
:init
(progn
(setq fci-rule-width 1)
(setq fci-rule-color "#D0BF8F")
;; manually register the minor mode since it does not define any
;; lighter
(push '(fci-mode "") minor-mode-alist)
(spacemacs|add-toggle fill-column-indicator
:status fci-mode
:on (turn-on-fci-mode)
:off (turn-off-fci-mode)
:documentation "Display the fill column indicator."
:evil-leader "tf"))
:config
(spacemacs|hide-lighter fci-mode)))
(defun spacemacs-base/init-helm ()
(use-package helm
:defer 1
:commands (spacemacs/helm-find-files)
:config
(progn
(when (and dotspacemacs-helm-resize
(or (eq dotspacemacs-helm-position 'bottom)
(eq dotspacemacs-helm-position 'top)))
(setq helm-autoresize-min-height 10)
(helm-autoresize-mode 1))
;; from https://www.reddit.com/r/emacs/comments/2z7nbv/lean_helm_window/
(defvar helm-source-header-default-background (face-attribute 'helm-source-header :background))
(defvar helm-source-header-default-foreground (face-attribute 'helm-source-header :foreground))
(defvar helm-source-header-default-box (face-attribute 'helm-source-header :box))
(defvar helm-source-header-default-height (face-attribute 'helm-source-header :height) )
(defun helm-toggle-header-line ()
"Hide the `helm' header is there is only one source."
(when dotspacemacs-helm-no-header
(if (> (length helm-sources) 1)
(set-face-attribute 'helm-source-header
nil
:foreground helm-source-header-default-foreground
:background helm-source-header-default-background
:box helm-source-header-default-box
:height helm-source-header-default-height)
(set-face-attribute 'helm-source-header
nil
:foreground (face-attribute 'helm-selection :background)
:background (face-attribute 'helm-selection :background)
:box nil
:height 0.1))))
(add-hook 'helm-before-initialize-hook 'helm-toggle-header-line)
(defun spacemacs/helm-find-files (arg)
"Custom spacemacs implementation for calling helm-find-files-1.
Removes the automatic guessing of the initial value based on thing at point. "
(interactive "P")
(let* ((hist (and arg helm-ff-history (helm-find-files-history)))
(default-input hist )
(input (cond ((and (eq major-mode 'dired-mode) default-input)
(file-name-directory default-input))
((and (not (string= default-input ""))
default-input))
(t (expand-file-name (helm-current-directory))))))
(set-text-properties 0 (length input) nil input)
(helm-find-files-1 input ))))
:init
(progn
(setq helm-prevent-escaping-from-minibuffer t
helm-bookmark-show-location t
helm-display-header-line nil
helm-split-window-in-side-p t
helm-always-two-windows t
helm-echo-input-in-header-line t
helm-imenu-execute-action-at-once-if-one nil)
;; hide minibuffer in Helm session, since we use the header line already
(defun helm-hide-minibuffer-maybe ()
(when (with-helm-buffer helm-echo-input-in-header-line)
(let ((ov (make-overlay (point-min) (point-max) nil nil t)))
(overlay-put ov 'window (selected-window))
(overlay-put ov 'face (let ((bg-color (face-background 'default nil)))
`(:background ,bg-color :foreground ,bg-color)))
(setq-local cursor-type nil))))
(add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
;; fuzzy matching setting
(setq helm-M-x-fuzzy-match t
helm-apropos-fuzzy-match t
helm-file-cache-fuzzy-match t
helm-imenu-fuzzy-match t
helm-lisp-fuzzy-completion t
helm-recentf-fuzzy-match t
helm-semantic-fuzzy-match t
helm-buffers-fuzzy-matching t)
;; Use helm to provide :ls, unless ibuffer is used
(unless (configuration-layer/package-usedp 'ibuffer)
(evil-ex-define-cmd "buffers" 'helm-buffers-list))
(defun spacemacs//helm-do-grep-region-or-symbol (&optional targs use-region-or-symbol-p)
"Version of `helm-do-grep' with a default input."
(interactive)
(require 'helm)
(cl-letf*
(((symbol-function 'this-fn) (symbol-function 'helm-do-grep-1))
((symbol-function 'helm-do-grep-1)
(lambda (targets &optional recurse zgrep exts default-input region-or-symbol-p)
(let* ((new-input (when region-or-symbol-p
(if (region-active-p)
(buffer-substring-no-properties
(region-beginning) (region-end))
(thing-at-point 'symbol t))))
(quoted-input (when new-input (rxt-quote-pcre new-input))))
(this-fn targets recurse zgrep exts default-input quoted-input))))
(preselection (or (dired-get-filename nil t)
(buffer-file-name (current-buffer))))
(targets (if targs
targs
(helm-read-file-name
"Search in file(s): "
:marked-candidates t
:preselect (and helm-do-grep-preselect-candidate
(if helm-ff-transformer-show-only-basename
(helm-basename preselection)
preselection))))))
(helm-do-grep-1 targets nil nil nil nil use-region-or-symbol-p)))
(defun spacemacs/helm-file-do-grep ()
"Search in current file with `grep' using a default input."
(interactive)
(spacemacs//helm-do-grep-region-or-symbol
(list (buffer-file-name (current-buffer))) nil))
(defun spacemacs/helm-file-do-grep-region-or-symbol ()
"Search in current file with `grep' using a default input."
(interactive)
(spacemacs//helm-do-grep-region-or-symbol
(list (buffer-file-name (current-buffer))) t))
(defun spacemacs/helm-files-do-grep ()
"Search in files with `grep'."
(interactive)
(spacemacs//helm-do-grep-region-or-symbol nil nil))
(defun spacemacs/helm-files-do-grep-region-or-symbol ()
"Search in files with `grep' using a default input."
(interactive)
(spacemacs//helm-do-grep-region-or-symbol nil t))
(defun spacemacs/helm-buffers-do-grep ()
"Search in opened buffers with `grep'."
(interactive)
(let ((buffers (cl-loop for buffer in (buffer-list)
when (buffer-file-name buffer)
collect (buffer-file-name buffer))))
(spacemacs//helm-do-grep-region-or-symbol buffers nil)))
(defun spacemacs/helm-buffers-do-grep-region-or-symbol ()
"Search in opened buffers with `grep' with a default input."
(interactive)
(let ((buffers (cl-loop for buffer in (buffer-list)
when (buffer-file-name buffer)
collect (buffer-file-name buffer))))
(spacemacs//helm-do-grep-region-or-symbol buffers t)))
(defun spacemacs/last-search-buffer ()
"open last helm-ag or hgrep buffer."
(interactive)
(cond ((get-buffer "*helm ag results*")
(switch-to-buffer-other-window "*helm ag results*"))
((get-buffer "*helm-ag*")
(helm-resume "*helm-ag*"))
((get-buffer "*hgrep*")
(switch-to-buffer-other-window "*hgrep*"))
(t
(message "No previous search buffer found"))))
(defun spacemacs/helm-faces ()
"Describe face."
(interactive)
(require 'helm-elisp)
(let ((default (or (face-at-point) (thing-at-point 'symbol))))
(helm :sources (helm-def-source--emacs-faces
(format "%s" (or default "default")))
:buffer "*helm faces*")))
;; use helm by default for M-x
(unless (configuration-layer/package-usedp 'smex)
(global-set-key (kbd "M-x") 'helm-M-x))
(spacemacs/set-leader-keys
"<f1>" 'helm-apropos
"bb" 'helm-mini
"Cl" 'helm-colors
"ff" 'spacemacs/helm-find-files
"fF" 'helm-find-files
"fL" 'helm-locate
"fr" 'helm-recentf
"hb" 'helm-filtered-bookmarks
"hdF" 'spacemacs/helm-faces
"hi" 'helm-info-at-point
"hl" 'helm-resume
"hm" 'helm-man-woman
"iu" 'helm-ucs
"ry" 'helm-show-kill-ring
"rr" 'helm-register
"rm" 'helm-all-mark-rings
"sl" 'spacemacs/last-search-buffer
"sj" 'spacemacs/jump-in-buffer)
;; search with grep
(spacemacs/set-leader-keys
"sgb" 'spacemacs/helm-buffers-do-grep
"sgB" 'spacemacs/helm-buffers-do-grep-region-or-symbol
"sgf" 'spacemacs/helm-files-do-grep
"sgF" 'spacemacs/helm-files-do-grep-region-or-symbol
"sgg" 'spacemacs/helm-file-do-grep
"sgG" 'spacemacs/helm-file-do-grep-region-or-symbol)
;; define the key binding at the very end in order to allow the user
;; to overwrite any key binding
(add-hook 'emacs-startup-hook
(lambda ()
(unless (configuration-layer/package-usedp 'smex)
(spacemacs/set-leader-keys dotspacemacs-command-key 'helm-M-x))))
(defun spacemacs//hide-cursor-in-helm-buffer ()
"Hide the cursor in helm buffers."
(with-helm-buffer
(setq cursor-in-non-selected-windows nil)))
(add-hook 'helm-after-initialize-hook 'spacemacs//hide-cursor-in-helm-buffer)
(defvar spacemacs-helm-display-help-buffer-regexp '("*.*Helm.*Help.**"))
(defvar spacemacs-helm-display-buffer-regexp `("*.*helm.**"
(display-buffer-in-side-window)
(inhibit-same-window . t)
(side . ,dotspacemacs-helm-position)
(window-width . 0.6)
(window-height . 0.4)))
(defvar spacemacs-display-buffer-alist nil)
(defun spacemacs//helm-prepare-display ()
"Prepare necessary settings to make Helm display properly."
;; avoid Helm buffer being diplaye twice when user
;; sets this variable to some function that pop buffer to
;; a window. See https://github.com/syl20bnr/spacemacs/issues/1396
(let ((display-buffer-base-action '(nil)))
(setq spacemacs-display-buffer-alist display-buffer-alist)
;; the only buffer to display is Helm, nothing else we must set this
;; otherwise Helm cannot reuse its own windows for copyinng/deleting
;; etc... because of existing popwin buffers in the alist
(setq display-buffer-alist nil)
(popwin-mode -1)
;; workaround for a helm-evil incompatibility
;; see https://github.com/syl20bnr/spacemacs/issues/3700
(when helm-prevent-escaping-from-minibuffer
(define-key evil-motion-state-map [down-mouse-1] nil))))
(defun spacemacs//display-helm-window (buffer)
(let ((display-buffer-alist (list spacemacs-helm-display-help-buffer-regexp
;; this or any specialized case of Helm buffer must be added AFTER
;; `spacemacs-helm-display-buffer-regexp'. Otherwise,
;; `spacemacs-helm-display-buffer-regexp' will be used before
;; `spacemacs-helm-display-help-buffer-regexp' and display
;; configuration for normal Helm buffer is applied for helm help
;; buffer, making the help buffer unable to be displayed.
spacemacs-helm-display-buffer-regexp)))
(helm-default-display-buffer buffer)))
(setq helm-display-function 'spacemacs//display-helm-window)
(defun spacemacs//restore-previous-display-config ()
;; workaround for a helm-evil incompatibility
;; see https://github.com/syl20bnr/spacemacs/issues/3700
(when helm-prevent-escaping-from-minibuffer
(define-key evil-motion-state-map [down-mouse-1] 'evil-mouse-drag-region))
(popwin-mode 1)
;; we must enable popwin-mode first then restore `display-buffer-alist'
;; Otherwise, popwin keeps adding up its own buffers to `display-buffer-alist'
;; and could slow down Emacs as the list grows
(setq display-buffer-alist spacemacs-display-buffer-alist))
(add-hook 'helm-after-initialize-hook 'spacemacs//helm-prepare-display)
;; Restore popwin-mode after a Helm session finishes.
(add-hook 'helm-cleanup-hook 'spacemacs//restore-previous-display-config)
;; Add minibuffer history with `helm-minibuffer-history'
(define-key minibuffer-local-map (kbd "C-c C-l") 'helm-minibuffer-history)
(defun spacemacs//helm-cleanup ()
"Cleanup some helm related states when quitting."
;; deactivate any running transient map (micro-state)
(setq overriding-terminal-local-map nil))
(add-hook 'helm-cleanup-hook 'spacemacs//helm-cleanup)
(defface spacemacs-helm-navigation-ms-face
`((t :background ,(face-attribute 'error :foreground) :foreground "black"))
"Face for helm heder when helm micro-state is activated."
:group 'spacemacs))
:config
(progn
(helm-mode +1)
;; helm-locate uses es (from everything on windows, which doesnt like fuzzy)
(helm-locate-set-command)
(setq helm-locate-fuzzy-match (string-match "locate" helm-locate-command))
(defun spacemacs//set-dotted-directory ()
"Set the face of diretories for `.' and `..'"
(set-face-attribute 'helm-ff-dotted-directory
nil
:foreground nil
:background nil
:inherit 'helm-ff-directory))
(add-hook 'helm-find-files-before-init-hook 'spacemacs//set-dotted-directory)
;; alter helm-bookmark key bindings to be simpler
(defun simpler-helm-bookmark-keybindings ()
(define-key helm-bookmark-map (kbd "C-d") 'helm-bookmark-run-delete)
(define-key helm-bookmark-map (kbd "C-e") 'helm-bookmark-run-edit)
(define-key helm-bookmark-map (kbd "C-f") 'helm-bookmark-toggle-filename)
(define-key helm-bookmark-map (kbd "C-o") 'helm-bookmark-run-jump-other-window)
(define-key helm-bookmark-map (kbd "C-/") 'helm-bookmark-help))
(add-hook 'helm-mode-hook 'simpler-helm-bookmark-keybindings)
;; helm navigation on hjkl
(defun spacemacs//helm-hjkl-navigation (&optional arg)
"Set navigation in helm on `jklh'.
ARG non nil means that the editing style is `vim'."
(cond
(arg
;; better navigation on homerow
;; rebind `describe-key' for convenience
(define-key helm-map (kbd "C-j") 'helm-next-line)
(define-key helm-map (kbd "C-k") 'helm-previous-line)
(define-key helm-map (kbd "C-h") 'helm-next-source)
(define-key helm-map (kbd "C-S-h") 'describe-key)
(define-key helm-map (kbd "C-l") (kbd "RET"))
(dolist (keymap (list helm-find-files-map helm-read-file-map))
(define-key keymap (kbd "C-l") 'helm-execute-persistent-action)
(define-key keymap (kbd "C-h") 'helm-find-files-up-one-level)
(define-key keymap (kbd "C-S-h") 'describe-key)))
(t
(define-key helm-map (kbd "C-j") 'helm-execute-persistent-action)
(define-key helm-map (kbd "C-k") 'helm-delete-minibuffer-contents)
(define-key helm-map (kbd "C-h") nil)
(define-key helm-map (kbd "C-l") 'helm-recenter-top-bottom-other-window))))
(spacemacs//helm-hjkl-navigation (member dotspacemacs-editing-style '(vim hybrid)))
(defun spacemacs/helm-edit ()
"Switch in edit mode depending on the current helm buffer."
(interactive)
(cond
((string-equal "*helm-ag*" helm-buffer)
(helm-ag-edit))))
(defun spacemacs//helm-navigation-ms-on-enter ()
"Initialization of helm micro-state."
;; faces
(spacemacs//helm-navigation-ms-set-face)
(setq spacemacs--helm-navigation-ms-face-cookie-minibuffer
(face-remap-add-relative
'minibuffer-prompt
'spacemacs-helm-navigation-ms-face)))
(defun spacemacs//helm-navigation-ms-set-face ()
"Set the face for helm header in helm navigation micro-state"
(with-helm-window
(setq spacemacs--helm-navigation-ms-face-cookie-header
(face-remap-add-relative
'helm-header
'spacemacs-helm-navigation-ms-face))))
(defun spacemacs//helm-navigation-ms-on-exit ()
"Action to perform when exiting helm micro-state."
(with-helm-window
(face-remap-remove-relative
spacemacs--helm-navigation-ms-face-cookie-header))
(face-remap-remove-relative
spacemacs--helm-navigation-ms-face-cookie-minibuffer))
(defun spacemacs//helm-navigation-ms-full-doc ()
"Full documentation for helm navigation micro-state."
"
[?] display this help
[a] toggle action selection page
[e] edit occurrences if supported
[j] [k] next/previous candidate
[h] [l] previous/next source
[t] toggle visible mark
[T] toggle all mark
[v] persistent action
[q] quit")
;; Define functions to pick actions
(dotimes (n 10)
(let ((func (intern (format "spacemacs/helm-action-%d" n)))
(doc (format "Select helm action #%d" n)))
(eval `(defun ,func ()
,doc
(intern)
(helm-select-nth-action ,(1- n))))))
(spacemacs|define-micro-state helm-navigation
:persistent t
:disable-evil-leader t
:define-key (helm-map . "M-SPC") (helm-map . "s-M-SPC")
:on-enter (spacemacs//helm-navigation-ms-on-enter)
:on-exit (spacemacs//helm-navigation-ms-on-exit)
:bindings
("1" spacemacs/helm-action-1 :exit t)
("2" spacemacs/helm-action-2 :exit t)
("3" spacemacs/helm-action-3 :exit t)
("4" spacemacs/helm-action-4 :exit t)
("5" spacemacs/helm-action-5 :exit t)
("6" spacemacs/helm-action-6 :exit t)
("7" spacemacs/helm-action-7 :exit t)
("8" spacemacs/helm-action-8 :exit t)
("9" spacemacs/helm-action-9 :exit t)
("0" spacemacs/helm-action-10 :exit t)
("<tab>" helm-select-action :exit t)
("TAB" helm-select-action :exit t)
("<RET>" helm-maybe-exit-minibuffer :exit t)
("?" nil :doc (spacemacs//helm-navigation-ms-full-doc))
("a" helm-select-action :post (spacemacs//helm-navigation-ms-set-face))
("e" spacemacs/helm-edit)
("h" helm-previous-source)
("j" helm-next-line)
("k" helm-previous-line)
("l" helm-next-source)
("q" nil :exit t)
("t" helm-toggle-visible-mark)
("T" helm-toggle-all-marks)
("v" helm-execute-persistent-action))
;; Swap default TAB and C-z commands.
;; For GUI.
(define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action)
(define-key helm-find-files-map (kbd "S-<tab>") 'helm-find-files-up-one-level)
(define-key helm-find-files-map (kbd "<backtab>") 'helm-find-files-up-one-level)
;; For terminal.
(define-key helm-map (kbd "TAB") 'helm-execute-persistent-action)
(define-key helm-find-files-map (kbd "S-TAB") 'helm-find-files-up-one-level)
(define-key helm-map (kbd "C-z") 'helm-select-action)
(with-eval-after-load 'helm-mode ; required
(spacemacs|hide-lighter helm-mode)))))
(defun spacemacs-base/init-helm-flx ()
(use-package helm-flx
:defer t)
(spacemacs|use-package-add-hook helm
:pre-config
(progn
;; Disable for helm-find-files until performance issues are sorted
;; https://github.com/PythonNut/helm-flx/issues/9
(setq helm-flx-for-helm-find-files nil)
(helm-flx-mode))))
(defun spacemacs-base/init-helm-descbinds ()
(use-package helm-descbinds
:defer t
:init
(progn
(setq helm-descbinds-window-style 'split)
(add-hook 'helm-mode-hook 'helm-descbinds-mode)
(spacemacs/set-leader-keys "?" 'helm-descbinds))))
(defun spacemacs-base/init-helm-projectile ()
(use-package helm-projectile
:commands (helm-projectile-switch-to-buffer
helm-projectile-find-dir
helm-projectile-dired-find-dir
helm-projectile-recentf
helm-projectile-find-file
helm-projectile-grep
helm-projectile
helm-projectile-switch-project)
:init
(progn
(setq projectile-switch-project-action 'helm-projectile)
(defconst spacemacs-use-helm-projectile t
"This variable is only defined if helm-projectile is used.")
;; needed for smart search if user's default tool is grep
(defalias 'spacemacs/helm-project-do-grep 'helm-projectile-grep)
(defalias
'spacemacs/helm-project-do-grep-region-or-symbol 'helm-projectile-grep)
(spacemacs/set-leader-keys
"pb" 'helm-projectile-switch-to-buffer
"pd" 'helm-projectile-find-dir
"pf" 'helm-projectile-find-file
"ph" 'helm-projectile
"pp" 'helm-projectile-switch-project
"pr" 'helm-projectile-recentf
"pv" 'projectile-vc
"sgp" 'helm-projectile-grep))))
(defun spacemacs-base/init-helm-spacemacs ()
(use-package helm-spacemacs
:commands (helm-spacemacs helm-spacemacs-faq)
:init
(progn
(spacemacs/set-leader-keys "feh" 'helm-spacemacs)
(spacemacs/set-leader-keys "fef" 'helm-spacemacs-faq)
(spacemacs/set-leader-keys "h SPC" 'helm-spacemacs))))
(defun spacemacs-base/init-help-fns+ ()
(use-package help-fns+
:commands (describe-keymap)
:init (spacemacs/set-leader-keys "hdK" 'describe-keymap)))
(defun spacemacs-base/init-hl-todo ()
(use-package hl-todo
:defer t
:init (add-hook 'prog-mode-hook 'hl-todo-mode)))
(defun spacemacs-base/init-hs-minor-mode ()
;; required for evil folding
(defun spacemacs//enable-hs-minor-mode ()
"Enable hs-minor-mode for code folding."
(ignore-errors
(hs-minor-mode)
(spacemacs|hide-lighter hs-minor-mode)))
(add-hook 'prog-mode-hook 'spacemacs//enable-hs-minor-mode))
(defun spacemacs-base/init-holy-mode ()
(use-package holy-mode
:commands holy-mode
:init
(progn
(when (eq 'emacs dotspacemacs-editing-style)
(holy-mode))
(spacemacs|add-toggle holy-mode
:status holy-mode
:on (progn (when (bound-and-true-p hybrid-mode)
(hybrid-mode -1))
(holy-mode))
:off (holy-mode -1)
:documentation "Globally toggle holy mode."
:evil-leader "tEe")
(spacemacs|diminish holy-mode " Ⓔe" " Ee"))))
(defun spacemacs-base/init-hybrid-mode ()
(use-package hybrid-mode