Refactor <//> & <//g> ex-arg types & :global
This commit is contained in:
parent
8af009f9b7
commit
76493bd8fc
4 changed files with 44 additions and 40 deletions
|
@ -10,7 +10,7 @@
|
|||
(message "evil-mc paused")
|
||||
(message "evil-mc resumed")))
|
||||
|
||||
;;;###autoload (autoload '+evil/mc-make-cursor-here "feature/evil/autoload/evil-mc" nil nil)
|
||||
;;;###autoload (autoload '+evil/mc-make-cursor-here "feature/evil/autoload/evil-mc" nil t)
|
||||
(evil-define-command +evil/mc-make-cursor-here ()
|
||||
"Create a cursor at point. If in visual block or line mode, then create
|
||||
cursors in column beneath+above the point on each line. Otherwise pauses
|
||||
|
@ -45,15 +45,15 @@ cursors."
|
|||
;; I assume I don't want the cursors to move yet
|
||||
(evil-mc-make-cursor-here))))
|
||||
|
||||
;;;###autoload (autoload '+evil:mc "feature/evil/autoload/evil-mc" nil nil)
|
||||
;;;###autoload (autoload '+evil:mc "feature/evil/autoload/evil-mc" nil t)
|
||||
(evil-define-command +evil:mc (beg end type pattern &optional bang)
|
||||
"Create mc cursors at each match of PATTERN within BEG and END, and leave the
|
||||
cursor at the final match. If BANG, then surround PATTERN with whole-word
|
||||
boundaries."
|
||||
cursor at the final match. If BANG, then treat PATTERN as literal."
|
||||
:move-point nil
|
||||
:evil-mc t
|
||||
(interactive "<R><a><!>")
|
||||
(setq evil-mc-pattern (cons (evil-mc-make-pattern pattern bang)
|
||||
(interactive "<R><//g><!>")
|
||||
(require 'evil-mc)
|
||||
(setq evil-mc-pattern (cons (evil-mc-make-pattern (if bang (regexp-quote pattern) pattern) nil)
|
||||
(list beg end type)))
|
||||
(save-excursion
|
||||
(evil-with-restriction beg end
|
||||
|
|
|
@ -171,8 +171,6 @@ evil-window-move-* (e.g. `evil-window-move-far-left')"
|
|||
|
||||
;; --- custom arg handlers ----------------
|
||||
|
||||
(defvar +evil--buffer-match-global evil-ex-substitute-global "")
|
||||
|
||||
(defun +evil--ex-match-init (name &optional face update-hook)
|
||||
(with-current-buffer evil-ex-current-buffer
|
||||
(cond
|
||||
|
@ -213,16 +211,35 @@ evil-window-move-* (e.g. `evil-window-move-far-left')"
|
|||
(let ((hl-name 'evil-ex-buffer-match))
|
||||
(with-selected-window (minibuffer-selected-window)
|
||||
(+evil--ex-match-init hl-name)
|
||||
(+evil--ex-buffer-match arg hl-name (list (if +evil--buffer-match-global ?g))))))
|
||||
(+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))
|
||||
(with-selected-window (minibuffer-selected-window)
|
||||
(+evil--ex-match-init hl-name)
|
||||
(let ((result (car-safe (evil-ex-parse-global arg))))
|
||||
(+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))
|
||||
(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 "feature/evil/autoload/evil" nil t)
|
||||
(evil-define-operator +evil:align (beg end pattern &optional bang)
|
||||
"Ex interface to `align-regexp'. Accepts vim-style regexps."
|
||||
(interactive "<r><//><!>")
|
||||
(align-regexp
|
||||
beg end
|
||||
(concat "\\(\\s-*\\)"
|
||||
(if bang
|
||||
(regexp-quote pattern)
|
||||
(evil-transform-vim-style-regexp pattern)))
|
||||
1 1))
|
||||
|
||||
|
||||
;; --- wgrep ------------------------------
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
(dolist (mode '(help-mode debugger-mode))
|
||||
(evil-set-initial-state mode 'normal))
|
||||
|
||||
;; make `try-expand-dabbrev' from `hippie-expand' work in mini-buffer
|
||||
;; make `try-expand-dabbrev' from `hippie-expand' work in minibuffer
|
||||
;; @see `he-dabbrev-beg', so we need re-define syntax for '/'
|
||||
(defun minibuffer-inactive-mode-hook-setup ()
|
||||
(set-syntax-table (let* ((table (make-syntax-table)))
|
||||
|
@ -120,41 +120,27 @@ across windows."
|
|||
(advice-add #'evil-ex-replace-special-filenames
|
||||
:override #'+evil*ex-replace-special-filenames)
|
||||
|
||||
;; By default :g[lobal] doesn't highlight matches in the current buffer. I've
|
||||
;; got to write my own argument type and interactive code to get it to do so.
|
||||
;; While I'm at it, I use this to write an :al[ign] command as a wrapper
|
||||
;; around `align-regexp'.
|
||||
|
||||
;; TODO Must be simpler way to do this
|
||||
;; These arg types will highlight matches in the current buffer
|
||||
(evil-ex-define-argument-type buffer-match :runner +evil-ex-buffer-match)
|
||||
(evil-ex-define-argument-type global-match :runner +evil-ex-global-match)
|
||||
|
||||
;; By default :g[lobal] doesn't highlight matches in the current buffer. I've
|
||||
;; got to write my own argument type and interactive code to get it to do so.
|
||||
(evil-ex-define-argument-type global-delim-match :runner +evil-ex-global-delim-match)
|
||||
|
||||
(dolist (sym '(evil-ex-global evil-ex-global-inverted))
|
||||
(evil-set-command-property sym :ex-arg 'global-delim-match))
|
||||
|
||||
;; Other commands can make use of this
|
||||
(evil-define-interactive-code "<//>"
|
||||
:ex-arg buffer-match (list (when (evil-ex-p) evil-ex-argument)))
|
||||
(evil-define-interactive-code "<g//>"
|
||||
:ex-arg global-match (when (evil-ex-p) (evil-ex-parse-global evil-ex-argument)))
|
||||
(evil-define-interactive-code "<//g>"
|
||||
:ex-arg global-match (list (when (evil-ex-p) evil-ex-argument)))
|
||||
|
||||
(evil-define-operator +evil:global (beg end pattern command &optional invert)
|
||||
"Rewritten :g[lobal] that will highlight buffer matches. Takes the same arguments."
|
||||
:motion mark-whole-buffer :move-point nil
|
||||
(interactive "<r><g//><!>")
|
||||
(evil-ex-global beg end pattern command invert))
|
||||
|
||||
(evil-define-operator +evil:align (&optional beg end bang pattern)
|
||||
"Ex interface to `align-regexp'. Accepts vim-style regexps."
|
||||
(interactive "<r><!><//>")
|
||||
(align-regexp
|
||||
beg end
|
||||
(concat "\\(\\s-*\\)"
|
||||
(if bang
|
||||
(regexp-quote pattern)
|
||||
(evil-transform-vim-style-regexp pattern)))
|
||||
1 1))
|
||||
|
||||
;; Must be aggressively defined here, otherwise the above highlighting won't
|
||||
;; work on first invocation
|
||||
(evil-ex-define-cmd "g[lobal]" #'+evil:global)
|
||||
(evil-ex-define-cmd "al[ign]" #'+evil:align)
|
||||
(evil-set-command-properties
|
||||
'+evil:align :move-point t :ex-arg 'buffer-match :ex-bang t :evil-mc t :keep-visual t :suppress-operator t)
|
||||
(evil-set-command-properties
|
||||
'+evil:mc :move-point nil :ex-arg 'global-match :ex-bang t :evil-mc t)
|
||||
|
||||
;; Move to new split -- setting `evil-split-window-below' &
|
||||
;; `evil-vsplit-window-right' to non-nil mimics this, but that doesn't update
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue