diff options
| author | Frank Fischer <frank-fischer@shadow-soft.de> | 2016-06-08 11:29:06 +0200 |
|---|---|---|
| committer | Frank Fischer <frank-fischer@shadow-soft.de> | 2016-06-08 11:29:06 +0200 |
| commit | 44541938764235edbbadf79664079c40c3f0f4b4 (patch) | |
| tree | f5e2daa3277ed3390824f290a0c242ea2a9621dd | |
| parent | 7503291d63ed6c95fb11aecd98237cb95d597592 (diff) | |
| parent | ccf2aa0996c755507b7a727dcc5c5d9ecd90efb8 (diff) | |
Merge PR #64
| -rw-r--r-- | evil-commands.el | 33 | ||||
| -rw-r--r-- | evil-states.el | 38 | ||||
| -rw-r--r-- | evil-vars.el | 4 |
3 files changed, 43 insertions, 32 deletions
diff --git a/evil-commands.el b/evil-commands.el index e40082f..b256763 100644 --- a/evil-commands.el +++ b/evil-commands.el @@ -2199,34 +2199,6 @@ switch to insert state." (unless (evil-visual-state-p) (evil-insert count))) -(defun evil-maybe-remove-spaces () - "Remove space from newly opened empty line. -This function should be called from `post-command-hook' after -`evil-open-above' or `evil-open-below'. If the last command -finished insert state and if the current line consists of -whitespaces only, then those spaces have been inserted because of -the indentation. In this case those spaces are removed leaving a -completely empty line." - (cond - ((memq this-command - '(evil-open-above - evil-open-below - evil-append - evil-append-line - newline - newline-and-indent - indent-and-newline))) - ((not (evil-insert-state-p)) - (when (save-excursion - (beginning-of-line) - (looking-at "^\\s-*$")) - (delete-region (line-beginning-position) - (line-end-position))) - (unless (evil-insert-state-p) - (remove-hook 'post-command-hook #'evil-maybe-remove-spaces))) - (t - (remove-hook 'post-command-hook #'evil-maybe-remove-spaces)))) - (defun evil-open-above (count) "Insert a new line above point and switch to Insert state. The insertion will be repeated COUNT times." @@ -2238,7 +2210,6 @@ The insertion will be repeated COUNT times." evil-insert-lines t evil-insert-vcount nil) (evil-insert-state 1) - (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (when evil-auto-indent (indent-according-to-mode))) @@ -2254,7 +2225,6 @@ The insertion will be repeated COUNT times." evil-insert-lines t evil-insert-vcount nil) (evil-insert-state 1) - (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (when evil-auto-indent (indent-according-to-mode))) @@ -2292,8 +2262,7 @@ next VCOUNT - 1 lines below the current one." (list (line-number-at-pos) #'end-of-line vcount))) - (evil-insert-state 1) - (add-hook 'post-command-hook #'evil-maybe-remove-spaces)) + (evil-insert-state 1)) (evil-define-command evil-insert-digraph (count) "Insert COUNT digraphs." diff --git a/evil-states.el b/evil-states.el index 522cb16..fdb285e 100644 --- a/evil-states.el +++ b/evil-states.el @@ -71,6 +71,40 @@ If the region is activated, enter Visual state." ;;; Insert state +(defun evil-maybe-remove-spaces (&optional do-remove) + "Remove space from newly opened empty line. +This function removes (indentation) spaces that have been +inserted by opening a new empty line. The behavior depends on the +variable `evil-maybe-remove-spaces'. If this variable is nil the +function does nothing. Otherwise the behavior depends on +DO-REMOVE. If DO-REMOVE is non-nil the spaces are +removed. Otherwise `evil-maybe-remove-spaces' is set to nil +unless the last command opened yet another new line. + +This function should be added as a post-command-hook to track +commands opening a new line." + (cond + ((not evil-maybe-remove-spaces) + (remove-hook 'post-command-hook #'evil-maybe-remove-spaces)) + (do-remove + (when (save-excursion + (beginning-of-line) + (looking-at "^\\s-*$")) + (delete-region (line-beginning-position) + (line-end-position))) + (setq evil-maybe-remove-spaces nil) + (remove-hook 'post-command-hook #'evil-maybe-remove-spaces)) + ((not (memq this-command + '(evil-open-above + evil-open-below + evil-append + evil-append-line + newline + newline-and-indent + indent-and-newline))) + (setq evil-maybe-remove-spaces nil) + (remove-hook 'post-command-hook #'evil-maybe-remove-spaces)))) + (evil-define-state insert "Insert state." :tag " <I> " @@ -81,11 +115,15 @@ If the region is activated, enter Visual state." :input-method t (cond ((evil-insert-state-p) + (add-hook 'post-command-hook #'evil-maybe-remove-spaces) (add-hook 'pre-command-hook #'evil-insert-repeat-hook) + (setq evil-maybe-remove-spaces t) (unless (eq evil-want-fine-undo t) (evil-start-undo-step))) (t + (remove-hook 'post-command-hook #'evil-maybe-remove-spaces) (remove-hook 'pre-command-hook #'evil-insert-repeat-hook) + (evil-maybe-remove-spaces t) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker ?^ nil t) (unless (eq evil-want-fine-undo t) diff --git a/evil-vars.el b/evil-vars.el index 17e81e3..740785c 100644 --- a/evil-vars.el +++ b/evil-vars.el @@ -1415,6 +1415,10 @@ has been repeated.") (defvar evil-repeat-count nil "The explicit count when repeating a command.") +(defvar evil-maybe-remove-spaces nil + "Flag to determine if newly inserted spaces should be removed. +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.") |
