diff options
| author | Tom Dalziel <tom_dl@hotmail.com> | 2023-06-06 22:23:01 +0100 |
|---|---|---|
| committer | Tom Dalziel <33435574+tomdl89@users.noreply.github.com> | 2023-06-06 23:41:29 +0200 |
| commit | 55446ec083bfec20733230e4c4365ae9cf43d3ae (patch) | |
| tree | 275053818417b778669dfff00e0aa6b6dc1b6b98 /evil-commands.el | |
| parent | fed81edfbac65b45de8831782ef9c6e76b61fcdc (diff) | |
Add ex-match
Diffstat (limited to 'evil-commands.el')
| -rw-r--r-- | evil-commands.el | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/evil-commands.el b/evil-commands.el index ee63979..ab4ad2c 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -1993,7 +1993,7 @@ mark | first line | last line | new cursor line . | ½ scr (or ½ count) back | ½ scr (or ½ count) forward | last line = | ½ scr (or ½ count) back | ½ scr (or ½ count) forward | current line -Specifying no mark at all is the same as +. +Specifying no mark at all is the same as `+'. If the mark is `=' a line of dashes is printed around the current line. If a `#' is included before the mark args, the lines are numbered." ;; TODO implement bang argument. @@ -4215,6 +4215,35 @@ This is the same as :%s//~/&" (apply #'evil-ex-substitute (point-min) (point-max) (evil-ex-get-substitute-info (concat "//~/&")))) +(evil-define-command evil-ex-match (args &optional bang) + "Define a pattern to highlight in the current buffer. +With no args, clear a highlight from the buffer +With only an ! argument, clear all highlights from the buffer. +With one arg, interpret as the pattern, and prompt for a face. +With two args, interpret as :match {face} /{pattern}/. +Unlike vim, multiple highlights can be set at once, so there is no need for +`:2match' and `:3match' ex commands." + (interactive "<a><!>") + (save-match-data + (string-match " *\\([^ ]*\\) *\\(.*\\)" (or args "")) + (cl-destructuring-bind (_ _ fs fe ss se) (match-data) + (let* ((face (unless (= fs fe) (substring args fs fe))) + (search-string (unless (= ss se) (substring args ss se))) + (patterns (evil-delimited-arguments (or search-string face ""))) + (pattern (if (and (car patterns) evil-ex-search-vim-style-regexp) + (evil-transform-vim-style-regexp (car patterns)) + (car patterns)))) + (cond + ((or (not face) (string= "none" face)) + (if bang + (hi-lock-unface-buffer t) + (call-interactively #'hi-lock-unface-buffer))) + ((/= 1 (length patterns)) + (user-error "Invalid pattern argument supplied")) + ((not search-string) + (hi-lock-face-buffer pattern (hi-lock-read-face-name))) + (t (hi-lock-face-buffer pattern face))))))) + (defun evil-keep-lines (pattern beg end) "Stripped down version of `keep-lines'. Delete lines between BEG & END which don't match PATTERN." |
