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

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

[nongnu] elpa/evil dd13874 4/7: Replace state pasting


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

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

    Replace state pasting
---
 evil-commands.el | 26 +++++++++++++++++---------
 evil-maps.el     |  4 ++--
 evil-states.el   |  9 +++++----
 evil-tests.el    |  9 ++++++++-
 4 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 8306854..e764857 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -2018,7 +2018,7 @@ the current line."
     (evil-shift-left (line-beginning-position) (line-beginning-position 2) 
count t)))
 
 (evil-define-operator evil-align-left (beg end type &optional width)
-  "Right-align lines in the region at WIDTH columns.
+  "Left-align lines in the region at WIDTH columns.
 The default for width is the value of `fill-column'."
   :motion evil-line
   :type line
@@ -2242,18 +2242,26 @@ The return value is the yanked text."
 (defun evil-paste-from-register (register)
   "Paste from REGISTER."
   (interactive
-   (let ((overlay (make-overlay (point) (point)))
-         (string "\""))
+   (let* ((opoint (point))
+          (overlay (make-overlay opoint (+ opoint (if (evil-replace-state-p) 1 
0)))))
      (unwind-protect
          (progn
-           ;; display " in the buffer while reading register
-           (put-text-property 0 1 'face 'minibuffer-prompt string)
-           (put-text-property 0 1 'cursor t string)
-           (overlay-put overlay 'after-string string)
+           (overlay-put overlay 'invisible t)
+           (overlay-put overlay 'after-string (propertize "\""
+                                                          'face 
'minibuffer-prompt
+                                                          'cursor 1))
            (list (or evil-this-register (read-char))))
        (delete-overlay overlay))))
-  (let (evil-move-cursor-back)
-    (evil-paste-before nil register t)))
+  (let ((opoint (point))
+        (evil-move-cursor-back nil)
+        reg-length chars-to-delete)
+    (evil-paste-before nil register t)
+    (when (evil-replace-state-p)
+      (setq reg-length (- (point) opoint)
+            chars-to-delete (min (- (point-at-eol) (point)) reg-length))
+      ;; TODO: handle multi-line paste backspacing
+      (evil-update-replace-alist (point) reg-length chars-to-delete 
chars-to-delete)
+      (delete-char chars-to-delete))))
 
 (defun evil-paste-last-insertion ()
   "Paste last insertion."
diff --git a/evil-maps.el b/evil-maps.el
index 482f2f4..10ee826 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -438,11 +438,11 @@ included in `evil-insert-state-bindings' by default."
 
 ;;; Replace state
 
+(dolist (binding evil-insert-state-bindings)
+  (define-key evil-replace-state-map (car binding) (cdr binding)))
 (define-key evil-replace-state-map (kbd "DEL") 'evil-replace-backspace)
 (define-key evil-replace-state-map [escape] 'evil-normal-state)
 (define-key evil-replace-state-map [insert] 'evil-append)
-(dolist (binding evil-insert-state-bindings)
-  (define-key evil-replace-state-map (car binding) (cdr binding)))
 
 ;;; Emacs state
 
diff --git a/evil-states.el b/evil-states.el
index d9784b5..0e3b9e9 100644
--- a/evil-states.el
+++ b/evil-states.el
@@ -905,15 +905,16 @@ CORNER defaults to `upper-left'."
         (when char
           (insert char))))))
 
-(defun evil-update-replace-alist (opoint count chars-to-delete)
+(defun evil-update-replace-alist (opoint count chars-to-delete &optional 
offset)
   "Add CHARS-TO-DELETE chars to evil-replace-alist, starting at OPOINT.
-If COUNT is greater than CHARS-TO-DELETE, pad the alist with nils."
+If COUNT is greater than CHARS-TO-DELETE, pad the alist with nils.
+Decrement recorded position by optional offset, or 0."
   (when (evil-replace-state-p)
     (dotimes (c count)
       (let ((pos (+ c opoint)))
         (add-to-list 'evil-replace-alist
-                     (cons pos (when (< c chars-to-delete)
-                                 (char-after pos))))))))
+                     (cons (- pos (or offset 0)) (when (< c chars-to-delete)
+                                                   (char-after pos))))))))
 
 ;;; Motion state
 
diff --git a/evil-tests.el b/evil-tests.el
index a0928ce..c17c97c 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -2987,7 +2987,14 @@ word3[]"))
     (evil-test-buffer
       "[a]lpha beta"
       ("\"ayiw" "w" "\"bciw" "\C-ra")
-      "alpha alpha[]")))
+      "alpha alpha[]"))
+  (ert-info ("Paste from register in replace state")
+    (evil-test-buffer
+      "[a]lpha bravo charlie"
+      ("yiw" "w" "R" "\C-r0")
+      "alpha alpha[ ]charlie"
+      ([backspace] [backspace] [backspace])
+      "alpha al[a]vo charlie")))
 
 (ert-deftest evil-test-last-insert-register ()
   "Test last insertion register."



reply via email to

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