diff --git a/modules/editor/evil/autoload/evil.el b/modules/editor/evil/autoload/evil.el index 298be82f4..057b680cc 100644 --- a/modules/editor/evil/autoload/evil.el +++ b/modules/editor/evil/autoload/evil.el @@ -13,7 +13,73 @@ ;; -;;; Commands +;;; Custom arg handlers + +(defvar +evil--flag nil) + +(defun +evil--ex-match-init (name &optional face update-hook) + (with-current-buffer evil-ex-current-buffer + (cond + ((eq +evil--flag 'start) + (evil-ex-make-hl name + :face (or face 'evil-ex-substitute-matches) + :update-hook (or update-hook #'evil-ex-pattern-update-ex-info)) + (setq +evil--flag 'update)) + + ((eq +evil--flag 'stop) + (evil-ex-delete-hl name))))) + +(defun +evil--ex-buffer-match (arg &optional hl-name flags beg end) + (when (and (eq +evil--flag 'update) + evil-ex-substitute-highlight-all + (not (zerop (length arg)))) + (condition-case lossage + (let ((pattern (evil-ex-make-substitute-pattern + arg + (or flags (list)))) + (range (or (evil-copy-range evil-ex-range) + (evil-range (or beg (line-beginning-position)) + (or end (line-end-position)) + 'line + :expanded t)))) + (evil-expand-range range) + (evil-ex-hl-set-region hl-name + (max (evil-range-beginning range) (window-start)) + (min (evil-range-end range) (window-end))) + (evil-ex-hl-change hl-name pattern)) + (end-of-file + (evil-ex-pattern-update-ex-info nil "incomplete replacement")) + (user-error + (evil-ex-pattern-update-ex-info nil (format "?%s" lossage)))))) + +;;;###autoload +(defun +evil-ex-buffer-match (flag &optional arg) + (let ((hl-name 'evil-ex-buffer-match) + (+evil--flag flag)) + (with-selected-window (minibuffer-selected-window) + (+evil--ex-match-init hl-name) + (+evil--ex-buffer-match arg hl-name (list (if evil-ex-substitute-global ?g)))))) + +;;;###autoload +(defun +evil-ex-global-match (flag &optional arg) + (let ((hl-name 'evil-ex-global-match) + (+evil--flag flag)) + (with-selected-window (minibuffer-selected-window) + (+evil--ex-match-init hl-name) + (+evil--ex-buffer-match arg hl-name nil (point-min) (point-max))))) + +;;;###autoload +(defun +evil-ex-global-delim-match (flag &optional arg) + (let ((hl-name 'evil-ex-global-delim-match) + (+evil--flag flag)) + (with-selected-window (minibuffer-selected-window) + (+evil--ex-match-init hl-name) + (let ((result (car-safe (evil-delimited-arguments arg 2)))) + (+evil--ex-buffer-match result hl-name nil (point-min) (point-max)))))) + + +;; +;;; Interactive commands ;;;###autoload (defun +evil/visual-indent () @@ -101,9 +167,27 @@ integration." t)) prefix))))) +;;;###autoload (autoload '+evil:align "editor/evil/autoload/evil" nil t) +(evil-define-operator +evil:align (beg end pattern &optional bang) + "Ex interface to `align-regexp'. PATTERN is a vim-style regexp. If BANG, +repeat the alignment for all matches (otherwise just the first match on each +line)." + (interactive "") + (align-regexp + beg end + (concat "\\(\\s-*\\)" (evil-transform-vim-style-regexp pattern)) + 1 1 bang)) -;; -;;; Evil commands/operators +;;;###autoload (autoload '+evil:align-right "editor/evil/autoload/evil" nil t) +(evil-define-operator +evil:align-right (beg end pattern &optional bang) + "Like `+evil:align', except alignments are right-justified. PATTERN is a +vim-style regexp. If BANG, repeat the alignment for all matches (otherwise just +the first match on each line)." + (interactive "") + (align-regexp + beg end + (concat "\\(" (evil-transform-vim-style-regexp pattern) "\\)") + -1 1 bang)) ;;;###autoload (autoload '+evil:apply-macro "editor/evil/autoload/evil" nil t) (evil-define-operator +evil:apply-macro (beg end) @@ -146,94 +230,6 @@ integration." (doom/clone-and-narrow-buffer beg end bang)) -;; -;;; Custom arg handlers - -(defvar +evil--flag nil) - -(defun +evil--ex-match-init (name &optional face update-hook) - (with-current-buffer evil-ex-current-buffer - (cond - ((eq +evil--flag 'start) - (evil-ex-make-hl name - :face (or face 'evil-ex-substitute-matches) - :update-hook (or update-hook #'evil-ex-pattern-update-ex-info)) - (setq +evil--flag 'update)) - - ((eq +evil--flag 'stop) - (evil-ex-delete-hl name))))) - -(defun +evil--ex-buffer-match (arg &optional hl-name flags beg end) - (when (and (eq +evil--flag 'update) - evil-ex-substitute-highlight-all - (not (zerop (length arg)))) - (condition-case lossage - (let ((pattern (evil-ex-make-substitute-pattern - arg - (or flags (list)))) - (range (or (evil-copy-range evil-ex-range) - (evil-range (or beg (line-beginning-position)) - (or end (line-end-position)) - 'line - :expanded t)))) - (evil-expand-range range) - (evil-ex-hl-set-region hl-name - (max (evil-range-beginning range) (window-start)) - (min (evil-range-end range) (window-end))) - (evil-ex-hl-change hl-name pattern)) - (end-of-file - (evil-ex-pattern-update-ex-info nil "incomplete replacement")) - (user-error - (evil-ex-pattern-update-ex-info nil (format "?%s" lossage)))))) - -;;;###autoload -(defun +evil-ex-buffer-match (flag &optional arg) - (let ((hl-name 'evil-ex-buffer-match) - (+evil--flag flag)) - (with-selected-window (minibuffer-selected-window) - (+evil--ex-match-init hl-name) - (+evil--ex-buffer-match arg hl-name (list (if evil-ex-substitute-global ?g)))))) - -;;;###autoload -(defun +evil-ex-global-match (flag &optional arg) - (let ((hl-name 'evil-ex-global-match) - (+evil--flag flag)) - (with-selected-window (minibuffer-selected-window) - (+evil--ex-match-init hl-name) - (+evil--ex-buffer-match arg hl-name nil (point-min) (point-max))))) - -;;;###autoload -(defun +evil-ex-global-delim-match (flag &optional arg) - (let ((hl-name 'evil-ex-global-delim-match) - (+evil--flag flag)) - (with-selected-window (minibuffer-selected-window) - (+evil--ex-match-init hl-name) - (let ((result (car-safe (evil-delimited-arguments arg 2)))) - (+evil--ex-buffer-match result hl-name nil (point-min) (point-max)))))) - -;;;###autoload (autoload '+evil:align "editor/evil/autoload/evil" nil t) -(evil-define-operator +evil:align (beg end pattern &optional bang) - "Ex interface to `align-regexp'. PATTERN is a vim-style regexp. If BANG, -repeat the alignment for all matches (otherwise just the first match on each -line)." - (interactive "") - (align-regexp - beg end - (concat "\\(\\s-*\\)" (evil-transform-vim-style-regexp pattern)) - 1 1 bang)) - -;;;###autoload (autoload '+evil:align-right "editor/evil/autoload/evil" nil t) -(evil-define-operator +evil:align-right (beg end pattern &optional bang) - "Like `+evil:align', except alignments are right-justified. PATTERN is a -vim-style regexp. If BANG, repeat the alignment for all matches (otherwise just -the first match on each line)." - (interactive "") - (align-regexp - beg end - (concat "\\(" (evil-transform-vim-style-regexp pattern) "\\)") - -1 1 bang)) - - ;; ;;; wgrep