-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.el
1985 lines (1771 loc) · 66.6 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
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
;; init.el --- Emacs user-init-file
;;; Commentary:
;; TODO: Explore byte compiling this file to improve startup time.
;; TODO: Prior config had a custom insert to avoid insert on read-only buffers.
;; TODO: Quoting lambdas doesn't let compiler to compile them, it seems is not necessary.
;; TODO: Zshell is not working right.
;; TODO: Use evil-window-map to define the C-w mappings.
;; TODO: Explore evil-want-* settings.
;; TODO: Adopt the usage of use-package's :hook keyword.
;; TODO: Explore the org-mode features from https://github.com/dieggsy/dotfiles/tree/master/emacs.d
;; TODO: Org easy templates expansion not working with ox-reveal (https://github.com/yjwen/org-reveal/issues/323)
;; TODO: Add settings for disabling auto-save on .gpg files (https://www.reddit.com/r/emacs/comments/46lv2q/is_there_any_easy_way_to_make_org_files_password/d08j4fb/)
;; TODO: Fix the up and down motions while visually selecting a hunk in magit status mode.
;; TODO: In haskell-mode pressing Y or C freezes Emacs https://github.com/expez/evil-smartparens/issues/50
;; TODO: When oppening text files or markdown files buffer loads until spell check finishes.
;; TODO: Fix defer issues with centered-window-mode and hide-mode-line
;; TODO: Try out "sebastiencs/omnibox"
;; TODO: How about using flyspell-prog-mode?
;; TODO: Move vanilla emacs configurations to the respective block (before org settings)
;; TODO: Dive in https://emacscast.org/ to find settings of org capture and ox-hugo
;; TODO: For PureScript https://github.com/kRITZCREEK/a-whole-new-world/blob/master/init.el#L360
;; TODO: Keybinding to kill the buffer and then close the window.
;; TODO: ':hook' can be used as a code block not a parenthesized expression?
;; TODO: What about https://github.com/dbordak/telephone-line for powerline replacement?
;; TODO: Add a function that does "vipgq" that is used frequently in org-mode.
;; ===================================================
;; NOTES & REMINDERS
;; ===================================================
;; => Before updating packages if all is working ok run straight-freeze-versions first.
;;(package-initialize)
;;; Code:
(setq gc-cons-threshold most-positive-fixnum)
(add-hook 'after-init-hook
#'(lambda () (setq gc-cons-threshold 800000)))
;; ===================================================
;; EARLY SETTINGS
;; ===================================================
;; Remove all GUI stuff
(menu-bar-mode -1)
(set-scroll-bar-mode nil)
(tool-bar-mode -1)
(setq straight-recipes-gnu-elpa-use-mirror t)
;; Turn off bells and whistles at startup
(setq inhibit-startup-message t
inhibit-startup-screen t
inhibit-startup-echo-area-message user-login-name
inhibit-default-init t
initial-major-mode 'fundamental-mode
initial-scratch-message nil
idle-update-delay 1)
(fset #'display-startup-echo-area-message #'ignore)
;; Straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(setq straight-use-package-by-default t
straight-vc-git-default-protocol 'ssh
straight-vc-git-force-protocol t)
(straight-use-package 'use-package)
(setq use-package-verbose t
use-package-always-defer t)
(eval-when-compile
(require 'use-package))
;; ===================================================
;; VARIABLES
;; ===================================================
(defvar zz-motion-up "h")
(defvar zz-motion-down "k")
(defvar zz-motion-left "j")
(defvar zz-motion-right "l")
;; ===================================================
;; FUNCTIONS
;; ===================================================
(defun zz-scroll-half-page (direction)
"Scroll half page up if DIRECTION is non-nil,other wise will scroll half page down."
(let ((opos (cdr (nth 6 (posn-at-point)))))
;; opos = original position line relative to window
(move-to-window-line nil) ;; Move cursor to middle line
(if direction
(recenter-top-bottom -1) ;; Current line becomes last
(recenter-top-bottom 0)) ;; Current line becomes first
(move-to-window-line opos)))
(defun zz-scroll-half-page-down ()
"Scrolls exactly half page down keeping cursor position."
(interactive)
(zz-scroll-half-page nil))
(defun zz-scroll-half-page-up ()
"Scrolls exactly half page up keeping cursor position."
(interactive)
(zz-scroll-half-page t))
(defun zz-reverse-selection (beg end)
"Reverses all the characters included in the region from BEG to END."
(interactive "r")
(insert (nreverse (delete-and-extract-region beg end))))
(defun zz-toggle-projectile-dired ()
"Toggle projectile-dired buffer."
(interactive)
(if (derived-mode-p 'dired-mode)
(evil-delete-buffer (current-buffer))
(if (projectile-project-p)
(projectile-dired)
(dired (file-name-directory buffer-file-name)))))
(defun zz-find-file ()
"When in a project use projectile to find a file otherwise use counsel."
(interactive)
(if (projectile-project-p)
(counsel-projectile-find-file)
(counsel-find-file)))
(defun zz-toggle-dired ()
"Toggle dired buffer."
(interactive)
(if (derived-mode-p 'dired-mode)
(evil-delete-buffer (current-buffer))
(dired (file-name-directory (or buffer-file-name "~/")))))
(defun zz-preferences ()
"Open the `user-init-file'."
(interactive)
(find-file user-init-file))
(defun zz-kill-buffer ()
"Alias for killing current buffer."
(interactive)
(kill-buffer nil))
(defun zz-kill-other-buffers ()
"Kill all other buffers."
(interactive)
(mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
(message "clear"))
(defun zz-evil-window-delete-or-die ()
"Delete the selected window. If this is the last one, exit Emacs."
(interactive)
(condition-case nil
(evil-window-delete)
(error (condition-case nil
(delete-frame)
(error (evil-quit))))))
(defun zz-minibuffer-keyboard-quit ()
"Abort recursive edit.
In Delete Selection mode, if the mark is active, just deactivate it;
then it takes a second \\[keyboard-quit] to abort the minibuffer."
(interactive)
(if (and delete-selection-mode transient-mark-mode mark-active)
(setq deactivate-mark t)
(when (get-buffer "*Completions*") (delete-windows-on "*Completions*"))
(abort-recursive-edit)))
(defun zz-dired-sort-directories-first ()
"Dired sort hook to list directories first."
(save-excursion
(let (buffer-read-only)
(forward-line 2) ;; beyond dir. header
(sort-regexp-fields t "^.*$" "[ ]*." (point) (point-max))))
(and (featurep 'xemacs)
(fboundp 'dired-insert-set-properties)
(dired-insert-set-properties (point-min) (point-max)))
(set-buffer-modified-p nil))
(defun zz-dired-up-directory ()
"Go up one level in the directory structure reusing dired buffer."
(interactive)
(find-alternate-file ".."))
(defun zz-save-to-escape ()
"First save the buffer and then escape from insert."
(interactive)
(save-buffer)
(evil-normal-state))
(defun zz-newline-and-enter-sexp (&rest _ignored)
"Open a new brace or bracket expression, with relevant newlines and indent."
(newline)
(indent-according-to-mode)
(forward-line -1)
(indent-according-to-mode))
(defun zz-git-gutter-stage-hunk ()
"Don't ask for confirmation when staging a hunk."
(interactive)
(setq git-gutter:ask-p nil)
(git-gutter:stage-hunk)
(setq git-gutter:ask-p t))
(defun zz-magit-checkout (revision)
"Check out a REVISION branch updating the mode line (reverts the buffer)."
(interactive (list (magit-read-other-branch-or-commit "Checkout")))
(magit-checkout revision)
(revert-buffer t t))
(defun zz-file-stats ()
"Gives the filename, current line and column of point."
(interactive)
(let* ((cursor-position (what-cursor-position))
(line (what-line))
(percent ((lambda ()
(string-match "\\([0-9]+\\)%" cursor-position)
(match-string 1 cursor-position))))
(column ((lambda ()
(string-match "column=\\([0-9]+\\)" cursor-position)
(match-string 1 cursor-position)))))
(message (format "%S %s Column %s | --%s%%%%--" buffer-file-name line column percent))))
(defun zz-scroll-line-to-quarter ()
"Scrolls windows so that the current line ends at ~25% of the window."
(interactive)
(evil-scroll-line-to-top (- (line-number-at-pos) 5))
(evil-next-visual-line 5))
(defun zz-eshell-current-dir ()
"Open eshell in the current dir or use projectile-run-eshell in a project."
(interactive)
(if (projectile-project-p)
(projectile-run-eshell)
(eshell)))
(defun zz-zshell-current-dir ()
"Open zshell in the current dir."
(interactive)
(if (projectile-project-p)
(projectile-run-term "/usr/local/bin/zsh")
(ansi-term "/usr/local/bin/zsh")))
(defun zz-shell-insert ()
"When entering insert mode do it at the prompt line."
(interactive)
(let* ((curline (line-number-at-pos))
(endline (line-number-at-pos (point-max))))
(if (= curline endline)
(if (not (eobp))
(let ((plist (text-properties-at (point)))
(next-change (or (next-property-change (point) (current-buffer))
(point-max))))
(if (plist-get plist 'read-only)
(goto-char next-change))))
(goto-char (point-max)))))
(defun zz-eshell-clear-buffer ()
"Clear eshell buffer."
(interactive)
(recenter-top-bottom 0))
(defun zz-evil-select-pasted ()
"Visually select last pasted text."
(interactive)
(evil-goto-mark ?\[)
(evil-visual-char)
(evil-goto-mark ?\]))
(defun zz-quit-help-like-windows (&optional kill frame)
"Quit all windows with help-like buffers.
Call `quit-windows-on' for every buffer named in
`zz-help-like-windows-name'. The optional parameters KILL and FRAME
are just as in `quit-windows-on', except FRAME defaults to t (so
that only windows on the selected frame are considered).
Note that a nil value for FRAME cannot be distinguished from an
omitted parameter and will be ignored; use some other value if
you want to quit windows on all frames."
(interactive)
(let ((frame (or frame t))
(zz-help-like-windows '(;; Ubiquitous help buffers
"*Help*"
"*Apropos*"
"*Messages*"
"*Completions*"
;; Other general buffers
"*Command History*"
"*Compile-Log*"
"*disabled command*")))
(dolist (name zz-help-like-windows)
(ignore-errors
(quit-windows-on name kill frame)))))
;; See: https://emacs.stackexchange.com/a/10233/12340
(defun zz-lisp-indent-function (indent-point state)
"This function is the normal value of the variable `lisp-indent-function'.
The function `calculate-lisp-indent' calls this to determine
if the arguments of a Lisp function call should be indented specially.
INDENT-POINT is the position at which the line being indented begins.
Point is located at the point to indent under (for default indentation);
STATE is the `parse-partial-sexp' state for that position.
If the current line is in a call to a Lisp function that has a non-nil
property `lisp-indent-function' (or the deprecated `lisp-indent-hook'),
it specifies how to indent. The property value can be:
* `defun', meaning indent `defun'-style
\(this is also the case if there is no property and the function
has a name that begins with \"def\", and three or more arguments);
* an integer N, meaning indent the first N arguments specially
(like ordinary function arguments), and then indent any further
arguments like a body;
* a function to call that returns the indentation (or nil).
`lisp-indent-function' calls this function with the same two arguments
that it itself received.
This function returns either the indentation to use, or nil if the
Lisp function does not specify a special indentation."
(let ((normal-indent (current-column))
(orig-point (point)))
(goto-char (1+ (elt state 1)))
(parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
(cond
;; car of form doesn't seem to be a symbol, or is a keyword
((and (elt state 2)
(or (not (looking-at "\\sw\\|\\s_"))
(looking-at ":")))
(if (not (> (save-excursion (forward-line 1) (point))
calculate-lisp-indent-last-sexp))
(progn (goto-char calculate-lisp-indent-last-sexp)
(beginning-of-line)
(parse-partial-sexp (point)
calculate-lisp-indent-last-sexp 0 t)))
;; Indent under the list or under the first sexp on the same
;; line as calculate-lisp-indent-last-sexp. Note that first
;; thing on that line has to be complete sexp since we are
;; inside the innermost containing sexp.
(backward-prefix-chars)
(current-column))
((and (save-excursion
(goto-char indent-point)
(skip-syntax-forward " ")
(not (looking-at ":")))
(save-excursion
(goto-char orig-point)
(looking-at ":")))
(save-excursion
(goto-char (+ 2 (elt state 1)))
(current-column)))
(t
(let ((function (buffer-substring (point)
(progn (forward-sexp 1) (point))))
method)
(setq method (or (function-get (intern-soft function)
'lisp-indent-function)
(get (intern-soft function) 'lisp-indent-hook)))
(cond ((or (eq method 'defun)
(and (null method)
(> (length function) 3)
(string-match "\\`def" function)))
(lisp-indent-defform state indent-point))
((integerp method)
(lisp-indent-specform method state
indent-point normal-indent))
(method
(funcall method indent-point state))))))))
(defun flyspell-goto-previous-error (arg)
"Go to ARG previous spelling error."
(interactive "p")
(while (not (= 0 arg))
(let ((pos (point))
(min (point-min)))
(if (and (eq (current-buffer) flyspell-old-buffer-error)
(eq pos flyspell-old-pos-error))
(progn
(if (= flyspell-old-pos-error min)
;; goto beginning of buffer
(progn
(message "Restarting from end of buffer")
(goto-char (point-max)))
(backward-word 1))
(setq pos (point))))
;; seek the next error
(while (and (> pos min)
(let ((ovs (overlays-at pos))
(r '()))
(while (and (not r) (consp ovs))
(if (flyspell-overlay-p (car ovs))
(setq r t)
(setq ovs (cdr ovs))))
(not r)))
;; (backward-word 1)
(evil-backward-word-begin 1)
(setq pos (point)))
;; save the current location for next invocation
(setq arg (1- arg))
(setq flyspell-old-pos-error pos)
(setq flyspell-old-buffer-error (current-buffer))
(goto-char pos)
(if (= pos min)
(progn
(message "No more miss-spelled word!")
(setq arg 0))))))
;; ===================================================
;; PACKAGES
;; ===================================================
(use-package no-littering
:demand t
:config
(require 'recentf)
(add-to-list 'recentf-exclude no-littering-var-directory)
(add-to-list 'recentf-exclude no-littering-etc-directory)
(setq backup-by-copying t
delete-old-versions t
kept-new-versions 6
kept-old-versions 2
version-control t)
(setq backup-directory-alist
`(("." . ,(no-littering-expand-var-file-name "backup/"))))
(setq auto-save-list-file-prefix
(no-littering-expand-var-file-name "auto-save/"))
(setq auto-save-file-name-transforms
`((".*" ,(no-littering-expand-var-file-name "auto-save/") t)))
(setq custom-file (no-littering-expand-etc-file-name "custom.el"))
(load custom-file 'noerror))
(use-package exec-path-from-shell
:if (memq window-system '(mac ns x))
:demand
:config
(dolist (envvar '("GOPATH" "GOROOT"))
(add-to-list 'exec-path-from-shell-variables envvar))
(exec-path-from-shell-initialize))
(use-package restart-emacs
:commands restart-emacs
:custom
(restart-emacs-restore-frames t))
(use-package diminish)
(use-package general
:demand t
:config
(general-define-key :states 'motion "M-," 'zz-preferences)
(general-define-key :states 'normal :prefix "SPC"
"q" 'zz-quit-help-like-windows
"u" 'universal-argument
"dk" 'describe-key
"dm" 'describe-mode
"db" 'describe-bindings
"dp" 'describe-package
"dv" 'describe-variable
"df" 'describe-function
"da" 'apropos-command
"dd" 'apropos-documentation
"di" 'info)
(general-define-key :keymaps '(normal visual) :prefix "SPC"
"lt" '(lambda ()
(interactive)
(counsel-load-theme)
(zz-fix-whitespace)
(zz-fix-spaceline))
"ln" 'linum-mode
"ta" 'align-regexp))
(use-package evil
:demand t
:init
(setq evil-respect-visual-line-mode t)
:custom
(evil-want-C-u-scroll t)
(evil-want-Y-yank-to-eol t)
(evil-undo-system 'undo-fu)
;; (evil-search-module 'evil-search)
:config
(evil-mode 1)
(fset 'evil-visual-update-x-selection 'ignore)
;; Fix scrolling (like in vim)
(evil-define-motion evil-scroll-up (count)
"Fixes the half-page scroll up to behave as in VIM"
:repeat motion
:type line
(zz-scroll-half-page t))
(evil-define-motion evil-scroll-down (count)
"Fixes the half-page scroll down to behave as in VIM"
:repeat motion
:type line
(zz-scroll-half-page nil))
(eval-after-load 'evil-ex
'(evil-ex-define-cmd "rev[erse]" 'zz-reverse-selection))
(general-define-key :states 'motion
zz-motion-up 'evil-previous-line
zz-motion-down 'evil-next-line
zz-motion-left 'evil-backward-char
zz-motion-right 'evil-forward-char
"<escape>" 'keyboard-quit
;; Windows
(concat "C-w " zz-motion-down) 'evil-window-down
(concat "C-w " zz-motion-up) 'evil-window-up
(concat "C-w " zz-motion-left) 'evil-window-left
(concat "C-w " (upcase zz-motion-up)) 'evil-window-move-very-top
(concat "C-w " (upcase zz-motion-down)) 'evil-window-move-very-bottom
(concat "C-w " (upcase zz-motion-left)) 'evil-window-move-far-left
(concat "C-w " (upcase zz-motion-right)) 'evil-window-move-far-right
;; Frames
"C-w x" 'other-frame
"C-w f" 'make-frame-command)
(general-define-key :keymaps 'normal
"M-s" 'evil-write
"C-s" 'evil-write
"gV" 'zz-evil-select-pasted
"zv" 'zz-scroll-line-to-quarter
"RET" 'newline
"ga" 'zz-file-stats
;; Buffer navigation
"gb" 'evil-buffer
"gr" 'revert-buffer
"M-{" 'evil-prev-buffer
"M-}" 'evil-next-buffer
"C-a k" 'zz-kill-buffer
"C-a c" 'zz-kill-other-buffers
"C-a d" 'zz-evil-window-delete-or-die)
(general-define-key :keymaps 'insert
"M-s" 'zz-save-to-escape
"C-s" 'zz-save-to-escape)
(general-define-key :keymaps 'visual
"M-c" 'evil-yank)
(general-define-key :keymaps '(minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map)
"<escape>" 'zz-minibuffer-keyboard-quit))
(use-package minibuffer
:straight nil
:hook (minibuffer-setup . (lambda ()
(when (eq this-command 'eval-expression)
(lispy-mode 1))))
:init
;; Don't garbage collect too often
(add-hook 'minibuffer-setup-hook #'(lambda () (interactive) (setq gc-cons-threshold most-positive-fixnum)))
(add-hook 'minibuffer-exit-hook #'(lambda () (interactive) (setq gc-cons-threshold 800000)))
:general
(:keymaps '(minibuffer-local-map
minibuffer-local-ns-map
minibuffer-local-completion-map
minibuffer-local-must-match-map
minibuffer-local-isearch-map)
"C-p" 'previous-history-element
"C-n" 'next-history-element
"C-w" 'backward-kill-word
"C-v" 'clipboard-yank
"<escape>" 'abort-recursive-edit))
(use-package autorevert
:straight nil
:diminish auto-revert-mode)
(use-package dired
:straight nil
:commands (auto-revert-mode zz-dired-sort-directories-first)
:hook ((dired-mode . dired-hide-details-mode)
(dired-mode . auto-revert-mode)
(dired-after-readin . zz-dired-sort-directories-first))
:config
(setq dired-dwim-target t
dired-use-ls-dired t
insert-directory-program "gls")
(put 'dired-find-alternate-file 'disabled nil)
(general-evil-define-key 'normal dired-mode-map
zz-motion-left nil
zz-motion-right nil
zz-motion-up 'dired-previous-line
zz-motion-down 'dired-next-line
"o" 'dired-find-alternate-file
"RET" 'dired-find-alternate-file
"u" 'zz-dired-up-directory
"C-r" 'revert-buffer
"C-p" 'zz-find-file
"r" 'dired-do-redisplay
"gb" 'evil-buffer
"M-{" 'evil-prev-buffer
"M-}" 'evil-next-buffer
"mc" 'dired-do-copy
"mm" 'dired-do-rename
"ma" 'dired-create-directory
"md" 'dired-do-delete)
:general
(:keymaps 'normal :prefix "SPC"
"tt" 'zz-toggle-dired))
(use-package dired-subtree
:after dired
:demand t
:config
(general-evil-define-key 'normal dired-mode-map
"<tab>" 'dired-subtree-toggle
"<backtab>" 'dired-subtree-cycle))
(use-package ivy
:diminish ivy-mode
:config
(ivy-mode 1)
(setq ivy-initial-inputs-alist nil)
(eval-after-load 'evil-ex
'(evil-ex-define-cmd "ls" 'ivy-switch-buffer))
:general
(:states 'normal :prefix "SPC"
"ls" 'ivy-switch-buffer)
(:keymaps '(ivy-minibuffer-map ivy-mode-map)
[escape] 'keyboard-escape-quit
"C-w" 'backward-kill-word
(concat "C-" zz-motion-down) 'ivy-next-line
(concat "C-" zz-motion-up) 'ivy-previous-line))
(use-package counsel
:diminish counsel-mode
:config
(when (eq system-type 'darwin)
(setq counsel-locate-cmd 'counsel-locate-cmd-mdfind))
(setq counsel-git-cmd "git ls-files --full-name --exclude-standard --others --cached --"
counsel-find-file-ignore-regexp "\\(?:\\`\\|[/\\]\\)\\(?:[#.]\\)")
(counsel-mode 1)
(defalias 'locate #'counsel-locate)
:general
("M-x" 'counsel-M-x
"C-x C-f" 'counsel-find-file)
(:keymaps 'normal :prefix "SPC"
"mx" 'counsel-M-x
"ff" 'counsel-find-file
"fr" 'counsel-recentf
"fw" 'swiper-isearch
"kr" 'counsel-yank-pop))
(use-package projectile
:commands (projectile-project-p)
:diminish projectile-mode
:config
(setq projectile-globally-ignored-files '(".DS_Store" ".class")
projectile-indexing-method 'hybrid
projectile-completion-system 'ivy)
(projectile-mode)
:general
(:keymaps 'normal
:prefix "SPC"
"tr" 'zz-toggle-projectile-dired))
(use-package counsel-projectile
:general
("M-P" 'counsel-projectile-switch-project
"M-p" 'zz-find-file)
(:states 'normal
"C-p" 'zz-find-file)
(:states 'normal :prefix "SPC"
"rg" 'counsel-projectile-rg))
(use-package flyspell
:straight nil
:commands (flyspell-mode flyspell-buffer git-commit-turn-on-flyspell)
:init
(add-hook 'org-mode-hook '(lambda () (flyspell-mode) (flyspell-buffer)))
(add-hook 'markdown-mode-hook '(lambda () (flyspell-mode) (flyspell-buffer)))
(add-hook 'git-commit-setup-hook #'git-commit-turn-on-flyspell)
:config
(flyspell-mode 1)
(setq ispell-program-name "aspell")
:general
(:keymaps 'normal
"]s" 'flyspell-goto-next-error
"[s" 'flyspell-goto-previous-error)
(:keymaps 'normal
:prefix "SPC"
"fl" 'flyspell-auto-correct-previous-word
"sa" 'flyspell-correct-word-before-point
"ss" '(lambda () (interactive) (ispell-change-dictionary "espanol") (flyspell-buffer))
"se" '(lambda () (interactive) (ispell-change-dictionary "english") (flyspell-buffer))))
(use-package flyspell-correct-ivy
:general
(:keymaps 'normal :prefix "SPC"
"fs" 'flyspell-correct-at-point
"fp" 'flyspell-correct-previous
"fn" 'flyspell-correct-next))
(use-package magit
:commands magit-read-other-branch-or-commit
:config
(defun zz/magit-status-with-prefix-arg ()
"Call `magit-status` with a prefix."
(interactive)
(let ((current-prefix-arg '(4)))
(call-interactively #'magit-status)))
(setq magit-display-buffer-function #'magit-display-buffer-fullframe-status-v1
magit-save-repository-buffers nil
magit-repository-directories '(("\~/workspace" . 2)))
(eval-after-load 'evil-ex
'(evil-ex-define-cmd "resolve" 'magit-ediff-resolve))
:general
(:states 'normal
"[c" 'smerge-prev
"]c" 'smerge-next)
(:states 'normal :prefix "SPC"
"gs" 'magit-status
"gd" 'magit-diff-buffer-file
"gS" 'zz/magit-status-with-prefix-arg
"gco" 'zz-magit-checkout
"gl" 'magit-log-current
"gb" 'magit-blame
"gm" 'magit-merge
"gca" 'magit-commit-amend
"gpl" 'magit-pull-branch
"gps" 'magit-push-other))
(use-package evil-magit
:after magit
:demand t
:init
(add-hook 'git-commit-mode-hook 'evil-insert-state)
:config
(evil-define-key evil-magit-state magit-mode-map
zz-motion-down 'evil-next-visual-line
zz-motion-up 'evil-previous-visual-line
(concat "C-w " zz-motion-down) 'evil-window-down
(concat "C-w " zz-motion-up) 'evil-window-up
(concat "C-w " zz-motion-left) 'evil-window-left))
(use-package evil-surround
:defer 5
:config
(global-evil-surround-mode 1))
(use-package evil-matchit
:defer 5
:config
(global-evil-matchit-mode 1))
(use-package evil-snipe
:defer 3
:diminish evil-snipe-local-mode
:commands turn-off-evil-snipe-override-mode
:init
(add-hook 'magit-mode-hook 'turn-off-evil-snipe-override-mode)
:config
(evil-snipe-mode 1)
(evil-snipe-override-mode 1)
(setq evil-snipe-spillover-scope 'whole-visible
evil-snipe-show-prompt nil))
(use-package evil-visualstar
:defer 3
:config
(global-evil-visualstar-mode))
(use-package evil-embrace
:defer 3
:config
(evil-embrace-enable-evil-surround-integration))
(use-package lispy
:hook ((emacs-lisp-mode lisp-mode clojure-mode) . lispy-mode)
:general
(:keymaps 'lispy-mode-map-lispy :states 'insert
"\"" 'lispy-doublequote
zz-motion-up 'special-lispy-up
zz-motion-down 'special-lispy-down
zz-motion-right 'special-lispy-right
zz-motion-left 'special-lispy-left))
(use-package lispyville
:hook (lispy-mode . lispyville-mode)
:config
(setq lispyville-motions-put-into-special t))
(use-package keyfreq
:defer 3
:config
(setq keyfreq-excluded-commands
'(self-insert-command
abort-recursive-edit
forward-char
backward-char
previous-line
evil-next-visual-line
evil-previous-visual-line
next-line
evil-write
evil-forward-char
evil-forward-word-begin
evil-scroll-donw
evil-backward-char
evil-previous-line
evil-next-line
evil-scroll-up
save-buffers-kill-terminal
save-buffers-kill-emacs))
(keyfreq-mode 1)
(keyfreq-autosave-mode 1))
(use-package treemacs
:config
(setq treemacs-width 35
treemacs-silent-refresh t
treemacs-silent-filewatch t
treemacs-file-event-delay 1000
treemacs-sorting 'alphabetic-case-insensitive-desc
treemacs-persist-file (no-littering-expand-var-file-name "treemacs"))
(dolist (face '(treemacs-root-face
treemacs-git-unmodified-face
treemacs-git-modified-face
treemacs-git-renamed-face
treemacs-git-ignored-face
treemacs-git-untracked-face
treemacs-git-added-face
treemacs-git-conflict-face
treemacs-directory-face
treemacs-directory-collapsed-face
treemacs-file-face
treemacs-tags-face))
(set-face-attribute face nil :family "Helvetica" :height 160))
:general
(:states 'normal "M-1" 'treemacs)
(:states 'normal :prefix "SPC"
"tl" 'treemacs)
(:states 'normal :keymaps 'treemacs-mode-map
"o" 'treemacs-RET-action
"l" 'treemacs-TAB-action
zz-motion-down 'treemacs-next-line
zz-motion-up 'treemacs-previous-line
(concat "C-" zz-motion-down) 'treemacs-next-project
(concat "C-" zz-motion-up) 'treemacs-previous-project
(concat "C-" zz-motion-left) 'treemacs-switch-workspace
(concat "C-" zz-motion-right) 'treemacs-switch-workspace
"M-," 'treemacs-edit-workspaces
"v" 'treemacs-visit-node-vertical-split
"s" 'treemacs-visit-node-horizontal-split
"O" 'treemacs-visit-node-in-external-application
"H" 'treemacs-toggle-show-dotfiles
"j" 'treemacs-collapse-parent-node
"J" 'treemacs-goto-parent-node
"mm" 'treemacs-move-file
"mr" 'treemacs-rename
"md" 'treemacs-delete
"ma" 'treemacs-create-dir
"mf" 'treemacs-create-file
"q" 'treemacs-quit
"u" 'treemacs-root-up
"C" 'treemacs-root-down
"yy" 'treemacs-copy-path-at-point
"yr" 'treemacs-copy-project-root
"yf" 'treemacs-copy-file
"b" 'treemacs-bookmark))
(use-package treemacs-projectile
:demand t
:after treemacs projectile)
(use-package treemacs-magit
:after treemacs magit)
(use-package yasnippet
:diminish yas-minor-mode
:hook (prog-mode . yas-minor-mode)
:config
(yas-reload-all))
(use-package flymake
:straight nil
:disabled t)
(use-package flycheck
:diminish flycheck-mode
:commands global-flycheck-mode
:hook (prog-mode . global-flycheck-mode)
:config
(setq flycheck-idle-change-delay 5
flycheck-check-syntax-automatically '(save idle-change)
flycheck-indication-mode nil)
(eval-after-load 'evil-ex
'(evil-ex-define-cmd "fly[check]" 'flycheck-list-errors))
:general
(:keymaps 'normal
:prefix "["
"e" 'flycheck-previous-error)
(:keymaps 'normal
:prefix "]"
"e" 'flycheck-next-error))
(use-package avy
:config
(avy-setup-default)
(setq avy-keys '(?a ?r ?s ?t ?d ?h ?n ?e ?i ?o)
avy-timeout-seconds 0.4)
:general
(:keymaps 'normal :prefix "SPC"
"SPC" 'avy-goto-char-timer
"go" 'avy-goto-char-2))
(use-package smartparens
:defer 3
:diminish smartparens-mode
:commands smartparens-mode
:hook ((prog-mode toml-mode) . smartparens-mode)
:config
(setq sp-autoskip-closing-pair (quote always))
(require 'smartparens-config)
(sp-with-modes 'emacs-lisp-mode
(sp-local-pair "'" nil :actions nil)
(sp-local-pair "`" "'" :when '(sp-in-string-p sp-in-comment-p)))
(sp-with-modes 'markdown-mode
(sp-local-pair "_" "_")
(sp-local-pair "**" "**")
(sp-local-pair "~~" "~~"))
;; For modes use: (sp-local-pair '(c-mode) "{" nil :post-handlers '((zz-newline-and-enter "RET")))
;; Indent a new line when pressing RET after pair insertion
(sp-pair "{" nil :post-handlers '((zz-newline-and-enter-sexp "RET")))
(sp-pair "(" nil :post-handlers '((zz-newline-and-enter-sexp "RET")))
(sp-pair "[" nil :post-handlers '((zz-newline-and-enter-sexp "RET"))))
(use-package evil-smartparens
:diminish evil-smartparens-mode
:hook (smartparens-enabled . evil-smartparens-mode))
(use-package expand-region
:general
(:keymaps 'visual
"v" 'er/expand-region
"V" 'er/contract-region))
(use-package evil-vimish-fold
:demand t
:diminish evil-vimish-fold-mode
:hook (prog-mode . evil-vimish-fold-mode)
:general
(:states '(normal motion) :keymaps 'evil-vimish-fold-mode-map
(concat "z" zz-motion-up) 'evil-vimish-fold/previous-fold
(concat "z" zz-motion-down) 'evil-vimish-fold/next-fold))
(use-package powerline
:if window-system
:config
(setq powerline-image-apple-rgb t
powerline-default-separator 'wave
powerline-text-scale-factor 0.90))
(use-package spaceline
:commands spaceline-spacemacs-theme
:init
(add-hook 'after-init-hook 'spaceline-spacemacs-theme)
:config
(defun zz-fix-spaceline ()
(interactive)
"Fix mode line appearance (useful after switching themes)."
(require 'spaceline-config)
(setq spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
(set-face-attribute 'mode-line nil :height 120 :family "Monaco")
(set-face-attribute 'mode-line-inactive nil :height 120 :family "Monaco")
(spaceline-toggle-minor-modes-off))
(zz-fix-spaceline))
(use-package rainbow-delimiters
:hook ((emacs-lisp-mode lisp-mode clojure-mode) . rainbow-delimiters-mode))
(use-package solaire-mode
:hook
((aftechange-major-mode after-revert ediff-prepare-buffer) . turn-on-solaire-mode)
(minibuffer-setup . solaire-mode-in-minibuffer)
:config
(setq solaire-mode-remap-modeline nil)