emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/evil 55446ec083: Add ex-match


From: ELPA Syncer
Subject: [nongnu] elpa/evil 55446ec083: Add ex-match
Date: Tue, 6 Jun 2023 19:01:57 -0400 (EDT)

branch: elpa/evil
commit 55446ec083bfec20733230e4c4365ae9cf43d3ae
Author: Tom Dalziel <tom_dl@hotmail.com>
Commit: Tom Dalziel <33435574+tomdl89@users.noreply.github.com>

    Add ex-match
---
 evil-commands.el | 31 ++++++++++++++++++++++++++++++-
 evil-maps.el     |  1 +
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/evil-commands.el b/evil-commands.el
index ee63979494..ab4ad2cf37 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."
diff --git a/evil-maps.el b/evil-maps.el
index 34fddd84cb..81b2790b48 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -552,6 +552,7 @@ included in `evil-insert-state-bindings' by default."
 (evil-ex-define-cmd "&&" 'evil-ex-repeat-substitute-with-flags)
 (evil-ex-define-cmd "~" 'evil-ex-repeat-substitute-with-search)
 (evil-ex-define-cmd "~&" 'evil-ex-repeat-substitute-with-search-and-flags)
+(evil-ex-define-cmd "mat[ch]" 'evil-ex-match)
 (evil-ex-define-cmd "registers" 'evil-show-registers)
 (evil-ex-define-cmd "di[splay]" "registers")
 (evil-ex-define-cmd "ma[rk]" 'evil-set-col-0-mark)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]