2019-04-21 19:59:44 -04:00
|
|
|
;; editor/evil/autoload/evil.el -*- lexical-binding: t; -*-
|
2017-01-31 19:50:02 -05:00
|
|
|
|
2018-06-15 02:58:12 +02:00
|
|
|
;;;###autodef
|
|
|
|
(defun set-evil-initial-state! (modes state)
|
2018-06-19 11:59:23 +02:00
|
|
|
"Set the initialize STATE of MODES using `evil-set-initial-state'."
|
2018-06-22 01:30:27 +02:00
|
|
|
(declare (indent defun))
|
2018-06-15 02:58:12 +02:00
|
|
|
(after! evil
|
|
|
|
(if (listp modes)
|
2018-06-19 11:59:23 +02:00
|
|
|
(dolist (mode (doom-enlist modes))
|
2018-06-15 02:58:12 +02:00
|
|
|
(evil-set-initial-state mode state))
|
|
|
|
(evil-set-initial-state modes state))))
|
|
|
|
|
2018-05-25 00:46:11 +02:00
|
|
|
|
2019-06-17 12:05:54 +02:00
|
|
|
;;
|
|
|
|
;;; Interactive commands
|
2018-05-25 00:46:11 +02:00
|
|
|
|
2017-02-19 18:14:46 -05:00
|
|
|
;;;###autoload
|
2021-01-03 17:18:43 -05:00
|
|
|
(defun +evil/shift-right ()
|
2017-02-19 18:14:46 -05:00
|
|
|
"vnoremap < <gv"
|
|
|
|
(interactive)
|
2021-01-03 17:18:43 -05:00
|
|
|
(call-interactively #'evil-shift-right)
|
2017-02-19 18:14:46 -05:00
|
|
|
(evil-normal-state)
|
|
|
|
(evil-visual-restore))
|
|
|
|
|
|
|
|
;;;###autoload
|
2021-01-03 17:18:43 -05:00
|
|
|
(defun +evil/shift-left ()
|
2017-02-19 18:14:46 -05:00
|
|
|
"vnoremap > >gv"
|
|
|
|
(interactive)
|
2021-01-03 17:18:43 -05:00
|
|
|
(call-interactively #'evil-shift-left)
|
2017-02-19 18:14:46 -05:00
|
|
|
(evil-normal-state)
|
|
|
|
(evil-visual-restore))
|
|
|
|
|
2018-05-07 18:16:46 +02:00
|
|
|
;;;###autoload
|
2019-12-21 03:59:46 -05:00
|
|
|
(defun +evil/alt-paste ()
|
|
|
|
"Call `evil-paste-after' but invert `evil-kill-on-visual-paste'.
|
|
|
|
By default, this replaces the selection with what's in the clipboard without
|
|
|
|
replacing its contents."
|
2018-05-07 18:16:46 +02:00
|
|
|
(interactive)
|
2019-12-21 03:59:46 -05:00
|
|
|
(let ((evil-kill-on-visual-paste (not evil-kill-on-visual-paste)))
|
2018-05-07 18:16:46 +02:00
|
|
|
(call-interactively #'evil-paste-after)))
|
|
|
|
|
2017-05-15 13:52:22 +02:00
|
|
|
(defun +evil--window-swap (direction)
|
2019-03-09 02:42:03 -05:00
|
|
|
"Move current window to the next window in DIRECTION.
|
|
|
|
If there are no windows there and there is only one window, split in that
|
|
|
|
direction and place this window there. If there are no windows and this isn't
|
|
|
|
the only window, use evil-window-move-* (e.g. `evil-window-move-far-left')."
|
2018-01-06 01:23:22 -05:00
|
|
|
(when (window-dedicated-p)
|
|
|
|
(user-error "Cannot swap a dedicated window"))
|
|
|
|
(let* ((this-window (selected-window))
|
2017-09-25 13:02:20 +02:00
|
|
|
(this-buffer (current-buffer))
|
|
|
|
(that-window (windmove-find-other-window direction nil this-window))
|
|
|
|
(that-buffer (window-buffer that-window)))
|
|
|
|
(when (or (minibufferp that-buffer)
|
2018-01-06 01:23:22 -05:00
|
|
|
(window-dedicated-p this-window))
|
2017-09-25 13:02:20 +02:00
|
|
|
(setq that-buffer nil that-window nil))
|
|
|
|
(if (not (or that-window (one-window-p t)))
|
|
|
|
(funcall (pcase direction
|
|
|
|
('left #'evil-window-move-far-left)
|
|
|
|
('right #'evil-window-move-far-right)
|
|
|
|
('up #'evil-window-move-very-top)
|
|
|
|
('down #'evil-window-move-very-bottom)))
|
|
|
|
(unless that-window
|
|
|
|
(setq that-window
|
|
|
|
(split-window this-window nil
|
|
|
|
(pcase direction
|
|
|
|
('up 'above)
|
|
|
|
('down 'below)
|
|
|
|
(_ direction))))
|
2017-01-31 19:50:02 -05:00
|
|
|
(with-selected-window that-window
|
2017-10-07 20:32:48 +02:00
|
|
|
(switch-to-buffer (doom-fallback-buffer)))
|
2017-09-25 13:02:20 +02:00
|
|
|
(setq that-buffer (window-buffer that-window)))
|
|
|
|
(with-selected-window this-window
|
|
|
|
(switch-to-buffer that-buffer))
|
|
|
|
(with-selected-window that-window
|
|
|
|
(switch-to-buffer this-buffer))
|
|
|
|
(select-window that-window))))
|
2017-01-31 19:50:02 -05:00
|
|
|
|
2017-02-19 18:14:46 -05:00
|
|
|
;;;###autoload
|
2019-12-25 21:04:52 -05:00
|
|
|
(defun +evil/window-move-left ()
|
|
|
|
"Swap windows to the left."
|
|
|
|
(interactive) (+evil--window-swap 'left))
|
2017-02-19 18:14:46 -05:00
|
|
|
;;;###autoload
|
2019-12-25 21:04:52 -05:00
|
|
|
(defun +evil/window-move-right ()
|
|
|
|
"Swap windows to the right"
|
|
|
|
(interactive) (+evil--window-swap 'right))
|
2017-02-19 18:14:46 -05:00
|
|
|
;;;###autoload
|
2019-12-25 21:04:52 -05:00
|
|
|
(defun +evil/window-move-up ()
|
|
|
|
"Swap windows upward."
|
|
|
|
(interactive) (+evil--window-swap 'up))
|
2017-02-19 18:14:46 -05:00
|
|
|
;;;###autoload
|
2019-12-25 21:04:52 -05:00
|
|
|
(defun +evil/window-move-down ()
|
|
|
|
"Swap windows downward."
|
|
|
|
(interactive) (+evil--window-swap 'down))
|
2017-02-19 18:14:46 -05:00
|
|
|
|
2021-03-06 09:59:50 -05:00
|
|
|
;;;###autoload
|
2021-03-06 10:30:32 -05:00
|
|
|
(defun +evil/window-split-and-follow ()
|
2021-03-06 09:59:50 -05:00
|
|
|
"Split current window horizontally, then focus new window.
|
2021-03-10 15:48:31 +01:00
|
|
|
If `evil-split-window-below' is non-nil, the new window isn't focused."
|
2021-03-06 09:59:50 -05:00
|
|
|
(interactive)
|
2021-03-10 15:48:31 +01:00
|
|
|
(let ((evil-split-window-below (not evil-split-window-below)))
|
2021-03-06 09:59:50 -05:00
|
|
|
(call-interactively #'evil-window-split)))
|
|
|
|
|
|
|
|
;;;###autoload
|
2021-03-06 10:30:32 -05:00
|
|
|
(defun +evil/window-vsplit-and-follow ()
|
2021-03-06 09:59:50 -05:00
|
|
|
"Split current window vertically, then focus new window.
|
2021-03-10 15:48:31 +01:00
|
|
|
If `evil-vsplit-window-right' is non-nil, the new window isn't focused."
|
2021-03-06 09:59:50 -05:00
|
|
|
(interactive)
|
2021-03-10 15:48:31 +01:00
|
|
|
(let ((evil-vsplit-window-right (not evil-vsplit-window-right)))
|
2021-03-06 09:59:50 -05:00
|
|
|
(call-interactively #'evil-window-vsplit)))
|
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
;;;###autoload (autoload '+evil:apply-macro "editor/evil/autoload/evil" nil t)
|
2018-03-24 07:24:22 -04:00
|
|
|
(evil-define-operator +evil:apply-macro (beg end)
|
2017-02-03 19:24:04 -05:00
|
|
|
"Apply macro to each line."
|
2018-03-24 07:24:22 -04:00
|
|
|
:move-point nil
|
|
|
|
(interactive "<r>")
|
|
|
|
(let ((register (or evil-this-register (read-char)))
|
|
|
|
macro)
|
|
|
|
(cond ((or (and (eq register ?@) (eq evil-last-register ?:))
|
|
|
|
(eq register ?:))
|
|
|
|
(setq macro (lambda () (evil-ex-repeat nil))
|
|
|
|
evil-last-register ?:))
|
|
|
|
((eq register ?@)
|
|
|
|
(unless evil-last-register
|
|
|
|
(user-error "No previously executed keyboard macro."))
|
|
|
|
(setq macro (evil-get-register evil-last-register t)))
|
|
|
|
((setq macro (evil-get-register register t)
|
|
|
|
evil-last-register register)))
|
2018-10-18 19:41:29 -04:00
|
|
|
(unless macro
|
|
|
|
(user-error "No macro recorded in %c register" register))
|
2018-03-24 07:24:22 -04:00
|
|
|
(evil-change-state 'normal)
|
|
|
|
(evil-with-single-undo
|
2018-10-18 19:41:29 -04:00
|
|
|
(let ((lines (count-lines beg end)))
|
|
|
|
(message "Applied macro in %c register %d times" register lines)
|
|
|
|
(apply-macro-to-region-lines beg end macro)
|
|
|
|
(message "Applied macro in %c register %d times...DONE" register lines)))))
|
2017-02-19 18:14:46 -05:00
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
;;;###autoload (autoload '+evil:retab "editor/evil/autoload/evil" nil t)
|
2017-05-15 13:52:22 +02:00
|
|
|
(evil-define-operator +evil:retab (&optional beg end)
|
|
|
|
"Wrapper around `doom/retab'."
|
|
|
|
:motion nil :move-point nil :type line
|
|
|
|
(interactive "<r>")
|
2021-02-02 02:38:12 +01:00
|
|
|
(doom/retab nil beg end))
|
2017-05-15 13:52:22 +02:00
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
;;;###autoload (autoload '+evil:narrow-buffer "editor/evil/autoload/evil" nil t)
|
2018-10-03 11:14:08 -04:00
|
|
|
(evil-define-operator +evil:narrow-buffer (beg end &optional bang)
|
2019-09-14 18:32:14 -04:00
|
|
|
"Narrow the buffer to region between BEG and END.
|
|
|
|
|
|
|
|
Widens narrowed buffers first. If BANG, use indirect buffer clones instead."
|
2017-05-15 13:52:22 +02:00
|
|
|
:move-point nil
|
|
|
|
(interactive "<r><!>")
|
2019-09-14 18:32:14 -04:00
|
|
|
(if (not bang)
|
|
|
|
(if (buffer-narrowed-p)
|
|
|
|
(widen)
|
|
|
|
(narrow-to-region beg end))
|
|
|
|
(when (buffer-narrowed-p)
|
|
|
|
(doom/widen-indirectly-narrowed-buffer t))
|
2019-09-14 01:56:38 -04:00
|
|
|
(doom/narrow-buffer-indirectly beg end)))
|
2017-05-15 13:52:22 +02:00
|
|
|
|
2019-10-10 12:32:33 -04:00
|
|
|
;;;###autoload (autoload '+evil:yank-unindented "editor/evil/autoload/evil" nil t)
|
2019-11-23 00:52:36 -05:00
|
|
|
(evil-define-operator +evil:yank-unindented (beg end _type _register _yank-handler)
|
2019-10-10 12:32:33 -04:00
|
|
|
"Saves the (reindented) characters in motion into the kill-ring."
|
|
|
|
:move-point nil
|
|
|
|
:repeat nil
|
|
|
|
(interactive "<R><x><y>")
|
|
|
|
(let ((indent (save-excursion (goto-char beg) (current-indentation)))
|
|
|
|
(text (buffer-substring beg end)))
|
|
|
|
(with-temp-buffer
|
|
|
|
(insert text)
|
|
|
|
(indent-rigidly (point-min) (point-max) (- indent))
|
|
|
|
(evil-yank (point-min) (point-max)))))
|
|
|
|
|
2017-05-15 13:52:22 +02:00
|
|
|
|
2019-03-02 01:56:32 -05:00
|
|
|
;;
|
|
|
|
;;; wgrep
|
2017-05-17 18:24:16 +02:00
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
;;;###autoload (autoload '+evil-delete "editor/evil/autoload/evil" nil t)
|
2017-05-17 18:24:16 +02:00
|
|
|
(evil-define-operator +evil-delete (beg end type register yank-handler)
|
|
|
|
"A wrapper around `evil-delete' for `wgrep' buffers that will invoke
|
|
|
|
`wgrep-mark-deletion' on lines you try to delete."
|
|
|
|
(interactive "<R><x><y>")
|
2017-06-08 11:47:56 +02:00
|
|
|
(condition-case _ex
|
2017-05-17 18:24:16 +02:00
|
|
|
(evil-delete beg end type register yank-handler)
|
|
|
|
('text-read-only
|
|
|
|
(evil-apply-on-block
|
|
|
|
(lambda (beg _)
|
|
|
|
(goto-char beg)
|
|
|
|
(call-interactively #'wgrep-mark-deletion))
|
|
|
|
beg (1- end) nil))))
|