aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYunhao Zhao <yunhaozhaots@gmail.com>2019-06-13 14:07:06 +0800
committerEivind Fonn <evfonn@gmail.com>2019-12-19 10:49:44 +0100
commit33bb8534f6f8d12ae071cb12a38db6306cb07f87 (patch)
tree2fddbd91360cc72bd89f7f951bbcf18028165fc2
parent36d4cfb5919d2b7c6c24478ef62d0820a5590b72 (diff)
Add evil-want-C-u-delete option
-rw-r--r--evil-commands.el15
-rw-r--r--evil-maps.el2
-rw-r--r--evil-tests.el22
-rw-r--r--evil-vars.el16
4 files changed, 55 insertions, 0 deletions
diff --git a/evil-commands.el b/evil-commands.el
index 83fb9f4..045b313 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1493,6 +1493,21 @@ be joined with the previous line if and only if
(line-beginning-position))
(point))))
+(evil-define-command evil-delete-back-to-indentation ()
+ "Delete from the cursor to the first non-whitespace character of the current line.
+If point is before the first non-whitespace character of a current line then
+delete from the point to the beginning of the current line."
+ (if (bolp)
+ (progn
+ (unless evil-backspace-join-lines (user-error "Beginning of line"))
+ (delete-char -1))
+ (delete-region (if (<= (current-column) (current-indentation))
+ (line-beginning-position)
+ (save-excursion
+ (evil-first-non-blank)
+ (point)))
+ (point))))
+
(defun evil-ex-delete-or-yank (should-delete beg end type register count yank-handler)
"Execute evil-delete or evil-yank on the given region.
If SHOULD-DELETE is t, evil-delete will be executed, otherwise
diff --git a/evil-maps.el b/evil-maps.el
index f28385c..2545511 100644
--- a/evil-maps.el
+++ b/evil-maps.el
@@ -379,6 +379,8 @@
,(if evil-want-C-w-delete
'("\C-w" . evil-delete-backward-word)
'("\C-w" . evil-window-map))
+ ,@(when evil-want-C-u-delete
+ '(("\C-u" . evil-delete-back-to-indentation)))
([mouse-2] . mouse-yank-primary))
"Evil's bindings for insert state (for
`evil-insert-state-map'), excluding <delete>, <escape>, and
diff --git a/evil-tests.el b/evil-tests.el
index ed9af7e..503f12e 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -1933,6 +1933,28 @@ ine3 line3 line3 l\n")))
(should-error (execute-kbd-macro (concat "i" (kbd "C-w"))))
"abc def\n[k]l\n")))
+(ert-deftest evil-test-delete-back-to-indentation ()
+ "Test `evil-delete-back-to-indentation' in insert state."
+ :tags '(evil)
+ (let ((evil-backspace-join-lines t))
+ (evil-test-buffer
+ "abc def\n ghi j[k]l\n"
+ ("i" (call-interactively #'evil-delete-back-to-indentation))
+ "abc def\n [k]l\n"
+ (execute-kbd-macro (concat (kbd "C-o") "2h"))
+ "abc def\n [ ] kl\n"
+ (call-interactively #'evil-delete-back-to-indentation)
+ "abc def\n[ ] kl\n"
+ (call-interactively #'evil-delete-back-to-indentation)
+ "abc def[ ] kl\n"))
+ (let (evil-backspace-join-lines)
+ (evil-test-buffer
+ "abc def\n[k]l\n"
+ (should-error
+ (progn (execute-kbd-macro "i")
+ (call-interactively #'evil-delete-back-to-indentation)))
+ "abc def\n[k]l\n")))
+
(ert-deftest evil-test-change ()
"Test `evil-change'"
:tags '(evil operator)
diff --git a/evil-vars.el b/evil-vars.el
index 7a0c794..62e1e2d 100644
--- a/evil-vars.el
+++ b/evil-vars.el
@@ -456,6 +456,22 @@ replicates the default vim behavior."
(not (lookup-key evil-motion-state-map (kbd "C-d"))))
(define-key evil-motion-state-map (kbd "C-d") 'evil-scroll-down))))))
+(defcustom evil-want-C-u-delete nil
+ "Whether \"C-u\" deletes back to indentation in Insert state."
+ :type 'boolean
+ :group 'evil
+ :set #'(lambda (sym value)
+ (set-default sym value)
+ (when (boundp 'evil-insert-state-map)
+ (cond
+ ((and (not value)
+ (eq (lookup-key evil-insert-state-map (kbd "C-u"))
+ 'evil-delete-back-to-indentation))
+ (define-key evil-insert-state-map (kbd "C-u") nil))
+ ((and value
+ (not (lookup-key evil-insert-state-map (kbd "C-u"))))
+ (define-key evil-insert-state-map (kbd "C-u") 'evil-delete-back-to-indentation))))))
+
(defcustom evil-want-C-w-delete t
"Whether \"C-w\" deletes a word in Insert state."
:type 'boolean