|
108 | 108 | "gc" #'evilnc-comment-operator
|
109 | 109 | "gC" #'evilnc-copy-and-comment-operator))
|
110 | 110 |
|
| 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 | + |
111 | 389 |
|
112 | 390 | (provide 'me-evil)
|
113 | 391 |
|
|
0 commit comments