summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeni Kolev <evgenysw@gmail.com>2017-10-03 08:55:14 +0300
committerFilipe Silva <ninrod@users.noreply.github.com>2017-10-04 10:00:39 -0300
commit822a0f61c3fd7c55cda4e04c8590ae5144401c26 (patch)
tree0e71eca1d17f077f1c61bf42667beed8c61edf84
parent853b9fdf117b1de665b02c7b3c978ce2a51f52e7 (diff)
Make `ysw` work like `cw`, not `ce`
-rw-r--r--evil-surround.el14
-rw-r--r--test/evil-surround-test.el31
-rw-r--r--test/make-test.el1
3 files changed, 43 insertions, 3 deletions
diff --git a/evil-surround.el b/evil-surround.el
index bfe6056..5a6db9a 100644
--- a/evil-surround.el
+++ b/evil-surround.el
@@ -44,6 +44,10 @@
:prefix "surround-"
:group 'evil)
+;; make surround's `ysw' work like `cw', not `ce'
+(when (boundp 'evil-change-commands)
+ (add-to-list 'evil-change-commands 'evil-surround-region))
+
(defcustom evil-surround-pairs-alist
'((?\( . ("( " . " )"))
(?\[ . ("[ " . " ]"))
@@ -245,6 +249,12 @@ This is necessary because `evil-yank' operator is not repeatable (:repeat nil)"
(evil-repeat-start)
(evil-repeat-record "y")
(evil-repeat-record (this-command-keys))
+
+ ;; set `this-command-keys' to the command that will be executed
+ ;; interactively; as a result, `evil-this-operator' will be
+ ;; correctly set to, for example, `evil-surround-region' instead of
+ ;; `evil-yank' when surround has been invoked by `ys'
+ (setq this-command callback)
(call-interactively callback)
(evil-repeat-keystrokes 'post)
(evil-repeat-stop))
@@ -309,8 +319,8 @@ Becomes this:
((eq type 'line)
(setq force-new-line
(or force-new-line
- ;; Force newline if not invoked from an operator, e.g. VS)
- (eq evil-this-operator 'evil-surround-region)
+ ;; Force newline if not invoked from an operator, e.g. visual line mode with VS)
+ (evil-visual-state-p)
;; Or on multi-line operator surrounds (like 'ysj]')
(/= (line-number-at-pos) (line-number-at-pos (1- end)))))
diff --git a/test/evil-surround-test.el b/test/evil-surround-test.el
index b0c363f..c2028de 100644
--- a/test/evil-surround-test.el
+++ b/test/evil-surround-test.el
@@ -96,4 +96,33 @@
"111 222 333\n[1]11 222 333\n111 222 333\n111 222 333\n"
(turn-on-evil-surround-mode)
("ysjb")
- "111 222 333\n(\n111 222 333\n111 222 333\n)\n111 222 333\n")))
+ "111 222 333\n(\n111 222 333\n111 222 333\n)\n111 222 333\n"))
+ (ert-info ("test with evil-want-change-word-to-end")
+ (evil-test-buffer
+ "[o]ne two three"
+ (setq evil-want-change-word-to-end nil)
+ (turn-on-evil-surround-mode)
+ ("yswb")
+ "[(]one )two three"
+ ("dsb")
+ "[o]ne two three"
+ ("ys2wb")
+ "[(]one two )three"
+ ("dsb")
+ "[o]ne two three"
+ ("ys3wb")
+ "[(]one two three)")
+ (evil-test-buffer
+ "[o]ne two three"
+ (setq evil-want-change-word-to-end t)
+ (turn-on-evil-surround-mode)
+ ("yswb")
+ "[(]one) two three"
+ ("dsb")
+ "[o]ne two three"
+ ("ys2wb")
+ "[(]one two) three"
+ ("dsb")
+ "[o]ne two three"
+ ("ys3wb")
+ "[(]one two three)")))
diff --git a/test/make-test.el b/test/make-test.el
index fb487b1..1964641 100644
--- a/test/make-test.el
+++ b/test/make-test.el
@@ -1,3 +1,4 @@
+(setq load-prefer-newer t)
(let ((current-directory (file-name-directory load-file-name)))
(setq evil-surround-test-path (expand-file-name "." current-directory))