Skip to content

Commit 5543a6c

Browse files
committed
refactor(evil)!: move all Evil related configs/packages to me-evil
NOTE: I'm moving away from Evil to the classic Emacs experience (maybe with Meow). I've left the `me-evil` module as it is with all the Evil related packages in this same module. I will spend some time on Emacs/Meow to see if it fits for me.
1 parent 0516d30 commit 5543a6c

14 files changed

+290
-173
lines changed

core/me-builtin.el

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,9 +481,7 @@ or file path may exist now."
481481
"j" #'next-line
482482
"k" #'previous-line
483483
"q" #'kill-buffer-and-window
484-
"ESC" #'kill-buffer-and-window)
485-
(with-eval-after-load 'evil
486-
(add-hook 'reftex-mode-hook #'evil-normalize-keymaps)))
484+
"ESC" #'kill-buffer-and-window))
487485

488486
(use-package bibtex
489487
:hook (bibtex-mode . display-line-numbers-mode)
@@ -817,10 +815,6 @@ This variable should be set early, either in \"early-config.el\" or \"init-tweak
817815
:preface
818816
;; Set to nil so we can detect user changes (in config.el)
819817
(setq org-directory nil)
820-
(with-eval-after-load 'evil
821-
;; Fix `evil' search problem (to be used with `evil-search')
822-
(when (eq evil-search-module 'evil-search)
823-
(setq org-fold-core-style 'overlays)))
824818
:custom
825819
(org-auto-align-tags nil)
826820
(org-clock-persist-file (concat minemacs-cache-dir "org/clock-persist.el"))
@@ -847,7 +841,7 @@ This variable should be set early, either in \"early-config.el\" or \"init-tweak
847841
(org-pretty-entities-include-sub-superscripts t)
848842
(org-preview-latex-image-directory (+directory-ensure minemacs-cache-dir "org/preview/latex-image/"))
849843
(org-publish-timestamp-directory (+directory-ensure minemacs-cache-dir "org/publish/timestamps/"))
850-
(org-return-follows-link t) ; RET follows link (a key bind has to be defined for Evil, see below)
844+
(org-return-follows-link t) ; RET follows link (a key bind has to be defined for Evil, (see `me-evil'))
851845
(org-special-ctrl-a/e t)
852846
(org-startup-indented nil)
853847
(org-tags-column 0)
@@ -875,8 +869,6 @@ This variable should be set early, either in \"early-config.el\" or \"init-tweak
875869
"s" #'org-edit-src-save
876870
"q" #'org-edit-src-abort
877871
"e" #'org-edit-src-exit)
878-
(+nmap! :keymaps 'org-mode-map
879-
"RET" #'org-open-at-point)
880872

881873
(setq org-export-async-debug minemacs-debug-p) ;; Can be useful!
882874

core/me-evil.el

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,284 @@
108108
"gc" #'evilnc-comment-operator
109109
"gC" #'evilnc-copy-and-comment-operator))
110110

111+
(cl-defmacro +evil-conf-for! (package module &optional &key init-form &key config-form)
112+
(declare (indent 2))
113+
`(when (and (not (+package-disabled-p ',package ',module))
114+
(memq ',module (append minemacs-core-modules minemacs-modules)))
115+
,init-form
116+
,(when config-form
117+
`(with-eval-after-load ',package ,config-form))))
118+
119+
120+
121+
;;; For `me-multi-cursors'
122+
123+
(use-package evil-multiedit ; This will load `iedit' and suppresses it
124+
:straight t
125+
:unless (+package-disabled-p 'iedit 'me-multi-cursors)
126+
:after evil minemacs-first-file
127+
:demand
128+
:init
129+
(+nvmap! :infix "g"
130+
"ze" '(nil :wk "evil-multiedit")
131+
"zee" #'evil-multiedit-match-all
132+
"zer" #'evil-multiedit-restore
133+
"zeq" #'evil-multiedit-abort
134+
"zen" #'evil-multiedit-next
135+
"zeN" #'evil-multiedit-prev
136+
"zet" #'evil-multiedit-toggle-or-restrict-region)
137+
(+vmap! :infix "g"
138+
"zed" #'evil-multiedit-match-and-next
139+
"zeD" #'evil-multiedit-match-and-prev)
140+
(+nmap! :infix "g"
141+
"zed" #'evil-multiedit-match-symbol-and-next
142+
"zeD" #'evil-multiedit-match-symbol-and-prev
143+
"zeT" #'evil-multiedit-toggle-marker-here)
144+
:config
145+
(evil-multiedit-default-keybinds))
146+
147+
(use-package evil-iedit-state
148+
:straight t
149+
:unless (+package-disabled-p 'iedit 'me-multi-cursors)
150+
:commands evil-iedit-state/iedit-mode
151+
:after iedit
152+
:init
153+
;; Use the `iedit' key to trigger `evil-iedit-state/iedit-mode'.
154+
(when iedit-toggle-key-default
155+
(keymap-global-set (key-description iedit-toggle-key-default) 'evil-iedit-state/iedit-mode))
156+
:config
157+
;; FIX: When we press "C-;" (`iedit-toggle-key-default') to enter `iedit-mode'
158+
;; and then "C-;" to quit it, `evil-iedit-state' will stay in `iedit-mode'
159+
;; even if the selections aren't displayed and no `iedit' indication is
160+
;; displayed in minibuffer.
161+
(when iedit-toggle-key-default
162+
(keymap-set evil-iedit-state-map (key-description iedit-toggle-key-default) 'evil-iedit-state/quit-iedit-mode)))
163+
164+
(use-package evil-mc
165+
:straight t
166+
:when (memq 'me-multi-cursors minemacs-modules)
167+
:hook (minemacs-first-file . global-evil-mc-mode)
168+
:config
169+
;; Use "gz" instead of "gr", this last is mapped to `xref-find-references' in some programming modes.
170+
(evil-define-key* '(normal visual) evil-mc-key-map (kbd "gr") nil)
171+
(evil-define-key* '(normal visual) evil-mc-key-map (kbd "gz") evil-mc-cursors-map)
172+
173+
;; Add support to repeat these commands when prefixed with a number
174+
(dolist (cmd '(evil-mc-make-and-goto-first-cursor evil-mc-make-and-goto-last-cursor
175+
evil-mc-make-and-goto-prev-cursor evil-mc-make-and-goto-next-cursor
176+
evil-mc-skip-and-goto-prev-cursor evil-mc-skip-and-goto-next-cursor
177+
evil-mc-make-and-goto-prev-match evil-mc-make-and-goto-next-match
178+
evil-mc-skip-and-goto-prev-match evil-mc-skip-and-goto-next-match))
179+
(let ((fn-name (intern (format "+%s--repeat:around-a" cmd))))
180+
(defalias fn-name (lambda (fn) (dotimes (i (if (integerp current-prefix-arg) current-prefix-arg 1)) (funcall fn))))
181+
(advice-add cmd :around fn-name)))
182+
183+
;; Custom commands to execute with `evil-mc'
184+
(setq evil-mc-custom-known-commands
185+
'((backward-kill-word (:default . evil-mc-execute-default-call-with-count))
186+
(evil-delete-back-to-indentation (:default . evil-mc-execute-default-call))
187+
(undo-fu-only-redo (:default . evil-mc-execute-default-redo))
188+
(undo-fu-only-undo (:default . evil-mc-execute-default-undo))
189+
(corfu-complete (:default . evil-mc-execute-default-complete))
190+
(evil-numbers/dec-at-pt-incremental (:default . evil-mc-execute-default-call-with-count))
191+
(evil-numbers/inc-at-pt-incremental (:default . evil-mc-execute-default-call-with-count))
192+
(evil-org-delete (:default . evil-mc-execute-default-evil-delete))
193+
(ess-smart-comma (:default . evil-mc-execute-call))
194+
(evil-digit-argument-or-evil-beginning-of-visual-line
195+
(:default . evil-mc-execute-default-call)
196+
(visual . evil-mc-execute-visual-call)))))
197+
198+
199+
200+
;;; For `me-org'
201+
202+
(use-package evil-org
203+
:straight t
204+
:hook (org-mode . evil-org-mode))
205+
206+
(use-package evil-org-agenda
207+
:after evil-org
208+
:demand
209+
:config
210+
(evil-org-agenda-set-keys))
211+
212+
213+
214+
;;; For `me-builtin'
215+
216+
(+evil-conf-for! org me-builtin
217+
:config-form
218+
(progn
219+
;; RET follows link (Evil equivalent for `org-return-follows-link')
220+
(+nmap! :keymaps 'org-mode-map "RET" #'org-open-at-point)
221+
(with-eval-after-load 'evil
222+
;; Fix `evil' search problem (to be used with `evil-search')
223+
(when (eq evil-search-module 'evil-search)
224+
(setq org-fold-core-style 'overlays)))))
225+
226+
(+evil-conf-for! reftex me-builtin
227+
:config-form
228+
(with-eval-after-load 'evil
229+
(add-hook 'reftex-mode-hook #'evil-normalize-keymaps)))
230+
231+
232+
233+
;;; For `me-completion'
234+
235+
(+evil-conf-for! corfu me-completion
236+
:config-form
237+
(progn
238+
(keymap-set corfu-map "C-j" #'corfu-next)
239+
(keymap-set corfu-map "C-k" #'corfu-previous)))
240+
241+
(+evil-conf-for! vertico me-completion
242+
:config-form
243+
(progn
244+
(keymap-set vertico-map "C-j" #'vertico-next)
245+
(keymap-set vertico-map "C-k" #'vertico-previous)))
246+
247+
248+
249+
;;; For `me-natural-langs'
250+
251+
(when (memq 'me-natural-langs minemacs-modules)
252+
(+nvmap! "z=" #'+spellcheck-correct))
253+
254+
255+
256+
;;; For `me-editor'
257+
258+
(when (memq 'me-editor minemacs-modules)
259+
;; Bind `+yank-region-as-paragraph' (autoloaded from "me-lib.el")
260+
(+nvmap! "gy" #'+kill-region-as-paragraph))
261+
262+
263+
264+
;;; For `me-tools'
265+
266+
(+evil-conf-for! vterm me-tools
267+
:config-form
268+
(+imap! :keymaps 'vterm-mode-map
269+
"C-l" #'vterm-send-right
270+
"C-h" #'vterm-send-left
271+
"C-k" #'vterm-send-up
272+
"C-j" #'vterm-send-down))
273+
274+
(+evil-conf-for! multi-vterm me-tools
275+
:config-form
276+
(+nvmap!
277+
:keymaps 'vterm-mode-map
278+
",c" #'multi-vterm
279+
",n" #'multi-vterm-next
280+
",p" #'multi-vterm-prev
281+
"<return>" #'evil-insert-resume))
282+
283+
284+
285+
;;; For `me-editor'
286+
287+
(+evil-conf-for! expreg me-prog
288+
:init-form
289+
(+vmap!
290+
"v" #'expreg-expand
291+
"q" #'expreg-contract))
292+
293+
294+
295+
;;; For `me-files'
296+
297+
(+evil-conf-for! dirvish me-files
298+
:config-form
299+
(+nvmap! :keymaps 'dirvish-mode-map
300+
"q" #'dirvish-quit
301+
"s" #'dirvish-subtree-toggle
302+
"y" #'dirvish-yank-menu))
303+
304+
305+
306+
;;; For `me-email'
307+
308+
(+evil-conf-for! mu4e me-email
309+
:config-form
310+
(progn
311+
(+nvmap! :keymaps 'mu4e-view-mode-map "p" #'mu4e-view-save-attachments)
312+
(+nvmap! :keymaps '(mu4e-headers-mode-map mu4e-view-mode-map)
313+
"gw" #'+mu4e-open-mail-as-html
314+
"g RET" #'browse-url-at-point)))
315+
316+
(+evil-conf-for! org-msg me-email
317+
:config-form
318+
(+nvmap! :keymaps 'org-msg-edit-mode-map "gg" #'org-msg-goto-body))
319+
320+
321+
322+
;;; For `me-docs'
323+
324+
(+evil-conf-for! nov me-docs
325+
:config-form
326+
(+nmap! :keymaps 'nov-mode-map "RET" #'nov-scroll-up))
327+
328+
329+
330+
;;; For `me-docs'
331+
332+
(+evil-conf-for! elfeed me-rss
333+
:config-form
334+
(progn
335+
(+nmap! :keymaps 'elfeed-search-mode-map "d" #'+elfeed-youtube-dl)
336+
(+nmap! :keymaps 'elfeed-show-mode-map "D" #'+elfeed-download-image)))
337+
338+
339+
340+
;;; For `me-org'
341+
342+
(+evil-conf-for! xkcd me-fun
343+
:config-form
344+
(+nvmap! :keymaps 'xkcd-mode-map
345+
"j" #'xkcd-next
346+
"k" #'xkcd-prev
347+
"l" #'xkcd-get-latest
348+
"L" #'xkcd-get-latest-cached
349+
"<right>" #'xkcd-next
350+
"<left>" #'xkcd-prev
351+
"o" #'xkcd-open-browser
352+
"O" #'xkcd-open-explanation-browser
353+
"r" #'xkcd-rand
354+
"y" #'xkcd-copy-link))
355+
356+
357+
358+
;;; For `me-vc'
359+
360+
(+evil-conf-for! git-commit me-vc
361+
:config-form
362+
(with-eval-after-load 'evil (evil-set-initial-state 'git-commit-mode 'insert)))
363+
364+
365+
366+
;;; For `me-vc'
367+
368+
(+evil-conf-for! diffview me-vc
369+
:config-form
370+
(+nvmap! :keymaps 'diffview--mode-map
371+
"=" #'diffview--align-windows
372+
"+" #'diffview--align-windows
373+
"C-j" #'diffview--next-file
374+
"C-k" #'diffview--prev-file
375+
"q" #'diffview--quit))
376+
377+
378+
379+
;;; For `me-ui'
380+
381+
(+evil-conf-for! pulsar me-ui
382+
:config-form
383+
(with-eval-after-load 'evil
384+
(cl-callf append pulsar-pulse-functions
385+
'(evil-yank evil-paste-after evil-paste-before
386+
evil-delete evil-delete-line evil-delete-whole-line
387+
evil-goto-last-change evil-goto-last-change-reverse))))
388+
111389

112390
(provide 'me-evil)
113391

modules/me-docs.el

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@
4040
:straight t
4141
:mode ("\\.[eE][pP][uU][bB]\\'" . nov-mode)
4242
:custom
43-
(nov-save-place-file (concat minemacs-local-dir "nov/save-place.el"))
44-
:config
45-
(+nmap! :keymaps 'nov-mode-map
46-
"RET" #'nov-scroll-up))
43+
(nov-save-place-file (concat minemacs-local-dir "nov/save-place.el")))
4744

4845
(defconst +tuntox-available-p (and (executable-find "tuntox") t))
4946
(defconst +stunnel-available-p (and (executable-find "stunnel") t))

modules/me-editor.el

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
:straight t
1313
:custom
1414
(tempel-trigger-prefix "<") ;; Require trigger prefix before template name when completing.
15-
(tempel-path
16-
(list (concat minemacs-assets-dir "templates/tempel/*.eld")
17-
(concat minemacs-config-dir "templates/tempel/*.eld")))
15+
(tempel-path (list (concat minemacs-assets-dir "templates/tempel/*.eld")
16+
(concat minemacs-config-dir "templates/tempel/*.eld")))
1817
:bind (("M-\"" . tempel-complete) ;; Alternative tempel-expand
1918
("M-*" . tempel-insert)
2019
:map tempel-map
@@ -69,11 +68,7 @@
6968

7069
(use-package expreg
7170
:straight (:host github :repo "casouri/expreg")
72-
:when (+emacs-features-p 'tree-sitter)
73-
:init
74-
(+vmap!
75-
"v" #'expreg-expand
76-
"q" #'expreg-contract))
71+
:when (+emacs-features-p 'tree-sitter))
7772

7873
;; Fallback to `expand-region' if `expreg' cannot be used
7974
(unless (+emacs-features-p 'tree-sitter)
@@ -117,9 +112,6 @@
117112
:straight t
118113
:bind (:package isearch :map isearch-mode-map ([f2] . cc-isearch-menu-transient)))
119114

120-
;; Bind `+yank-region-as-paragraph' (autoloaded from "me-lib.el")
121-
(+nvmap! "gy" #'+kill-region-as-paragraph)
122-
123115

124116
(provide 'me-editor)
125117

modules/me-email.el

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@
6565
(mail-specify-envelope-from t)
6666
(mail-user-agent 'mu4e-user-agent)
6767
:config
68-
(+nvmap! :keymaps 'mu4e-view-mode-map
69-
"p" #'mu4e-view-save-attachments)
70-
(+nvmap! :keymaps '(mu4e-headers-mode-map mu4e-view-mode-map)
71-
"gw" #'+mu4e-open-mail-as-html
72-
"g RET" #'browse-url-at-point)
7368
(+map-local! :keymaps '(mu4e-compose-mode-map org-msg-edit-mode-map)
7469
"s" #'message-send-and-exit
7570
"d" #'message-kill-buffer
@@ -166,8 +161,6 @@
166161
(seq (or (seq "pi" (any ?e) "ce") "fichier" "document") (? "s") (+ (or " " eol)) "joint" (? "e") (? "s")) ;; pièce jointe
167162
(seq (or (seq space "p" (zero-or-one (any ?- ?.)) "j" (any space ?: ?\; ?, ?.))))))) ;; p.j
168163
:config
169-
(+nvmap! :keymaps 'org-msg-edit-mode-map
170-
"gg" #'org-msg-goto-body)
171164
(+map-local! :keymaps 'org-msg-edit-mode-map
172165
"a" '(nil :wk "attach")
173166
"aa" #'org-msg-attach-attach

0 commit comments

Comments
 (0)