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

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

[nongnu] elpa/evil b644a0f 2/7: Replace state evil-quoted-insert


From: ELPA Syncer
Subject: [nongnu] elpa/evil b644a0f 2/7: Replace state evil-quoted-insert
Date: Sun, 19 Dec 2021 12:57:43 -0500 (EST)

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

    Replace state evil-quoted-insert
---
 evil-commands.el | 26 ++++++++++++++++++++++++++
 evil-maps.el     |  3 ++-
 evil-tests.el    | 28 ++++++++++++++++++++++++++++
 3 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/evil-commands.el b/evil-commands.el
index 9c9075e..79f23da 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -2573,6 +2573,32 @@ switch to insert state."
   (unless (evil-visual-state-p)
     (evil-insert count)))
 
+(defun evil-quoted-insert (count)
+  "Like `quoted-insert' but delete COUNT chars forward in replace state.
+Adds a `^' overlay as an input prompt."
+  (interactive "p")
+  (let* ((cnt (or count 1))
+         (pnt (point))
+         (chars-to-delete (min (- (point-at-eol) pnt) cnt))
+         (insert-prompt (make-overlay pnt (+ chars-to-delete pnt))))
+    (unwind-protect
+        (progn
+          (when (evil-replace-state-p)
+            (dotimes (c cnt)
+              (let ((pos (+ c pnt)))
+                (add-to-list 'evil-replace-alist
+                             (cons pos (when (< c chars-to-delete)
+                                         (char-after pos))))))
+            (overlay-put insert-prompt 'invisible t))
+          ;; The nature of the insert cursor means it has to be after
+          ;; the prompt rather than before (unlike vim).
+          (overlay-put insert-prompt
+                       'before-string (propertize "^" 'face 'escape-glyph))
+          (let (overwrite-mode) ;; Force `read-quoted-char'
+            (quoted-insert cnt))
+          (when (evil-replace-state-p) (delete-char chars-to-delete)))
+      (delete-overlay insert-prompt))))
+
 (defun evil-open-above (count)
   "Insert a new line above point and switch to Insert state.
 The insertion will be repeated COUNT times."
diff --git a/evil-maps.el b/evil-maps.el
index 65fd51f..482f2f4 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -379,7 +379,8 @@
 
 (defvar evil-insert-state-bindings
   `(([insert] . evil-replace-state)
-    ("\C-v" . quoted-insert)
+    ("\C-q" . evil-quoted-insert)
+    ("\C-v" . evil-quoted-insert)
     ("\C-k" . evil-insert-digraph)
     ("\C-o" . evil-execute-in-normal-state)
     ("\C-r" . evil-paste-from-register)
diff --git a/evil-tests.el b/evil-tests.el
index 4827486..03c20c4 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -987,6 +987,34 @@ This buffer is for notes")))
     ("^")
     "xxxline 1\nline 2\nyyyline 3\n[x]xxline 4"))
 
+(ert-deftest evil-test-quoted-insert ()
+  "Test evil-quoted-insert in replace state."
+  (ert-info ("Simple replace C-v")
+    (evil-test-buffer
+      "ab[c]defg"
+      ("R\C-vx")
+      "abx[d]efg"))
+  (ert-info ("Control char replace C-v")
+    (evil-test-buffer
+      "ab[c]defg"
+      ("R\C-v\C-g")
+      "ab[d]efg"))
+  (ert-info ("C-v with count")
+    (evil-test-buffer
+      "ab[c]defg"
+      ("R\C-u3\C-vx")
+      "abxxx[f]g"))
+  (ert-info ("C-v with count near eol")
+    (evil-test-buffer
+      "abcde[f]g"
+      ("R\C-u3\C-vx")
+      "abcdexxx[]"))
+  (ert-info ("C-v in replace can be backspaced")
+    (evil-test-buffer
+      "ab[c]defg"
+      ("R\C-u3\C-vx" [backspace])
+      "abxx[e]fg")))
+
 (ert-deftest evil-test-repeat-quoted-insert ()
   "Test whether `quoted-insert' can be repeated."
   (ert-info ("Insert C-v")



reply via email to

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