From 1a4bc20f158aa9f4e4811a6363cc65ea24f167ce Mon Sep 17 00:00:00 2001 From: tam5 Date: Sat, 15 Dec 2018 21:38:29 -0500 Subject: add csw, csW, css and csp shortcuts --- evil-surround.el | 10 +++++++++- test/evil-surround-test.el | 12 ++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/evil-surround.el b/evil-surround.el index 854c42f..383c0fd 100644 --- a/evil-surround.el +++ b/evil-surround.el @@ -137,6 +137,13 @@ Each item is of the form (OPERATOR . OPERATION)." "Returns whether CHAR is a valid surround char or not." (not (memq char '(?\C-\[ ?\C-?)))) +(defun evil-surround-delete-char-noop-p (char) + "Returns whether CHAR is a noop when used with surround delete." + (memq char (list (string-to-char "w") + (string-to-char "W") + (string-to-char "s") + (string-to-char "p")))) + (defun evil-surround-pair (char) "Return the evil-surround pair of char. This is a cons cell (LEFT . RIGHT), both strings." @@ -232,7 +239,8 @@ overlays OUTER and INNER, which are passed to `evil-surround-delete'." (interactive (evil-surround-input-char)) (cond ((and outer inner) - (evil-surround-delete char outer inner) + (unless (evil-surround-delete-char-noop-p char) + (evil-surround-delete char outer inner)) (let ((key (evil-surround-read-char))) (evil-surround-region (overlay-start outer) (overlay-end outer) diff --git a/test/evil-surround-test.el b/test/evil-surround-test.el index df8a03f..df71b11 100644 --- a/test/evil-surround-test.el +++ b/test/evil-surround-test.el @@ -37,6 +37,18 @@ "one 'two' three" ("ds'") "one two three")) + (ert-info ("shortcut surrounding") + (evil-test-buffer + "One, and two. Also three.\n\n" + (turn-on-evil-surround-mode) + ("csw)") + "(One), and two. Also three.\n\n" + ("csW'") + "'(One),' and two. Also three.\n\n" + ("css.") + ".'(One),' and two. Also three..\n\n" + ("csp0") + "0.'(One),' and two. Also three..0\n\n")) (ert-info ("examples from readme") (evil-test-buffer :visual-start nil -- cgit v1.0