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

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

[nongnu] elpa/evil 477fe8e83e 1/2: Add `evil-enter-replace-state` & supp


From: ELPA Syncer
Subject: [nongnu] elpa/evil 477fe8e83e 1/2: Add `evil-enter-replace-state` & support replace repetition
Date: Mon, 1 Aug 2022 05:58:23 -0400 (EDT)

branch: elpa/evil
commit 477fe8e83e58739215ea3b601098ee134484114f
Author: Tom Dalziel <tom_dl@hotmail.com>
Commit: Tom Dalziel <tom_dl@hotmail.com>

    Add `evil-enter-replace-state` & support replace repetition
---
 evil-commands.el | 10 ++++++++++
 evil-common.el   | 39 ++++++++++++++++++++-------------------
 evil-maps.el     |  4 ++--
 evil-states.el   |  8 +++++++-
 evil-vars.el     |  2 +-
 5 files changed, 40 insertions(+), 23 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 94a43f5b61..916e024003 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -2863,6 +2863,16 @@ COL defaults to the current column."
                                 (min (line-end-position)
                                      (+ n (point))))))))
 
+(defun evil-enter-replace-state (count)
+  "Switch to Replace state at point.
+The insertion will be repeated COUNT times."
+  (interactive "p")
+  (setq evil-insert-count count)
+  (setq evil-insert-count count
+        evil-insert-lines nil
+        evil-insert-vcount nil)
+  (evil-replace-state 1))
+
 ;; completion
 (evil-define-command evil-complete-next (&optional arg)
   "Complete to the nearest following word.
diff --git a/evil-common.el b/evil-common.el
index 5a5a1dc734..e6f2ec954e 100644
--- a/evil-common.el
+++ b/evil-common.el
@@ -2533,29 +2533,30 @@ disjoint union is not a single range."
       (setq ranges (cdr ranges)))
     range))
 
-(defun evil-track-last-insertion (beg end len)
+(defun evil-track-last-insertion (chg-beg chg-end len)
   "Track the last insertion range and its text.
+CHG-BEG CHG-END & LEN are supplied as for `after-change-functions'.
 The insertion range is stored as a pair of buffer positions in
-`evil-current-insertion'. If a subsequent change is compatible,
+`evil-current-insertion'.  If a subsequent change is compatible,
 then the current range is modified, otherwise it is replaced by a
-new range. Compatible changes are changes that do not create a
+new range.  Compatible changes are changes that do not create a
 disjoin range."
-  ;; deletion
-  (when (> len 0)
-    (if (and evil-current-insertion
-             (>= beg (car evil-current-insertion))
-             (<= (+ beg len) (cdr evil-current-insertion)))
-        (setcdr evil-current-insertion
-                (- (cdr evil-current-insertion) len))
-      (setq evil-current-insertion nil)))
-  ;; insertion
-  (if (and evil-current-insertion
-           (>= beg (car evil-current-insertion))
-           (<= beg (cdr evil-current-insertion)))
-      (setcdr evil-current-insertion
-              (+ (- end beg)
-                 (cdr evil-current-insertion)))
-    (setq evil-current-insertion (cons beg end))))
+  (let* ((ins-beg (car evil-current-insertion))
+         (ins-end (cdr evil-current-insertion))
+         (chg-beg-ok (and evil-current-insertion (<= ins-beg chg-beg))))
+    (cond
+     ;; Replace-state deletion - ignore
+     ((and (< 0 (- chg-end chg-beg)) (= 0 len) (evil-replace-state-p)) nil)
+     ;; Insert-state deletion - contract current insertion
+     ((= 0 (- chg-end chg-beg))
+      (if (and chg-beg-ok (<= (+ chg-beg len) ins-end))
+          (setcdr evil-current-insertion (- ins-end len))
+        (setq evil-current-insertion nil)))
+     ;; Insert- or Replace-state insertion - expand current insertion
+     (t
+      (if (and chg-beg-ok (<= chg-beg ins-end))
+          (setcdr evil-current-insertion (+ ins-end (- chg-end chg-beg)))
+        (setq evil-current-insertion (cons chg-beg chg-end)))))))
 (put 'evil-track-last-insertion 'permanent-local-hook t)
 
 (defun evil-start-track-last-insertion ()
diff --git a/evil-maps.el b/evil-maps.el
index 2166d9ad9a..36c530e27f 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -53,7 +53,7 @@
 (define-key evil-normal-state-map "P" 'evil-paste-before)
 (define-key evil-normal-state-map "q" 'evil-record-macro)
 (define-key evil-normal-state-map "r" 'evil-replace)
-(define-key evil-normal-state-map "R" 'evil-replace-state)
+(define-key evil-normal-state-map "R" 'evil-enter-replace-state)
 (define-key evil-normal-state-map "s" 'evil-substitute)
 (define-key evil-normal-state-map "S" 'evil-change-whole-line)
 (define-key evil-normal-state-map "x" 'evil-delete-char)
@@ -383,7 +383,7 @@
 ;;; Insert state
 
 (defvar evil-insert-state-bindings
-  `(([insert] . evil-replace-state)
+  `(([insert] . evil-enter-replace-state)
     ("\C-q" . evil-quoted-insert)
     ("\C-v" . evil-quoted-insert)
     ("\C-k" . evil-insert-digraph)
diff --git a/evil-states.el b/evil-states.el
index a2e0e6e675..9615bf2cce 100644
--- a/evil-states.el
+++ b/evil-states.el
@@ -141,7 +141,7 @@ commands opening a new line."
 (put 'evil-insert-repeat-hook 'permanent-local-hook t)
 
 (defun evil-cleanup-insert-state ()
-  "Called when Insert state is about to be exited.
+  "Called when Insert or Replace state is about to be exited.
 Handles the repeat-count of the insertion command."
   (when evil-insert-count
     (dotimes (_ (1- evil-insert-count))
@@ -868,16 +868,22 @@ CORNER defaults to `upper-left'."
   :tag " <R> "
   :cursor hbar
   :message "-- REPLACE --"
+  :entry-hook (evil-start-track-last-insertion)
+  :exit-hook (evil-cleanup-insert-state evil-stop-track-last-insertion)
   :input-method t
   (cond
    ((evil-replace-state-p)
     (overwrite-mode 1)
     (add-hook 'pre-command-hook #'evil-replace-pre-command nil t)
+    (add-hook 'pre-command-hook #'evil-insert-repeat-hook)
     (unless (eq evil-want-fine-undo t)
       (evil-start-undo-step)))
    (t
     (overwrite-mode -1)
     (remove-hook 'pre-command-hook #'evil-replace-pre-command t)
+    (remove-hook 'pre-command-hook #'evil-insert-repeat-hook)
+    (setq evil-insert-repeat-info evil-repeat-info)
+    (evil-set-marker ?^ nil t)
     (unless (eq evil-want-fine-undo t)
       (evil-end-undo-step))
     (evil-move-cursor-back)))
diff --git a/evil-vars.el b/evil-vars.el
index b24004f6f1..251652b9d2 100644
--- a/evil-vars.el
+++ b/evil-vars.el
@@ -1588,7 +1588,7 @@ has been repeated.")
 See the function `evil-maybe-remove-spaces'.")
 
 (evil-define-local-var evil-insert-count nil
-  "The explicit count passed to an command starting Insert state.")
+  "The explicit count passed to a command starting Insert or Replace state.")
 
 (evil-define-local-var evil-insert-vcount nil
   "The information about the number of following lines the



reply via email to

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